F_HR_0901.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0901.cs
  5. * 2.功能描述:员工报餐
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/10/6 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.Basics.Library;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. using Dongke.IBOSS.PRD.WCF.Proxys.CommonModuleService;
  22. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  23. namespace Dongke.IBOSS.PRD.Client.HRModule
  24. {
  25. /// <summary>
  26. /// 员工报餐
  27. /// </summary>
  28. public partial class F_HR_0901 : DockPanelBase
  29. {
  30. #region 成员变量
  31. // 单例模式
  32. private static F_HR_0901 _instance;
  33. // 最后选择行
  34. //private int _selecedRow;
  35. //Grid当前选中的行
  36. private int _selectedRowIndex;
  37. // 查询条件实体
  38. private HR_CMN_StaffEntity _staffEntity = new HR_CMN_StaffEntity();
  39. #endregion
  40. #region 构造函数
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. public F_HR_0901()
  45. {
  46. InitializeComponent();
  47. this.SetFromTitleInfo();
  48. }
  49. #endregion
  50. #region 单例模式
  51. /// <summary>
  52. /// 单例模式,防止重复创建窗体
  53. /// </summary>
  54. public static F_HR_0901 Instance
  55. {
  56. get
  57. {
  58. if (_instance == null)
  59. {
  60. _instance = new F_HR_0901();
  61. }
  62. return _instance;
  63. }
  64. }
  65. #endregion
  66. #region 事件
  67. /// <summary>
  68. /// 窗体加载事件
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. private void F_HR_0901_Load(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. this.dkStaffName.WhereCondition = "(StaffStatus = 1 Or StaffStatus = 2) AND ValueFlag = 1";
  77. FormPermissionManager.FormPermissionControl(this.Name, this,
  78. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  79. }
  80. catch (Exception ex)
  81. {
  82. // 对异常进行共通处理
  83. ExceptionManager.HandleEventException(this.ToString(),
  84. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  85. }
  86. }
  87. /// <summary>
  88. /// 窗体关闭事件
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. private void F_HR_0901_FormClosed(object sender, FormClosedEventArgs e)
  93. {
  94. _instance = null;
  95. }
  96. /// <summary>
  97. /// 选项改变事件
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void chkMealDate_CheckedChanged(object sender, EventArgs e)
  102. {
  103. if (this.chkMealDate.Checked)
  104. {
  105. this.dtpMealDateBegin.Enabled = true;
  106. this.dtpMealDateEnd.Enabled = true;
  107. }
  108. else
  109. {
  110. this.dtpMealDateBegin.Enabled = false;
  111. this.dtpMealDateEnd.Enabled = false;
  112. }
  113. }
  114. /// <summary>
  115. /// 行获取焦点事件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void dgvStaffDailyMeal_CellEnter(object sender, DataGridViewCellEventArgs e)
  120. {
  121. try
  122. {
  123. if (this.dgvStaffDailyMeal.CurrentCell != null)
  124. {
  125. // 记录最后选择行
  126. this._selectedRowIndex = this.dgvStaffDailyMeal.CurrentCell.RowIndex;
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. // 对异常进行共通处理
  132. ExceptionManager.HandleEventException(this.ToString(),
  133. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  134. }
  135. }
  136. /// <summary>
  137. /// 单元格鼠标双击事件
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void dgvStaffDailyMeal_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  142. {
  143. if (Constant.INT_IS_NEGATIE_ONE < e.RowIndex && Constant.INT_IS_NEGATIE_ONE < e.ColumnIndex
  144. && this.tsbtnDownloadTemplate.Enabled && this.tsbtnDownloadTemplate.Visible)
  145. {
  146. this.tsbtnEdit_Click(sender, e);
  147. }
  148. }
  149. /// <summary>
  150. /// 添加按钮
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. private void tsbtnAdd_Click(object sender, EventArgs e)
  155. {
  156. try
  157. {
  158. F_HR_0902 frmHR0902 = new F_HR_0902(Constant.FormMode.Add);
  159. if (frmHR0902.ShowDialog() == DialogResult.OK)
  160. {
  161. SearchDailyMealEntity searchDailyMealEntity = SetSearchDailyMealEntity();
  162. DataSet dsResultStaff = (DataSet)DoAsync(new AsyncMethod(() =>
  163. {
  164. return HRModuleProxy.Service.SearcStaffDailyMealInfo(searchDailyMealEntity);
  165. }));
  166. if (dsResultStaff != null && dsResultStaff.Tables.Count > Constant.INT_IS_ZERO
  167. && dsResultStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  168. {
  169. this.dgvStaffDailyMeal.DataSource = null;
  170. this.dgvStaffDailyMeal.DataSource = dsResultStaff.Tables[0];
  171. this.dgvStaffDailyMeal.ReadOnly = true;
  172. }
  173. }
  174. }
  175. catch (Exception ex)
  176. {
  177. // 对异常进行共通处理
  178. ExceptionManager.HandleEventException(this.ToString(),
  179. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  180. }
  181. }
  182. /// <summary>
  183. /// 编辑用餐按钮
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void tsbtnEdit_Click(object sender, EventArgs e)
  188. {
  189. try
  190. {
  191. F_HR_0902 frmHR0902 = new F_HR_0902(Constant.FormMode.LimitEdit);
  192. if (frmHR0902.ShowDialog() == DialogResult.OK)
  193. {
  194. SearchDailyMealEntity searchDailyMealEntity = SetSearchDailyMealEntity();
  195. DataSet dsResultStaff = (DataSet)DoAsync(new AsyncMethod(() =>
  196. {
  197. return HRModuleProxy.Service.SearcStaffDailyMealInfo(searchDailyMealEntity);
  198. }));
  199. if (dsResultStaff != null && dsResultStaff.Tables.Count > Constant.INT_IS_ZERO
  200. && dsResultStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  201. {
  202. this.dgvStaffDailyMeal.DataSource = null;
  203. this.dgvStaffDailyMeal.DataSource = dsResultStaff.Tables[0];
  204. this.dgvStaffDailyMeal.ReadOnly = true;
  205. }
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. // 对异常进行共通处理
  211. ExceptionManager.HandleEventException(this.ToString(),
  212. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  213. }
  214. }
  215. /// <summary>
  216. /// 更多条件按钮
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void tsbtnMoreCondition_Click(object sender, EventArgs e)
  221. {
  222. HR_CMN_001 frmCMN001 = new HR_CMN_001();
  223. frmCMN001.StaffEntity = this._staffEntity;
  224. if (frmCMN001.ShowDialog() == DialogResult.OK)
  225. {
  226. this.txtOtherWhere.Text = frmCMN001.StaffEntity.GetSqlDispText();
  227. this._staffEntity = frmCMN001.StaffEntity;
  228. }
  229. }
  230. /// <summary>
  231. /// 下载模板按钮
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void tsbtnDownloadTemplate_Click(object sender, EventArgs e)
  236. {
  237. try
  238. {
  239. TempletFileEntity resultTemplet = (TempletFileEntity)DoAsync(new AsyncMethod(() =>
  240. {
  241. return CommonModuleProxy.Service.GetTempletFileContentByUrl(Constant.HR_STAFF_DAILYMEAL_TEMPLET);
  242. }));
  243. if (string.IsNullOrEmpty(resultTemplet.FileName))
  244. {
  245. // 提示未查找到数据
  246. MessageBox.Show(Messages.MSG_CMN_W021, this.Text,
  247. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  248. return;
  249. }
  250. this.sfDialogTemplet.FileName = resultTemplet.FileName;
  251. this.sfDialogTemplet.Filter = "压缩文件(*.rar)|*.rar";
  252. if (this.sfDialogTemplet.ShowDialog() == DialogResult.OK)
  253. {
  254. string localFilePath = this.sfDialogTemplet.FileName.ToString(); //获得文件路径
  255. System.IO.File.WriteAllBytes(localFilePath, resultTemplet.FileContent);
  256. }
  257. }
  258. catch (Exception ex)
  259. {
  260. // 对异常进行共通处理
  261. ExceptionManager.HandleEventException(this.ToString(),
  262. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  263. }
  264. }
  265. /// <summary>
  266. /// 自动适应列宽
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  271. {
  272. this.dgvStaffDailyMeal.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  273. }
  274. /// <summary>
  275. /// 关闭按钮事件
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void tsbtnClose_Click(object sender, EventArgs e)
  280. {
  281. this.Close();
  282. }
  283. /// <summary>
  284. /// 查询按钮事件
  285. /// </summary>
  286. /// <param name="sender"></param>
  287. /// <param name="e"></param>
  288. private void btnSearch_Click(object sender, EventArgs e)
  289. {
  290. try
  291. {
  292. // 记录当前选中行
  293. int selectRowIndex = this._selectedRowIndex;
  294. SearchDailyMealEntity searchDailyMealEntity = SetSearchDailyMealEntity();
  295. DataSet dsResultStaff = (DataSet)DoAsync(new AsyncMethod(() =>
  296. {
  297. return HRModuleProxy.Service.SearcStaffDailyMealInfo(searchDailyMealEntity);
  298. }));
  299. if (dsResultStaff != null)
  300. {
  301. base.DataSource = dsResultStaff;
  302. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  303. {
  304. this.dgvStaffDailyMeal.DataSource = this.DataSource.Tables[0];
  305. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  306. {
  307. // 提示未查找到数据
  308. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  309. MessageBoxButtons.OK, MessageBoxIcon.Information);
  310. }
  311. else
  312. {
  313. #region 选择原有行
  314. if (selectRowIndex >= Constant.INT_IS_ZERO)
  315. {
  316. if (selectRowIndex >= dsResultStaff.Tables[0].Rows.Count)
  317. {
  318. this.dgvStaffDailyMeal.Rows[this.dgvStaffDailyMeal.Rows.Count - 1].Selected = true;
  319. this.dgvStaffDailyMeal.CurrentCell = this.dgvStaffDailyMeal.Rows[this.dgvStaffDailyMeal.Rows.Count - 1].Cells["StaffName"];
  320. }
  321. else
  322. {
  323. this.dgvStaffDailyMeal.Rows[selectRowIndex].Selected = true;
  324. this.dgvStaffDailyMeal.CurrentCell = this.dgvStaffDailyMeal.Rows[selectRowIndex].Cells["StaffName"];
  325. }
  326. }
  327. #endregion
  328. }
  329. }
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. // 对异常进行共通处理
  335. ExceptionManager.HandleEventException(this.ToString(),
  336. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  337. }
  338. }
  339. /// <summary>
  340. /// 清空条件
  341. /// </summary>
  342. /// <param name="sender"></param>
  343. /// <param name="e"></param>
  344. private void btnClearCondition_Click(object sender, EventArgs e)
  345. {
  346. this.dkStaffName.UserID = null;
  347. this.dkStaffName.UserCode = string.Empty;
  348. this.dkStaffName.UserName = string.Empty;
  349. this.dkStaffName.StaffEntity = null;
  350. this.chkMealDate.Checked = false;
  351. this.txtOtherWhere.Text = string.Empty;
  352. this.chkOrderBreakfast.ClearItemCheck();
  353. this.chkOrderLunch.ClearItemCheck();
  354. this.chkOrderDinner.ClearItemCheck();
  355. this.chkMealBreakfast.ClearItemCheck();
  356. this.chkMealLunch.ClearItemCheck();
  357. this.chkMealDinner.ClearItemCheck();
  358. this._staffEntity.ClearEntityValue();
  359. }
  360. #endregion
  361. #region 私有方法
  362. /// <summary>
  363. /// 设置窗体按钮的文本信息
  364. /// </summary>
  365. private void SetFromTitleInfo()
  366. {
  367. this.Text = FormTitles.F_HR_0901;
  368. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  369. this.tsbtnDownloadTemplate.Text = ButtonText.TSBTN_DOWNLOADTEMPLATE;
  370. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  371. this.tsbtnMoreCondition.Text = ButtonText.TSBTN_MORECONDITION;
  372. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  373. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  374. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  375. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  376. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  377. }
  378. /// <summary>
  379. /// 根据查询条件 形成查询实体
  380. /// </summary>
  381. /// <returns></returns>
  382. public SearchDailyMealEntity SetSearchDailyMealEntity()
  383. {
  384. SearchDailyMealEntity searchDailyMealEntity = new SearchDailyMealEntity();
  385. DataConvert.Convert(this._staffEntity, searchDailyMealEntity);
  386. if (this.dkStaffName.UserID != null)
  387. {
  388. searchDailyMealEntity.StaffID = this.dkStaffName.UserID;
  389. }
  390. if (this.chkMealDate.Checked)
  391. {
  392. searchDailyMealEntity.StartMealDate = new DateTime(this.dtpMealDateBegin.Value.Year, this.dtpMealDateBegin.Value.Month, this.dtpMealDateBegin.Value.Day);
  393. searchDailyMealEntity.EndMealDate = new DateTime(this.dtpMealDateBegin.Value.Year, this.dtpMealDateBegin.Value.Month, this.dtpMealDateBegin.Value.Day + 1);
  394. }
  395. object[] orderBreakfasts = this.chkOrderBreakfast.SelectedValues;
  396. if (orderBreakfasts.Length == Constant.INT_IS_ONE)
  397. {
  398. searchDailyMealEntity.OrderBreakfast = orderBreakfasts[Constant.INT_IS_ZERO].ToString();
  399. }
  400. object[] orderLunchs = this.chkOrderLunch.SelectedValues;
  401. if (orderLunchs.Length == Constant.INT_IS_ONE)
  402. {
  403. searchDailyMealEntity.OrderLunch = orderLunchs[Constant.INT_IS_ZERO].ToString();
  404. }
  405. object[] orderDinners = this.chkOrderDinner.SelectedValues;
  406. if (orderDinners.Length == Constant.INT_IS_ONE)
  407. {
  408. searchDailyMealEntity.OrderDinner = orderDinners[Constant.INT_IS_ZERO].ToString();
  409. }
  410. object[] mealBreakfasts = this.chkMealBreakfast.SelectedValues;
  411. if (mealBreakfasts.Length == Constant.INT_IS_ONE)
  412. {
  413. searchDailyMealEntity.MealBreakfast = mealBreakfasts[Constant.INT_IS_ZERO].ToString();
  414. }
  415. object[] mealLunchs = this.chkMealLunch.SelectedValues;
  416. if (mealLunchs.Length == Constant.INT_IS_ONE)
  417. {
  418. searchDailyMealEntity.MealLunch = mealLunchs[Constant.INT_IS_ZERO].ToString();
  419. }
  420. object[] mealDinners = this.chkMealDinner.SelectedValues;
  421. if (mealDinners.Length == Constant.INT_IS_ONE)
  422. {
  423. searchDailyMealEntity.MealDinner = mealDinners[Constant.INT_IS_ZERO].ToString();
  424. }
  425. return searchDailyMealEntity;
  426. }
  427. #endregion
  428. }
  429. }