/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_0211.cs * 2.功能描述:新增/编辑员工关联 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2014/09/12 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.DataModels; namespace Dongke.IBOSS.PRD.Client.SystemModule { /// /// 新增/编辑员工关联 /// public partial class F_MST_0211 : FormBase { #region 成员变量 // 打开选择窗体的标识 private bool _showFromFlag = true; // 选中的员工编码 private string _staffCode; // 选中的工号ID private int? _userId; // 选中的工号编码 private string _userCode; // 页面数据源 private DataTable _dtSourse = new DataTable(); // 当前选择工号 private SUserEntity _selectUser = new SUserEntity(); // 当前工号的工种集合 private DataTable _userJobsTable = new DataTable(); #endregion #region 构造函数 public F_MST_0211(int? UserId, string UserCode) { InitializeComponent(); if (UserId == null) { this.Text = FormTitles.F_MST_0211_ADD; } else { this.Text = FormTitles.F_MST_0211_EDIT; } this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; this._userId = UserId; this._userCode = UserCode; } #endregion #region 事件 /// /// 单元格值改变事件 /// /// /// private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -Constant.INT_IS_ONE) { if (!_showFromFlag) { return; } DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex]; // 用编号获取员工信息 if (columnItem.Name == "StaffCode" && !string.IsNullOrEmpty(this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "")) { _showFromFlag = false; FormUtility.BindStaffRowDataSource(this.dgvDataJobs, e.RowIndex, columnItem.Name, this._staffCode, scbUser.SearchedPKMember, true); _showFromFlag = true; for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++) { if (i != e.RowIndex) { if (this.dgvDataJobs.Rows[i].IsNewRow == true) { return; } String NowStaffID = this.dgvDataJobs.Rows[e.RowIndex].Cells["StaffID"].Value.ToString(); if (NowStaffID == "") { this.dgvDataJobs.Rows.RemoveAt(e.RowIndex); return; } String ForStaffID = ""; if (this.dgvDataJobs.Rows[i].Cells["StaffID"].Value != null) { ForStaffID = this.dgvDataJobs.Rows[i].Cells["StaffID"].Value.ToString(); } if (NowStaffID == ForStaffID) { this.dgvDataJobs.Rows.RemoveAt(e.RowIndex); //仅限当前页面,工号间的待修改 MessageBox.Show("员工信息不可重复配置!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } } else if (columnItem.Name == "UserJobsCode") { string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (JobsCode != string.Empty && JobsCode != null) { DataTable TableCopy = _userJobsTable.Copy(); TableCopy.DefaultView.RowFilter = "UserJobsId='" + JobsCode + "'"; DataTable EndTable = TableCopy.DefaultView.ToTable(); if (EndTable.Rows.Count != 0) { this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsName"].Value = EndTable.Rows[0]["UserJobsName"].ToString(); this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsID"].Value = EndTable.Rows[0]["UserJobsID"].ToString(); } else { ((DataTable)this.dgvDataJobs.DataSource).Rows[e.RowIndex].Delete(); } } } if ((rowItem.Cells["StaffCode"].Value == null || rowItem.Cells["StaffCode"].Value == DBNull.Value) && (rowItem.Cells["UserJobsCode"].Value == null || rowItem.Cells["UserJobsCode"].Value == DBNull.Value)) { this.dgvDataJobs.Rows.Remove(rowItem); } } } catch (Exception ex) { this._showFromFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 工号值改变事件 /// /// /// private void scbUser_SearchedItemChanged(object sender, EventArgs e) { try { BindUserJobs(); this.scbUser.Enabled = false; this.dgvDataJobs.Enabled = true; this.dgvDataJobs.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单元格开始编辑事件 /// /// /// private void dgvDataJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { try { if (e.RowIndex != -Constant.INT_IS_ONE) { DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex]; if ("StaffCode".Equals(columnItem.Name)) { this._staffCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体加载事件 /// /// /// private void F_MST_0211_Load(object sender, EventArgs e) { try { this.dgvDataJobs.AutoGenerateColumns = false; if (this._userId != null) { this.scbUser.SearchedPKMember = Convert.ToInt32(this._userId); scbUser.InitValue(_userCode, _userCode); BindUserJobs(); this.scbUser.Enabled = false; this.dgvDataJobs.Enabled = true; } this.dgvDataJobs.IsSetInputColumnsColor = true; } catch (Exception ex) { throw ex; } } /// /// 工号值改变事件 /// /// /// private void dkUser_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e) { //try //{ // BindUserJobs(); // this.scbUser.Enabled = false; // this.dgvDataJobs.Enabled = true; // this.dgvDataJobs.IsSetInputColumnsColor = true; //} //catch (Exception ex) //{ // // 对异常进行共通处理 // ExceptionManager.HandleEventException(this.ToString(), // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); //} } /// /// 保存按钮事件 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { if (this.dgvDataJobs.Rows.Count == Constant.INT_IS_ZERO || this.scbUser.SearchedPKMember == 0) { return; } //信息必填 foreach (DataGridViewRow gvrFor in this.dgvDataJobs.Rows) { if (gvrFor.IsNewRow != true) { if (gvrFor.Cells["UserJobsID"].Value == null || gvrFor.Cells["UserJobsID"].Value == DBNull.Value) { MessageBox.Show("请为所有员工配置工种!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } if (gvrFor.Cells["StaffID"].Value == null || gvrFor.Cells["StaffID"].Value == DBNull.Value) { MessageBox.Show("请为已选择工种配置员工!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } } int ReturnRows = SystemModuleProxy.Service.AddUserStaff(scbUser.SearchedPKMember, (DataTable)this.dgvDataJobs.DataSource); if (ReturnRows > Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); this.DialogResult = DialogResult.OK; } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工关联", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } } /// /// 取消按钮事件 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } /// /// 添加行事件 /// /// /// private void dgvDataJobs_UserAddedRow(object sender, DataGridViewRowEventArgs e) { this.dgvDataJobs.IsSetInputColumnsColor = true; } #endregion #region 私有方法 /// /// 根据工号ID获取该工号的工种关联 /// /// private DataSet GetUserRowData() { try { return SystemModuleProxy.Service.GetJobByUserId(scbUser.SearchedPKMember); } catch (Exception ex) { throw ex; } } /// /// 绑定工种 /// private void BindUserJobs() { try { //获取可选择的工种数据源 DataSet userJobsData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserRowData)); foreach (DataRow dr in userJobsData.Tables[0].Rows) { dr["UserJobsCode"] = dr["UserJobsCode"].ToString() + "-" + dr["UserJobsName"].ToString(); } this.UserJobsCode.DisplayMember = "UserJobsCode"; this.UserJobsCode.ValueMember = "UserJobsId"; this.UserJobsCode.DataSource = userJobsData.Tables[0]; this._userJobsTable = userJobsData.Tables[0]; //获取用户当前关联的员工关系数据源 DataSet userStaffData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserStaffData)); this.dgvDataJobs.DataSource = userStaffData.Tables[0]; } catch (Exception ex) { throw ex; } } /// /// 获取工号下的员工 /// /// private DataSet GetUserStaffData() { return SystemModuleProxy.Service.GetUserStaffByUserId(scbUser.SearchedPKMember); } #endregion } }