/******************************************************************************* * Copyright(c) 2014 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_1203.cs * 2.功能描述:仓库 * 编辑履历: * 作者 日期 版本 修改内容 * 张忠帅 2024/1/15 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Basics.Library; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; namespace Dongke.IBOSS.PRD.Client.SystemModule { /// /// 仓库管理 /// public partial class F_MST_1203 : FormBase { #region 成员变量 // 窗体的单例模式 private static F_MST_1203 _instance; // 仓库管理数据源 private DataTable _dtSourse; #endregion #region 构造函数 /// /// 构造函数 /// public F_MST_1203() { InitializeComponent(); // 窗口标题 this.Text = FormTitles.F_MST_1203; // 按钮 this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_MST_1203 Instance { get { if (_instance == null) { _instance = new F_MST_1203(); } return _instance; } } #endregion #region 事件 /// /// 窗体加载 /// /// /// private void F_MST_1203_Load(object sender, System.EventArgs e) { try { // 设置datagridview不自动创建列 this.dgvDataDefect.AutoGenerateColumns = false; // 窗体启动立即加载全部仓库信息 this.GetSendWareHouse(); //权限控制 FormPermissionManager.FormPermissionControl(this.Name, this, LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData); this.dgvDataDefect.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 点击右上角关闭按钮 /// /// /// private void F_MST_1203_FormClosing(object sender, FormClosingEventArgs e) { try { // 关闭的时候需要判断是否有数据变化 if (DataJudge.IsChange((DataTable)this.dgvDataDefect.DataSource)) { DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); // 保存改变的数据 if (dialogResult == DialogResult.Yes) { DataGridViewRow row = dgvDataDefect.CurrentRow; if (!row.IsNewRow) { // 判断产品缺陷编码不能为空 if (row.Cells["WAREHOUSECODE"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSECODE"].Value + string.Empty)) { // 错误消息 MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库代码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; this.btnSave.Enabled = false; return; } // 判断产品缺陷名称不能为空 if (row.Cells["WAREHOUSENAME"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSENAME"].Value + string.Empty)) { // 单元格的错误消息 MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库名称"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; this.btnSave.Enabled = false; return; } // 判断缺陷类别不能为空 if (row.Cells["WAREHOUSETYPE"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSETYPE"].Value + string.Empty)) { // 单元格的错误消息 MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库类型"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; this.btnSave.Enabled = false; return; } } // 异步处理 object result = DoAsync(new BaseAsyncMethod(SaveDefectData)); if (result.Equals(Constant.INT_IS_ONE)) { MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "仓库代码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; this.btnSave.Enabled = false; return; } // 保存成功,不关闭窗体 if (Convert.ToInt32(result) > Constant.INT_IS_ZERO) { e.Cancel = true; MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "仓库管理", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.btnSave.Enabled = false; // 加载产品缺陷管理数据 GetSendWareHouse(); } else if (Convert.ToInt32(result) == (int)Constant.RETURN_IS_EXIST) { e.Cancel = true; MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "仓库代码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { e.Cancel = true; MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "仓库管理", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (dialogResult == DialogResult.Cancel) { e.Cancel = true; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体关闭后,释放单例资源 /// /// /// private void F_MST_1203_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 选中新行时,设置默认值 /// /// /// private void dgvDataDefect_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) { // 设置有效属性为选中状态 e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE; } /// /// 仓库管理信息输入格式控制 /// /// /// private void dgvDataDefect_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { try { TextBox tb = (e.Control as TextBox); if (tb != null) { if ("WAREHOUSECODE" == this.dgvDataDefect.Columns[this.dgvDataDefect.CurrentCell.ColumnIndex].Name) { tb.CharacterCasing = CharacterCasing.Upper; } else { tb.CharacterCasing = CharacterCasing.Normal; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单元格验证,检查 /// /// /// private void dgvDataDefect_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { try { if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name)) { return; } if (!dgvDataDefect.CurrentRow.IsNewRow) { DataGridViewRow rowItem = dgvDataDefect.Rows[e.RowIndex]; DataGridViewColumn columnItem = dgvDataDefect.Columns[e.ColumnIndex]; object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue; // 仓库编码 if ("WAREHOUSECODE".Equals(columnItem.Name)) { if (columnvalue != null && !string.IsNullOrEmpty(columnvalue + string.Empty)) { if (!Utility.IsUnique(columnvalue.ToString(), dgvDataDefect.CurrentRow.Index, this.dgvDataDefect, "WAREHOUSECODE")) { // 单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Format( Messages.MSG_CMN_W006, "仓库编码"); e.Cancel = true; this.btnSave.Enabled = false; return; } } } // 清除单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Empty; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 根据数据是否变化,设置保存按钮的可用状态 /// /// /// private void dgvDataDefect_CellValidated(object sender, DataGridViewCellEventArgs e) { try { this.SetSaveBtnStatus(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 行校验 /// /// /// private void dgvDataDefect_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { try { // 按Esc键时不校验 if (!dgvDataDefect.IsCurrentRowDirty) { this.dgvDataDefect.IsSetInputColumnsColor = true; return; } if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name)) { // 清除单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Empty; return; } DataGridViewRow row = dgvDataDefect.CurrentRow; if (!row.IsNewRow) { // 判断仓库编码能为空 if (row.Cells["WAREHOUSECODE"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSECODE"].Value + string.Empty)) { // 单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "仓库编码"); e.Cancel = true; this.btnSave.Enabled = false; return; } // 判断仓库名称不能为空 if (row.Cells["WAREHOUSENAME"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSENAME"].Value + string.Empty)) { // 单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "仓库名称"); e.Cancel = true; this.btnSave.Enabled = false; return; } // 判断仓库类别不能为空 if (row.Cells["WAREHOUSETYPE"].Value == null || string.IsNullOrEmpty(row.Cells["WAREHOUSETYPE"].Value + string.Empty)) { // 单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "仓库类型"); e.Cancel = true; this.btnSave.Enabled = false; return; } // 清除单元格的错误消息 this.dgvDataDefect.CurrentRow.ErrorText = string.Empty; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 根据数据是否变化,设置保存按钮的可用状态 /// /// /// private void dgvDataDefect_RowValidated(object sender, DataGridViewCellEventArgs e) { try { this.SetSaveBtnStatus(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 根据是否选中停用数据,加载数据 /// /// /// private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e) { try { this.SetSaveBtnStatus(); this.dgvDataDefect.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单元格输入时,给自动生成的行设置颜色 /// /// /// private void dgvDataDefect_UserAddedRow(object sender, DataGridViewRowEventArgs e) { this.dgvDataDefect.IsSetInputColumnsColor = true; } /// /// 设置排序时列表的颜色 /// private void dgvDataDefect_Sorted(object sender, EventArgs e) { this.dgvDataDefect.IsSetInputColumnsColor = true; } /// /// 保存仓库数据 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { int results = Conservation(); //判断单元格必输项不能为空 if (results == Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库代码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.btnSave.Enabled = false; return; } if (results == Constant.INT_IS_TWO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库名称"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.btnSave.Enabled = false; return; } if (results == Constant.INT_IS_THREE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "仓库类别"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.btnSave.Enabled = false; return; } // 异步处理 this.btnSave.Enabled = false; this.btnCancel.Enabled = false; int result = (int)DoAsync(new BaseAsyncMethod(SaveDefectData)); this.btnSave.Enabled = true; this.btnCancel.Enabled = true; // 产品缺陷数据保存成功 if (result == Constant.INT_IS_TWO) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "仓库管理", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // 加载产品缺陷管理数据 GetSendWareHouse(); this.btnSave.Enabled = false; } else if (result == Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "仓库代码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "仓库管理", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.dgvDataDefect.IsSetInputColumnsColor = true; } 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 btnCancel_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 私有方法 /// /// 获取产品缺陷管理的全部数据 /// /// 用户信息 /// /// /// 2014.10.30 任海 新建 /// private void GetSendWareHouse() { try { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_MST_1203"; cre.Name = "GetSendWareHouse"; ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre); if (sre.Status == Constant.ServiceResultStatus.NoSearchResults || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0) { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } dgvDataDefect.DataSource = sre.Data.Tables[0]; } catch (Exception ex) { throw ex; } } /// /// 保存数据 /// /// 是否成功 private object SaveDefectData() { try { // 获取当前dataDefectData数据源 DataTable dataDefectData = new DataTable(); DataSet ds = new DataSet(); dataDefectData = ((DataTable)this.dgvDataDefect.DataSource).Copy(); ds.Tables.Add(dataDefectData); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_MST_1203"; cre.Name = "AddSendWareHouse"; cre.Data = ds; ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre); return sre.Result; } catch (Exception ex) { throw ex; } } /// /// 设置保存按钮的可用状态 /// private void SetSaveBtnStatus() { if (DataJudge.IsChange((DataTable)this.dgvDataDefect.DataSource)) { this.btnSave.Enabled = true; } else { this.btnSave.Enabled = false; } } /// /// 保存时单元格必输项不能为空 /// private int Conservation() { int isConservation = Constant.INT_IS_ZERO; DataTable dataDefectData = (DataTable)this.dgvDataDefect.DataSource; foreach (DataRow drproductionData in dataDefectData.Rows) { //判断必输项是否为空 if (drproductionData["WAREHOUSECODE"].ToString() == string.Empty) { isConservation = Constant.INT_IS_ONE; break; } if (drproductionData["WAREHOUSENAME"].ToString() == string.Empty) { isConservation = Constant.INT_IS_TWO; break; } if (drproductionData["WAREHOUSETYPE"].ToString() == string.Empty) { isConservation = Constant.INT_IS_THREE; break; } } return isConservation; } #endregion } }