/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_0202.cs * 2.功能描述:新建/编辑用户管理 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2014/09/12 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Basics.Library; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; namespace Dongke.IBOSS.PRD.Client.SystemModule { /// /// 新建/编辑用户管理 /// public partial class F_MST_0202 : FormBase { #region 成员变量 // 页面传过来用户ID private int _userID; // 用户实体类 private SUserEntity _userEntity; // 编辑状态 private Constant.FormMode _editStatus; // 新建的用户ID集合 private List _userIDList = new List(); // 用户代码 private string _userCode; // 工种集合 private DataTable _dtJobs; // 工种关联数据源 private DataTable _dtUserJobs = new DataTable(); // 记录编辑前的缺陷编码 private string _jobsCodeValue; // 控制弹窗标识 private bool _ShowFlag = true; #endregion #region 构造函数 public F_MST_0202() { InitializeComponent(); } /// /// 构造函数 /// /// 窗体状态 public F_MST_0202(Constant.FormMode frmStatus) { InitializeComponent(); _editStatus = frmStatus; // 设置窗口标题,当为新建状态时显示新建用户,当为编辑状态时显示编辑用户 if (frmStatus == Constant.FormMode.Add) { this.Text = FormTitles.F_MST_0202_ADD; this.dtpLimitStartTime.Text = "8:00:00"; this.dtpLimitEndTime.Text = "17:00:00"; } else if (frmStatus == Constant.FormMode.Edit) { this.Text = FormTitles.F_MST_0202_EDIT; this.txtUserCode.Enabled = false; } // 工具栏按钮文本赋值 this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; } #endregion #region 属性 /// /// 页面传过来的用户ID /// public int UserID { get { return this._userID; } set { this._userID = value; } } /// /// 页面传过来的用户代码 /// public string UserCode { get { return this._userCode; } set { this._userCode = value; } } /// /// 用户ID集合 /// public List UserIDList { get { return _userIDList; } set { _userIDList = value; } } #endregion #region 事件 /// /// 保存按钮事件 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { // 验证输入是否正确 if (!this.CheckInputValidity()) { return; } //校验绑定工种情况 int rowCount = 0; foreach (DataGridViewRow gvrFor in this.dgvDataJobs.Rows) { if (gvrFor.IsNewRow == false) { //JobsID if (gvrFor.Cells["JobsID"].Value != null && gvrFor.Cells["JobsID"].Value.ToString() != "") { rowCount++; } } } if (chkIsWorker.Checked == true) { if (rowCount == Constant.INT_IS_ZERO) { // 提示信息 MessageBox.Show("生产工号必须绑定至少一个工种!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { if (rowCount > Constant.INT_IS_ONE) { // 提示信息 MessageBox.Show("非生产工号只能绑定一个工种!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } int returnUserID = Constant.INT_IS_ZERO; _userEntity = this.SetUserEntity(); if (_editStatus == Constant.FormMode.Add || _editStatus == Constant.FormMode.CopyAndAdd) { // 判断是否存在重复的用户编号 DataSet userCodeData = (DataSet)DoAsync(new BaseAsyncMethod(IsExistsUserCode)); if (userCodeData.Tables[0].Rows.Count > Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W011, this.txtUserCode.Text.Trim(), "用户信息"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtUserCode.Focus(); return; } if (_editStatus == Constant.FormMode.CopyAndAdd) { _userEntity.UserID = UserID; } // 新建用户,返回新建的用户ID this.btnSave.Enabled = false; this.btnCancel.Enabled = false; returnUserID = (int)DoAsync(new BaseAsyncMethod(AddUserInfo)); this.btnSave.Enabled = true; this.btnCancel.Enabled = true; if (returnUserID > Constant.INT_IS_ZERO) { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建用户", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this._userIDList.Add(returnUserID); if (_editStatus == Constant.FormMode.CopyAndAdd) { this.Close(); return; } this.InitializationForm(); }// 组织机构不存在 else if (returnUserID == -Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "不存在所选择的组织机构"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // 组织机构是一级组织机构不允许建立用户 else if (returnUserID == -Constant.INT_IS_TWO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构是一级组织机构,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // 该组织机构下存在子级组织机构,不允许建立用户 else if (returnUserID == -Constant.INT_IS_THREE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构存在子级组织,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (returnUserID == -Constant.INT_IS_FIVE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n系统活动的用户数已经超过授权数,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "新建用户", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { // 编辑 this.btnSave.Enabled = false; this.btnCancel.Enabled = false; _userEntity.UserID = UserID; returnUserID = (int)DoAsync(new BaseAsyncMethod(EditUserInfo)); this.btnSave.Enabled = true; this.btnCancel.Enabled = true; if (returnUserID > Constant.INT_IS_ZERO) { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "编辑用户", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } // 组织机构不存在 else if (returnUserID == -Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "不存在所选择的组织机构"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // 组织机构是一级组织机构不允许建立用户 else if (returnUserID == -Constant.INT_IS_TWO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构是一级组织机构,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // 该组织机构下存在子级组织机构,不允许建立用户 else if (returnUserID == -Constant.INT_IS_THREE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构存在子级组织,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (returnUserID == -Constant.INT_IS_FIVE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n系统活动的用户数已经超过授权数,不允许创建用户"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (returnUserID == -Constant.INT_IS_SIX) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n在审批流程节点中存在的用户不能停用"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "编辑用户", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { this.btnSave.Enabled = true; this.btnCancel.Enabled = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体加载事件 /// /// /// private void F_MST_0202_Load(object sender, EventArgs e) { try { if (this._editStatus == Constant.FormMode.CopyAndAdd) { this.Text = "复制工号【" + this.UserCode + "】"; this.dtpLimitStartTime.Text = "8:00:00"; this.dtpLimitEndTime.Text = "17:00:00"; } //获取工种集合 //GetJobs(); // 为画面控件赋初始值 this.chkValueFlag.Checked = true; this.dgvDataJobs.AutoGenerateColumns = false; // 加载打印机数据 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "MST0412"; cre.Name = "GetBarcodePrinter"; ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre); if (sre != null && sre.Status == Constant.ServiceResultStatus.Success) { DataTable dt = sre.Data.Tables[0]; DataRow dr = dt.NewRow(); dr["PrinterName"] = "无"; dt.Rows.InsertAt(dr, 0); this.cobBarcodePrinter.DataSource = sre.Data.Tables[0]; this.cobBarcodePrinter.DisplayMember = "PrinterName"; this.cobBarcodePrinter.ValueMember = "PrinterID"; } // 加载PLC cre = new ClientRequestEntity(); cre.NameSpace = "MST0413"; cre.Name = "GetPLC"; sre = CommonModuleProxy.Service.DoRequest(cre); if (sre != null && sre.Status == Constant.ServiceResultStatus.Success) { DataTable dt = sre.Data.Tables[0]; DataRow dr = dt.NewRow(); dr["PLCName"] = "无"; dt.Rows.InsertAt(dr, 0); this.cobPLC.DataSource = sre.Data.Tables[0]; this.cobPLC.DisplayMember = "PLCName"; this.cobPLC.ValueMember = "PLCID"; } // 获取用户信息数据集 DataSet userInfoData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserRowData)); int isJobsHave = 0; if (userInfoData != null && userInfoData.Tables.Count > Constant.INT_IS_ZERO) { // 编辑数据 给页面所有项赋值 if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[0].Rows.Count > Constant.INT_IS_ZERO) { DataRow userData = userInfoData.Tables[0].Rows[0]; if (this._editStatus == Constant.FormMode.Edit) { this.txtUserCode.Text = userData["UserCode"].ToString(); this.txtUserCode.Enabled = false; this.txtUserName.Text = userData["UserName"].ToString(); } this.txtMAC.Text = userData["LIMITMAC"].ToString(); this.txtRemarks.Text = userData["Remarks"].ToString(); this.chkValueFlag.Checked = userData["ValueFlag"].ToString() == "1" ? true : false; this.chkCanSmartLogin.Checked = userData["CanSmartLogin"].ToString() == "1" ? true : false; this.chkCanPCLogin.Checked = userData["CanPCLogin"].ToString() == "1" ? true : false; scbOrganization.CheckedData = userInfoData.Tables[0]; scbOrganization.Text = userData["OrganizationName"].ToString(); this.chkIsWorker.Checked = userData["IsWorker"].ToString() == "1" ? true : false; this.chkIsGroutingWorker.Checked = userData["IsGroutingWorker"].ToString() == "1" ? true : false; this.chkPublicBody.Checked = userData["ispublicbody"].ToString() == "1" ? true : false; this.chkPRD.Checked = userData["CanLoginPRD"].ToString() == "1" ? true : false; this.chkMBC.Checked = userData["CanLoginMBC"].ToString() == "1" ? true : false; if (userData["POST"] != DBNull.Value && userData["POST"] != null) { this.dkPost.PostName = userData["POSTName"].ToString(); this.dkPost.PostID = Convert.ToInt32(userData["POSTId"]); } if (userData["LimitStartTime"] != DBNull.Value && userData["LimitStartTime"] != null) { this.cbTime.Checked = true; this.dtpLimitStartTime.Text = userData["LimitStartTime"].ToString(); this.dtpLimitEndTime.Text = userData["LimitEndTime"].ToString(); } else { this.cbTime.Checked = false; this.dtpLimitStartTime.Text = "8:00:00"; this.dtpLimitEndTime.Text = "17:00:00"; } // 条码打印机 this.cobBarcodePrinter.SelectedValue = userData["BarcodePrinterID"]; this.cobPLC.SelectedValue = userData["plcID"]; } if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[1].Rows.Count > Constant.INT_IS_ZERO) { this.dgvDataJobs.AutoGenerateColumns = false; this.dgvDataJobs.DataSource = userInfoData.Tables[1]; isJobsHave++; } } if (isJobsHave == Constant.INT_IS_ZERO) { _dtUserJobs.Columns.Add("JobsCode", System.Type.GetType("System.String")); _dtUserJobs.Columns.Add("JobsID", System.Type.GetType("System.String")); _dtUserJobs.Columns.Add("JobsName", System.Type.GetType("System.String")); _dtUserJobs.Columns.Add("Remarks", System.Type.GetType("System.String")); this.dgvDataJobs.DataSource = _dtUserJobs; } this.dgvDataJobs.IsSetInputColumnsColor = true; this.dtpLimitStartTime.Enabled = this.cbTime.Checked; this.dtpLimitEndTime.Enabled = this.cbTime.Checked; } 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 (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE) { return; } DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex]; if ("JobsCode".Equals(columnItem.Name)) { this._jobsCodeValue = 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 dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e) { #region 改用弹出窗体模式 /* if (e.RowIndex != -1) { if (this.dgvDataJobs.Columns[e.ColumnIndex].Name == "JobsCode") { string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); //看看这条记录有没有被选过 for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++) { if (i != e.RowIndex) { if (this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value != null) { if (JobsCode == this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value.ToString()) { // 提示信息 MessageBox.Show("已经选择了该工种!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.dgvDataJobs.Rows.RemoveAt(e.RowIndex); return; } } } } StringBuilder strbFilterExpressions = new StringBuilder(); strbFilterExpressions.Append(string.Format("JobsId='{0}'", JobsCode)); DataTable TableCopy = _dtJobs.Copy(); TableCopy.DefaultView.RowFilter = strbFilterExpressions.ToString(); DataTable EndTable = TableCopy.DefaultView.ToTable(); if (EndTable.Rows.Count != 0) { this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsName"].Value = EndTable.Rows[0]["JobsName"].ToString(); this.dgvDataJobs.Rows[e.RowIndex].Cells["Remarks"].Value = EndTable.Rows[0]["Remarks"].ToString(); this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsID"].Value = EndTable.Rows[0]["JobsID"].ToString(); } else { this.dgvDataJobs.Rows.RemoveAt(e.RowIndex); } } } */ #endregion try { if (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE || !_ShowFlag) { return; } DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex]; // 工种编号获取产品信息 if ("JobsCode".Equals(columnItem.Name)) { _ShowFlag = false; FormUtility.BindJobsRowDataSource(this.dgvDataJobs, e.RowIndex, columnItem.Name, _jobsCodeValue); // 设置可输入单元格的颜色 this.dgvDataJobs.IsSetInputColumnsColor = true; } this._ShowFlag = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 限制登陆时间选定改变事件 /// /// /// private void cbTime_CheckedChanged(object sender, EventArgs e) { this.dtpLimitStartTime.Enabled = this.cbTime.Checked; this.dtpLimitEndTime.Enabled = this.cbTime.Checked; } #endregion #region 私有方法 /// /// 获取用户明细数据 /// /// private DataSet GetUserRowData() { try { return SystemModuleProxy.Service.GetUserRowData(UserID); } catch (Exception ex) { throw ex; } } /// /// 添加用户数据 /// /// private object AddUserInfo() { try { DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource; dtJobs.TableName = "dtJobs"; this._userEntity.UserJobs = dtJobs; return SystemModuleProxy.Service.AddUserInfo(_userEntity); } catch (Exception ex) { throw ex; } } /// /// 是否存在相同的用户编码 /// /// private DataSet IsExistsUserCode() { try { return SystemModuleProxy.Service.IsExistsUserCode(this.txtUserCode.Text); } catch (Exception ex) { throw ex; } } /// /// 绑定下拉数据源 /// /// public DataTable datasourceCombox() { DataTable dt = new DataTable(); dt.Columns.Add("ValueID"); dt.Columns.Add("TextString"); DataRow dr = dt.NewRow(); dr["ValueID"] = 0; dr["TextString"] = "没有关联"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ValueID"] = 1; dr["TextString"] = "关联员工"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["ValueID"] = 2; dr["TextString"] = "关联员工组"; dt.Rows.Add(dr); return dt; } /// /// 编辑用户信息 /// /// private object EditUserInfo() { try { DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource; dtJobs.TableName = "dtJobs"; this._userEntity.UserJobs = dtJobs; return SystemModuleProxy.Service.EditUserInfo(this._userEntity); } catch (Exception ex) { throw ex; } } /// /// 清空输入项 /// private void InitializationForm() { this.txtUserCode.Clear(); this.txtUserName.Clear(); this.txtMAC.Clear(); this.txtRemarks.Clear(); this.scbOrganization.ClearValue(); this.chkValueFlag.Checked = true; this._dtUserJobs.Rows.Clear(); this.dgvDataJobs.IsSetInputColumnsColor = true; this.cobBarcodePrinter.SelectedIndex = 0; } /// /// 根据页面输入值,给用户对象实体赋值 /// /// private SUserEntity SetUserEntity() { SUserEntity userEntity = new SUserEntity(); userEntity.UserCode = this.txtUserCode.Text.Trim(); userEntity.UserName = this.txtUserName.Text.Trim(); userEntity.OrganizationID = scbOrganization.SearchedPKMember; userEntity.IsWorker = chkIsWorker.Checked ? 1 : 0; userEntity.IsGroutingWorker = chkIsGroutingWorker.Checked ? 1 : 0; userEntity.LimitMAC = txtMAC.Text; if (this.cbTime.Checked == true) { userEntity.LimitStartTime = Convert.ToDateTime(dtpLimitStartTime.Text); userEntity.LimitEndTime = Convert.ToDateTime(dtpLimitEndTime.Text); } else { userEntity.LimitStartTime = null; userEntity.LimitEndTime = null; } if (this.dkPost.PostID != null) { userEntity.PostID = Convert.ToInt32(this.dkPost.PostID); } userEntity.CanSmartLogin = chkCanSmartLogin.Checked ? 1 : 0; userEntity.CanPCLogin = chkCanPCLogin.Checked ? 1 : 0; userEntity.Remarks = txtRemarks.Text; userEntity.ValueFlag = chkValueFlag.Checked ? 1 : 0; userEntity.Ispublicbody = chkPublicBody.Checked ? 1 : 0; userEntity.CanLoginPRD = "1"; // chkPRD.Checked ? "1" : "0"; userEntity.CanLoginMBC = "0"; // chkMBC.Checked ? "1" : "0"; // 新建用户默认密码 DataSet ds = (DataSet)CommonModuleProxy.Service.GetSysSettingBySettingType("S_CMN_0001"); string pwd = "dongke"; if (ds.Tables[0].Rows.Count > 0) { pwd = ds.Tables[0].Rows[0]["SETTINGVALUE"].ToString(); } userEntity.Password = Encryption.GetMD5String(pwd); if (this.cobBarcodePrinter.SelectedValue != null && this.cobBarcodePrinter.SelectedValue != DBNull.Value) { userEntity.BarcodePrinterID = Convert.ToInt32(this.cobBarcodePrinter.SelectedValue); } if (this.cobPLC.SelectedValue != null && this.cobPLC.SelectedValue != DBNull.Value) { userEntity.PLCID = Convert.ToInt32(this.cobPLC.SelectedValue); } return userEntity; } /// /// 验证输入格式是否正确 /// /// private bool CheckInputValidity() { if (string.IsNullOrEmpty(this.txtUserCode.Text.Trim())) { this.txtUserCode.IsMustInput = true; this.txtUserCode.Focus(); return false; } this.txtUserCode.IsMustInput = false; if (string.IsNullOrEmpty(this.txtUserName.Text.Trim())) { this.txtUserName.IsMustInput = true; this.txtUserName.Focus(); return false; } this.txtUserName.IsMustInput = false; if (this.scbOrganization.SearchedPKMember == 0) { lblOrganization.IsMustInput = true; this.scbOrganization.Focus(); return false; } lblOrganization.IsMustInput = false; return true; } /// /// 获取工种方法 /// private void GetJobs() { try { //byte valueFlag = Convert.ToByte(false); //_dtJobs = SystemModuleProxy.Service.GetJobsData(valueFlag).Tables[0]; //foreach(DataRow dr in _dtJobs.Rows) //{ // dr["JobsCode"] = dr["JobsCode"].ToString() + "-" + dr["JobsName"].ToString(); //} //this.JobsCode.DisplayMember = "JobsCode"; //this.JobsCode.ValueMember = "JobsId"; //this.JobsCode.DataSource = _dtJobs; } catch (Exception ex) { throw ex; } } #endregion } }