/******************************************************************************* * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PC_0602.cs * 2.功能描述:新增/编辑员工关联 * 编辑履历: * 作者 日期 版本 修改内容 * 袁新成 2015/04/17 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.PCModule { /// /// 新增/编辑员工关联 /// public partial class F_PC_0602 : DKFormBase { #region 成员变量 // 打开选择窗体的标识 private bool _showFromFlag = true; // 选中的员工编码 private string _staffCode; // 选中的工号ID private int? _userId; // 选中的工号编码 private string _userCode; // 页面数据源 private DataTable _dtSourse = new DataTable(); // 当前工号的工种集合 private DataTable _userJobsTable = new DataTable(); #endregion #region 构造函数 public F_PC_0602(int? UserId, string UserCode) { InitializeComponent(); if (UserId == null) { this.Text = FormTitles.F_PC_0602_ADD; } else { this.Text = FormTitles.F_PC_0602_EDIT; } this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; this._userId = UserId; this._userCode = UserCode; this.btnSave.Enabled = false; } #endregion #region 事件 /// /// 单元格值改变事件 /// /// /// private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -Constant.INT_IS_ONE) { if (!_showFromFlag) { return; } btnSave.Enabled = true; 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, this.dkUser.UserID.Value, 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 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_PC_0602_Load(object sender, EventArgs e) { try { this.dgvDataJobs.AutoGenerateColumns = false; if (this._userId != null) { this.dkUser.UserID = this._userId; this.dkUser.UserCode = this._userCode; this.dkUser.Text = this._userCode; } this.dgvDataJobs.IsSetInputColumnsColor = true; } catch (Exception ex) { throw ex; } } /// /// 工号值改变事件 /// /// /// private void dkUser_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e) { try { BindUserJobs(); this.dkUser.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.dkUser.UserID == null) { 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; } } } // 获取成型线类型数据并绑定到控件上 ServiceResultEntity sre = this.DoAsync(() => { return PCModuleProxyNew.Service.SetFPC0602Data(Convert.ToInt32(this.dkUser.UserID), this.DataSource); } ); if (sre.Status == Constant.ServiceResultStatus.Other) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); this.DialogResult = DialogResult.Cancel; this.Close(); return; } if (sre.Status != Constant.ServiceResultStatus.Success) { return; } if (sre.Status == Constant.ServiceResultStatus.Success) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); this.DialogResult = DialogResult.OK; } /* int ReturnRows = SystemModuleProxy.Service.AddUserStaff(Convert.ToInt32(this.dkUser.UserID), (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(Convert.ToInt32(this.dkUser.UserID)); } catch (Exception ex) { throw ex; } } */ /// /// 绑定工种 /// private void BindUserJobs() { try { //获取可选择的工种数据源 DataSet userJobsData=new DataSet(); // 调用服务器端获取数据集 ServiceResultEntity sre = DoAsync(() => { return PCModuleProxyNew.Service.GetJobByUserId(Convert.ToInt32(this.dkUser.UserID)); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { userJobsData = sre.Data; } this.UserJobsCode.DisplayMember = "UserJobsCodeName"; this.UserJobsCode.ValueMember = "UserJobsId"; this.UserJobsCode.DataSource = userJobsData.Tables[0]; this._userJobsTable = userJobsData.Tables[0]; //获取用户当前关联的员工关系数据源 this.GetUserStaffData(); } catch (Exception ex) { throw ex; } } /// /// 获取工号下的员工 /// /// private void GetUserStaffData() { int id = Convert.ToInt32(this.dkUser.UserID); this.dgvDataJobs.DataSource = null; // 调用服务器端获取数据集 ServiceResultEntity sre = DoAsync(() => { return PCModuleProxyNew.Service.GetFPC0601SNData(id); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { this.DataSource = sre.Data; this.dgvDataJobs.DataSource = this.DataSource.Tables[0];// sre.Data.Tables[0]; } } #endregion private void dgvDataJobs_UserDeletedRow(object sender, DataGridViewRowEventArgs e) { btnSave.Enabled = true; } } }