F_HR_0101.cs 32 KB

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