F_HR_0101.cs 32 KB

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