F_HR_0101.cs 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0101.cs
  5. * 2.功能描述:员工档案
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/12 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. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  24. namespace Dongke.IBOSS.PRD.Client.HRModule
  25. {
  26. /// <summary>
  27. /// 员工档案
  28. /// </summary>
  29. public partial class F_HR_0101 : DockPanelBase
  30. {
  31. #region 成员变量
  32. // 单例模式
  33. private static F_HR_0101 _instance;
  34. // 最后选择行
  35. private int _selecedRow;
  36. // 员工ID
  37. private int _staffID;
  38. // 查询条件实体
  39. private HR_CMN_StaffEntity _staffEntity = new HR_CMN_StaffEntity();
  40. //用户编辑的ID集合
  41. int[] _staffIDList;
  42. #endregion
  43. #region 单例模式
  44. /// <summary>
  45. /// 单例模式,防止重复创建窗体
  46. /// </summary>
  47. public static F_HR_0101 Instance
  48. {
  49. get
  50. {
  51. if (_instance == null)
  52. {
  53. _instance = new F_HR_0101();
  54. }
  55. return _instance;
  56. }
  57. }
  58. #endregion
  59. #region 构造函数
  60. public F_HR_0101()
  61. {
  62. InitializeComponent();
  63. //设置按钮显示的文本
  64. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  65. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  66. this.tsbtnDisable.Text = ButtonText.TSBTN_DISABLE;
  67. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  68. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  69. this.tsbtnMoreCondition.Text = ButtonText.TSBTN_MORECONDITION;
  70. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  71. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  72. this.Text = FormTitles.F_HR_0101;
  73. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  74. }
  75. #endregion
  76. #region 事件
  77. /// <summary>
  78. /// 关闭按钮事件
  79. /// </summary>
  80. /// <param name="sender"></param>
  81. /// <param name="e"></param>
  82. private void tsbtnClose_Click(object sender, EventArgs e)
  83. {
  84. this.Close();
  85. }
  86. /// <summary>
  87. /// 自动适应列宽
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  92. {
  93. this.dgvStaff.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  94. }
  95. /// <summary>
  96. /// 清空按钮事件
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. private void btnClearCondition_Click(object sender, EventArgs e)
  101. {
  102. // 加载员工状态
  103. DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
  104. this.SelStaffStatus.DataSource = dtStaffStatus;
  105. this.SelStaffStatus.AllItemCheck();
  106. this.txtStaffCode.Clear();
  107. this.txtStaffName.Clear();
  108. this.txtOther.Clear();
  109. this._staffEntity.ClearEntityValue();
  110. }
  111. /// <summary>
  112. /// 搜索按钮事件
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void btnSearch_Click(object sender, EventArgs e)
  117. {
  118. try
  119. {
  120. this._staffIDList = null;
  121. // 记录当前选中行
  122. int selectRowIndex = this._selecedRow;
  123. // 异步处理
  124. this.btnSearch.Enabled = false;
  125. this.btnClearCondition.Enabled = false;
  126. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  127. this.btnSearch.Enabled = true;
  128. this.btnClearCondition.Enabled = true;
  129. //this.sbxOrganization.ReadOnly = true;
  130. if (dsHrStaff != null)
  131. {
  132. base.DataSource = (DataSet)dsHrStaff;
  133. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  134. {
  135. this.dgvStaff.DataSource = this.DataSource.Tables[0];
  136. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  137. {
  138. // 提示未查找到数据
  139. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  140. MessageBoxButtons.OK, MessageBoxIcon.Information);
  141. }
  142. else
  143. {
  144. if (selectRowIndex >= Constant.INT_IS_ZERO)
  145. {
  146. if (selectRowIndex >= dsHrStaff.Tables[0].Rows.Count)
  147. {
  148. this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Selected = true;
  149. this.dgvStaff.CurrentCell = this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Cells["StaffCode"];
  150. }
  151. else
  152. {
  153. this.dgvStaff.Rows[selectRowIndex].Selected = true;
  154. this.dgvStaff.CurrentCell = this.dgvStaff.Rows[selectRowIndex].Cells["StaffCode"];
  155. }
  156. }
  157. }
  158. }
  159. }
  160. this.SetToolStripButtonEnable();
  161. }
  162. catch (Exception ex)
  163. {
  164. this.btnSearch.Enabled = true;
  165. this.btnClearCondition.Enabled = true;
  166. // 对异常进行共通处理
  167. ExceptionManager.HandleEventException(this.ToString(),
  168. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  169. }
  170. }
  171. /// <summary>
  172. /// 窗体关闭事件
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void F_HR_0101_FormClosed(object sender, FormClosedEventArgs e)
  177. {
  178. _instance = null;
  179. }
  180. /// <summary>
  181. /// 窗体加载事件
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void F_HR_0101_Load(object sender, EventArgs e)
  186. {
  187. try
  188. {
  189. // 加载权限
  190. FormPermissionManager.FormPermissionControl(this.Name, this,
  191. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  192. // 设置ToolStripButton状态
  193. this.SetToolStripButtonEnable();
  194. // 加载员工状态
  195. DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
  196. this.SelStaffStatus.DataSource = dtStaffStatus;
  197. this.SelStaffStatus.AllItemCheck();
  198. }
  199. catch (Exception ex)
  200. {
  201. // 对异常进行共通处理
  202. ExceptionManager.HandleEventException(this.ToString(),
  203. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  204. }
  205. }
  206. /// <summary>
  207. /// 更多条件按钮事件
  208. /// </summary>
  209. /// <param name="sender"></param>
  210. /// <param name="e"></param>
  211. private void tsbtnMoreCondition_Click(object sender, EventArgs e)
  212. {
  213. Dongke.IBOSS.PRD.Basics.BaseControls.HR_CMN_001 frmHRCMN001 = new Basics.BaseControls.HR_CMN_001();
  214. frmHRCMN001.StaffEntity = this._staffEntity;
  215. if (frmHRCMN001.ShowDialog() == DialogResult.OK)
  216. {
  217. this.txtOther.Text = frmHRCMN001.StaffEntity.GetSqlDispText();
  218. this._staffEntity = frmHRCMN001.StaffEntity;
  219. }
  220. }
  221. /// <summary>
  222. /// 新建按钮事件
  223. /// </summary>
  224. /// <param name="sender"></param>
  225. /// <param name="e"></param>
  226. private void tsbtnAdd_Click(object sender, EventArgs e)
  227. {
  228. try
  229. {
  230. F_HR_0102 frmHR0102 = new F_HR_0102(Constant.FormMode.Add);
  231. DialogResult dialogResult = frmHR0102.ShowDialog();
  232. // 重新加载GridView
  233. if (dialogResult == DialogResult.OK)
  234. {
  235. this._staffIDList = frmHR0102.StaffIDList.ToArray();
  236. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  237. if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
  238. && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  239. {
  240. this.dgvStaff.DataSource = null;
  241. this.dgvStaff.DataSource = dsHrStaff.Tables[0];
  242. // 设置ToolStripButton按钮状态
  243. this.SetToolStripButtonEnable();
  244. this.dgvStaff.ReadOnly = true;
  245. }
  246. }
  247. }
  248. catch (Exception ex)
  249. {
  250. // 对异常进行共通处理
  251. ExceptionManager.HandleEventException(this.ToString(),
  252. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  253. }
  254. }
  255. /// <summary>
  256. /// 单元格进入事件
  257. /// </summary>
  258. /// <param name="sender"></param>
  259. /// <param name="e"></param>
  260. private void dgvStaff_CellEnter(object sender, DataGridViewCellEventArgs e)
  261. {
  262. this.SetToolStripButtonEnable();
  263. if (this.dgvStaff.Rows.Count > Constant.INT_IS_ZERO)
  264. {
  265. this._selecedRow = this.dgvStaff.CurrentCell.RowIndex;
  266. }
  267. }
  268. /// <summary>
  269. /// 单元格双击事件
  270. /// </summary>
  271. /// <param name="sender"></param>
  272. /// <param name="e"></param>
  273. private void dgvStaff_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  274. {
  275. if (-Constant.INT_IS_ONE < e.RowIndex && -Constant.INT_IS_ONE < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
  276. {
  277. this.tsbtnEdit_Click(sender, e);
  278. }
  279. }
  280. /// <summary>
  281. /// 编辑按钮事件
  282. /// </summary>
  283. /// <param name="sender"></param>
  284. /// <param name="e"></param>
  285. private void tsbtnEdit_Click(object sender, EventArgs e)
  286. {
  287. try
  288. {
  289. if (this.dgvStaff.CurrentRow != null)
  290. {
  291. F_HR_0102 frmHR0102 = new F_HR_0102(Constant.FormMode.Edit);
  292. frmHR0102.StaffID = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffID"].Value);
  293. DialogResult dialogResult = frmHR0102.ShowDialog();
  294. if (dialogResult.Equals(DialogResult.OK))
  295. {
  296. this._staffIDList = frmHR0102.StaffIDList.ToArray();
  297. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  298. if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
  299. && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  300. {
  301. this.dgvStaff.DataSource = null;
  302. this.dgvStaff.DataSource = dsHrStaff.Tables[0];
  303. // 设置ToolStripButton按钮状态
  304. this.SetToolStripButtonEnable();
  305. this.dgvStaff.ReadOnly = true;
  306. }
  307. }
  308. }
  309. }
  310. catch (Exception ex)
  311. {
  312. // 对异常进行共通处理
  313. ExceptionManager.HandleEventException(this.ToString(),
  314. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  315. }
  316. }
  317. /// <summary>
  318. /// 停用按钮事件
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void tsbtnDisable_Click(object sender, EventArgs e)
  323. {
  324. try
  325. {
  326. DialogResult msgBoxResult = MessageBox.Show(
  327. string.Format(Messages.MSG_CMN_Q002, "该员工", "停用"), this.Text,
  328. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  329. if (msgBoxResult == DialogResult.Yes)
  330. {
  331. int staffid = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["staffID"].Value);
  332. this._staffID = staffid;
  333. HRResultEntity returenRow = (HRResultEntity)DoAsync(new AsyncMethod(this.SetValueFlag));
  334. this.dgvStaff.ReadOnly = true;
  335. // 修改成功
  336. if (returenRow.OperateStatus > Constant.INT_IS_ZERO)
  337. {
  338. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工管理", "停用"),
  339. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  340. this.btnSearch_Click(sender, e);
  341. }
  342. else if (returenRow.OperateStatus == Constant.INT_IS_NEGATIE_FOUR)
  343. {
  344. MessageBox.Show(Messages.MSG_HR_W001,
  345. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  346. }
  347. else
  348. {
  349. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工管理", "停用"),
  350. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  351. }
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. // 对异常进行共通处理
  357. ExceptionManager.HandleEventException(this.ToString(),
  358. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  359. }
  360. }
  361. /// <summary>
  362. /// 设置停用
  363. /// </summary>
  364. /// <param name="staffid"></param>
  365. /// <returns></returns>
  366. private HRResultEntity SetValueFlag()
  367. {
  368. try
  369. {
  370. return HRModuleProxy.Service.SetValueFlag(this._staffID);
  371. }
  372. catch (Exception ex)
  373. {
  374. throw ex;
  375. }
  376. }
  377. /// <summary>
  378. /// 设置启用
  379. /// </summary>
  380. /// <param name="staffid"></param>
  381. /// <returns></returns>
  382. private void EnableValueFlag()
  383. {
  384. ClientRequestEntity cre = new ClientRequestEntity();
  385. cre.NameSpace = "F_HR_0101";
  386. cre.Name = "STAFF";
  387. cre.Properties["Staffid"] = this._staffID;
  388. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  389. if (sre.OtherStatus > 0)
  390. {
  391. DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002);
  392. return;
  393. }
  394. else if (Convert.ToInt32(sre.OtherStatus) == -1001)
  395. {
  396. MessageBox.Show(string.Format(Messages.MSG_HR_W0001,
  397. ""),
  398. "",
  399. MessageBoxButtons.OK,
  400. MessageBoxIcon.Warning);
  401. return;
  402. }
  403. }
  404. private void tsbtnDown_Click(object sender, EventArgs e)
  405. {
  406. try
  407. {
  408. TempletFileEntity resultTemplet = (TempletFileEntity)DoAsync(new AsyncMethod(() =>
  409. {
  410. return CommonModuleProxy.Service.GetTempletFileContentByUrl(Constant.HR_STAFF_INFO_TEMPLET);
  411. }));
  412. if (string.IsNullOrEmpty(resultTemplet.FileName))
  413. {
  414. // 提示未查找到数据
  415. MessageBox.Show(Messages.MSG_CMN_W021, this.Text,
  416. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  417. return;
  418. }
  419. this.sfDialogTemplet.FileName = resultTemplet.FileName;
  420. this.sfDialogTemplet.Filter = "Excel文件(*.xlsx)|*.xlsx";
  421. if (this.sfDialogTemplet.ShowDialog() == DialogResult.OK)
  422. {
  423. string localFilePath = this.sfDialogTemplet.FileName.ToString(); //获得文件路径
  424. System.IO.File.WriteAllBytes(localFilePath, resultTemplet.FileContent);
  425. }
  426. }
  427. catch (Exception ex)
  428. {
  429. // 对异常进行共通处理
  430. ExceptionManager.HandleEventException(this.ToString(),
  431. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  432. }
  433. }
  434. private void tsbtnUpdate_Click(object sender, EventArgs e)
  435. {
  436. try
  437. {
  438. this.oFileDialog.Filter = "Excel文件|*.xls;*.xlsx|Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
  439. this.oFileDialog.FileName = string.Empty;
  440. if (this.oFileDialog.ShowDialog() != DialogResult.OK)
  441. {
  442. return;
  443. }
  444. int v = (".xlsx" == System.IO.Path.GetExtension(this.oFileDialog.FileName)) ? 1 : 0;
  445. DataTable dtStaffInfo = ExcelLayer.GetDataTable(this.oFileDialog.FileName, "Staff", v);
  446. #region 对数据进行验证
  447. if (dtStaffInfo == null || dtStaffInfo.Rows.Count < 1)
  448. {
  449. // 提示信息
  450. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "文件正在被占用 或 导入的Excel文件中没有符合规则的数据!"),
  451. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  452. return;
  453. }
  454. F_HR_0103 frmHR0103 = new F_HR_0103();
  455. if (frmHR0103.ShowDialog() == DialogResult.OK)
  456. {
  457. if (!CheckImportExcel(dtStaffInfo))
  458. {
  459. // 提示信息
  460. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入模板错误!"),
  461. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  462. return;
  463. }
  464. if (!CheckImportExcelData(dtStaffInfo, frmHR0103.StaffStatus))
  465. {
  466. return;
  467. }
  468. if (dtStaffInfo.Rows.Count < 1)
  469. {
  470. // 提示信息
  471. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入的Excel文件中的数据没有员工编码!"),
  472. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  473. return;
  474. }
  475. #endregion
  476. DataColumn dc = new DataColumn("StaffStatus", typeof(int));
  477. dc.DefaultValue = frmHR0103.StaffStatus;
  478. dtStaffInfo.Columns.Add(dc);
  479. ServiceResultEntity result = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
  480. {
  481. return HRModuleProxy.Service.ImportStaffInfo(dtStaffInfo);
  482. }));
  483. if (result.Status == Constant.ServiceResultStatus.Success)
  484. {
  485. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工档案", "导入"),
  486. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  487. string[] ids = result.Result.ToString().Split(',');
  488. this._staffIDList = new int[ids.Length];
  489. for (int i = 0; i < ids.Length; i++)
  490. {
  491. this._staffIDList[i] = int.Parse(ids[i]);
  492. }
  493. DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
  494. if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
  495. && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  496. {
  497. this.dgvStaff.DataSource = null;
  498. this.dgvStaff.DataSource = dsHrStaff.Tables[0];
  499. // 设置ToolStripButton按钮状态
  500. this.SetToolStripButtonEnable();
  501. this.dgvStaff.ReadOnly = true;
  502. }
  503. }
  504. else
  505. {
  506. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, result.Message),
  507. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  508. }
  509. }
  510. }
  511. catch (Exception ex)
  512. {
  513. // 对异常进行共通处理
  514. ExceptionManager.HandleEventException(this.ToString(),
  515. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  516. }
  517. }
  518. #endregion
  519. #region 私有方法
  520. /// <summary>
  521. /// 获取员工档案数据集
  522. /// </summary>
  523. /// <returns></returns>
  524. private DataSet SearchHrStaff()
  525. {
  526. SearchStaffEntity pSearchStaff = new SearchStaffEntity();
  527. if (this._staffIDList != null && this._staffIDList.Length > Constant.INT_IS_ZERO)
  528. {
  529. pSearchStaff.RStaffRecordIDList = this._staffIDList;
  530. this._staffIDList = null;
  531. }
  532. else
  533. {
  534. DataConvert.Convert(_staffEntity, pSearchStaff);
  535. pSearchStaff.StaffCode = this.txtStaffCode.Text.Trim();
  536. pSearchStaff.StaffName = this.txtStaffName.Text.Trim();
  537. object[] objListValue = chkValueFlag.SelectedValues;
  538. if (objListValue.Length>=2 || objListValue.Length<1)
  539. {
  540. pSearchStaff.ValueFlag = null;
  541. }
  542. if (objListValue.Length == 1) {
  543. if (objListValue[0].ToString() == "1") {
  544. pSearchStaff.ValueFlag = true;
  545. }
  546. if (objListValue[0].ToString() == "0")
  547. {
  548. pSearchStaff.ValueFlag = false;
  549. }
  550. }
  551. pSearchStaff.StaffStatusArray = SelStaffStatus.SelectedArray;
  552. }
  553. try
  554. {
  555. return HRModuleProxy.Service.SearchHrStaff(pSearchStaff);
  556. }
  557. catch (Exception ex)
  558. {
  559. throw ex;
  560. }
  561. }
  562. /// <summary>
  563. /// 设置工具按钮的可用状态
  564. /// </summary>
  565. private void SetToolStripButtonEnable()
  566. {
  567. if (this.dgvStaff.CurrentCell != null)
  568. {
  569. this.tsbtnEdit.Enabled = true;
  570. this.tsbtnDisable.Enabled = true;
  571. }
  572. else
  573. {
  574. this.tsbtnEdit.Enabled = false;
  575. this.tsbtnDisable.Enabled = false;
  576. }
  577. }
  578. private bool CheckImportExcel(DataTable datatable)
  579. {
  580. if (datatable.Columns.Count < 1)
  581. {
  582. return false;
  583. }
  584. if (!datatable.Columns.Contains("员工编码"))
  585. {
  586. return false;
  587. }
  588. //datatable.Columns["员工编码"].ColumnName = "StaffCode";
  589. if (!datatable.Columns.Contains("员工姓名"))
  590. {
  591. return false;
  592. }
  593. if (!datatable.Columns.Contains("身份证号码"))
  594. {
  595. return false;
  596. }
  597. if (!datatable.Columns.Contains("生日"))
  598. {
  599. return false;
  600. }
  601. if (!datatable.Columns.Contains("性别"))
  602. {
  603. return false;
  604. }
  605. if (!datatable.Columns.Contains("婚姻状况"))
  606. {
  607. return false;
  608. }
  609. if (!datatable.Columns.Contains("籍贯"))
  610. {
  611. return false;
  612. }
  613. if (!datatable.Columns.Contains("政治面貌"))
  614. {
  615. return false;
  616. }
  617. if (!datatable.Columns.Contains("民族"))
  618. {
  619. return false;
  620. }
  621. if (!datatable.Columns.Contains("学历"))
  622. {
  623. return false;
  624. }
  625. if (!datatable.Columns.Contains("毕业学校"))
  626. {
  627. return false;
  628. }
  629. if (!datatable.Columns.Contains("专业"))
  630. {
  631. return false;
  632. }
  633. if (!datatable.Columns.Contains("联系电话"))
  634. {
  635. return false;
  636. }
  637. if (!datatable.Columns.Contains("身高(CM)"))
  638. {
  639. return false;
  640. }
  641. if (!datatable.Columns.Contains("血型"))
  642. {
  643. return false;
  644. }
  645. if (!datatable.Columns.Contains("体重(KG)"))
  646. {
  647. return false;
  648. }
  649. if (!datatable.Columns.Contains("家庭住址"))
  650. {
  651. return false;
  652. }
  653. if (!datatable.Columns.Contains("下岗职工"))
  654. {
  655. return false;
  656. }
  657. if (!datatable.Columns.Contains("残疾职工"))
  658. {
  659. return false;
  660. }
  661. if (!datatable.Columns.Contains("入党日期"))
  662. {
  663. return false;
  664. }
  665. if (!datatable.Columns.Contains("电子邮箱"))
  666. {
  667. return false;
  668. }
  669. if (!datatable.Columns.Contains("开户行"))
  670. {
  671. return false;
  672. }
  673. if (!datatable.Columns.Contains("开户账号"))
  674. {
  675. return false;
  676. }
  677. if (!datatable.Columns.Contains("备注"))
  678. {
  679. return false;
  680. }
  681. if (!datatable.Columns.Contains("部门(全称)"))
  682. {
  683. return false;
  684. }
  685. if (!datatable.Columns.Contains("工种"))
  686. {
  687. return false;
  688. }
  689. if (!datatable.Columns.Contains("职务"))
  690. {
  691. return false;
  692. }
  693. return true;
  694. }
  695. private bool CheckImportExcelData(DataTable datatable, int? StaffStatus)
  696. {
  697. try
  698. {
  699. // 性别
  700. DataTable dtGender =
  701. LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Gender, null);
  702. // 婚姻状况
  703. DataTable dtMaritalStatus =
  704. LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_MaritalStatus, null);
  705. // 民族
  706. DataTable dtNational =
  707. LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_National, null);
  708. // 学历
  709. DataTable dtEducational =
  710. LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Educational, null);
  711. // 获取部门编码
  712. OrganizationEntity orgEntity = new OrganizationEntity();
  713. orgEntity.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
  714. orgEntity.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
  715. DataSet dtOrganization = (DataSet)DoAsync(new AsyncMethod(() =>
  716. {
  717. return SystemModuleProxy.Service.SelectOrganizationData(orgEntity);
  718. }));
  719. // 获取工种编码
  720. DataSet dsJobs = (DataSet)DoAsync(new AsyncMethod(() =>
  721. {
  722. return SystemModuleProxy.Service.GetAllJobsInfo();
  723. }));
  724. // 获取职务编码
  725. DataSet dsPost = (DataSet)DoAsync(new AsyncMethod(() =>
  726. {
  727. return SystemModuleProxy.Service.GetAllPostInfo();
  728. }));
  729. List<string> codes = new List<string>();
  730. foreach (DataRow item in datatable.Rows)
  731. {
  732. string code = item["员工编码"].ToString();
  733. if (string.IsNullOrWhiteSpace(code))
  734. {
  735. item.Delete();
  736. continue;
  737. }
  738. if (codes.Contains(code))
  739. {
  740. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "员工编码【" + code + "】重复。"),
  741. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  742. return false;
  743. }
  744. codes.Add(code);
  745. code = "员工编码[" + code + "]";
  746. if (string.IsNullOrWhiteSpace(item["员工姓名"].ToString()))
  747. {
  748. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的员工姓名为空。"),
  749. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  750. return false;
  751. }
  752. // 如果性别没填,默认【男】
  753. if (string.IsNullOrEmpty(item["性别"] + ""))
  754. {
  755. item["性别"] = "男";
  756. }
  757. DataRow[] drs1 = dtGender.Select("GenderName = '" + item["性别"].ToString() + "'");
  758. if (drs1 != null && drs1.Length > 0)
  759. {
  760. item["性别"] = drs1[0]["GenderCode"];
  761. }
  762. else
  763. {
  764. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的性别输入错误。"),
  765. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  766. return false;
  767. }
  768. // 如果婚姻状况没填,默认【其他】
  769. if (string.IsNullOrEmpty(item["婚姻状况"] + ""))
  770. {
  771. item["婚姻状况"] = "其他";
  772. }
  773. DataRow[] drs2 = dtMaritalStatus.Select("MaritalStatusName = '" + item["婚姻状况"].ToString() + "'");
  774. if (drs2 != null && drs2.Length > 0)
  775. {
  776. item["婚姻状况"] = drs2[0]["MaritalStatusID"];
  777. }
  778. else
  779. {
  780. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的婚姻状况输入错误。"),
  781. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  782. return false;
  783. }
  784. // 如果民族没填,默认【其他】
  785. if (string.IsNullOrEmpty(item["民族"] + ""))
  786. {
  787. item["民族"] = "汉族";
  788. }
  789. DataRow[] drs3 = dtNational.Select("NationalName = '" + item["民族"].ToString() + "'");
  790. if (drs3 != null && drs3.Length > 0)
  791. {
  792. item["民族"] = drs3[0]["NationalID"];
  793. }
  794. else
  795. {
  796. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的民族输入错误。"),
  797. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  798. return false;
  799. }
  800. // 如果民族没填,默认【其他】
  801. if (string.IsNullOrEmpty(item["学历"] + ""))
  802. {
  803. item["学历"] = "其他";
  804. }
  805. DataRow[] drs4 = dtEducational.Select("EducationalName = '" + item["学历"].ToString() + "'");
  806. if (drs4 != null && drs4.Length > 0)
  807. {
  808. item["学历"] = drs4[0]["EducationalID"];
  809. }
  810. else
  811. {
  812. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的学历输入错误。"),
  813. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  814. return false;
  815. }
  816. if (StaffStatus == 2)
  817. {
  818. //----------部门编码--------------
  819. // 如果部门全称没填,默认001部门
  820. DataRow[] drsOrganization = dtOrganization.Tables[0].Select("OrganizationCode = '001' AND ValueFlag= '1'", " OrganizationID ASC ");
  821. if (string.IsNullOrEmpty(item["部门(全称)"] + ""))
  822. {
  823. item["部门(全称)"] = (drsOrganization[0]["OrganizationFullName"] + "").Replace("→", "-");
  824. }
  825. DataRow[] drs5 = dtOrganization.Tables[0].Select("OrganizationName = '" + item["部门(全称)"].ToString() + "'", " FullNameLength ASC ");
  826. if (drs5 != null && drs5.Length > 0)
  827. {
  828. item["部门(全称)"] = drs5[0]["OrganizationID"];
  829. }
  830. else
  831. {
  832. DataRow[] drs51 = dtOrganization.Tables[0].Select("OrganizationFullName like '%" + item["部门(全称)"].ToString().Replace("-", "→") + "'", " FullNameLength ASC ");
  833. if (drs51 != null && drs51.Length > 0)
  834. {
  835. item["部门(全称)"] = drs51[0]["OrganizationID"];
  836. }
  837. else
  838. {
  839. item["部门(全称)"] = drsOrganization[0]["OrganizationID"];
  840. //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的部门输入错误。"),
  841. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  842. //return false;
  843. }
  844. }
  845. //------------------------
  846. //----------工种--------------
  847. DataRow[] drs6 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName = '" + item["工种"].ToString() + "'");
  848. if (drs6 != null && drs6.Length > 0)
  849. {
  850. item["工种"] = drs6[0]["JobsID"];
  851. }
  852. else
  853. {
  854. DataRow[] drs61 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName like '%" + item["工种"].ToString() + "%'");
  855. if (drs61 != null && drs61.Length == 1)
  856. {
  857. item["工种"] = drs61[0]["JobsID"];
  858. }
  859. else
  860. {
  861. // 如果未匹配到,默认第一个工种
  862. DataRow[] drsJobs = dsJobs.Tables[0].Select(" ValueFlag= '1'", " JobsID ASC ");
  863. item["工种"] = drsJobs[0]["JobsID"];
  864. //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的工种输入错误。"),
  865. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  866. // return false;
  867. }
  868. }
  869. //------------------------
  870. //----------职务--------------
  871. DataRow[] drs7 = dsPost.Tables[0].Select("ValueFlag='1' and PostCode = '" + item["职务"].ToString() + "'");
  872. if (drs7 != null && drs7.Length > 0)
  873. {
  874. item["职务"] = drs7[0]["PostID"];
  875. }
  876. else
  877. {
  878. DataRow[] drs71 = dsPost.Tables[0].Select("ValueFlag='1' and PostName like '%" + item["职务"].ToString() + "%'");
  879. if (drs71 != null && drs71.Length == 1)
  880. {
  881. item["职务"] = drs71[0]["PostID"];
  882. }
  883. else
  884. {
  885. // 如果未匹配到,默认第一个职务
  886. DataRow[] drsPost = dsPost.Tables[0].Select(" ValueFlag= '1'", " PostID ASC ");
  887. item["职务"] = drsPost[0]["PostID"];
  888. //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的职务输入错误。"),
  889. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  890. //return false;
  891. }
  892. }
  893. }
  894. else
  895. {
  896. //----------部门编码--------------
  897. // 如果部门全称没填,默认001部门
  898. DataRow[] drsOrganization = dtOrganization.Tables[0].Select("OrganizationCode = '001' AND ValueFlag= '1'", " OrganizationID ASC ");
  899. if (string.IsNullOrEmpty(item["部门(全称)"] + ""))
  900. {
  901. item["部门(全称)"] = (drsOrganization[0]["OrganizationFullName"] + "").Replace("→", "-");
  902. }
  903. DataRow[] drs5 = dtOrganization.Tables[0].Select("OrganizationCode = '" + item["部门(全称)"].ToString() + "'");
  904. if (drs5 != null && drs5.Length > 0)
  905. {
  906. item["部门(全称)"] = drs5[0]["OrganizationID"];
  907. }
  908. else
  909. {
  910. DataRow[] drs51 = dtOrganization.Tables[0].Select("OrganizationFullName like '%" + item["部门(全称)"].ToString() + "'");
  911. if (drs51 != null && drs51.Length == 1)
  912. {
  913. item["部门(全称)"] = drs51[0]["OrganizationID"];
  914. }
  915. else
  916. {
  917. // 如果未匹配到,默认001部门
  918. item["部门(全称)"] = drsOrganization[0]["OrganizationID"];
  919. }
  920. }
  921. //------------------------
  922. //----------工种--------------
  923. DataRow[] drs6 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsCode = '" + item["工种"].ToString() + "'");
  924. if (drs6 != null && drs6.Length > 0)
  925. {
  926. item["工种"] = drs6[0]["JobsID"];
  927. }
  928. else
  929. {
  930. DataRow[] drs61 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName like '%" + item["工种"].ToString() + "%'");
  931. if (drs61 != null && drs61.Length == 1)
  932. {
  933. item["工种"] = drs61[0]["JobsID"];
  934. }
  935. else
  936. {
  937. // 如果未匹配到,默认第一个工种
  938. DataRow[] drsJobs = dsJobs.Tables[0].Select(" ValueFlag= '1'", " JobsID ASC ");
  939. item["工种"] = drsJobs[0]["JobsID"];
  940. //item["工种编码"] = "";
  941. }
  942. }
  943. //------------------------
  944. //----------职务--------------
  945. DataRow[] drs7 = dsPost.Tables[0].Select("ValueFlag='1' and PostCode = '" + item["职务"].ToString() + "'");
  946. if (drs7 != null && drs7.Length > 0)
  947. {
  948. item["职务"] = drs7[0]["PostID"];
  949. }
  950. else
  951. {
  952. DataRow[] drs71 = dsPost.Tables[0].Select("ValueFlag='1' and PostName like '%" + item["职务"].ToString() + "%'");
  953. if (drs71 != null && drs71.Length == 1)
  954. {
  955. item["职务"] = drs71[0]["PostID"];
  956. }
  957. else
  958. {
  959. // 如果未匹配到,默认第一个职务
  960. DataRow[] drsPost = dsPost.Tables[0].Select(" ValueFlag= '1'", " PostID ASC ");
  961. item["职务"] = drsPost[0]["PostID"];
  962. //item["职务编码"] = "";
  963. }
  964. }
  965. }
  966. //------------------------
  967. if ("下岗职工" == item["下岗职工"].ToString())
  968. {
  969. item["下岗职工"] = "1";
  970. }
  971. else
  972. {
  973. item["下岗职工"] = "0";
  974. }
  975. if ("残疾职工" == item["残疾职工"].ToString())
  976. {
  977. item["残疾职工"] = "1";
  978. }
  979. else
  980. {
  981. item["残疾职工"] = "0";
  982. }
  983. string date = item["生日"].ToString();
  984. if (string.IsNullOrWhiteSpace(date))
  985. {
  986. item["生日"] = DBNull.Value;
  987. }
  988. else
  989. {
  990. DateTime datetime;
  991. if (DateTime.TryParse(date, out datetime))
  992. {
  993. item["生日"] = datetime.ToString("yyyy-MM-dd");
  994. }
  995. else
  996. {
  997. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的生日输入错误。"),
  998. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  999. return false;
  1000. }
  1001. }
  1002. date = item["入党日期"].ToString();
  1003. if (string.IsNullOrWhiteSpace(date))
  1004. {
  1005. item["入党日期"] = DBNull.Value;
  1006. }
  1007. else
  1008. {
  1009. DateTime datetime;
  1010. if (DateTime.TryParse(date, out datetime))
  1011. {
  1012. item["入党日期"] = datetime.ToString("yyyy-MM-dd");
  1013. }
  1014. else
  1015. {
  1016. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的入党日期输入错误。"),
  1017. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1018. return false;
  1019. }
  1020. }
  1021. date = item["身高(CM)"].ToString();
  1022. if (string.IsNullOrWhiteSpace(date))
  1023. {
  1024. item["身高(CM)"] = DBNull.Value;
  1025. }
  1026. else
  1027. {
  1028. decimal d;
  1029. if (decimal.TryParse(date, out d))
  1030. {
  1031. item["身高(CM)"] = d;
  1032. }
  1033. else
  1034. {
  1035. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的身高(CM)输入错误。"),
  1036. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1037. return false;
  1038. }
  1039. }
  1040. date = item["体重(KG)"].ToString();
  1041. if (string.IsNullOrWhiteSpace(date))
  1042. {
  1043. item["体重(KG)"] = DBNull.Value;
  1044. }
  1045. else
  1046. {
  1047. decimal d;
  1048. if (decimal.TryParse(date, out d))
  1049. {
  1050. item["体重(KG)"] = d;
  1051. }
  1052. else
  1053. {
  1054. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的体重(KG)输入错误。"),
  1055. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1056. return false;
  1057. }
  1058. }
  1059. }
  1060. datatable.AcceptChanges();
  1061. return true;
  1062. }
  1063. catch (Exception ex)
  1064. {
  1065. throw ex;
  1066. }
  1067. }
  1068. #endregion
  1069. private void enableButton_Click(object sender, EventArgs e)
  1070. {
  1071. try
  1072. {
  1073. DialogResult msgBoxResult = MessageBox.Show(
  1074. string.Format(Messages.MSG_CMN_Q002, "该员工", "启用"), this.Text,
  1075. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1076. if (msgBoxResult == DialogResult.Yes)
  1077. {
  1078. int staffid = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffID"].Value);
  1079. this._staffID = staffid;
  1080. EnableValueFlag();
  1081. }
  1082. }
  1083. catch (Exception ex)
  1084. {
  1085. // 对异常进行共通处理
  1086. ExceptionManager.HandleEventException(this.ToString(),
  1087. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1088. }
  1089. }
  1090. }
  1091. }