F_HR_0401.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0401.cs
  5. * 2.功能描述:员工离职
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/16 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.DockPanel;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. using Dongke.IBOSS.PRD.Client.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
  22. using Dongke.IBOSS.PRD.WCF.Proxys;
  23. namespace Dongke.IBOSS.PRD.Client.HRModule
  24. {
  25. /// <summary>
  26. /// 员工离职
  27. /// </summary>
  28. public partial class F_HR_0401 : DockPanelBase
  29. {
  30. #region 成员变量
  31. // 窗体的单例模式
  32. private static F_HR_0401 _instance;
  33. //Grid当前选中的行
  34. private int _selectedRowIndex;
  35. // 查询条件实体
  36. private HR_CMN_StaffEntity _staffEntity = new HR_CMN_StaffEntity();
  37. //用户编辑的ID集合
  38. int[] _staffIDList;
  39. // 员工ID
  40. private int _staffID;
  41. #endregion
  42. #region 构造函数处理
  43. /// <summary>
  44. /// 构造函数
  45. /// </summary>
  46. public F_HR_0401()
  47. {
  48. InitializeComponent();
  49. this.SetFromTitleInfo();
  50. // 设置ToolStripButton状态
  51. //this.SetToolStripButtonEnable();
  52. }
  53. #endregion
  54. #region 单例模式
  55. /// <summary>
  56. /// 单例模式,防止重复创建窗体
  57. /// </summary>
  58. public static F_HR_0401 Instance
  59. {
  60. get
  61. {
  62. if (_instance == null)
  63. {
  64. _instance = new F_HR_0401();
  65. }
  66. return _instance;
  67. }
  68. }
  69. #endregion
  70. #region 事件处理
  71. /// <summary>
  72. /// 页面加载事件
  73. /// </summary>
  74. /// <param name="sender"></param>
  75. /// <param name="e"></param>
  76. private void F_HR_0401_Load(object sender, EventArgs e)
  77. {
  78. try
  79. {
  80. FormPermissionManager.FormPermissionControl(this.Name, this,
  81. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  82. this.tsbtnDisable.Visible = false;
  83. // 加载员工状态
  84. DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
  85. this.SelStaffStatus.DataSource = dtStaffStatus;
  86. this.SelStaffStatus.SelectedValues = new object[] { 0, 1, 2 };
  87. //this.SelStaffStatus.AllItemCheck();
  88. }
  89. catch (Exception ex)
  90. {
  91. // 对异常进行共通处理
  92. ExceptionManager.HandleEventException(this.ToString(),
  93. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  94. }
  95. }
  96. /// <summary>
  97. /// 窗体关闭事件
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void F_HR_0401_FormClosed(object sender, FormClosedEventArgs e)
  102. {
  103. _instance = null;
  104. }
  105. /// <summary>
  106. /// 行获取焦点后查看明细
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void dgvStaff_CellEnter(object sender, DataGridViewCellEventArgs e)
  111. {
  112. try
  113. {
  114. if (this.dgvStaff.CurrentCell != null)
  115. {
  116. // 记录最后选择行
  117. this._selectedRowIndex = this.dgvStaff.CurrentCell.RowIndex;
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. // 对异常进行共通处理
  123. ExceptionManager.HandleEventException(this.ToString(),
  124. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  125. }
  126. }
  127. /// <summary>
  128. /// 单元格鼠标双击事件
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. // private void dgvStaff_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  133. // {
  134. // if (Constant.INT_IS_NEGATIE_ONE < e.RowIndex && Constant.INT_IS_NEGATIE_ONE < e.ColumnIndex
  135. // && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
  136. // {
  137. //this.tsbtnTurnover_Click(sender, e);
  138. // }
  139. // }
  140. /// <summary>
  141. /// 添加按钮
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. //private void tsbtnAdd_Click(object sender, EventArgs e)
  146. //{
  147. // try
  148. // {
  149. //F_HR_0402 frmHR0402 = new F_HR_0402(Constant.FormMode.Add, Constant.INT_IS_NEGATIE_ONE, Constant.INT_IS_NEGATIE_ONE);
  150. //if (frmHR0402.ShowDialog() == DialogResult.OK)
  151. //{
  152. // this._staffIDList = frmHR0402.StaffIDList.ToArray();
  153. // DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.GetDataGridViewInfo));
  154. // if (userDataSet != null && userDataSet.Tables.Count > Constant.INT_IS_ZERO
  155. // && userDataSet.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  156. // {
  157. // this.dgvStaff.DataSource = null;
  158. // this.dgvStaff.DataSource = userDataSet.Tables[0];
  159. // // 设置ToolStripButton按钮状态
  160. // this.SetToolStripButtonEnable();
  161. // this.dgvStaff.ReadOnly = true;
  162. // }
  163. //}
  164. // }
  165. // catch (Exception ex)
  166. // {
  167. // // 对异常进行共通处理
  168. // ExceptionManager.HandleEventException(this.ToString(),
  169. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  170. // }
  171. //}
  172. /// <summary>
  173. /// 编辑按钮
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. //private void tsbtnEdit_Click(object sender, EventArgs e)
  178. //{
  179. // try
  180. // {
  181. //if (this.dgvStaff.CurrentRow != null)
  182. //{
  183. // if (this.dgvStaff.CurrentRow.Cells["ApprovalStatus"].Value == null || this.dgvStaff.CurrentRow.Cells["RecordType"].Value == null)
  184. // {
  185. // MessageBox.Show(string.Format(Messages.MSG_HR_W007, "员工离职", "编辑"),
  186. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  187. // return;
  188. // }
  189. // string strApprovalStatus = this.dgvStaff.CurrentRow.Cells["ApprovalStatus"].Value.ToString();
  190. // string strRecordType = this.dgvStaff.CurrentRow.Cells["RecordType"].Value.ToString();
  191. // if (Constant.ApprovalStatus.Pending.GetHashCode().ToString().Equals(strApprovalStatus)
  192. // && Constant.StaffRecordType.Departure.GetHashCode().ToString().Equals(strRecordType))
  193. // {
  194. // int intStaffID = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffID"].Value);
  195. // int intStaffRecordID = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffRecordID"].Value);
  196. // F_HR_0402 frmHR0402 = new F_HR_0402(Constant.FormMode.Edit, intStaffID, intStaffRecordID);
  197. // if (frmHR0402.ShowDialog() == DialogResult.OK)
  198. // {
  199. // this._staffIDList = frmHR0402.StaffIDList.ToArray();
  200. // DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.GetDataGridViewInfo));
  201. // if (userDataSet != null && userDataSet.Tables.Count > Constant.INT_IS_ZERO
  202. // && userDataSet.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  203. // {
  204. // this.dgvStaff.DataSource = null;
  205. // this.dgvStaff.DataSource = userDataSet.Tables[0];
  206. // // 设置ToolStripButton按钮状态
  207. // this.SetToolStripButtonEnable();
  208. // this.dgvStaff.ReadOnly = true;
  209. // }
  210. // }
  211. // }
  212. // else
  213. // {
  214. // MessageBox.Show(string.Format(Messages.MSG_HR_W007, "员工离职", "编辑"),
  215. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  216. // return;
  217. // }
  218. //}
  219. // }
  220. // catch (Exception ex)
  221. // {
  222. // // 对异常进行共通处理
  223. // ExceptionManager.HandleEventException(this.ToString(),
  224. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  225. // }
  226. //}
  227. /// <summary>
  228. /// 停用按钮事件
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void tsbtnDisable_Click(object sender, EventArgs e)
  233. {
  234. try
  235. {
  236. DialogResult msgBoxResult = MessageBox.Show(
  237. string.Format(Messages.MSG_CMN_Q002, "该员工", "停用"), this.Text,
  238. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  239. if (msgBoxResult == DialogResult.Yes)
  240. {
  241. int staffid = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffRecordID"].Value);
  242. this._staffID = staffid;
  243. HRResultEntity resultStaff = (HRResultEntity)DoAsync(() =>
  244. {
  245. return HRModuleProxy.Service.SetStaffRecordValueFlag(_staffID);
  246. }
  247. );
  248. //this.dgvStaff.ReadOnly = true;
  249. // 修改成功
  250. if (resultStaff.OperateStatus > Constant.INT_IS_ZERO)
  251. {
  252. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工离职", "停用"),
  253. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  254. this.btnSearch_Click(sender, e);
  255. }
  256. else if (resultStaff.OperateStatus == Constant.INT_IS_NEGATIE_FIVE)
  257. {
  258. MessageBox.Show(Messages.MSG_HR_W002,
  259. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  260. }
  261. else
  262. {
  263. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工离职", "停用"),
  264. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  265. }
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. // 对异常进行共通处理
  271. ExceptionManager.HandleEventException(this.ToString(),
  272. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  273. }
  274. }
  275. /// <summary>
  276. /// 更多条件按钮
  277. /// </summary>
  278. /// <param name="sender"></param>
  279. /// <param name="e"></param>
  280. private void tsbtnMoreCondition_Click(object sender, EventArgs e)
  281. {
  282. HR_CMN_001 frmCMN001 = new HR_CMN_001();
  283. frmCMN001.StaffEntity = _staffEntity;
  284. if (frmCMN001.ShowDialog() == DialogResult.OK)
  285. {
  286. this.txtOtherWhere.Text = frmCMN001.StaffEntity.GetSqlDispText();
  287. this._staffEntity = frmCMN001.StaffEntity;
  288. }
  289. }
  290. /// <summary>
  291. /// 自动适应列宽
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  296. {
  297. this.dgvStaff.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  298. }
  299. /// <summary>
  300. /// 关闭按钮事件
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void tsbtnClose_Click(object sender, EventArgs e)
  305. {
  306. this.Close();
  307. }
  308. /// <summary>
  309. /// 查询按钮
  310. /// </summary>
  311. /// <param name="sender"></param>
  312. /// <param name="e"></param>
  313. private void btnSearch_Click(object sender, EventArgs e)
  314. {
  315. try
  316. {
  317. this._staffIDList = null;
  318. // 记录当前选中行
  319. int selectRowIndex = this._selectedRowIndex;
  320. DataSet dsResultStaff = (DataSet)DoAsync(new AsyncMethod(this.GetDataGridViewInfo));
  321. if (dsResultStaff != null)
  322. {
  323. if (!dsResultStaff.Tables[0].Columns.Contains("Sel"))
  324. {
  325. dsResultStaff.Tables[0].Columns.Add("Sel", typeof(int));
  326. }
  327. base.DataSource = dsResultStaff;
  328. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  329. {
  330. this.dgvStaff.DataSource = this.DataSource.Tables[0];
  331. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  332. {
  333. // 提示未查找到数据
  334. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  335. MessageBoxButtons.OK, MessageBoxIcon.Information);
  336. }
  337. else
  338. {
  339. #region 选择原有行
  340. if (selectRowIndex >= Constant.INT_IS_ZERO)
  341. {
  342. if (selectRowIndex >= dsResultStaff.Tables[0].Rows.Count)
  343. {
  344. this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Selected = true;
  345. this.dgvStaff.CurrentCell = this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Cells["StaffCode"];
  346. }
  347. else
  348. {
  349. this.dgvStaff.Rows[selectRowIndex].Selected = true;
  350. this.dgvStaff.CurrentCell = this.dgvStaff.Rows[selectRowIndex].Cells["StaffCode"];
  351. }
  352. }
  353. #endregion
  354. }
  355. }
  356. foreach (DataGridViewColumn col in this.dgvStaff.Columns)
  357. {
  358. col.ReadOnly = col.Name == "Sel" ? false:true;
  359. }
  360. }
  361. //this.SetToolStripButtonEnable();
  362. }
  363. catch (Exception ex)
  364. {
  365. // 对异常进行共通处理
  366. ExceptionManager.HandleEventException(this.ToString(),
  367. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  368. }
  369. }
  370. /// <summary>
  371. /// 清空条件
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void btnClearCondition_Click(object sender, EventArgs e)
  376. {
  377. // 加载员工状态
  378. DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
  379. this.SelStaffStatus.DataSource = dtStaffStatus;
  380. this.SelStaffStatus.SelectedValues = new object[] { 0, 1, 2 };
  381. //this.SelStaffStatus.AllItemCheck();
  382. this.txtStaffCode.Clear();
  383. this.txtStaffName.Clear();
  384. this.txtOtherWhere.Clear();
  385. this._staffEntity.ClearEntityValue();
  386. }
  387. /// <summary>
  388. /// 导入按钮点击事件
  389. /// </summary>
  390. /// <param name="sender"></param>
  391. /// <param name="e"></param>
  392. private void tsbtnImport_Click(object sender, EventArgs e)
  393. {
  394. try
  395. {
  396. this.oFileDialog.Filter = "Excel文件|*.xls;*.xlsx|Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
  397. this.oFileDialog.FileName = string.Empty;
  398. if (this.oFileDialog.ShowDialog() != DialogResult.OK)
  399. {
  400. return;
  401. }
  402. int v = (".xlsx" == System.IO.Path.GetExtension(this.oFileDialog.FileName)) ? 1 : 0;
  403. DataTable dtStaffInfo = ExcelLayer.GetDataTable(this.oFileDialog.FileName, "Staff", v);
  404. #region 对数据进行验证
  405. if (dtStaffInfo == null || dtStaffInfo.Rows.Count < 1)
  406. {
  407. // 提示信息
  408. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "文件正在被占用 或 导入的Excel文件中没有符合规则的数据!"),
  409. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  410. return;
  411. }
  412. if (!CheckImportExcel(dtStaffInfo))
  413. {
  414. // 提示信息
  415. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入模板错误!"),
  416. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  417. return;
  418. }
  419. if (!CheckImportExcelData(dtStaffInfo))
  420. {
  421. return;
  422. }
  423. if (dtStaffInfo.Rows.Count < 1)
  424. {
  425. // 提示信息
  426. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入的Excel文件中的数据没有员工编码!"),
  427. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  428. return;
  429. }
  430. #endregion
  431. if (MessageBox.Show("导入成功,是否全部离职", this.Text,
  432. MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  433. {
  434. DataSet dsStaffInfo = new DataSet();
  435. dsStaffInfo.Tables.Add(dtStaffInfo.Copy());
  436. ClientRequestEntity cre = new ClientRequestEntity();
  437. cre.NameSpace = "HR001";
  438. cre.Name = "ImportStaffTurnover";
  439. cre.Data = dsStaffInfo;
  440. ServiceResultEntity result = CommonModuleProxy.Service.DoRequest(cre);
  441. if (result.Status == Constant.ServiceResultStatus.Success)
  442. {
  443. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工离职", "导入"),
  444. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  445. // 导入成功之后,查询
  446. string[] ids = (result.Result + "").Split(',');
  447. this._staffIDList = new int[ids.Length];
  448. for (int i = 0; i < ids.Length; i++)
  449. {
  450. this._staffIDList[i] = int.Parse(ids[i]);
  451. }
  452. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  453. if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
  454. && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  455. {
  456. this.dgvStaff.DataSource = null;
  457. this.dgvStaff.DataSource = dsHrStaff.Tables[0];
  458. }
  459. }
  460. else
  461. {
  462. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, result.Message),
  463. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  464. }
  465. }
  466. }
  467. catch (Exception ex)
  468. {
  469. // 对异常进行共通处理
  470. ExceptionManager.HandleEventException(this.ToString(),
  471. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  472. }
  473. }
  474. /// <summary>
  475. /// 下载模板按钮点击事件
  476. /// </summary>
  477. /// <param name="sender"></param>
  478. /// <param name="e"></param>
  479. private void tsbtnDown_Click(object sender, EventArgs e)
  480. {
  481. try
  482. {
  483. TempletFileEntity resultTemplet = (TempletFileEntity)DoAsync(new AsyncMethod(() =>
  484. {
  485. return CommonModuleProxy.Service.GetTempletFileContentByUrl(Constant.HR_STAFF_DIMISSION_TEMPLET);
  486. }));
  487. if (string.IsNullOrEmpty(resultTemplet.FileName))
  488. {
  489. // 提示未查找到数据
  490. MessageBox.Show(Messages.MSG_CMN_W021, this.Text,
  491. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  492. return;
  493. }
  494. this.sfDialogTemplet.FileName = resultTemplet.FileName;
  495. this.sfDialogTemplet.Filter = "Excel文件(*.xlsx)|*.xlsx";
  496. if (this.sfDialogTemplet.ShowDialog() == DialogResult.OK)
  497. {
  498. string localFilePath = this.sfDialogTemplet.FileName.ToString(); //获得文件路径
  499. System.IO.File.WriteAllBytes(localFilePath, resultTemplet.FileContent);
  500. }
  501. }
  502. catch (Exception ex)
  503. {
  504. // 对异常进行共通处理
  505. ExceptionManager.HandleEventException(this.ToString(),
  506. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  507. }
  508. }
  509. /// <summary>
  510. /// 离职按钮点击事件
  511. /// </summary>
  512. /// <param name="sender"></param>
  513. /// <param name="e"></param>
  514. private void tsbtnTurnover_Click(object sender, EventArgs e)
  515. {
  516. try
  517. {
  518. if (this.dgvStaff.DataSource == null || this.dgvStaff.CurrentRow == null)
  519. {
  520. // 提示未查找到数据
  521. MessageBox.Show("未选择任何数据", this.Text,
  522. MessageBoxButtons.OK, MessageBoxIcon.Information);
  523. return;
  524. }
  525. (this.dgvStaff.DataSource as DataTable).AcceptChanges();
  526. DataTable dtStaff = (this.dgvStaff.DataSource as DataTable).Copy();
  527. dtStaff.DefaultView.RowFilter = "Sel = 1";
  528. dtStaff = dtStaff.DefaultView.ToTable();
  529. if (dtStaff.Rows.Count == 0)
  530. {
  531. // 提示未查找到数据
  532. MessageBox.Show("未选择任何数据", this.Text,
  533. MessageBoxButtons.OK, MessageBoxIcon.Information);
  534. return;
  535. }
  536. if (MessageBox.Show("是否进行离职操作?", this.Text,
  537. MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  538. {
  539. string staffIDs = string.Empty;
  540. foreach (DataRow row in dtStaff.Rows)
  541. {
  542. staffIDs += row["StaffID"] + ",";
  543. }
  544. staffIDs = staffIDs.Substring(0, staffIDs.Length - 1);
  545. ClientRequestEntity cre = new ClientRequestEntity();
  546. cre.NameSpace = "HR001";
  547. cre.Name = "StaffTurnover";
  548. cre.Properties["staffIDs"] = staffIDs;
  549. DataSet dsStaff = new DataSet();
  550. dsStaff.Tables.Add(dtStaff);
  551. cre.Data = dsStaff;
  552. ServiceResultEntity result = CommonModuleProxy.Service.DoRequest(cre);
  553. if (result.Status == Constant.ServiceResultStatus.Success)
  554. {
  555. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工离职", "离职"),
  556. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  557. // 操作成功之后,查询
  558. string[] ids = staffIDs.Split(',');
  559. this._staffIDList = new int[ids.Length];
  560. for (int i = 0; i < ids.Length; i++)
  561. {
  562. this._staffIDList[i] = int.Parse(ids[i]);
  563. }
  564. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  565. if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
  566. && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  567. {
  568. this.dgvStaff.DataSource = null;
  569. this.dgvStaff.DataSource = dsHrStaff.Tables[0];
  570. // 设置ToolStripButton按钮状态
  571. //this.SetToolStripButtonEnable();
  572. }
  573. }
  574. else
  575. {
  576. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, result.Message),
  577. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  578. }
  579. }
  580. }
  581. catch (Exception ex)
  582. {
  583. // 对异常进行共通处理
  584. ExceptionManager.HandleEventException(this.ToString(),
  585. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  586. }
  587. }
  588. /// <summary>
  589. /// 提交对选择列的修改
  590. /// </summary>
  591. /// <param name="sender"></param>
  592. /// <param name="e"></param>
  593. private void dgvStaff_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  594. {
  595. try
  596. {
  597. if (this.dgvStaff.CurrentRow != null && this.dgvStaff.IsCurrentCellDirty)
  598. {
  599. if ("Sel".Equals(this.dgvStaff.Columns[this.dgvStaff.CurrentCell.ColumnIndex].Name))
  600. {
  601. this.dgvStaff.CommitEdit(DataGridViewDataErrorContexts.Commit);
  602. if ("已离职".Equals(this.dgvStaff.CurrentRow.Cells["StaffStatusName"].Value + ""))
  603. {
  604. MessageBox.Show("不能选择已经离职的员工",
  605. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  606. this.dgvStaff.CurrentRow.Cells["Sel"].Value = 0;
  607. }
  608. }
  609. }
  610. }
  611. catch (Exception ex)
  612. {
  613. // 对异常进行共通处理
  614. ExceptionManager.HandleEventException(this.ToString(),
  615. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  616. }
  617. }
  618. #endregion
  619. #region 私有方法
  620. /// <summary>
  621. /// 获取员工档案数据集
  622. /// </summary>
  623. /// <returns></returns>
  624. private DataSet SearchHrStaff()
  625. {
  626. SearchStaffEntity pSearchStaff = new SearchStaffEntity();
  627. if (this._staffIDList != null && this._staffIDList.Length > Constant.INT_IS_ZERO)
  628. {
  629. pSearchStaff.RStaffRecordIDList = this._staffIDList;
  630. this._staffIDList = null;
  631. }
  632. else
  633. {
  634. DataConvert.Convert(_staffEntity, pSearchStaff);
  635. pSearchStaff.StaffCode = this.txtStaffCode.Text.Trim();
  636. pSearchStaff.StaffName = this.txtStaffName.Text.Trim();
  637. pSearchStaff.ValueFlag = true;
  638. pSearchStaff.StaffStatusArray = SelStaffStatus.SelectedArray;
  639. }
  640. try
  641. {
  642. return HRModuleProxy.Service.SearchHrStaff(pSearchStaff);
  643. }
  644. catch (Exception ex)
  645. {
  646. throw ex;
  647. }
  648. }
  649. /// <summary>
  650. /// 设置工具按钮的可用状态
  651. /// </summary>
  652. /// <remarks>
  653. //private void SetToolStripButtonEnable()
  654. // {
  655. // if (this.dgvStaff.CurrentCell != null)
  656. // {
  657. // this.tsbtnEdit.Enabled = true;
  658. // }
  659. // else
  660. // {
  661. // this.tsbtnEdit.Enabled = false;
  662. // }
  663. // }
  664. /// <summary>
  665. /// 设置窗体按钮的文本信息
  666. /// </summary>
  667. private void SetFromTitleInfo()
  668. {
  669. this.Text = FormTitles.F_HR_0401;
  670. //this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  671. //this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  672. this.tsbtnDisable.Text = ButtonText.TSBTN_DISABLE;
  673. this.tsbtnMoreCondition.Text = ButtonText.TSBTN_MORECONDITION;
  674. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  675. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  676. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  677. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  678. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  679. }
  680. /// <summary>
  681. /// 根据查询条件获取要显示的数据
  682. /// </summary>
  683. /// <returns>返回查询的结果集</returns>
  684. private DataSet GetDataGridViewInfo()
  685. {
  686. SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
  687. DataConvert.Convert(this._staffEntity, searchStaffEntity);
  688. searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  689. searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
  690. //searchStaffEntity.Recordtype = Constant.StaffRecordType.Departure.GetHashCode(); //6:离职
  691. //searchStaffEntity.RValueflag = Constant.ValueFlag.Effective.GetHashCode(); //1:正常
  692. searchStaffEntity.StaffStatusArray = SelStaffStatus.SelectedArray;
  693. searchStaffEntity.ValueFlag = true;
  694. if (this._staffIDList != null && this._staffIDList.Length > Constant.INT_IS_ZERO)
  695. {
  696. searchStaffEntity.RStaffRecordIDList = this._staffIDList;
  697. }
  698. //return WCF.Proxys.HRModuleProxy.Service.SearchHrStaffAndRecord(searchStaffEntity);
  699. return WCF.Proxys.HRModuleProxy.Service.SearchHrStaff(searchStaffEntity);
  700. }
  701. /// <summary>
  702. /// 导入的Excel列验证
  703. /// </summary>
  704. /// <param name="datatable"></param>
  705. /// <returns></returns>
  706. private bool CheckImportExcel(DataTable datatable)
  707. {
  708. if (datatable.Columns.Count < 1)
  709. {
  710. return false;
  711. }
  712. if (!datatable.Columns.Contains("员工编码"))
  713. {
  714. return false;
  715. }
  716. if (!datatable.Columns.Contains("离职日期"))
  717. {
  718. return false;
  719. }
  720. return true;
  721. }
  722. /// <summary>
  723. /// 导入的Excel数据验证
  724. /// </summary>
  725. /// <param name="datatable"></param>
  726. /// <returns></returns>
  727. private bool CheckImportExcelData(DataTable datatable)
  728. {
  729. List<string> codes = new List<string>();
  730. string code = string.Empty;
  731. foreach (DataRow item in datatable.Rows)
  732. {
  733. code = item["员工编码"] + "";
  734. if (string.IsNullOrWhiteSpace(code))
  735. {
  736. item.Delete();
  737. continue;
  738. }
  739. if (codes.Contains(code))
  740. {
  741. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "员工编码【" + code + "】重复。"),
  742. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  743. return false;
  744. }
  745. codes.Add(code);
  746. }
  747. datatable.AcceptChanges();
  748. return true;
  749. }
  750. #endregion
  751. }
  752. }