/*******************************************************************************
* 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
{
///
/// 新建/编辑员工档案
///
public partial class F_HR_0102 : FormBase
{
#region 成员变量
// 页面传过来员工ID
private int _staffID;
// 用户实体类
private StaffEntity _staffEntity;
// 编辑状态
private Constant.FormMode _editStatus;
// 新建的员工ID集合
private List _staffIDList = new List();
// 时间戳
private DateTime _optimestamp;
// 图片字节集
private List _PicByte = new List();
// 缩略图片字节集
private List _smallByte = new List();
// 图片实体集合
private List _imgList = new List();
// 已存在的图片实体集合(修改)
private List _updateImgList = new List();
#endregion
#region 构造函数
public F_HR_0102()
{
InitializeComponent();
}
///
/// 构造函数
///
/// 窗体状态
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 属性
///
/// 页面传过来的员工ID
///
public int StaffID
{
get
{
return this._staffID;
}
set
{
this._staffID = value;
}
}
///
/// 员工ID集合
///
public List StaffIDList
{
get
{
return _staffIDList;
}
set
{
_staffIDList = value;
}
}
///
/// 时间戳
///
public DateTime PTimeStamp
{
get
{
return _optimestamp;
}
set
{
_optimestamp = value;
}
}
#endregion
#region 按钮事件
///
/// 保存按钮事件
///
///
///
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);
}
}
///
/// 窗体加载事件
///
///
///
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);
}
}
///
/// 上传图片
///
///
///
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);
}
}
///
/// 删除图片按钮事件
///
///
///
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();
}
///
/// 取消按钮
///
///
///
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;
}
}
///
/// 身份证号离开事件
///
///
///
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);
}
}
///
/// 入党日期选中改变事件
///
///
///
private void cbJoinPartyDate_CheckedChanged(object sender, EventArgs e)
{
this.txtJoinPartyDate.Enabled = this.cbJoinPartyDate.Checked;
}
#endregion
#region 私有方法
///
/// 验证输入格式是否正确
///
///
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;
}
///
/// 根据页面输入值,给员工对象实体赋值
///
///
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;
}
///
/// 清空输入项
///
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();
}
///
/// 编辑员工档案
///
///
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 staffPhoto = new List();
#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;
}
}
///
/// 添加员工档案
///
///
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 staffPhoto = new List();
#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;
}
}
///
/// 是否存在相同的员工编码
///
///
private DataSet IsExistsStaffCode()
{
try
{
return HRModuleProxy.Service.IsExistsStaffCode(this.txtStaffCode.Text);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取明细数据
///
///
private DataSet GetRowData()
{
try
{
return HRModuleProxy.Service.GetRowData(StaffID);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取员工图片
///
///
private DataSet GetImageByStaffId()
{
try
{
return HRModuleProxy.Service.GetImageByStaffId(StaffID);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 将图片文件转换成二进制
///
///
///
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;
}
///
/// 重绘缩略图并把缩略图转为二进制储存
///
/// 图片源路径
/// 缩放后图片高度
/// 缩放后图片宽度
///
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();
}
///
/// 绑定缩略图到控件中
///
protected void BindImg()
{
//每次绑定要清空数据源
this.ilPic.Images.Clear();
//将缩略图二进制集合中的数据转换成图片文件
List LSImageList = new List();
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();
}
///
/// 根据原图片宽高比获取缩略图的高(根据宽)
///
///
///
///
///
protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
{
decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
return Convert.ToInt32(SmallWidth / scale);
}
///
/// 将数据库中的二进制转换成图片
///
///
///
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;
}
///
/// 绑定并显示图片
///
///
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();
}
///
/// 获取性别数据源
///
///
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;
}
///
/// 获取婚姻状况数据源
///
///
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;
}
///
/// 获取民族数据源
///
///
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;
}
///
/// 获取学历数据源
///
///
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;
}
///
/// 获取工种数据
///
///
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;
}
///
/// 获取职务数据
///
///
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
}
}