| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_HR_0102.cs
- * 2.功能描述:新建/编辑员工档案
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2014/09/12 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
- namespace Dongke.IBOSS.PRD.Client.HRModule
- {
- /// <summary>
- /// 新建/编辑员工档案
- /// </summary>
- public partial class F_HR_0102 : FormBase
- {
- #region 成员变量
- // 页面传过来员工ID
- private int _staffID;
- // 用户实体类
- private StaffEntity _staffEntity;
- // 编辑状态
- private Constant.FormMode _editStatus;
- // 新建的员工ID集合
- private List<int> _staffIDList = new List<int>();
- // 时间戳
- private DateTime _optimestamp;
- // 图片字节集
- private List<byte[]> _PicByte = new List<byte[]>();
- // 缩略图片字节集
- private List<byte[]> _smallByte = new List<byte[]>();
- // 图片实体集合
- private List<StaffPhotoEntity> _imgList = new List<StaffPhotoEntity>();
- // 已存在的图片实体集合(修改)
- private List<StaffPhotoEntity> _updateImgList = new List<StaffPhotoEntity>();
- #endregion
- #region 构造函数
- public F_HR_0102()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="frmStatus">窗体状态</param>
- public F_HR_0102(Constant.FormMode frmStatus)
- {
- InitializeComponent();
- _editStatus = frmStatus;
- // 设置窗口标题,当为新建状态时显示新建员工,当为编辑状态时显示编辑员工
- if (frmStatus == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_HR_0102_ADD;
- }
- else if (frmStatus == Constant.FormMode.Edit)
- {
- this.Text = FormTitles.F_HR_0102_EDIT;
- this.txtStaffCode.Enabled = false;
- }
- // 工具栏按钮文本赋值
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this.btnUpload.Text = ButtonText.BTN_UPLOAD;
- this.btnDelete.Text = ButtonText.BTN_DELETE;
- #region 绑定数据源
- // 性别
- DataTable dtT_SYS_Gender = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByName));
- this.dropGender.DisplayMember = "GenderName";
- this.dropGender.ValueMember = "GenderCode";
- this.dropGender.DataSource = dtT_SYS_Gender;
- // 婚姻状况
- DataTable dtT_SYS_MaritalStatus = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameMaritalStatu));
- this.dropMaritalStatus.DisplayMember = "maritalstatusname";
- this.dropMaritalStatus.ValueMember = "maritalstatusid";
- this.dropMaritalStatus.DataSource = dtT_SYS_MaritalStatus;
- // 民族
- DataTable dtT_SYS_National = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameNational));
- this.dropNational.DisplayMember = "nationalname";
- this.dropNational.ValueMember = "nationalid";
- this.dropNational.DataSource = dtT_SYS_National;
- // 学历
- DataTable dtT_SYS_Educational = (DataTable)DoAsync(new BaseAsyncMethod(GetSystemParameterByNameEducational));
- this.dropEducational.DisplayMember = "educationalname";
- this.dropEducational.ValueMember = "educationalid";
- this.dropEducational.DataSource = dtT_SYS_Educational;
- #endregion
- }
- #endregion
- #region 属性
- /// <summary>
- /// 页面传过来的员工ID
- /// </summary>
- public int StaffID
- {
- get
- {
- return this._staffID;
- }
- set
- {
- this._staffID = value;
- }
- }
- /// <summary>
- /// 员工ID集合
- /// </summary>
- public List<int> StaffIDList
- {
- get
- {
- return _staffIDList;
- }
- set
- {
- _staffIDList = value;
- }
- }
- /// <summary>
- /// 时间戳
- /// </summary>
- public DateTime PTimeStamp
- {
- get
- {
- return _optimestamp;
- }
- set
- {
- _optimestamp = value;
- }
- }
- #endregion
- #region 按钮事件
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- // 验证输入是否正确
- if (!this.CheckInputValidity())
- {
- return;
- }
- this._staffEntity = this.SetStaffEntity();
- if (this._editStatus == Constant.FormMode.Add)
- {
- if (this.txtStaffCode.Text.Trim() != string.Empty)
- {
- // 判断是否存在重复的员工编号
- DataSet staffCodeData = (DataSet)DoAsync(new BaseAsyncMethod(this.IsExistsStaffCode));
- if (staffCodeData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W011, this.txtStaffCode.Text.Trim(), "员工编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtStaffCode.Focus();
- return;
- }
- }
- // 新建用户,返回新建的员工ID
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- HRResultEntity returnStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(this.AddStaffInfo));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- if (returnStaff.OperateStatus > Constant.INT_IS_ZERO)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this._staffIDList.Add(returnStaff.HRStaffID);
- this.InitializationForm();
- }
- else if (returnStaff.OperateStatus == Constant.INT_IS_NEGATIE_THREE)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W012, "新建员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "新建员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else
- {
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- this._staffEntity.StaffID = StaffID;
- this._staffEntity.OPTimeStamp = PTimeStamp;
- HRResultEntity returnStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(this.EditStaffInfo));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- if (returnStaff.OperateStatus > Constant.INT_IS_ZERO)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "编辑员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- //this._staffIDList.Add(returnStaff.HRStaffID);
- this.InitializationForm();
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- else if (returnStaff.OperateStatus == Constant.INT_IS_NEGATIE_THREE)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W012, "编辑员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "编辑员工", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_HR_0102_Load(object sender, EventArgs e)
- {
- try
- {
- // 加载权限
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- #region 绑定工种职务数据源
- this.dropJobs.DisplayMember = "JOBSNAME";
- this.dropJobs.ValueMember = "JOBSID";
- this.dropJobs.DataSource = (DataTable)DoAsync(new BaseAsyncMethod(this.GetJobsData));
- this.droppost.DisplayMember = "POSTNAME";
- this.droppost.ValueMember = "POSTID";
- this.droppost.DataSource = (DataTable)DoAsync(new BaseAsyncMethod(this.GetPostData));
- #endregion
- // 获取用户信息数据集
- DataSet dsGetRowData = (DataSet)DoAsync(new BaseAsyncMethod(this.GetRowData));
- if (dsGetRowData != null && dsGetRowData.Tables.Count > Constant.INT_IS_ZERO)
- {
- // 编辑数据 给页面所有项赋值
- if (this._editStatus == Constant.FormMode.Edit && dsGetRowData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow staffData = dsGetRowData.Tables[0].Rows[0];
- this.txtStaffCode.Text = staffData["StaffCode"].ToString();
- this.txtStaffCode.Enabled = false;
- this.txtStaffName.Text = staffData["StaffName"].ToString();
- this.txtIDCardNo.Text = staffData["IDCardNo"].ToString();
- if (staffData["Birthday"] != DBNull.Value)
- this.txtBirthday.Value = Convert.ToDateTime(staffData["Birthday"]);
- this.dropGender.SelectedValue = staffData["Gender"].ToString();
- this.dropMaritalStatus.SelectedValue = staffData["MaritalStatus"].ToString();
- this.txtHomeTown.Text = staffData["HomeTown"].ToString();
- this.txtPolicitalStatus.Text = staffData["PolicitalStatus"].ToString();
- this.dropNational.SelectedValue = staffData["National"].ToString();
- this.dropEducational.SelectedValue = staffData["Educational"].ToString();
- this.txtGraduated.Text = staffData["Graduated"].ToString();
- this.txtSpecialField.Text = staffData["SpecialField"].ToString();
- this.txtTelephone.Text = staffData["Telephone"].ToString();
- this.txtHeight.Text = staffData["Height"].ToString();
- this.txtBloodGroup.Text = staffData["BloodGroup"].ToString();
- this.txtEmail.Text = staffData["Email"].ToString();
- this.txtWeight.Text = staffData["Weight"].ToString();
- if (staffData["JoinPartyDate"] != DBNull.Value)
- {
- this.cbJoinPartyDate.Checked = true;
- this.txtJoinPartyDate.Enabled = true;
- this.txtJoinPartyDate.Value = Convert.ToDateTime(staffData["JoinPartyDate"]);
- }
- this.txtOpeningBank.Text = staffData["OpeningBank"].ToString();
- this.txtAccountNo.Text = staffData["AccountNo"].ToString();
- this.chkLaidOff.Checked = Convert.ToBoolean(Convert.ToInt32(staffData["LaidOff"]));
- this.chkDisability.Checked = Convert.ToBoolean(Convert.ToInt32(staffData["Disability"]));
- this.txtAddress.Text = staffData["Address"].ToString();
- this.txtRemarks.Text = staffData["Remarks"].ToString();
- this.PTimeStamp = Convert.ToDateTime(staffData["OPTimeStamp"]);
- if (staffData["staffstatusname"] != DBNull.Value)
- {
- this.lblStaffStatusName.Text = staffData["staffstatusname"].ToString();
- }
- //this.dkOrganizationSearch.Text = staffData["organizationname"].ToString();
- //this.dkOrganizationSearch.OrganizationID = Convert.ToInt32(staffData["OrganizationID"]);
- this.scbOrganization.InitValue(staffData["organizationname"].ToString()
- , Convert.ToInt32(staffData["OrganizationID"]));
- this.dropJobs.SelectedValue = staffData["Jobs"].ToString();
- this.droppost.SelectedValue = staffData["Post"].ToString();
- //if (staffData["StaffStatus"].ToString() != Constant.INT_IS_ZERO.ToString())
- // {
- // //入职后才有的三个属性
- // if (staffData["jobsname"] != DBNull.Value)
- // {
- // this.lblJobsName.Text = staffData["jobsname"].ToString();
- // }
- // if (staffData["organizationname"] != DBNull.Value)
- // {
- // this.lblOrganizationName.Text = staffData["organizationname"].ToString();
- // }
- // if (staffData["postname"] != DBNull.Value)
- // {
- // this.lblPostName.Text = staffData["postname"].ToString();
- // }
- // }
- }
- DataSet dsImg = (DataSet)DoAsync(new BaseAsyncMethod(this.GetImageByStaffId));
- BindByteImage(dsImg);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 上传图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnUpload_Click(object sender, EventArgs e)
- {
- try
- {
- this.odlgFile.Filter = Constant.FILTER_PIC;
- this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
- this.odlgFile.RestoreDirectory = true;
- this.odlgFile.Title = "选择员工图片";
- this.odlgFile.FileName = null;
- this.odlgFile.RestoreDirectory = true;
- if (this.odlgFile.ShowDialog() == DialogResult.OK)
- {
- FileInfo file = new FileInfo(odlgFile.FileName);
- if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "员工图片", "大小", "1M"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- Image PicImage = Image.FromStream(file.OpenRead());
- this.pic.Image = PicImage;
- //_PicByte.Add(ImageToByte(PicImage));
- //GetThumbnail(file);
- //BindImg();
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 删除图片按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelete_Click(object sender, EventArgs e)
- {
- try
- {
- this.pic.Image = Dongke.IBOSS.PRD.Client.HRModule.Properties.Resources.nopic;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- //foreach (ListViewItem lvSelect in lvPic.SelectedItems)
- //{
- // int index = lvSelect.Index;
- // if (index < Constant.INT_IS_ZERO)
- // {
- // index = Constant.INT_IS_ZERO;
- // }
- // this.ilPic.Images.RemoveAt(index);
- // this._PicByte.RemoveAt(index);
- // this._smallByte.RemoveAt(index);
- // this.lvPic.Items.RemoveAt(index);
- // if (index < this._imgList.Count)
- // {
- // if (this._imgList[index].StaffPhotoID != Constant.INT_IS_ZERO)
- // {
- // StaffPhotoEntity deleteImgEntity = this._imgList[index];
- // this._imgList[index].ValueFlag = Constant.INT_IS_ZERO;
- // this._updateImgList.Add(deleteImgEntity);
- // this._imgList.RemoveAt(index);
- // }
- // }
- //}
- //BindImg();
- }
- /// <summary>
- /// 取消按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- if (this._staffIDList != null && this._staffIDList.Count > 0)
- {
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- else
- {
- this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- }
- }
- /// <summary>
- /// 身份证号离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtIDCardNo_Leave(object sender, EventArgs e)
- {
- try
- {
- if (this.txtIDCardNo.Text.Trim() != string.Empty)
- {
- string BirStr = this.txtIDCardNo.Text.Substring(6, 8);
- DateTime BirDate = Convert.ToDateTime(BirStr.Substring(0, 4) + "/" + BirStr.Substring(4, 2)
- + "/" + BirStr.Substring(6, 2));
- this.txtBirthday.Text = BirDate.ToString();
- }
- }
- catch
- {
- this.txtIDCardNo.Focus();
- // 提示信息
- MessageBox.Show("身份证号不合法,请重新输入!",
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- /// <summary>
- /// 入党日期选中改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cbJoinPartyDate_CheckedChanged(object sender, EventArgs e)
- {
- this.txtJoinPartyDate.Enabled = this.cbJoinPartyDate.Checked;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 验证输入格式是否正确
- /// </summary>
- /// <returns></returns>
- private bool CheckInputValidity()
- {
- if (string.IsNullOrEmpty(this.txtStaffCode.Text.Trim()))
- {
- this.txtStaffCode.IsMustInput = true;
- this.txtStaffCode.Focus();
- return false;
- }
- this.txtStaffCode.IsMustInput = false;
- if (string.IsNullOrEmpty(this.txtStaffName.Text.Trim()))
- {
- this.txtStaffName.IsMustInput = true;
- this.txtStaffName.Focus();
- return false;
- }
- this.txtStaffName.IsMustInput = false;
- //所属部门
- if (this.scbOrganization.SearchedPKMember == 0)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "所属部门"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.scbOrganization.Focus();
- return false;
- }
- //工种
- if (this.dropJobs.SelectedValue == null || this.dropJobs.SelectedValue.ToString() == string.Empty)
- {
- this.dropJobs.IsMustInput = true;
- this.dropJobs.Focus();
- return false;
- }
- //职务
- if (this.droppost.SelectedValue == null || this.droppost.SelectedValue.ToString() == string.Empty)
- {
- this.droppost.IsMustInput = true;
- this.droppost.Focus();
- return false;
- }
- this.dropNational.IsMustInput = false;
- return true;
- }
- /// <summary>
- /// 根据页面输入值,给员工对象实体赋值
- /// </summary>
- /// <returns></returns>
- private StaffEntity SetStaffEntity()
- {
- StaffEntity staffEntity = new StaffEntity();
- staffEntity.StaffCode = this.txtStaffCode.Text.Trim();
- staffEntity.StaffName = this.txtStaffName.Text.Trim();
- staffEntity.IDCardNo = this.txtIDCardNo.Text;
- if (!txtBirthday.Text.Trim().Contains("1900"))
- staffEntity.Birthday = txtBirthday.Value;
- staffEntity.Gender = Constant.INT_IS_ZERO.ToString();
- staffEntity.MaritalStatus = Constant.INT_IS_ZERO;
- staffEntity.HomeTown = txtHomeTown.Text.Trim();
- staffEntity.PolicitalStatus = txtPolicitalStatus.Text.Trim();
- staffEntity.National = Constant.INT_IS_ZERO;
- staffEntity.Educational = Constant.INT_IS_ZERO;
- staffEntity.Graduated = txtGraduated.Text.Trim();
- staffEntity.SpecialField = txtSpecialField.Text.Trim();
- staffEntity.Telephone = txtTelephone.Text.Trim();
- staffEntity.Height = txtHeight.Text.Trim() == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(txtHeight.Text);
- staffEntity.BloodGroup = txtBloodGroup.Text.Trim();
- staffEntity.Weight = txtWeight.Text.Trim() == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(txtWeight.Text);
- staffEntity.Address = txtAddress.Text;
- staffEntity.LaidOff = chkLaidOff.Checked;
- staffEntity.Disability = chkDisability.Checked;
- if (!txtJoinPartyDate.Text.Trim().Contains("1900"))
- staffEntity.JoinPartyDate = txtJoinPartyDate.Value;
- staffEntity.Email = txtEmail.Text.Trim();
- staffEntity.OpeningBank = txtOpeningBank.Text.Trim();
- staffEntity.AccountNo = txtAccountNo.Text.Trim();
- staffEntity.Remarks = txtRemarks.Text.Trim();
- // 员工档案新建保存后,直接是入职状态
- //staffEntity.StaffStatus = Constant.INT_IS_ZERO;
- staffEntity.StaffStatus = Constant.INT_IS_TWO;
- staffEntity.ValueFlag = true;
- //所属部门
- staffEntity.OrganizationID = scbOrganization.SearchedPKMember;
- //职务
- staffEntity.Post = Convert.ToInt32(droppost.SelectedValue);
- //原工种
- staffEntity.Jobs = Convert.ToInt32(dropJobs.SelectedValue);
- return staffEntity;
- }
- /// <summary>
- /// 清空输入项
- /// </summary>
- private void InitializationForm()
- {
- this.scbOrganization.ClearValue();
- this.dropJobs.Text = "";
- this.dropJobs.SelectedValue = null;
- this.dropJobs.SelectedText = null;
- this.droppost.Text = "";
- this.droppost.SelectedValue = null;
- this.droppost.SelectedText = null;
- this.txtStaffCode.Text = "";
- this.txtStaffName.Text = "";
- this.txtIDCardNo.Text = "";
- this.txtBirthday.Value = new DateTime(1900, 1, 1);
- this.dropGender.Text = "";
- this.dropGender.SelectedValue = null;
- this.dropGender.SelectedText = null;
- this.dropMaritalStatus.Text = "";
- this.dropMaritalStatus.SelectedValue = null;
- this.dropMaritalStatus.SelectedText = null;
- this.txtHomeTown.Text = "";
- this.txtPolicitalStatus.Text = "";
- this.dropNational.Text = "";
- this.dropNational.SelectedValue = null;
- this.dropNational.SelectedText = null;
- this.dropEducational.Text = "";
- this.dropEducational.SelectedValue = null;
- this.dropEducational.SelectedText = null;
- this.txtGraduated.Text = "";
- this.txtSpecialField.Text = "";
- this.txtTelephone.Text = "";
- this.txtHeight.Text = "";
- this.txtBloodGroup.Text = "";
- this.txtEmail.Text = "";
- this.txtWeight.Text = "";
- this.txtJoinPartyDate.Value = new DateTime(1900, 1, 1);
- this.txtOpeningBank.Text = "";
- this.txtAccountNo.Text = "";
- this.chkLaidOff.Checked = false;
- this.chkDisability.Checked = false;
- this.txtAddress.Text = "";
- this.txtRemarks.Text = "";
- this.pic.Image = Dongke.IBOSS.PRD.Client.HRModule.Properties.Resources.nopic;
- /*
- foreach (ListViewItem lvSelect in lvPic.SelectedItems)
- {
- int index = lvSelect.Index;
- if (index < Constant.INT_IS_ZERO)
- {
- index = Constant.INT_IS_ZERO;
- }
- this.ilPic.Images.RemoveAt(index);
- this._PicByte.RemoveAt(index);
- this._smallByte.RemoveAt(index);
- this.lvPic.Items.RemoveAt(index);
- if (index < this._imgList.Count)
- {
- if (this._imgList[index].StaffPhotoID != Constant.INT_IS_ZERO)
- {
- StaffPhotoEntity deleteImgEntity = this._imgList[index];
- this._imgList[index].ValueFlag = Constant.INT_IS_ZERO;
- this._updateImgList.Add(deleteImgEntity);
- this._imgList.RemoveAt(index);
- }
- }
- }*/
- //BindImg();
- //this.lvPic.Items.Clear();
- }
- /// <summary>
- /// 编辑员工档案
- /// </summary>
- /// <returns></returns>
- private HRResultEntity EditStaffInfo()
- {
- try
- {
- /*
- //首先将未修改的图片从集合中删除
- for (int i = 0; i < _imgList.Count; i++)
- {
- this._PicByte.RemoveAt(Constant.INT_IS_ZERO);
- _smallByte.RemoveAt(Constant.INT_IS_ZERO);
- }
- _imgList.Clear();
- //循环插入图片
- for (int i = 0; i < _PicByte.Count; i++)
- {
- StaffPhotoEntity imgEntity = new StaffPhotoEntity();
- imgEntity.ValueFlag = Constant.INT_IS_ONE;
- byte[] buffer = _PicByte[i];
- imgEntity.Photo = buffer;
- imgEntity.Thumbnail = _smallByte[i];
- this._imgList.Add(imgEntity);
- }
- //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
- if (_updateImgList.Count != 0)
- {
- for (int i = Constant.INT_IS_ZERO; i < _updateImgList.Count; i++)
- {
- StaffPhotoEntity updateImgEntity = _updateImgList[i];
- _imgList.Add(updateImgEntity);
- }
- }
- */
- List<StaffPhotoEntity> staffPhoto = new List<StaffPhotoEntity>();
- #region Image to byte
- byte[] data = null;
- using (MemoryStream ms = new MemoryStream())
- {
- using (Bitmap Bitmap = new Bitmap(this.pic.Image))
- {
- Bitmap.Save(ms, ImageFormat.Jpeg);
- ms.Position = 0;
- data = new byte[ms.Length];
- ms.Read(data, 0, Convert.ToInt32(ms.Length));
- ms.Flush();
- }
- }
- #endregion
- staffPhoto.Add(new StaffPhotoEntity() { Photo = data });
- return HRModuleProxy.Service.EditStaffInfo(_staffEntity, staffPhoto);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 添加员工档案
- /// </summary>
- /// <returns></returns>
- private object AddStaffInfo()
- {
- try
- {
- /*
- //首先将未修改的图片从集合中删除
- for (int i = 0; i < _imgList.Count; i++)
- {
- _PicByte.RemoveAt(Constant.INT_IS_ZERO);
- _smallByte.RemoveAt(Constant.INT_IS_ZERO);
- }
- _imgList.Clear();
- //循环插入图片
- for (int i = 0; i < _PicByte.Count; i++)
- {
- StaffPhotoEntity imgEntity = new StaffPhotoEntity();
- imgEntity.ValueFlag = Constant.INT_IS_ONE;
- byte[] buffer = _PicByte[i];
- imgEntity.Photo = buffer;
- imgEntity.Thumbnail = _smallByte[i];
- _imgList.Add(imgEntity);
- }
- //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
- if (_updateImgList.Count != Constant.INT_IS_ZERO)
- {
- for (int i = 0; i < _updateImgList.Count; i++)
- {
- StaffPhotoEntity updateImgEntity = _updateImgList[i];
- this._imgList.Add(updateImgEntity);
- }
- }*/
- List<StaffPhotoEntity> staffPhoto = new List<StaffPhotoEntity>();
- #region Image to byte
- byte[] data = null;
- using (MemoryStream ms = new MemoryStream())
- {
- using (Bitmap Bitmap = new Bitmap(this.pic.Image))
- {
- Bitmap.Save(ms, ImageFormat.Jpeg);
- ms.Position = 0;
- data = new byte[ms.Length];
- ms.Read(data, 0, Convert.ToInt32(ms.Length));
- ms.Flush();
- }
- }
- #endregion
- staffPhoto.Add(new StaffPhotoEntity() { Photo = data });
- return HRModuleProxy.Service.AddStaffInfo(_staffEntity, staffPhoto);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 是否存在相同的员工编码
- /// </summary>
- /// <returns></returns>
- private DataSet IsExistsStaffCode()
- {
- try
- {
- return HRModuleProxy.Service.IsExistsStaffCode(this.txtStaffCode.Text);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取明细数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetRowData()
- {
- try
- {
- return HRModuleProxy.Service.GetRowData(StaffID);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取员工图片
- /// </summary>
- /// <returns></returns>
- private DataSet GetImageByStaffId()
- {
- try
- {
- return HRModuleProxy.Service.GetImageByStaffId(StaffID);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 将图片文件转换成二进制
- /// </summary>
- /// <param name="img"></param>
- /// <returns></returns>
- public static byte[] ImageToByte(Image img)
- {
- byte[] smallbuffer = null;
- using (MemoryStream ms = new MemoryStream())
- {
- img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
- ms.Position = Constant.INT_IS_ZERO;
- smallbuffer = new byte[ms.Length];
- ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
- ms.Flush();
- }
- return smallbuffer;
- }
- /// <SUMMARY>
- /// 重绘缩略图并把缩略图转为二进制储存
- /// </SUMMARY>
- /// <PARAM name="sourceFile">图片源路径</PARAM>
- /// <PARAM name="destHeight">缩放后图片高度</PARAM>
- /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
- /// <RETURNS></RETURNS>
- public void GetThumbnail(FileInfo sourceFile)
- {
- Image imgSource = Image.FromStream(sourceFile.OpenRead());
- ImageFormat thisFormat = imgSource.RawFormat;
- int sW = 0, sH = 0;
- // 按比例缩放
- int sWidth = imgSource.Width;
- int sHeight = imgSource.Height;
- int destWidth = 100;
- int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
- if (sHeight > destHeight || sWidth > destWidth)
- {
- if ((sWidth * destHeight) > (sHeight * destWidth))
- {
- sW = destWidth;
- sH = (destWidth * sHeight) / sWidth;
- }
- else
- {
- sH = destHeight;
- sW = (sWidth * destHeight) / sHeight;
- }
- }
- else
- {
- sW = sWidth;
- sH = sHeight;
- }
- Bitmap outBmp = new Bitmap(destWidth, destHeight);
- Graphics g = Graphics.FromImage(outBmp);
- g.Clear(Color.Black);
- // 设置画布的描绘质量
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.SmoothingMode = SmoothingMode.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
- g.Dispose();
- //将重绘的图片转为二进制并保存
- Image image = (Image)outBmp;
- byte[] smallbuffer = ImageToByte(image);
- _smallByte.Add(smallbuffer);
- imgSource.Dispose();
- outBmp.Dispose();
- }
- /// <summary>
- /// 绑定缩略图到控件中
- /// </summary>
- protected void BindImg()
- {
- //每次绑定要清空数据源
- this.ilPic.Images.Clear();
- //将缩略图二进制集合中的数据转换成图片文件
- List<Image> LSImageList = new List<Image>();
- foreach (byte[] smallby in _smallByte)
- {
- LSImageList.Add(byteArrayToImage(smallby));
- }
- //添加数据源
- foreach (Image img in LSImageList)
- {
- ilPic.Images.Add(img);
- }
- //this.ilPic.ImageSize = new Size(100, 100);
- //this.lvPic.LargeImageList = this.ilPic;
- //this.lvPic.BeginUpdate();
- ////清空列表的数据源
- //lvPic.Items.Clear();
- ////添加列表的数据源
- //for (int i = 0; i < ilPic.Images.Count; i++)
- //{
- // ListViewItem lvi = new ListViewItem();
- // lvi.ImageIndex = i;
- // this.lvPic.Items.Add(lvi);
- //}
- //this.lvPic.EndUpdate();
- }
- /// <summary>
- /// 根据原图片宽高比获取缩略图的高(根据宽)
- /// </summary>
- /// <param name="BigWidth"></param>
- /// <param name="BigHeight"></param>
- /// <param name="SmallWidth"></param>
- /// <returns></returns>
- protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
- {
- decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
- return Convert.ToInt32(SmallWidth / scale);
- }
- /// <summary>
- /// 将数据库中的二进制转换成图片
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public static Image byteArrayToImage(object data)
- {
- System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
- System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
- return returnImage;
- }
- /// <summary>
- /// 绑定并显示图片
- /// </summary>
- /// <param name="ImageData"></param>
- protected void BindByteImage(DataSet ImageData)
- {
- foreach (DataRow dr in ImageData.Tables[0].Rows)
- {
- //将数据库中的缩略图取出
- //_smallByte.Add((byte[])dr[2]);
- //_PicByte.Add((byte[])dr[3]);
- MemoryStream ms = new MemoryStream((byte[])dr[3]);
- Image img = Image.FromStream(ms);
- this.pic.Image = img;
- //绑定实体到修改图片集合中
- StaffPhotoEntity imgEntity = new StaffPhotoEntity();
- imgEntity.StaffPhotoID = Convert.ToInt32(dr[0]);
- imgEntity.StaffID = Convert.ToInt32(dr[1]);
- imgEntity.Thumbnail = (byte[])dr[2];
- imgEntity.Photo = (byte[])dr[3];
- imgEntity.AccountID = Convert.ToInt32(dr[4]);
- imgEntity.ValueFlag = Convert.ToInt32(dr[5]);
- imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
- imgEntity.CreateUserID = Convert.ToInt32(dr[7]);
- imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
- imgEntity.UpdateUserID = Convert.ToInt32(dr[9]);
- imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
- _imgList.Add(imgEntity);
- }
- //绑定缩略图
- //BindImg();
- }
- /// <summary>
- /// 获取性别数据源
- /// </summary>
- /// <returns></returns>
- private DataTable GetSystemParameterByName()
- {
- DataTable dtSystemParameterByName = null;
- try
- {
- dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Gender, "displayno ASC");
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return dtSystemParameterByName;
- }
- /// <summary>
- /// 获取婚姻状况数据源
- /// </summary>
- /// <returns></returns>
- private DataTable GetSystemParameterByNameMaritalStatu()
- {
- DataTable dtSystemParameterByName = null;
- try
- {
- dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_MaritalStatus, "displayno ASC");
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return dtSystemParameterByName;
- }
- /// <summary>
- /// 获取民族数据源
- /// </summary>
- /// <returns></returns>
- private DataTable GetSystemParameterByNameNational()
- {
- DataTable dtSystemParameterByName = null;
- try
- {
- return LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_National, "displayno ASC");
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return dtSystemParameterByName;
- }
- /// <summary>
- /// 获取学历数据源
- /// </summary>
- /// <returns></returns>
- private DataTable GetSystemParameterByNameEducational()
- {
- DataTable dtSystemParameterByName = null;
- try
- {
- dtSystemParameterByName = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Educational, "displayno ASC");
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return dtSystemParameterByName;
- }
- /// <summary>
- /// 获取工种数据
- /// </summary>
- /// <returns></returns>
- private DataTable GetJobsData()
- {
- DataTable returntJobsData = null;
- try
- {
- returntJobsData = SystemModuleProxy.Service.GetJobsData(0).Tables[0];
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return returntJobsData;
- }
- /// <summary>
- /// 获取职务数据
- /// </summary>
- /// <returns></returns>
- private DataTable GetPostData()
- {
- DataTable returntPostData = null;
- try
- {
- returntPostData = SystemModuleProxy.Service.GetPostData(0).Tables[0];
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- return returntPostData;
- }
- #endregion
- }
- }
|