F_HR_0902.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0902.cs
  5. * 2.功能描述:员工报餐新增/编辑
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/10/6 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Basics.Library;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
  19. using Dongke.IBOSS.PRD.Client.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.Proxys;
  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_0902 : FormBase
  29. {
  30. #region 成员变量
  31. // 记录备注
  32. private string _isMeal;
  33. // 记录备注
  34. private string _remarks;
  35. //格式刷是否开启
  36. private bool _isBrushIsOpen = false;
  37. // 当前列序号
  38. private int _columnIndex = -1;
  39. // 窗体状态的枚举 新建/编辑
  40. private Constant.FormMode _editStatus;
  41. #endregion
  42. #region 构造函数
  43. /// <summary>
  44. /// 构造函数
  45. /// </summary>
  46. /// <param name="editStatus">编辑状态</param>
  47. /// <param name="pStaffId">员工ID</param>
  48. /// <param name="pSealDate">报餐日期</param>
  49. public F_HR_0902(Constant.FormMode editStatus)
  50. {
  51. InitializeComponent();
  52. this._editStatus = editStatus;
  53. this.dkStaffName.WhereCondition = "(StaffStatus = 1 Or StaffStatus = 2) AND ValueFlag = 1";
  54. this.SetFromTitleInfo();
  55. }
  56. #endregion
  57. #region 事件
  58. /// <summary>
  59. /// 窗体加载事件
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. private void F_HR_0902_Load(object sender, EventArgs e)
  64. {
  65. try
  66. {
  67. FormPermissionManager.FormPermissionControl(this.Name, this,
  68. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  69. if (this._editStatus == Constant.FormMode.LimitEdit)
  70. {
  71. this.dgvStaffDailyMeal.Columns["OrderBreakfast"].ReadOnly = true;
  72. this.dgvStaffDailyMeal.Columns["OrderLunch"].ReadOnly = true;
  73. this.dgvStaffDailyMeal.Columns["OrderDinner"].ReadOnly = true;
  74. this.dgvStaffDailyMeal.Columns["Remarks"].ReadOnly = true;
  75. }
  76. this.dgvStaffDailyMeal.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  77. this.dkStaffName.WhereCondition = "StaffStatus in(1,2) and ValueFlag=1";//筛选适用的试用与正式员工
  78. }
  79. catch (Exception ex)
  80. {
  81. // 对异常进行共通处理
  82. ExceptionManager.HandleEventException(this.ToString(),
  83. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  84. }
  85. }
  86. /// <summary>
  87. /// 数据刷刷数据
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void dgvStaffDailyMeal_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
  92. {
  93. try
  94. {
  95. if (this.dgvStaffDailyMeal.CurrentCell == null
  96. || this.dgvStaffDailyMeal.Rows.Count < Constant.INT_IS_ONE)
  97. {
  98. return;
  99. }
  100. DataGridViewCell currentCell = this.dgvStaffDailyMeal.CurrentCell;
  101. if (_columnIndex != -Constant.INT_IS_ONE && _columnIndex != currentCell.ColumnIndex)
  102. {
  103. this.SetBrushNotEnable();
  104. }
  105. List<string> checkColList = GetGirdViewCheckColName();
  106. if (checkColList.Contains(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
  107. {
  108. if (this._isBrushIsOpen)
  109. {
  110. this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value = this._isMeal;
  111. }
  112. this._columnIndex = currentCell.ColumnIndex;
  113. }
  114. else if ("Remarks".Equals(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
  115. {
  116. if (this._isBrushIsOpen && !this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].ReadOnly)
  117. {
  118. this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value = this._remarks;
  119. }
  120. this._columnIndex = currentCell.ColumnIndex;
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. // 对异常进行共通处理
  126. ExceptionManager.HandleEventException(this.ToString(),
  127. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  128. }
  129. }
  130. /// <summary>
  131. /// 导入按钮
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void tsbtnImport_Click(object sender, EventArgs e)
  136. {
  137. try
  138. {
  139. this.oFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  140. this.oFileDialog.FileName = string.Empty;
  141. if (this.oFileDialog.ShowDialog() == DialogResult.OK)
  142. {
  143. DataTable dtStaffMeal = ExcelLayer.GetDataTable(this.oFileDialog.FileName, 1);
  144. #region 对数据进行验证
  145. if (dtStaffMeal == null && dtStaffMeal.Rows.Count <= Constant.INT_IS_ZERO)
  146. {
  147. // 提示信息
  148. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "数据表中没有数据!"),
  149. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  150. return;
  151. }
  152. if (!CheckExcelImportData(dtStaffMeal.Columns))
  153. {
  154. // 提示信息
  155. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入模板错误!"),
  156. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  157. return;
  158. }
  159. #endregion
  160. DataSet dsResultStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  161. {
  162. if (this._editStatus == Constant.FormMode.Edit)
  163. {
  164. return HRModuleProxy.Service.GetStaffDailyMealInfoForExcel(dtStaffMeal, WCFConstant.FormMode.Edit);
  165. }
  166. return HRModuleProxy.Service.GetStaffDailyMealInfoForExcel(dtStaffMeal, WCFConstant.FormMode.MealEdit);
  167. }));
  168. if (dsResultStaff != null)
  169. {
  170. base.DataSource = dsResultStaff;
  171. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  172. {
  173. this.dgvStaffDailyMeal.DataSource = this.DataSource.Tables[0];
  174. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  175. {
  176. // 提示未查找到数据
  177. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  178. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. catch (Exception ex)
  185. {
  186. // 对异常进行共通处理
  187. ExceptionManager.HandleEventException(this.ToString(),
  188. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  189. }
  190. }
  191. /// <summary>
  192. /// 数据刷按钮
  193. /// </summary>
  194. /// <param name="sender"></param>
  195. /// <param name="e"></param>
  196. private void tsbtnDataBrush_Click(object sender, EventArgs e)
  197. {
  198. try
  199. {
  200. if (this.dgvStaffDailyMeal.CurrentCell == null || this.dgvStaffDailyMeal.Rows.Count < Constant.INT_IS_ONE)
  201. {
  202. return;
  203. }
  204. DataGridViewCell currentCell = this.dgvStaffDailyMeal.CurrentCell;
  205. List<string> checkColList = GetGirdViewCheckColName();
  206. if (checkColList.Contains(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
  207. {
  208. if (!_isBrushIsOpen)
  209. {
  210. this.tsbtnBrush.Checked = true;
  211. this._isBrushIsOpen = true;
  212. this.dgvStaffDailyMeal.Cursor = Cursors.Hand;
  213. this.dgvStaffDailyMeal.MultiSelect = true;
  214. this._isMeal = this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value + "";
  215. }
  216. else
  217. {
  218. this.dgvStaffDailyMeal.Cursor = Cursors.Default;
  219. this.dgvStaffDailyMeal.MultiSelect = false;
  220. this.tsbtnBrush.Checked = false;
  221. this._isBrushIsOpen = false;
  222. }
  223. }
  224. else if ("Remarks".Equals(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
  225. {
  226. if (!_isBrushIsOpen)
  227. {
  228. this.tsbtnBrush.Checked = true;
  229. this._isBrushIsOpen = true;
  230. this.dgvStaffDailyMeal.Cursor = Cursors.Hand;
  231. this.dgvStaffDailyMeal.MultiSelect = true;
  232. this._remarks = this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value + "";
  233. }
  234. else
  235. {
  236. this.dgvStaffDailyMeal.Cursor = Cursors.Default;
  237. this.dgvStaffDailyMeal.MultiSelect = false;
  238. this.tsbtnBrush.Checked = false;
  239. this._isBrushIsOpen = false;
  240. }
  241. }
  242. }
  243. catch (Exception ex)
  244. {
  245. // 对异常进行共通处理
  246. ExceptionManager.HandleEventException(this.ToString(),
  247. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  248. }
  249. }
  250. /// <summary>
  251. /// 自动适应列宽
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  256. {
  257. this.dgvStaffDailyMeal.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  258. }
  259. /// <summary>
  260. /// 关闭按钮事件
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void tsbtnClose_Click(object sender, EventArgs e)
  265. {
  266. this.Close();
  267. }
  268. /// <summary>
  269. /// 查询按钮事件
  270. /// </summary>
  271. /// <param name="sender"></param>
  272. /// <param name="e"></param>
  273. private void btnSearch_Click(object sender, EventArgs e)
  274. {
  275. try
  276. {
  277. SearchDailyMealEntity searchDailyMealEntity = SetSearchDailyMealEntity();
  278. DataSet dsResultStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  279. {
  280. return HRModuleProxy.Service.SearcStaffDailyMealInfoForEdit(searchDailyMealEntity);
  281. }));
  282. if (dsResultStaff != null)
  283. {
  284. base.DataSource = dsResultStaff;
  285. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  286. {
  287. this.dgvStaffDailyMeal.DataSource = this.DataSource.Tables[0];
  288. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  289. {
  290. // 提示未查找到数据
  291. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  292. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  293. }
  294. }
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. // 对异常进行共通处理
  300. ExceptionManager.HandleEventException(this.ToString(),
  301. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  302. }
  303. }
  304. /// <summary>
  305. /// 清空条件
  306. /// </summary>
  307. /// <param name="sender"></param>
  308. /// <param name="e"></param>
  309. private void btnClearCondition_Click(object sender, EventArgs e)
  310. {
  311. this.dkStaffName.UserID = null;
  312. this.dkStaffName.UserCode = string.Empty;
  313. this.dkStaffName.UserName = string.Empty;
  314. this.dkStaffName.StaffEntity = null;
  315. this.scbOrganization.ClearValue();
  316. this.dkJobs.JobsID = null;
  317. this.dkJobs.JobsCode = string.Empty;
  318. this.dkJobs.JobsName = string.Empty;
  319. this.dtpMealDate.Value = DateTime.Now;
  320. }
  321. /// <summary>
  322. /// 保存按钮
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void btnSave_Click(object sender, EventArgs e)
  327. {
  328. try
  329. {
  330. DataTable dtStaffMeal = this.dgvStaffDailyMeal.DataSource as DataTable;
  331. dtStaffMeal.AcceptChanges();
  332. HRResultEntity resultStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(() =>
  333. {
  334. if (this._editStatus == Constant.FormMode.Edit)
  335. {
  336. return WCF.Proxys.HRModuleProxy.Service.SaveStaffDailyMealInfo(dtStaffMeal, WCFConstant.FormMode.Edit);
  337. }
  338. return WCF.Proxys.HRModuleProxy.Service.SaveStaffDailyMealInfo(dtStaffMeal, WCFConstant.FormMode.MealEdit);
  339. }));
  340. if (!string.IsNullOrEmpty(resultStaff.OperateLogInfo))
  341. {
  342. // 提示信息
  343. MessageBox.Show(resultStaff.OperateLogInfo,
  344. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  345. }
  346. else if (resultStaff.OperateStatus > Constant.INT_IS_ZERO)
  347. {
  348. // 提示信息
  349. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工报餐", "保存"),
  350. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  351. }
  352. else
  353. {
  354. // 提示信息
  355. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工报餐", "保存"),
  356. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  357. }
  358. }
  359. catch (Exception ex)
  360. {
  361. // 对异常进行共通处理
  362. ExceptionManager.HandleEventException(this.ToString(),
  363. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  364. }
  365. }
  366. /// <summary>
  367. /// 关闭按钮
  368. /// </summary>
  369. /// <param name="sender"></param>
  370. /// <param name="e"></param>
  371. private void btnCancel_Click(object sender, EventArgs e)
  372. {
  373. this.Close();
  374. }
  375. #endregion
  376. #region 私有方法
  377. /// <summary>
  378. /// 设置窗体按钮的文本信息
  379. /// </summary>
  380. private void SetFromTitleInfo()
  381. {
  382. if (this._editStatus == Constant.FormMode.Add)
  383. {
  384. this.Text = FormTitles.F_HR_0902_ADD;
  385. }
  386. else if (this._editStatus == Constant.FormMode.Edit)
  387. {
  388. this.Text = FormTitles.F_HR_0902_EDIT;
  389. }
  390. this.tsbtnImport.Text = ButtonText.TSBTN_IMPORT;
  391. this.tsbtnBrush.Text = ButtonText.TSBTN_BRUSH;
  392. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  393. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  394. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  395. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  396. this.btnSave.Text = ButtonText.BTN_SAVE;
  397. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  398. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  399. }
  400. /// <summary>
  401. /// 使格式刷不可用
  402. /// </summary>
  403. private void SetBrushNotEnable()
  404. {
  405. this._isBrushIsOpen = false;
  406. this.tsbtnBrush.Checked = false;
  407. this.dgvStaffDailyMeal.Cursor = Cursors.Default;
  408. this.dgvStaffDailyMeal.MultiSelect = false;
  409. }
  410. /// <summary>
  411. /// 验证Excel模板中列是否符合规则
  412. /// </summary>
  413. /// <param name="pColumns">列集合</param>
  414. /// <returns></returns>
  415. private bool CheckExcelImportData(DataColumnCollection pColumns)
  416. {
  417. #region 定义模板中的标题
  418. List<string> excelColName = new List<string>();
  419. excelColName.Add("员工编号");
  420. excelColName.Add("员工姓名");
  421. excelColName.Add("报餐日期");
  422. if (this._editStatus == Constant.FormMode.Edit)
  423. {
  424. excelColName.Add("预定早餐");
  425. excelColName.Add("预定午餐");
  426. excelColName.Add("预定晚餐");
  427. excelColName.Add("备注");
  428. }
  429. else if (this._editStatus == Constant.FormMode.LimitEdit)
  430. {
  431. excelColName.Add("吃早餐");
  432. excelColName.Add("吃午餐");
  433. excelColName.Add("吃晚餐");
  434. }
  435. #endregion
  436. foreach (DataColumn itemCol in pColumns)
  437. {
  438. string strColName = itemCol.ColumnName;
  439. if (!excelColName.Contains(strColName))
  440. {
  441. return false;
  442. }
  443. }
  444. return true;
  445. }
  446. /// <summary>
  447. /// 返回GridView表中Check列名称
  448. /// </summary>
  449. /// <returns></returns>
  450. private List<string> GetGirdViewCheckColName()
  451. {
  452. List<string> checkColNames = new List<string>();
  453. checkColNames.Add("OrderBreakfast");
  454. checkColNames.Add("OrderLunch");
  455. checkColNames.Add("OrderDinner");
  456. checkColNames.Add("MealBreakfast");
  457. checkColNames.Add("MealLunch");
  458. checkColNames.Add("MealDinner");
  459. return checkColNames;
  460. }
  461. /// <summary>
  462. /// 根据查询条件 形成查询实体
  463. /// </summary>
  464. /// <returns></returns>
  465. public SearchDailyMealEntity SetSearchDailyMealEntity()
  466. {
  467. SearchDailyMealEntity searchDailyMealEntity = new SearchDailyMealEntity();
  468. if (this.dkStaffName.UserID != null)
  469. {
  470. searchDailyMealEntity.StaffID = this.dkStaffName.UserID;
  471. }
  472. if (this.scbOrganization.SearchedPKMember == 0)
  473. {
  474. searchDailyMealEntity.OrganizationID = this.scbOrganization.SearchedPKMember;
  475. }
  476. if (this.dkJobs.JobsID != null)
  477. {
  478. searchDailyMealEntity.Jobs = this.dkJobs.JobsID;
  479. }
  480. if (this.dtpMealDate.Value != null)
  481. {
  482. searchDailyMealEntity.MealDate = new DateTime(this.dtpMealDate.Value.Year, this.dtpMealDate.Value.Month, this.dtpMealDate.Value.Day);
  483. }
  484. return searchDailyMealEntity;
  485. }
  486. #endregion
  487. }
  488. }