| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103 |
- /*******************************************************************************
- * 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);
- // 设置表格不自动创建列
- this.dgvStaff.AutoGenerateColumns = false;
- // 设置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
- }
- }
|