| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157 |
- /*******************************************************************************
- * 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.dropGender.SelectedValue == null || this.dropGender.SelectedValue.ToString() == string.Empty)
- {
- this.dropGender.IsMustInput = true;
- this.dropGender.Focus();
- return false;
- }
- this.dropGender.IsMustInput = false;
- if (this.dropMaritalStatus.SelectedValue == null || this.dropMaritalStatus.SelectedValue.ToString() == string.Empty)
- {
- this.dropMaritalStatus.IsMustInput = true;
- this.dropMaritalStatus.Focus();
- return false;
- }
- this.dropMaritalStatus.IsMustInput = false;
- if (this.dropEducational.SelectedValue == null || this.dropEducational.SelectedValue.ToString() == string.Empty)
- {
- this.dropEducational.IsMustInput = true;
- this.dropEducational.Focus();
- return false;
- }
- this.dropEducational.IsMustInput = false;
- if (this.dropNational.SelectedValue == null || this.dropNational.SelectedValue.ToString() == string.Empty)
- {
- this.dropNational.IsMustInput = true;
- this.dropNational.Focus();
- return 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 = dropGender.SelectedValue.ToString();
- staffEntity.MaritalStatus = Convert.ToInt32(dropMaritalStatus.SelectedValue);
- staffEntity.HomeTown = txtHomeTown.Text.Trim();
- staffEntity.PolicitalStatus = txtPolicitalStatus.Text.Trim();
- staffEntity.National = Convert.ToInt32(dropNational.SelectedValue);
- staffEntity.Educational = Convert.ToInt32(dropEducational.SelectedValue);
- 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
- }
- }
|