F_HR_0102.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0102.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.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Drawing.Imaging;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. using Dongke.IBOSS.PRD.Basics.BaseControls;
  19. using Dongke.IBOSS.PRD.Basics.BaseResources;
  20. using Dongke.IBOSS.PRD.Client.CommonModule;
  21. using Dongke.IBOSS.PRD.Client.DataModels;
  22. using Dongke.IBOSS.PRD.WCF.DataModels;
  23. using Dongke.IBOSS.PRD.WCF.Proxys;
  24. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  25. namespace Dongke.IBOSS.PRD.Client.HRModule
  26. {
  27. /// <summary>
  28. /// 新建/编辑员工档案
  29. /// </summary>
  30. public partial class F_HR_0102 : FormBase
  31. {
  32. #region 成员变量
  33. // 页面传过来员工ID
  34. private int _staffID;
  35. // 用户实体类
  36. private StaffEntity _staffEntity;
  37. // 编辑状态
  38. private Constant.FormMode _editStatus;
  39. // 新建的员工ID集合
  40. private List<int> _staffIDList = new List<int>();
  41. // 时间戳
  42. private DateTime _optimestamp;
  43. // 图片字节集
  44. private List<byte[]> _PicByte = new List<byte[]>();
  45. // 缩略图片字节集
  46. private List<byte[]> _smallByte = new List<byte[]>();
  47. // 图片实体集合
  48. private List<StaffPhotoEntity> _imgList = new List<StaffPhotoEntity>();
  49. // 已存在的图片实体集合(修改)
  50. private List<StaffPhotoEntity> _updateImgList = new List<StaffPhotoEntity>();
  51. #endregion
  52. #region 构造函数
  53. public F_HR_0102()
  54. {
  55. InitializeComponent();
  56. }
  57. /// <summary>
  58. /// 构造函数
  59. /// </summary>
  60. /// <param name="frmStatus">窗体状态</param>
  61. public F_HR_0102(Constant.FormMode frmStatus)
  62. {
  63. InitializeComponent();
  64. _editStatus = frmStatus;
  65. // 设置窗口标题,当为新建状态时显示新建员工,当为编辑状态时显示编辑员工
  66. if (frmStatus == Constant.FormMode.Add)
  67. {
  68. this.Text = FormTitles.F_HR_0102_ADD;
  69. }
  70. else if (frmStatus == Constant.FormMode.Edit)
  71. {
  72. this.Text = FormTitles.F_HR_0102_EDIT;
  73. this.txtStaffCode.Enabled = false;
  74. }
  75. // 工具栏按钮文本赋值
  76. this.btnSave.Text = ButtonText.BTN_SAVE;
  77. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  78. this.btnUpload.Text = ButtonText.BTN_UPLOAD;
  79. this.btnDelete.Text = ButtonText.BTN_DELETE;
  80. #region 绑定数据源
  81. // 性别
  82. DataTable dtT_SYS_Gender = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByName));
  83. this.dropGender.DisplayMember = "GenderName";
  84. this.dropGender.ValueMember = "GenderCode";
  85. this.dropGender.DataSource = dtT_SYS_Gender;
  86. // 婚姻状况
  87. DataTable dtT_SYS_MaritalStatus = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameMaritalStatu));
  88. this.dropMaritalStatus.DisplayMember = "maritalstatusname";
  89. this.dropMaritalStatus.ValueMember = "maritalstatusid";
  90. this.dropMaritalStatus.DataSource = dtT_SYS_MaritalStatus;
  91. // 民族
  92. DataTable dtT_SYS_National = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameNational));
  93. this.dropNational.DisplayMember = "nationalname";
  94. this.dropNational.ValueMember = "nationalid";
  95. this.dropNational.DataSource = dtT_SYS_National;
  96. // 学历
  97. DataTable dtT_SYS_Educational = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameEducational));
  98. this.dropEducational.DisplayMember = "educationalname";
  99. this.dropEducational.ValueMember = "educationalid";
  100. this.dropEducational.DataSource = dtT_SYS_Educational;
  101. #endregion
  102. }
  103. #endregion
  104. #region 属性
  105. /// <summary>
  106. /// 页面传过来的员工ID
  107. /// </summary>
  108. public int StaffID
  109. {
  110. get
  111. {
  112. return this._staffID;
  113. }
  114. set
  115. {
  116. this._staffID = value;
  117. }
  118. }
  119. /// <summary>
  120. /// 员工ID集合
  121. /// </summary>
  122. public List<int> StaffIDList
  123. {
  124. get
  125. {
  126. return _staffIDList;
  127. }
  128. set
  129. {
  130. _staffIDList = value;
  131. }
  132. }
  133. /// <summary>
  134. /// 时间戳
  135. /// </summary>
  136. public DateTime PTimeStamp
  137. {
  138. get
  139. {
  140. return _optimestamp;
  141. }
  142. set
  143. {
  144. _optimestamp = value;
  145. }
  146. }
  147. #endregion
  148. #region 按钮事件
  149. /// <summary>
  150. /// 保存按钮事件
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. private void btnSave_Click(object sender, EventArgs e)
  155. {
  156. try
  157. {
  158. // 验证输入是否正确
  159. if (!this.CheckInputValidity())
  160. {
  161. return;
  162. }
  163. this._staffEntity = this.SetStaffEntity();
  164. if (this._editStatus == Constant.FormMode.Add)
  165. {
  166. if (this.txtStaffCode.Text.Trim() != string.Empty)
  167. {
  168. // 判断是否存在重复的员工编号
  169. DataSet staffCodeData = (DataSet)DoAsync(new BaseAsyncMethod(this.IsExistsStaffCode));
  170. if (staffCodeData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  171. {
  172. MessageBox.Show(string.Format(Messages.MSG_CMN_W011, this.txtStaffCode.Text.Trim(), "员工编码"),
  173. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  174. this.txtStaffCode.Focus();
  175. return;
  176. }
  177. }
  178. // 新建用户,返回新建的员工ID
  179. this.btnSave.Enabled = false;
  180. this.btnCancel.Enabled = false;
  181. HRResultEntity returnStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(this.AddStaffInfo));
  182. this.btnSave.Enabled = true;
  183. this.btnCancel.Enabled = true;
  184. if (returnStaff.OperateStatus > Constant.INT_IS_ZERO)
  185. {
  186. // 提示信息
  187. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建员工", "保存"),
  188. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  189. this._staffIDList.Add(returnStaff.HRStaffID);
  190. this.InitializationForm();
  191. }
  192. else if (returnStaff.OperateStatus == Constant.INT_IS_NEGATIE_THREE)
  193. {
  194. // 提示信息
  195. MessageBox.Show(string.Format(Messages.MSG_CMN_W012, "新建员工", "保存"),
  196. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  197. }
  198. else
  199. {
  200. // 提示信息
  201. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "新建员工", "保存"),
  202. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  203. }
  204. }
  205. else
  206. {
  207. this.btnSave.Enabled = false;
  208. this.btnCancel.Enabled = false;
  209. this._staffEntity.StaffID = StaffID;
  210. this._staffEntity.OPTimeStamp = PTimeStamp;
  211. HRResultEntity returnStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(this.EditStaffInfo));
  212. this.btnSave.Enabled = true;
  213. this.btnCancel.Enabled = true;
  214. if (returnStaff.OperateStatus > Constant.INT_IS_ZERO)
  215. {
  216. // 提示信息
  217. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "编辑员工", "保存"),
  218. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  219. //this._staffIDList.Add(returnStaff.HRStaffID);
  220. this.InitializationForm();
  221. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  222. }
  223. else if (returnStaff.OperateStatus == Constant.INT_IS_NEGATIE_THREE)
  224. {
  225. // 提示信息
  226. MessageBox.Show(string.Format(Messages.MSG_CMN_W012, "编辑员工", "保存"),
  227. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  228. }
  229. else
  230. {
  231. // 提示信息
  232. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "编辑员工", "保存"),
  233. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  234. }
  235. }
  236. }
  237. catch (Exception ex)
  238. {
  239. this.btnSave.Enabled = true;
  240. this.btnCancel.Enabled = true;
  241. // 对异常进行共通处理
  242. ExceptionManager.HandleEventException(this.ToString(),
  243. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  244. }
  245. }
  246. /// <summary>
  247. /// 窗体加载事件
  248. /// </summary>
  249. /// <param name="sender"></param>
  250. /// <param name="e"></param>
  251. private void F_HR_0102_Load(object sender, EventArgs e)
  252. {
  253. try
  254. {
  255. // 加载权限
  256. FormPermissionManager.FormPermissionControl(this.Name, this,
  257. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  258. #region 绑定工种职务数据源
  259. this.dropJobs.DisplayMember = "JOBSNAME";
  260. this.dropJobs.ValueMember = "JOBSID";
  261. this.dropJobs.DataSource = (DataTable)DoAsync(new BaseAsyncMethod(this.GetJobsData));
  262. this.droppost.DisplayMember = "POSTNAME";
  263. this.droppost.ValueMember = "POSTID";
  264. this.droppost.DataSource = (DataTable)DoAsync(new BaseAsyncMethod(this.GetPostData));
  265. #endregion
  266. // 获取用户信息数据集
  267. DataSet dsGetRowData = (DataSet)DoAsync(new BaseAsyncMethod(this.GetRowData));
  268. if (dsGetRowData != null && dsGetRowData.Tables.Count > Constant.INT_IS_ZERO)
  269. {
  270. // 编辑数据 给页面所有项赋值
  271. if (this._editStatus == Constant.FormMode.Edit && dsGetRowData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  272. {
  273. DataRow staffData = dsGetRowData.Tables[0].Rows[0];
  274. this.txtStaffCode.Text = staffData["StaffCode"].ToString();
  275. this.txtStaffCode.Enabled = false;
  276. this.txtStaffName.Text = staffData["StaffName"].ToString();
  277. this.txtIDCardNo.Text = staffData["IDCardNo"].ToString();
  278. if (staffData["Birthday"] != DBNull.Value)
  279. this.txtBirthday.Value = Convert.ToDateTime(staffData["Birthday"]);
  280. this.dropGender.SelectedValue = staffData["Gender"].ToString();
  281. this.dropMaritalStatus.SelectedValue = staffData["MaritalStatus"].ToString();
  282. this.txtHomeTown.Text = staffData["HomeTown"].ToString();
  283. this.txtPolicitalStatus.Text = staffData["PolicitalStatus"].ToString();
  284. this.dropNational.SelectedValue = staffData["National"].ToString();
  285. this.dropEducational.SelectedValue = staffData["Educational"].ToString();
  286. this.txtGraduated.Text = staffData["Graduated"].ToString();
  287. this.txtSpecialField.Text = staffData["SpecialField"].ToString();
  288. this.txtTelephone.Text = staffData["Telephone"].ToString();
  289. this.txtHeight.Text = staffData["Height"].ToString();
  290. this.txtBloodGroup.Text = staffData["BloodGroup"].ToString();
  291. this.txtEmail.Text = staffData["Email"].ToString();
  292. this.txtWeight.Text = staffData["Weight"].ToString();
  293. if (staffData["JoinPartyDate"] != DBNull.Value)
  294. {
  295. this.cbJoinPartyDate.Checked = true;
  296. this.txtJoinPartyDate.Enabled = true;
  297. this.txtJoinPartyDate.Value = Convert.ToDateTime(staffData["JoinPartyDate"]);
  298. }
  299. this.txtOpeningBank.Text = staffData["OpeningBank"].ToString();
  300. this.txtAccountNo.Text = staffData["AccountNo"].ToString();
  301. this.chkLaidOff.Checked = Convert.ToBoolean(Convert.ToInt32(staffData["LaidOff"]));
  302. this.chkDisability.Checked = Convert.ToBoolean(Convert.ToInt32(staffData["Disability"]));
  303. this.txtAddress.Text = staffData["Address"].ToString();
  304. this.txtRemarks.Text = staffData["Remarks"].ToString();
  305. this.PTimeStamp = Convert.ToDateTime(staffData["OPTimeStamp"]);
  306. if (staffData["staffstatusname"] != DBNull.Value)
  307. {
  308. this.lblStaffStatusName.Text = staffData["staffstatusname"].ToString();
  309. }
  310. //this.dkOrganizationSearch.Text = staffData["organizationname"].ToString();
  311. //this.dkOrganizationSearch.OrganizationID = Convert.ToInt32(staffData["OrganizationID"]);
  312. this.scbOrganization.InitValue(staffData["organizationname"].ToString()
  313. , Convert.ToInt32(staffData["OrganizationID"]));
  314. this.dropJobs.SelectedValue = staffData["Jobs"].ToString();
  315. this.droppost.SelectedValue = staffData["Post"].ToString();
  316. //if (staffData["StaffStatus"].ToString() != Constant.INT_IS_ZERO.ToString())
  317. // {
  318. // //入职后才有的三个属性
  319. // if (staffData["jobsname"] != DBNull.Value)
  320. // {
  321. // this.lblJobsName.Text = staffData["jobsname"].ToString();
  322. // }
  323. // if (staffData["organizationname"] != DBNull.Value)
  324. // {
  325. // this.lblOrganizationName.Text = staffData["organizationname"].ToString();
  326. // }
  327. // if (staffData["postname"] != DBNull.Value)
  328. // {
  329. // this.lblPostName.Text = staffData["postname"].ToString();
  330. // }
  331. // }
  332. }
  333. DataSet dsImg = (DataSet)DoAsync(new BaseAsyncMethod(this.GetImageByStaffId));
  334. BindByteImage(dsImg);
  335. }
  336. }
  337. catch (Exception ex)
  338. {
  339. // 对异常进行共通处理
  340. ExceptionManager.HandleEventException(this.ToString(),
  341. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  342. }
  343. }
  344. /// <summary>
  345. /// 上传图片
  346. /// </summary>
  347. /// <param name="sender"></param>
  348. /// <param name="e"></param>
  349. private void btnUpload_Click(object sender, EventArgs e)
  350. {
  351. try
  352. {
  353. this.odlgFile.Filter = Constant.FILTER_PIC;
  354. this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  355. this.odlgFile.RestoreDirectory = true;
  356. this.odlgFile.Title = "选择员工图片";
  357. this.odlgFile.FileName = null;
  358. this.odlgFile.RestoreDirectory = true;
  359. if (this.odlgFile.ShowDialog() == DialogResult.OK)
  360. {
  361. FileInfo file = new FileInfo(odlgFile.FileName);
  362. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  363. {
  364. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "员工图片", "大小", "1M"),
  365. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  366. }
  367. else
  368. {
  369. Image PicImage = Image.FromStream(file.OpenRead());
  370. this.pic.Image = PicImage;
  371. //_PicByte.Add(ImageToByte(PicImage));
  372. //GetThumbnail(file);
  373. //BindImg();
  374. }
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. // 对异常进行共通处理
  380. ExceptionManager.HandleEventException(this.ToString(),
  381. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  382. }
  383. }
  384. /// <summary>
  385. /// 删除图片按钮事件
  386. /// </summary>
  387. /// <param name="sender"></param>
  388. /// <param name="e"></param>
  389. private void btnDelete_Click(object sender, EventArgs e)
  390. {
  391. try
  392. {
  393. this.pic.Image = Dongke.IBOSS.PRD.Client.HRModule.Properties.Resources.nopic;
  394. }
  395. catch (Exception ex)
  396. {
  397. // 对异常进行共通处理
  398. ExceptionManager.HandleEventException(this.ToString(),
  399. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  400. }
  401. //foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  402. //{
  403. // int index = lvSelect.Index;
  404. // if (index < Constant.INT_IS_ZERO)
  405. // {
  406. // index = Constant.INT_IS_ZERO;
  407. // }
  408. // this.ilPic.Images.RemoveAt(index);
  409. // this._PicByte.RemoveAt(index);
  410. // this._smallByte.RemoveAt(index);
  411. // this.lvPic.Items.RemoveAt(index);
  412. // if (index < this._imgList.Count)
  413. // {
  414. // if (this._imgList[index].StaffPhotoID != Constant.INT_IS_ZERO)
  415. // {
  416. // StaffPhotoEntity deleteImgEntity = this._imgList[index];
  417. // this._imgList[index].ValueFlag = Constant.INT_IS_ZERO;
  418. // this._updateImgList.Add(deleteImgEntity);
  419. // this._imgList.RemoveAt(index);
  420. // }
  421. // }
  422. //}
  423. //BindImg();
  424. }
  425. /// <summary>
  426. /// 取消按钮
  427. /// </summary>
  428. /// <param name="sender"></param>
  429. /// <param name="e"></param>
  430. private void btnCancel_Click(object sender, EventArgs e)
  431. {
  432. if (this._staffIDList != null && this._staffIDList.Count > 0)
  433. {
  434. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  435. }
  436. else
  437. {
  438. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  439. }
  440. }
  441. /// <summary>
  442. /// 身份证号离开事件
  443. /// </summary>
  444. /// <param name="sender"></param>
  445. /// <param name="e"></param>
  446. private void txtIDCardNo_Leave(object sender, EventArgs e)
  447. {
  448. try
  449. {
  450. if (this.txtIDCardNo.Text.Trim() != string.Empty)
  451. {
  452. string BirStr = this.txtIDCardNo.Text.Substring(6, 8);
  453. DateTime BirDate = Convert.ToDateTime(BirStr.Substring(0, 4) + "/" + BirStr.Substring(4, 2)
  454. + "/" + BirStr.Substring(6, 2));
  455. this.txtBirthday.Text = BirDate.ToString();
  456. }
  457. }
  458. catch
  459. {
  460. this.txtIDCardNo.Focus();
  461. // 提示信息
  462. MessageBox.Show("身份证号不合法,请重新输入!",
  463. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  464. }
  465. }
  466. /// <summary>
  467. /// 入党日期选中改变事件
  468. /// </summary>
  469. /// <param name="sender"></param>
  470. /// <param name="e"></param>
  471. private void cbJoinPartyDate_CheckedChanged(object sender, EventArgs e)
  472. {
  473. this.txtJoinPartyDate.Enabled = this.cbJoinPartyDate.Checked;
  474. }
  475. #endregion
  476. #region 私有方法
  477. /// <summary>
  478. /// 验证输入格式是否正确
  479. /// </summary>
  480. /// <returns></returns>
  481. private bool CheckInputValidity()
  482. {
  483. if (string.IsNullOrEmpty(this.txtStaffCode.Text.Trim()))
  484. {
  485. this.txtStaffCode.IsMustInput = true;
  486. this.txtStaffCode.Focus();
  487. return false;
  488. }
  489. this.txtStaffCode.IsMustInput = false;
  490. if (string.IsNullOrEmpty(this.txtStaffName.Text.Trim()))
  491. {
  492. this.txtStaffName.IsMustInput = true;
  493. this.txtStaffName.Focus();
  494. return false;
  495. }
  496. this.txtStaffName.IsMustInput = false;
  497. //所属部门
  498. if (this.scbOrganization.SearchedPKMember == 0)
  499. {
  500. // 提示信息
  501. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "所属部门"),
  502. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  503. this.scbOrganization.Focus();
  504. return false;
  505. }
  506. //工种
  507. if (this.dropJobs.SelectedValue == null || this.dropJobs.SelectedValue.ToString() == string.Empty)
  508. {
  509. this.dropJobs.IsMustInput = true;
  510. this.dropJobs.Focus();
  511. return false;
  512. }
  513. //职务
  514. if (this.droppost.SelectedValue == null || this.droppost.SelectedValue.ToString() == string.Empty)
  515. {
  516. this.droppost.IsMustInput = true;
  517. this.droppost.Focus();
  518. return false;
  519. }
  520. this.dropNational.IsMustInput = false;
  521. return true;
  522. }
  523. /// <summary>
  524. /// 根据页面输入值,给员工对象实体赋值
  525. /// </summary>
  526. /// <returns></returns>
  527. private StaffEntity SetStaffEntity()
  528. {
  529. StaffEntity staffEntity = new StaffEntity();
  530. staffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  531. staffEntity.StaffName = this.txtStaffName.Text.Trim();
  532. staffEntity.IDCardNo = this.txtIDCardNo.Text;
  533. if (!txtBirthday.Text.Trim().Contains("1900"))
  534. staffEntity.Birthday = txtBirthday.Value;
  535. staffEntity.Gender = Constant.INT_IS_ZERO.ToString();
  536. staffEntity.MaritalStatus = Constant.INT_IS_ZERO;
  537. staffEntity.HomeTown = txtHomeTown.Text.Trim();
  538. staffEntity.PolicitalStatus = txtPolicitalStatus.Text.Trim();
  539. staffEntity.National = Constant.INT_IS_ZERO;
  540. staffEntity.Educational = Constant.INT_IS_ZERO;
  541. staffEntity.Graduated = txtGraduated.Text.Trim();
  542. staffEntity.SpecialField = txtSpecialField.Text.Trim();
  543. staffEntity.Telephone = txtTelephone.Text.Trim();
  544. staffEntity.Height = txtHeight.Text.Trim() == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(txtHeight.Text);
  545. staffEntity.BloodGroup = txtBloodGroup.Text.Trim();
  546. staffEntity.Weight = txtWeight.Text.Trim() == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(txtWeight.Text);
  547. staffEntity.Address = txtAddress.Text;
  548. staffEntity.LaidOff = chkLaidOff.Checked;
  549. staffEntity.Disability = chkDisability.Checked;
  550. if (!txtJoinPartyDate.Text.Trim().Contains("1900"))
  551. staffEntity.JoinPartyDate = txtJoinPartyDate.Value;
  552. staffEntity.Email = txtEmail.Text.Trim();
  553. staffEntity.OpeningBank = txtOpeningBank.Text.Trim();
  554. staffEntity.AccountNo = txtAccountNo.Text.Trim();
  555. staffEntity.Remarks = txtRemarks.Text.Trim();
  556. // 员工档案新建保存后,直接是入职状态
  557. //staffEntity.StaffStatus = Constant.INT_IS_ZERO;
  558. staffEntity.StaffStatus = Constant.INT_IS_TWO;
  559. staffEntity.ValueFlag = true;
  560. //所属部门
  561. staffEntity.OrganizationID = scbOrganization.SearchedPKMember;
  562. //职务
  563. staffEntity.Post = Convert.ToInt32(droppost.SelectedValue);
  564. //原工种
  565. staffEntity.Jobs = Convert.ToInt32(dropJobs.SelectedValue);
  566. return staffEntity;
  567. }
  568. /// <summary>
  569. /// 清空输入项
  570. /// </summary>
  571. private void InitializationForm()
  572. {
  573. this.scbOrganization.ClearValue();
  574. this.dropJobs.Text = "";
  575. this.dropJobs.SelectedValue = null;
  576. this.dropJobs.SelectedText = null;
  577. this.droppost.Text = "";
  578. this.droppost.SelectedValue = null;
  579. this.droppost.SelectedText = null;
  580. this.txtStaffCode.Text = "";
  581. this.txtStaffName.Text = "";
  582. this.txtIDCardNo.Text = "";
  583. this.txtBirthday.Value = new DateTime(1900, 1, 1);
  584. this.dropGender.Text = "";
  585. this.dropGender.SelectedValue = null;
  586. this.dropGender.SelectedText = null;
  587. this.dropMaritalStatus.Text = "";
  588. this.dropMaritalStatus.SelectedValue = null;
  589. this.dropMaritalStatus.SelectedText = null;
  590. this.txtHomeTown.Text = "";
  591. this.txtPolicitalStatus.Text = "";
  592. this.dropNational.Text = "";
  593. this.dropNational.SelectedValue = null;
  594. this.dropNational.SelectedText = null;
  595. this.dropEducational.Text = "";
  596. this.dropEducational.SelectedValue = null;
  597. this.dropEducational.SelectedText = null;
  598. this.txtGraduated.Text = "";
  599. this.txtSpecialField.Text = "";
  600. this.txtTelephone.Text = "";
  601. this.txtHeight.Text = "";
  602. this.txtBloodGroup.Text = "";
  603. this.txtEmail.Text = "";
  604. this.txtWeight.Text = "";
  605. this.txtJoinPartyDate.Value = new DateTime(1900, 1, 1);
  606. this.txtOpeningBank.Text = "";
  607. this.txtAccountNo.Text = "";
  608. this.chkLaidOff.Checked = false;
  609. this.chkDisability.Checked = false;
  610. this.txtAddress.Text = "";
  611. this.txtRemarks.Text = "";
  612. this.pic.Image = Dongke.IBOSS.PRD.Client.HRModule.Properties.Resources.nopic;
  613. /*
  614. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  615. {
  616. int index = lvSelect.Index;
  617. if (index < Constant.INT_IS_ZERO)
  618. {
  619. index = Constant.INT_IS_ZERO;
  620. }
  621. this.ilPic.Images.RemoveAt(index);
  622. this._PicByte.RemoveAt(index);
  623. this._smallByte.RemoveAt(index);
  624. this.lvPic.Items.RemoveAt(index);
  625. if (index < this._imgList.Count)
  626. {
  627. if (this._imgList[index].StaffPhotoID != Constant.INT_IS_ZERO)
  628. {
  629. StaffPhotoEntity deleteImgEntity = this._imgList[index];
  630. this._imgList[index].ValueFlag = Constant.INT_IS_ZERO;
  631. this._updateImgList.Add(deleteImgEntity);
  632. this._imgList.RemoveAt(index);
  633. }
  634. }
  635. }*/
  636. //BindImg();
  637. //this.lvPic.Items.Clear();
  638. }
  639. /// <summary>
  640. /// 编辑员工档案
  641. /// </summary>
  642. /// <returns></returns>
  643. private HRResultEntity EditStaffInfo()
  644. {
  645. try
  646. {
  647. /*
  648. //首先将未修改的图片从集合中删除
  649. for (int i = 0; i < _imgList.Count; i++)
  650. {
  651. this._PicByte.RemoveAt(Constant.INT_IS_ZERO);
  652. _smallByte.RemoveAt(Constant.INT_IS_ZERO);
  653. }
  654. _imgList.Clear();
  655. //循环插入图片
  656. for (int i = 0; i < _PicByte.Count; i++)
  657. {
  658. StaffPhotoEntity imgEntity = new StaffPhotoEntity();
  659. imgEntity.ValueFlag = Constant.INT_IS_ONE;
  660. byte[] buffer = _PicByte[i];
  661. imgEntity.Photo = buffer;
  662. imgEntity.Thumbnail = _smallByte[i];
  663. this._imgList.Add(imgEntity);
  664. }
  665. //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
  666. if (_updateImgList.Count != 0)
  667. {
  668. for (int i = Constant.INT_IS_ZERO; i < _updateImgList.Count; i++)
  669. {
  670. StaffPhotoEntity updateImgEntity = _updateImgList[i];
  671. _imgList.Add(updateImgEntity);
  672. }
  673. }
  674. */
  675. List<StaffPhotoEntity> staffPhoto = new List<StaffPhotoEntity>();
  676. #region Image to byte
  677. byte[] data = null;
  678. using (MemoryStream ms = new MemoryStream())
  679. {
  680. using (Bitmap Bitmap = new Bitmap(this.pic.Image))
  681. {
  682. Bitmap.Save(ms, ImageFormat.Jpeg);
  683. ms.Position = 0;
  684. data = new byte[ms.Length];
  685. ms.Read(data, 0, Convert.ToInt32(ms.Length));
  686. ms.Flush();
  687. }
  688. }
  689. #endregion
  690. staffPhoto.Add(new StaffPhotoEntity() { Photo = data });
  691. return HRModuleProxy.Service.EditStaffInfo(_staffEntity, staffPhoto);
  692. }
  693. catch (Exception ex)
  694. {
  695. throw ex;
  696. }
  697. }
  698. /// <summary>
  699. /// 添加员工档案
  700. /// </summary>
  701. /// <returns></returns>
  702. private object AddStaffInfo()
  703. {
  704. try
  705. {
  706. /*
  707. //首先将未修改的图片从集合中删除
  708. for (int i = 0; i < _imgList.Count; i++)
  709. {
  710. _PicByte.RemoveAt(Constant.INT_IS_ZERO);
  711. _smallByte.RemoveAt(Constant.INT_IS_ZERO);
  712. }
  713. _imgList.Clear();
  714. //循环插入图片
  715. for (int i = 0; i < _PicByte.Count; i++)
  716. {
  717. StaffPhotoEntity imgEntity = new StaffPhotoEntity();
  718. imgEntity.ValueFlag = Constant.INT_IS_ONE;
  719. byte[] buffer = _PicByte[i];
  720. imgEntity.Photo = buffer;
  721. imgEntity.Thumbnail = _smallByte[i];
  722. _imgList.Add(imgEntity);
  723. }
  724. //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
  725. if (_updateImgList.Count != Constant.INT_IS_ZERO)
  726. {
  727. for (int i = 0; i < _updateImgList.Count; i++)
  728. {
  729. StaffPhotoEntity updateImgEntity = _updateImgList[i];
  730. this._imgList.Add(updateImgEntity);
  731. }
  732. }*/
  733. List<StaffPhotoEntity> staffPhoto = new List<StaffPhotoEntity>();
  734. #region Image to byte
  735. byte[] data = null;
  736. using (MemoryStream ms = new MemoryStream())
  737. {
  738. using (Bitmap Bitmap = new Bitmap(this.pic.Image))
  739. {
  740. Bitmap.Save(ms, ImageFormat.Jpeg);
  741. ms.Position = 0;
  742. data = new byte[ms.Length];
  743. ms.Read(data, 0, Convert.ToInt32(ms.Length));
  744. ms.Flush();
  745. }
  746. }
  747. #endregion
  748. staffPhoto.Add(new StaffPhotoEntity() { Photo = data });
  749. return HRModuleProxy.Service.AddStaffInfo(_staffEntity, staffPhoto);
  750. }
  751. catch (Exception ex)
  752. {
  753. throw ex;
  754. }
  755. }
  756. /// <summary>
  757. /// 是否存在相同的员工编码
  758. /// </summary>
  759. /// <returns></returns>
  760. private DataSet IsExistsStaffCode()
  761. {
  762. try
  763. {
  764. return HRModuleProxy.Service.IsExistsStaffCode(this.txtStaffCode.Text);
  765. }
  766. catch (Exception ex)
  767. {
  768. throw ex;
  769. }
  770. }
  771. /// <summary>
  772. /// 获取明细数据
  773. /// </summary>
  774. /// <returns></returns>
  775. private DataSet GetRowData()
  776. {
  777. try
  778. {
  779. return HRModuleProxy.Service.GetRowData(StaffID);
  780. }
  781. catch (Exception ex)
  782. {
  783. throw ex;
  784. }
  785. }
  786. /// <summary>
  787. /// 获取员工图片
  788. /// </summary>
  789. /// <returns></returns>
  790. private DataSet GetImageByStaffId()
  791. {
  792. try
  793. {
  794. return HRModuleProxy.Service.GetImageByStaffId(StaffID);
  795. }
  796. catch (Exception ex)
  797. {
  798. throw ex;
  799. }
  800. }
  801. /// <summary>
  802. /// 将图片文件转换成二进制
  803. /// </summary>
  804. /// <param name="img"></param>
  805. /// <returns></returns>
  806. public static byte[] ImageToByte(Image img)
  807. {
  808. byte[] smallbuffer = null;
  809. using (MemoryStream ms = new MemoryStream())
  810. {
  811. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  812. ms.Position = Constant.INT_IS_ZERO;
  813. smallbuffer = new byte[ms.Length];
  814. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  815. ms.Flush();
  816. }
  817. return smallbuffer;
  818. }
  819. /// <SUMMARY>
  820. /// 重绘缩略图并把缩略图转为二进制储存
  821. /// </SUMMARY>
  822. /// <PARAM name="sourceFile">图片源路径</PARAM>
  823. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  824. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  825. /// <RETURNS></RETURNS>
  826. public void GetThumbnail(FileInfo sourceFile)
  827. {
  828. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  829. ImageFormat thisFormat = imgSource.RawFormat;
  830. int sW = 0, sH = 0;
  831. // 按比例缩放
  832. int sWidth = imgSource.Width;
  833. int sHeight = imgSource.Height;
  834. int destWidth = 100;
  835. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  836. if (sHeight > destHeight || sWidth > destWidth)
  837. {
  838. if ((sWidth * destHeight) > (sHeight * destWidth))
  839. {
  840. sW = destWidth;
  841. sH = (destWidth * sHeight) / sWidth;
  842. }
  843. else
  844. {
  845. sH = destHeight;
  846. sW = (sWidth * destHeight) / sHeight;
  847. }
  848. }
  849. else
  850. {
  851. sW = sWidth;
  852. sH = sHeight;
  853. }
  854. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  855. Graphics g = Graphics.FromImage(outBmp);
  856. g.Clear(Color.Black);
  857. // 设置画布的描绘质量
  858. g.CompositingQuality = CompositingQuality.HighQuality;
  859. g.SmoothingMode = SmoothingMode.HighQuality;
  860. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  861. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  862. g.Dispose();
  863. //将重绘的图片转为二进制并保存
  864. Image image = (Image)outBmp;
  865. byte[] smallbuffer = ImageToByte(image);
  866. _smallByte.Add(smallbuffer);
  867. imgSource.Dispose();
  868. outBmp.Dispose();
  869. }
  870. /// <summary>
  871. /// 绑定缩略图到控件中
  872. /// </summary>
  873. protected void BindImg()
  874. {
  875. //每次绑定要清空数据源
  876. this.ilPic.Images.Clear();
  877. //将缩略图二进制集合中的数据转换成图片文件
  878. List<Image> LSImageList = new List<Image>();
  879. foreach (byte[] smallby in _smallByte)
  880. {
  881. LSImageList.Add(byteArrayToImage(smallby));
  882. }
  883. //添加数据源
  884. foreach (Image img in LSImageList)
  885. {
  886. ilPic.Images.Add(img);
  887. }
  888. //this.ilPic.ImageSize = new Size(100, 100);
  889. //this.lvPic.LargeImageList = this.ilPic;
  890. //this.lvPic.BeginUpdate();
  891. ////清空列表的数据源
  892. //lvPic.Items.Clear();
  893. ////添加列表的数据源
  894. //for (int i = 0; i < ilPic.Images.Count; i++)
  895. //{
  896. // ListViewItem lvi = new ListViewItem();
  897. // lvi.ImageIndex = i;
  898. // this.lvPic.Items.Add(lvi);
  899. //}
  900. //this.lvPic.EndUpdate();
  901. }
  902. /// <summary>
  903. /// 根据原图片宽高比获取缩略图的高(根据宽)
  904. /// </summary>
  905. /// <param name="BigWidth"></param>
  906. /// <param name="BigHeight"></param>
  907. /// <param name="SmallWidth"></param>
  908. /// <returns></returns>
  909. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  910. {
  911. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  912. return Convert.ToInt32(SmallWidth / scale);
  913. }
  914. /// <summary>
  915. /// 将数据库中的二进制转换成图片
  916. /// </summary>
  917. /// <param name="data"></param>
  918. /// <returns></returns>
  919. public static Image byteArrayToImage(object data)
  920. {
  921. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  922. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  923. return returnImage;
  924. }
  925. /// <summary>
  926. /// 绑定并显示图片
  927. /// </summary>
  928. /// <param name="ImageData"></param>
  929. protected void BindByteImage(DataSet ImageData)
  930. {
  931. foreach (DataRow dr in ImageData.Tables[0].Rows)
  932. {
  933. //将数据库中的缩略图取出
  934. //_smallByte.Add((byte[])dr[2]);
  935. //_PicByte.Add((byte[])dr[3]);
  936. MemoryStream ms = new MemoryStream((byte[])dr[3]);
  937. Image img = Image.FromStream(ms);
  938. this.pic.Image = img;
  939. //绑定实体到修改图片集合中
  940. StaffPhotoEntity imgEntity = new StaffPhotoEntity();
  941. imgEntity.StaffPhotoID = Convert.ToInt32(dr[0]);
  942. imgEntity.StaffID = Convert.ToInt32(dr[1]);
  943. imgEntity.Thumbnail = (byte[])dr[2];
  944. imgEntity.Photo = (byte[])dr[3];
  945. imgEntity.AccountID = Convert.ToInt32(dr[4]);
  946. imgEntity.ValueFlag = Convert.ToInt32(dr[5]);
  947. imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
  948. imgEntity.CreateUserID = Convert.ToInt32(dr[7]);
  949. imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
  950. imgEntity.UpdateUserID = Convert.ToInt32(dr[9]);
  951. imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
  952. _imgList.Add(imgEntity);
  953. }
  954. //绑定缩略图
  955. //BindImg();
  956. }
  957. /// <summary>
  958. /// 获取性别数据源
  959. /// </summary>
  960. /// <returns></returns>
  961. private DataTable GetSystemParameterByName()
  962. {
  963. DataTable dtSystemParameterByName = null;
  964. try
  965. {
  966. dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Gender, "displayno ASC");
  967. }
  968. catch (Exception ex)
  969. {
  970. // 对异常进行共通处理
  971. ExceptionManager.HandleEventException(this.ToString(),
  972. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  973. }
  974. return dtSystemParameterByName;
  975. }
  976. /// <summary>
  977. /// 获取婚姻状况数据源
  978. /// </summary>
  979. /// <returns></returns>
  980. private DataTable GetSystemParameterByNameMaritalStatu()
  981. {
  982. DataTable dtSystemParameterByName = null;
  983. try
  984. {
  985. dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_MaritalStatus, "displayno ASC");
  986. }
  987. catch (Exception ex)
  988. {
  989. // 对异常进行共通处理
  990. ExceptionManager.HandleEventException(this.ToString(),
  991. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  992. }
  993. return dtSystemParameterByName;
  994. }
  995. /// <summary>
  996. /// 获取民族数据源
  997. /// </summary>
  998. /// <returns></returns>
  999. private DataTable GetSystemParameterByNameNational()
  1000. {
  1001. DataTable dtSystemParameterByName = null;
  1002. try
  1003. {
  1004. return LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_National, "displayno ASC");
  1005. }
  1006. catch (Exception ex)
  1007. {
  1008. // 对异常进行共通处理
  1009. ExceptionManager.HandleEventException(this.ToString(),
  1010. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1011. }
  1012. return dtSystemParameterByName;
  1013. }
  1014. /// <summary>
  1015. /// 获取学历数据源
  1016. /// </summary>
  1017. /// <returns></returns>
  1018. private DataTable GetSystemParameterByNameEducational()
  1019. {
  1020. DataTable dtSystemParameterByName = null;
  1021. try
  1022. {
  1023. dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Educational, "displayno ASC");
  1024. }
  1025. catch (Exception ex)
  1026. {
  1027. // 对异常进行共通处理
  1028. ExceptionManager.HandleEventException(this.ToString(),
  1029. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1030. }
  1031. return dtSystemParameterByName;
  1032. }
  1033. /// <summary>
  1034. /// 获取工种数据
  1035. /// </summary>
  1036. /// <returns></returns>
  1037. private DataTable GetJobsData()
  1038. {
  1039. DataTable returntJobsData = null;
  1040. try
  1041. {
  1042. returntJobsData = SystemModuleProxy.Service.GetJobsData(0).Tables[0];
  1043. }
  1044. catch (Exception ex)
  1045. {
  1046. // 对异常进行共通处理
  1047. ExceptionManager.HandleEventException(this.ToString(),
  1048. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1049. }
  1050. return returntJobsData;
  1051. }
  1052. /// <summary>
  1053. /// 获取职务数据
  1054. /// </summary>
  1055. /// <returns></returns>
  1056. private DataTable GetPostData()
  1057. {
  1058. DataTable returntPostData = null;
  1059. try
  1060. {
  1061. returntPostData = SystemModuleProxy.Service.GetPostData(0).Tables[0];
  1062. }
  1063. catch (Exception ex)
  1064. {
  1065. // 对异常进行共通处理
  1066. ExceptionManager.HandleEventException(this.ToString(),
  1067. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1068. }
  1069. return returntPostData;
  1070. }
  1071. #endregion
  1072. }
  1073. }