F_HR_1001.cs 20 KB

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