| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_HR_0101.cs
- * 2.功能描述:员工档案
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2014/09/12 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.DockPanel;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
- 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_0101 : DockPanelBase
- {
- #region 成员变量
- // 单例模式
- private static F_HR_0101 _instance;
- // 最后选择行
- private int _selecedRow;
- // 员工ID
- private int _staffID;
- // 查询条件实体
- private HR_CMN_StaffEntity _staffEntity = new HR_CMN_StaffEntity();
- //用户编辑的ID集合
- int[] _staffIDList;
- #endregion
- #region 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- public static F_HR_0101 Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new F_HR_0101();
- }
- return _instance;
- }
- }
- #endregion
- #region 构造函数
- public F_HR_0101()
- {
- InitializeComponent();
- //设置按钮显示的文本
- this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
- this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
- this.tsbtnDisable.Text = ButtonText.TSBTN_DISABLE;
- this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
- this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
- this.tsbtnMoreCondition.Text = ButtonText.TSBTN_MORECONDITION;
- this.btnSearch.Text = ButtonText.BTN_SEARCH;
- this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
- this.Text = FormTitles.F_HR_0101;
- this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 自动适应列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvStaff.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- /// <summary>
- /// 清空按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnClearCondition_Click(object sender, EventArgs e)
- {
- // 加载员工状态
- DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
- this.SelStaffStatus.DataSource = dtStaffStatus;
- this.SelStaffStatus.AllItemCheck();
- this.txtStaffCode.Clear();
- this.txtStaffName.Clear();
- this.txtOther.Clear();
- this._staffEntity.ClearEntityValue();
- }
- /// <summary>
- /// 搜索按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSearch_Click(object sender, EventArgs e)
- {
- try
- {
- this._staffIDList = null;
- // 记录当前选中行
- int selectRowIndex = this._selecedRow;
- // 异步处理
- this.btnSearch.Enabled = false;
- this.btnClearCondition.Enabled = false;
- DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
- this.btnSearch.Enabled = true;
- this.btnClearCondition.Enabled = true;
- //this.sbxOrganization.ReadOnly = true;
- if (dsHrStaff != null)
- {
- base.DataSource = (DataSet)dsHrStaff;
- if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaff.DataSource = this.DataSource.Tables[0];
- if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
- {
- // 提示未查找到数据
- MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- if (selectRowIndex >= Constant.INT_IS_ZERO)
- {
- if (selectRowIndex >= dsHrStaff.Tables[0].Rows.Count)
- {
- this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Selected = true;
- this.dgvStaff.CurrentCell = this.dgvStaff.Rows[this.dgvStaff.Rows.Count - 1].Cells["StaffCode"];
- }
- else
- {
- this.dgvStaff.Rows[selectRowIndex].Selected = true;
- this.dgvStaff.CurrentCell = this.dgvStaff.Rows[selectRowIndex].Cells["StaffCode"];
- }
- }
- }
- }
- }
- this.SetToolStripButtonEnable();
- }
- catch (Exception ex)
- {
- this.btnSearch.Enabled = true;
- this.btnClearCondition.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_0101_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_HR_0101_Load(object sender, EventArgs e)
- {
- try
- {
- // 加载权限
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- // 设置ToolStripButton状态
- this.SetToolStripButtonEnable();
- // 加载员工状态
- DataTable dtStaffStatus = LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_StaffStatus);
- this.SelStaffStatus.DataSource = dtStaffStatus;
- this.SelStaffStatus.AllItemCheck();
- }
- 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 tsbtnMoreCondition_Click(object sender, EventArgs e)
- {
- Dongke.IBOSS.PRD.Basics.BaseControls.HR_CMN_001 frmHRCMN001 = new Basics.BaseControls.HR_CMN_001();
- frmHRCMN001.StaffEntity = this._staffEntity;
- if (frmHRCMN001.ShowDialog() == DialogResult.OK)
- {
- this.txtOther.Text = frmHRCMN001.StaffEntity.GetSqlDispText();
- this._staffEntity = frmHRCMN001.StaffEntity;
- }
- }
- /// <summary>
- /// 新建按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnAdd_Click(object sender, EventArgs e)
- {
- try
- {
- F_HR_0102 frmHR0102 = new F_HR_0102(Constant.FormMode.Add);
- DialogResult dialogResult = frmHR0102.ShowDialog();
- // 重新加载GridView
- if (dialogResult == DialogResult.OK)
- {
- this._staffIDList = frmHR0102.StaffIDList.ToArray();
- DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
- if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
- && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaff.DataSource = null;
- this.dgvStaff.DataSource = dsHrStaff.Tables[0];
- // 设置ToolStripButton按钮状态
- this.SetToolStripButtonEnable();
- this.dgvStaff.ReadOnly = true;
- }
- }
- }
- 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 dgvStaff_CellEnter(object sender, DataGridViewCellEventArgs e)
- {
- this.SetToolStripButtonEnable();
- if (this.dgvStaff.Rows.Count > Constant.INT_IS_ZERO)
- {
- this._selecedRow = this.dgvStaff.CurrentCell.RowIndex;
- }
- }
- /// <summary>
- /// 单元格双击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvStaff_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (-Constant.INT_IS_ONE < e.RowIndex && -Constant.INT_IS_ONE < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
- {
- this.tsbtnEdit_Click(sender, e);
- }
- }
- /// <summary>
- /// 编辑按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnEdit_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvStaff.CurrentRow != null)
- {
- F_HR_0102 frmHR0102 = new F_HR_0102(Constant.FormMode.Edit);
- frmHR0102.StaffID = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffID"].Value);
- DialogResult dialogResult = frmHR0102.ShowDialog();
- if (dialogResult.Equals(DialogResult.OK))
- {
- this._staffIDList = frmHR0102.StaffIDList.ToArray();
- DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
- if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
- && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaff.DataSource = null;
- this.dgvStaff.DataSource = dsHrStaff.Tables[0];
- // 设置ToolStripButton按钮状态
- this.SetToolStripButtonEnable();
- this.dgvStaff.ReadOnly = true;
- }
- }
- }
- }
- 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 tsbtnDisable_Click(object sender, EventArgs e)
- {
- try
- {
- DialogResult msgBoxResult = MessageBox.Show(
- string.Format(Messages.MSG_CMN_Q002, "该员工", "停用"), this.Text,
- MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (msgBoxResult == DialogResult.Yes)
- {
- int staffid = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["staffID"].Value);
- this._staffID = staffid;
- HRResultEntity returenRow = (HRResultEntity)DoAsync(new AsyncMethod(this.SetValueFlag));
- this.dgvStaff.ReadOnly = true;
- // 修改成功
- if (returenRow.OperateStatus > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工管理", "停用"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.btnSearch_Click(sender, e);
- }
- else if (returenRow.OperateStatus == Constant.INT_IS_NEGATIE_FOUR)
- {
- MessageBox.Show(Messages.MSG_HR_W001,
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工管理", "停用"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 设置停用
- /// </summary>
- /// <param name="staffid"></param>
- /// <returns></returns>
- private HRResultEntity SetValueFlag()
- {
- try
- {
- return HRModuleProxy.Service.SetValueFlag(this._staffID);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 设置启用
- /// </summary>
- /// <param name="staffid"></param>
- /// <returns></returns>
- private void EnableValueFlag()
- {
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "F_HR_0101";
- cre.Name = "STAFF";
- cre.Properties["Staffid"] = this._staffID;
- ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
- if (sre.OtherStatus > 0)
- {
- DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002);
- return;
- }
- else if (Convert.ToInt32(sre.OtherStatus) == -1001)
- {
- MessageBox.Show(string.Format(Messages.MSG_HR_W0001,
- ""),
- "",
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- return;
- }
- }
- private void tsbtnDown_Click(object sender, EventArgs e)
- {
- try
- {
- TempletFileEntity resultTemplet = (TempletFileEntity)DoAsync(new AsyncMethod(() =>
- {
- return CommonModuleProxy.Service.GetTempletFileContentByUrl(Constant.HR_STAFF_INFO_TEMPLET);
- }));
- if (string.IsNullOrEmpty(resultTemplet.FileName))
- {
- // 提示未查找到数据
- MessageBox.Show(Messages.MSG_CMN_W021, this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- this.sfDialogTemplet.FileName = resultTemplet.FileName;
- this.sfDialogTemplet.Filter = "Excel文件(*.xlsx)|*.xlsx";
- if (this.sfDialogTemplet.ShowDialog() == DialogResult.OK)
- {
- string localFilePath = this.sfDialogTemplet.FileName.ToString(); //获得文件路径
- System.IO.File.WriteAllBytes(localFilePath, resultTemplet.FileContent);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void tsbtnUpdate_Click(object sender, EventArgs e)
- {
- try
- {
- this.oFileDialog.Filter = "Excel文件|*.xls;*.xlsx|Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
- this.oFileDialog.FileName = string.Empty;
- if (this.oFileDialog.ShowDialog() != DialogResult.OK)
- {
- return;
- }
- int v = (".xlsx" == System.IO.Path.GetExtension(this.oFileDialog.FileName)) ? 1 : 0;
- DataTable dtStaffInfo = ExcelLayer.GetDataTable(this.oFileDialog.FileName, "Staff", v);
- #region 对数据进行验证
- if (dtStaffInfo == null || dtStaffInfo.Rows.Count < 1)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "文件正在被占用 或 导入的Excel文件中没有符合规则的数据!"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- F_HR_0103 frmHR0103 = new F_HR_0103();
- if (frmHR0103.ShowDialog() == DialogResult.OK)
- {
- if (!CheckImportExcel(dtStaffInfo))
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入模板错误!"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (!CheckImportExcelData(dtStaffInfo, frmHR0103.StaffStatus))
- {
- return;
- }
- if (dtStaffInfo.Rows.Count < 1)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入的Excel文件中的数据没有员工编码!"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- #endregion
- DataColumn dc = new DataColumn("StaffStatus", typeof(int));
- dc.DefaultValue = frmHR0103.StaffStatus;
- dtStaffInfo.Columns.Add(dc);
- ServiceResultEntity result = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
- {
- return HRModuleProxy.Service.ImportStaffInfo(dtStaffInfo);
- }));
- if (result.Status == Constant.ServiceResultStatus.Success)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工档案", "导入"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- string[] ids = result.Result.ToString().Split(',');
- this._staffIDList = new int[ids.Length];
- for (int i = 0; i < ids.Length; i++)
- {
- this._staffIDList[i] = int.Parse(ids[i]);
- }
- DataSet dsHrStaff = (DataSet)DoAsync(new AsyncMethod(this.SearchHrStaff));
- if (dsHrStaff != null && dsHrStaff.Tables.Count > Constant.INT_IS_ZERO
- && dsHrStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaff.DataSource = null;
- this.dgvStaff.DataSource = dsHrStaff.Tables[0];
- // 设置ToolStripButton按钮状态
- this.SetToolStripButtonEnable();
- this.dgvStaff.ReadOnly = true;
- }
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, result.Message),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 获取员工档案数据集
- /// </summary>
- /// <returns></returns>
- private DataSet SearchHrStaff()
- {
- SearchStaffEntity pSearchStaff = new SearchStaffEntity();
- if (this._staffIDList != null && this._staffIDList.Length > Constant.INT_IS_ZERO)
- {
- pSearchStaff.RStaffRecordIDList = this._staffIDList;
- this._staffIDList = null;
- }
- else
- {
- DataConvert.Convert(_staffEntity, pSearchStaff);
- pSearchStaff.StaffCode = this.txtStaffCode.Text.Trim();
- pSearchStaff.StaffName = this.txtStaffName.Text.Trim();
- object[] objListValue = chkValueFlag.SelectedValues;
- if (objListValue.Length>=2 || objListValue.Length<1)
- {
- pSearchStaff.ValueFlag = null;
- }
- if (objListValue.Length == 1) {
- if (objListValue[0].ToString() == "1") {
- pSearchStaff.ValueFlag = true;
- }
- if (objListValue[0].ToString() == "0")
- {
- pSearchStaff.ValueFlag = false;
- }
- }
-
- pSearchStaff.StaffStatusArray = SelStaffStatus.SelectedArray;
- }
- try
- {
- return HRModuleProxy.Service.SearchHrStaff(pSearchStaff);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 设置工具按钮的可用状态
- /// </summary>
- private void SetToolStripButtonEnable()
- {
- if (this.dgvStaff.CurrentCell != null)
- {
- this.tsbtnEdit.Enabled = true;
- this.tsbtnDisable.Enabled = true;
- }
- else
- {
- this.tsbtnEdit.Enabled = false;
- this.tsbtnDisable.Enabled = false;
- }
- }
- private bool CheckImportExcel(DataTable datatable)
- {
- if (datatable.Columns.Count < 1)
- {
- return false;
- }
- if (!datatable.Columns.Contains("员工编码"))
- {
- return false;
- }
- //datatable.Columns["员工编码"].ColumnName = "StaffCode";
- if (!datatable.Columns.Contains("员工姓名"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("身份证号码"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("生日"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("性别"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("婚姻状况"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("籍贯"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("政治面貌"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("民族"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("学历"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("毕业学校"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("专业"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("联系电话"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("身高(CM)"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("血型"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("体重(KG)"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("家庭住址"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("下岗职工"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("残疾职工"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("入党日期"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("电子邮箱"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("开户行"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("开户账号"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("备注"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("部门(全称)"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("工种"))
- {
- return false;
- }
- if (!datatable.Columns.Contains("职务"))
- {
- return false;
- }
- return true;
- }
- private bool CheckImportExcelData(DataTable datatable, int? StaffStatus)
- {
- try
- {
- // 性别
- DataTable dtGender =
- LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Gender, null);
- // 婚姻状况
- DataTable dtMaritalStatus =
- LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_MaritalStatus, null);
- // 民族
- DataTable dtNational =
- LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_National, null);
- // 学历
- DataTable dtEducational =
- LogInUserInfo.CurrentUser.GetSystemParameterByName(Constant.SysCacheTable.TP_SYS_Educational, null);
- // 获取部门编码
- OrganizationEntity orgEntity = new OrganizationEntity();
- orgEntity.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
- orgEntity.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
- DataSet dtOrganization = (DataSet)DoAsync(new AsyncMethod(() =>
- {
- return SystemModuleProxy.Service.SelectOrganizationData(orgEntity);
- }));
- // 获取工种编码
- DataSet dsJobs = (DataSet)DoAsync(new AsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllJobsInfo();
- }));
- // 获取职务编码
- DataSet dsPost = (DataSet)DoAsync(new AsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllPostInfo();
- }));
- List<string> codes = new List<string>();
- foreach (DataRow item in datatable.Rows)
- {
- string code = item["员工编码"].ToString();
- if (string.IsNullOrWhiteSpace(code))
- {
- item.Delete();
- continue;
- }
- if (codes.Contains(code))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "员工编码【" + code + "】重复。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- codes.Add(code);
- code = "员工编码[" + code + "]";
- if (string.IsNullOrWhiteSpace(item["员工姓名"].ToString()))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的员工姓名为空。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- // 如果性别没填,默认【男】
- if (string.IsNullOrEmpty(item["性别"] + ""))
- {
- item["性别"] = "男";
- }
- DataRow[] drs1 = dtGender.Select("GenderName = '" + item["性别"].ToString() + "'");
- if (drs1 != null && drs1.Length > 0)
- {
- item["性别"] = drs1[0]["GenderCode"];
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的性别输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- // 如果婚姻状况没填,默认【其他】
- if (string.IsNullOrEmpty(item["婚姻状况"] + ""))
- {
- item["婚姻状况"] = "其他";
- }
- DataRow[] drs2 = dtMaritalStatus.Select("MaritalStatusName = '" + item["婚姻状况"].ToString() + "'");
- if (drs2 != null && drs2.Length > 0)
- {
- item["婚姻状况"] = drs2[0]["MaritalStatusID"];
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的婚姻状况输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- // 如果民族没填,默认【其他】
- if (string.IsNullOrEmpty(item["民族"] + ""))
- {
- item["民族"] = "汉族";
- }
- DataRow[] drs3 = dtNational.Select("NationalName = '" + item["民族"].ToString() + "'");
- if (drs3 != null && drs3.Length > 0)
- {
- item["民族"] = drs3[0]["NationalID"];
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的民族输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- // 如果民族没填,默认【其他】
- if (string.IsNullOrEmpty(item["学历"] + ""))
- {
- item["学历"] = "其他";
- }
- DataRow[] drs4 = dtEducational.Select("EducationalName = '" + item["学历"].ToString() + "'");
- if (drs4 != null && drs4.Length > 0)
- {
- item["学历"] = drs4[0]["EducationalID"];
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的学历输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- if (StaffStatus == 2)
- {
- //----------部门编码--------------
- // 如果部门全称没填,默认001部门
- DataRow[] drsOrganization = dtOrganization.Tables[0].Select("OrganizationCode = '001' AND ValueFlag= '1'", " OrganizationID ASC ");
- if (string.IsNullOrEmpty(item["部门(全称)"] + ""))
- {
- item["部门(全称)"] = (drsOrganization[0]["OrganizationFullName"] + "").Replace("→", "-");
- }
- DataRow[] drs5 = dtOrganization.Tables[0].Select("OrganizationName = '" + item["部门(全称)"].ToString() + "'", " FullNameLength ASC ");
- if (drs5 != null && drs5.Length > 0)
- {
- item["部门(全称)"] = drs5[0]["OrganizationID"];
- }
- else
- {
- DataRow[] drs51 = dtOrganization.Tables[0].Select("OrganizationFullName like '%" + item["部门(全称)"].ToString().Replace("-", "→") + "'", " FullNameLength ASC ");
- if (drs51 != null && drs51.Length > 0)
- {
- item["部门(全称)"] = drs51[0]["OrganizationID"];
- }
- else
- {
- item["部门(全称)"] = drsOrganization[0]["OrganizationID"];
- //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的部门输入错误。"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- //return false;
- }
- }
- //------------------------
- //----------工种--------------
- DataRow[] drs6 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName = '" + item["工种"].ToString() + "'");
- if (drs6 != null && drs6.Length > 0)
- {
- item["工种"] = drs6[0]["JobsID"];
- }
- else
- {
- DataRow[] drs61 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName like '%" + item["工种"].ToString() + "%'");
- if (drs61 != null && drs61.Length == 1)
- {
- item["工种"] = drs61[0]["JobsID"];
- }
- else
- {
- // 如果未匹配到,默认第一个工种
- DataRow[] drsJobs = dsJobs.Tables[0].Select(" ValueFlag= '1'", " JobsID ASC ");
- item["工种"] = drsJobs[0]["JobsID"];
- //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的工种输入错误。"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- // return false;
- }
- }
- //------------------------
- //----------职务--------------
- DataRow[] drs7 = dsPost.Tables[0].Select("ValueFlag='1' and PostCode = '" + item["职务"].ToString() + "'");
- if (drs7 != null && drs7.Length > 0)
- {
- item["职务"] = drs7[0]["PostID"];
- }
- else
- {
- DataRow[] drs71 = dsPost.Tables[0].Select("ValueFlag='1' and PostName like '%" + item["职务"].ToString() + "%'");
- if (drs71 != null && drs71.Length == 1)
- {
- item["职务"] = drs71[0]["PostID"];
- }
- else
- {
- // 如果未匹配到,默认第一个职务
- DataRow[] drsPost = dsPost.Tables[0].Select(" ValueFlag= '1'", " PostID ASC ");
- item["职务"] = drsPost[0]["PostID"];
- //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的职务输入错误。"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- //return false;
- }
- }
- }
- else
- {
- //----------部门编码--------------
- // 如果部门全称没填,默认001部门
- DataRow[] drsOrganization = dtOrganization.Tables[0].Select("OrganizationCode = '001' AND ValueFlag= '1'", " OrganizationID ASC ");
- if (string.IsNullOrEmpty(item["部门(全称)"] + ""))
- {
- item["部门(全称)"] = (drsOrganization[0]["OrganizationFullName"] + "").Replace("→", "-");
- }
- DataRow[] drs5 = dtOrganization.Tables[0].Select("OrganizationCode = '" + item["部门(全称)"].ToString() + "'");
- if (drs5 != null && drs5.Length > 0)
- {
- item["部门(全称)"] = drs5[0]["OrganizationID"];
- }
- else
- {
- DataRow[] drs51 = dtOrganization.Tables[0].Select("OrganizationFullName like '%" + item["部门(全称)"].ToString() + "'");
- if (drs51 != null && drs51.Length == 1)
- {
- item["部门(全称)"] = drs51[0]["OrganizationID"];
- }
- else
- {
- // 如果未匹配到,默认001部门
- item["部门(全称)"] = drsOrganization[0]["OrganizationID"];
- }
- }
- //------------------------
- //----------工种--------------
- DataRow[] drs6 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsCode = '" + item["工种"].ToString() + "'");
- if (drs6 != null && drs6.Length > 0)
- {
- item["工种"] = drs6[0]["JobsID"];
- }
- else
- {
- DataRow[] drs61 = dsJobs.Tables[0].Select("ValueFlag='1' and JobsName like '%" + item["工种"].ToString() + "%'");
- if (drs61 != null && drs61.Length == 1)
- {
- item["工种"] = drs61[0]["JobsID"];
- }
- else
- {
- // 如果未匹配到,默认第一个工种
- DataRow[] drsJobs = dsJobs.Tables[0].Select(" ValueFlag= '1'", " JobsID ASC ");
- item["工种"] = drsJobs[0]["JobsID"];
- //item["工种编码"] = "";
- }
- }
- //------------------------
- //----------职务--------------
- DataRow[] drs7 = dsPost.Tables[0].Select("ValueFlag='1' and PostCode = '" + item["职务"].ToString() + "'");
- if (drs7 != null && drs7.Length > 0)
- {
- item["职务"] = drs7[0]["PostID"];
- }
- else
- {
- DataRow[] drs71 = dsPost.Tables[0].Select("ValueFlag='1' and PostName like '%" + item["职务"].ToString() + "%'");
- if (drs71 != null && drs71.Length == 1)
- {
- item["职务"] = drs71[0]["PostID"];
- }
- else
- {
- // 如果未匹配到,默认第一个职务
- DataRow[] drsPost = dsPost.Tables[0].Select(" ValueFlag= '1'", " PostID ASC ");
- item["职务"] = drsPost[0]["PostID"];
- //item["职务编码"] = "";
- }
- }
- }
- //------------------------
- if ("下岗职工" == item["下岗职工"].ToString())
- {
- item["下岗职工"] = "1";
- }
- else
- {
- item["下岗职工"] = "0";
- }
- if ("残疾职工" == item["残疾职工"].ToString())
- {
- item["残疾职工"] = "1";
- }
- else
- {
- item["残疾职工"] = "0";
- }
- string date = item["生日"].ToString();
- if (string.IsNullOrWhiteSpace(date))
- {
- item["生日"] = DBNull.Value;
- }
- else
- {
- DateTime datetime;
- if (DateTime.TryParse(date, out datetime))
- {
- item["生日"] = datetime.ToString("yyyy-MM-dd");
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的生日输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- date = item["入党日期"].ToString();
- if (string.IsNullOrWhiteSpace(date))
- {
- item["入党日期"] = DBNull.Value;
- }
- else
- {
- DateTime datetime;
- if (DateTime.TryParse(date, out datetime))
- {
- item["入党日期"] = datetime.ToString("yyyy-MM-dd");
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的入党日期输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- date = item["身高(CM)"].ToString();
- if (string.IsNullOrWhiteSpace(date))
- {
- item["身高(CM)"] = DBNull.Value;
- }
- else
- {
- decimal d;
- if (decimal.TryParse(date, out d))
- {
- item["身高(CM)"] = d;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的身高(CM)输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- date = item["体重(KG)"].ToString();
- if (string.IsNullOrWhiteSpace(date))
- {
- item["体重(KG)"] = DBNull.Value;
- }
- else
- {
- decimal d;
- if (decimal.TryParse(date, out d))
- {
- item["体重(KG)"] = d;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, code + "的体重(KG)输入错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- }
- datatable.AcceptChanges();
- return true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- private void enableButton_Click(object sender, EventArgs e)
- {
- try
- {
- DialogResult msgBoxResult = MessageBox.Show(
- string.Format(Messages.MSG_CMN_Q002, "该员工", "启用"), this.Text,
- MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (msgBoxResult == DialogResult.Yes)
- {
- int staffid = Convert.ToInt32(this.dgvStaff.CurrentRow.Cells["StaffID"].Value);
- this._staffID = staffid;
- EnableValueFlag();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- }
- }
|