| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- /*******************************************************************************
- * 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.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;
- }
- }
- 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();
- pSearchStaff.ValueFlag = true;
- 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
- }
- }
|