/******************************************************************************* * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_3602.cs * 2.功能描述:首件登记新建编辑 * 编辑履历: * 作者 日期 版本 修改内容 * 秦祺 2024/09/14 1.00 新建 *******************************************************************************/ 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; using System; using System.Data; using System.Windows.Forms; namespace Dongke.IBOSS.PRD.Client.PMModule { public partial class F_PM_3602 : DKDockPanelBase { #region 成员变量 // 窗体的单例模式 private static F_PM_3602 _instance; // 存储窗口的编辑状态 private Constant.FormMode _editStatus; private int _registerID; private int _barID; #endregion #region 构造函数 public F_PM_3602() { InitializeComponent(); } /// /// 构造函数 /// public F_PM_3602(Constant.FormMode editStatus, int registerID) { InitializeComponent(); this._editStatus = editStatus; // 根据新建、编辑状态为标题赋值 if (editStatus == Constant.FormMode.Add) { this.Text = "新建首件登记单"; } else { this.Text = "编辑首件登记单"; this._registerID = registerID; this.txtRegisterNo.ReadOnly = true; } // 按钮文本 this.btnSave.Text = ButtonText.BTN_SAVE; } /// /// 构造函数 /// public F_PM_3602(Constant.FormMode editStatus, int registerID, int barID) { InitializeComponent(); this._editStatus = editStatus; this.Text = "编辑首件登记单"; this._registerID = registerID; this._barID = barID; this.txtRegisterNo.ReadOnly = true; // 按钮文本 this.btnSave.Text = ButtonText.BTN_SAVE; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_PM_3602 Instance { get { if (_instance == null || _instance.IsDisposed) { _instance = new F_PM_3602(); } return _instance; } } #endregion #region 事件处理 /// /// 窗体加载事件 /// /// /// private void F_PM_3602_Load(object sender, EventArgs e) { try { //不自动添加列 dgvRegisterDetail.AutoGenerateColumns = false; #region 车间 DataTable dtWorkShop = new DataTable(); dtWorkShop.Columns.Add("WorkShopID"); dtWorkShop.Columns.Add("WorkShopNames"); DataRow drWorkShop = dtWorkShop.NewRow(); drWorkShop["WorkShopID"] = DBNull.Value; drWorkShop["WorkShopNames"] = Constant.CBO_SELECT_EMPTY_NAME; dtWorkShop.Rows.Add(drWorkShop); drWorkShop = dtWorkShop.NewRow(); drWorkShop["WorkShopID"] = 1; drWorkShop["WorkShopNames"] = "1"; dtWorkShop.Rows.Add(drWorkShop); drWorkShop = dtWorkShop.NewRow(); drWorkShop["WorkShopID"] = 2; drWorkShop["WorkShopNames"] = "2"; dtWorkShop.Rows.Add(drWorkShop); drWorkShop = dtWorkShop.NewRow(); drWorkShop["WorkShopID"] = 3; drWorkShop["WorkShopNames"] = "3"; dtWorkShop.Rows.Add(drWorkShop); cmbWORKSHOP.DisplayMember = "WorkShopID"; cmbWORKSHOP.ValueMember = "WorkShopNames"; cmbWORKSHOP.DataSource = dtWorkShop; #endregion #region 检验结果数据源 DataTable dt = new DataTable(); dt.Columns.Add("itemsValueID",typeof(decimal)); dt.Columns.Add("itemsValueName"); DataRow dr = dt.NewRow(); dr["itemsValueID"] = 1; dr["itemsValueName"] = "合格"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["itemsValueID"] = 0; dr["itemsValueName"] = "不合格"; dt.Rows.Add(dr); this.citemsvalue.DisplayMember = "itemsValueName"; this.citemsvalue.ValueMember = "itemsValueID"; this.citemsvalue.DataSource = dt; #endregion #region 首件检验产品类型 // 获取产品类型 ServiceResultEntity sreType = DoAsync(() => { return ReportModuleProxy.Service.GetRptDictionaryData(0, "TPC025"); } ); if (sreType.Data == null) { return; } if (sreType.Data != null && sreType.Data.Tables[0].Rows.Count > 0) { // 设置空选项 DataRow dataRow = sreType.Data.Tables[0].NewRow(); dataRow["DictionaryID"] = DBNull.Value; dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME; dataRow["DisplayNo"] = 0; sreType.Data.Tables[0].Rows.InsertAt(dataRow, 0); this.cmbFIRGOODSTYPE.DisplayMember = "DictionaryValue"; this.cmbFIRGOODSTYPE.ValueMember = "DictionaryID"; this.cmbFIRGOODSTYPE.DataSource = sreType.Data.Tables[0]; } #endregion #region 首件检验检验依据 // 获取检验依据 ServiceResultEntity sreType1 = DoAsync(() => { return ReportModuleProxy.Service.GetRptDictionaryData(0, "TPC026"); } ); if (sreType1.Data == null) { return; } if (sreType1.Data != null && sreType1.Data.Tables[0].Rows.Count > 0) { // 设置空选项 DataRow dataRow = sreType1.Data.Tables[0].NewRow(); dataRow["DictionaryID"] = DBNull.Value; dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME; dataRow["DisplayNo"] = 0; sreType1.Data.Tables[0].Rows.InsertAt(dataRow, 0); this.cmbFIRBASIS.DisplayMember = "DictionaryValue"; this.cmbFIRBASIS.ValueMember = "DictionaryID"; this.cmbFIRBASIS.DataSource = sreType1.Data.Tables[0]; } #endregion #region 查询当天的登记单号下一位 this.txtRegisterNo.Text = DateTime.Now.ToString("yyyyMMddHHmmss"); #endregion #region 编辑时查询数据 总单状态为已登记的不能修改总单,未登记的可以修改总单 if (_registerID > 0) { ServiceResultEntity sreno = DoAsync(() => { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_PM_3602"; cre.Name = "GetInfo"; cre.Properties["REGISTERID"] = _registerID; if (_barID > 0) { cre.Properties["BARID"] = _barID; } return PMModuleProxyNew.Service.HandleRequest(cre); }); if (sreno != null && sreno.Data.Tables.Count > 0 && sreno.Data.Tables[0].Rows.Count > 0) { DataTable dtable = sreno.Data.Tables[0]; this.txtRegisterNo.Text = dtable.Rows[0]["REGISTERNO"].ToString(); this.cmbWORKSHOP.SelectedValue = Convert.ToInt32(dtable.Rows[0]["WORKSHOP"]); this.scbGoods.CheckedData = sreno.Data.Tables[0]; this.scbGoods.Text = dtable.Rows[0]["GOODSNAME"].ToString(); this.txtGoodsCode.Text = dtable.Rows[0]["GOODSCODE"].ToString(); this.txtMATERIALCODE.Text = dtable.Rows[0]["MATERIALCODE"].ToString(); this.txtFIRQUANTITY.Text = dtable.Rows[0]["FIRQUANTITY"].ToString(); this.cmbFIRGOODSTYPE.SelectedValue = Convert.ToInt32(dtable.Rows[0]["FIRGOODSTYPE"]); this.cmbFIRBASIS.SelectedValue = Convert.ToInt32(dtable.Rows[0]["FIRBASIS"]); this.txtremarks.Text = dtable.Rows[0]["REMARKS"].ToString(); this.txtBarcodes.Text = dtable.Rows[0]["BARCODES"].ToString(); this.dtpACCOUNTDATE.Value = Convert.ToDateTime(dtable.Rows[0]["ACCOUNTDATE"].ToString()); //加载商标 scbGoods_SearchedItemChanged_1(null,null); this.cmbLogo.SelectedValue = Convert.ToInt32(dtable.Rows[0]["LOGOID"]); //状态不为0时,不允许修改总单 if (Convert.ToInt32(dtable.Rows[0]["STATUS"]) != 0) { this.txtRegisterNo.ReadOnly = true; this.cmbWORKSHOP.Enabled = false; this.scbGoods.ReadOnly = true; this.txtGoodsCode.ReadOnly = true; this.txtMATERIALCODE.ReadOnly = true; this.cmbLogo.Enabled = false; this.txtFIRQUANTITY.ReadOnly = true; this.cmbFIRGOODSTYPE.Enabled = false; this.cmbFIRBASIS.Enabled = false; this.txtremarks.ReadOnly = true; this.txtBarcodes.ReadOnly = true; this.dtpACCOUNTDATE.Enabled = false; } //条码明细 if (sreno.Data.Tables.Count > 1) { DataTable dtable2 = sreno.Data.Tables[1]; this.dgvRegisterDetail.DataSource = dtable2; this.ITEMSYTPE.ReadOnly = true; this.ITEMSNAME.ReadOnly = true; this.ITEMSINFO.ReadOnly = true; } } } #endregion } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体关闭事件 /// /// /// private void F_PM_3602_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 保存 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { //校验 if (string.IsNullOrEmpty(this.txtRegisterNo.Text)) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "登记单号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (string.IsNullOrWhiteSpace(this.cmbWORKSHOP.SelectedValue.ToString())) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "车间"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (Convert.ToInt32(this.scbGoods.SearchedPKMember) == 0) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (string.IsNullOrEmpty(this.txtFIRQUANTITY.Text.ToString())) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "检验数量"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (string.IsNullOrWhiteSpace(this.cmbFIRGOODSTYPE.SelectedValue.ToString())) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品类型"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (string.IsNullOrWhiteSpace(this.cmbFIRBASIS.SelectedValue.ToString())) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "检验依据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } //保存 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_PM_3602"; cre.Name = "SaveFirstRegister"; cre.Properties["REGISTERNO"] = this.txtRegisterNo.Text; cre.Properties["WORKSHOP"] = Convert.ToInt32(this.cmbWORKSHOP.SelectedValue); cre.Properties["GOODSID"] = Convert.ToInt32(this.scbGoods.SearchedPKMember); cre.Properties["GOODSCODE"] = this.txtGoodsCode.Text; cre.Properties["MATERIALCODE"] = this.txtMATERIALCODE.Text; cre.Properties["LOGOID"] = Convert.ToInt32(this.cmbLogo.SelectedValue); cre.Properties["FIRQUANTITY"] = Convert.ToInt32(this.txtFIRQUANTITY.Text); cre.Properties["FIRGOODSTYPE"] = Convert.ToInt32(this.cmbFIRGOODSTYPE.SelectedValue); cre.Properties["FIRBASIS"] = Convert.ToInt32(this.cmbFIRBASIS.SelectedValue); cre.Properties["REMARKS"] = this.txtremarks.Text; cre.Properties["BARCODES"] = this.txtBarcodes.Text; cre.Properties["ACCOUNTDATE"] = this.dtpACCOUNTDATE.Value; //判断新建、编辑 //编辑 dgvRegisterDetail.EndEdit(); if (_registerID > 0 ) { cre.Properties["REGISTERID"] = _registerID; if ( _barID > 0) { cre.Properties["BARID"] = _barID; if (dgvRegisterDetail.DataSource != null) { DataTable detail = (DataTable)(dgvRegisterDetail.DataSource); cre.Data = new DataSet(); cre.Data.Tables.Add(detail.Copy()); } } } ServiceResultEntity sre = DoAsync(() => { return PMModuleProxyNew.Service.HandleRequest(cre); }); if (Convert.ToInt32(sre.Result) < 0) { MessageBox.Show(sre.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.btnSave.Visible = false; this.Close(); } } catch (Exception ex) { this.btnSave.Enabled = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 商标变更事件 /// /// /// private void cmbLogo_SelectedValueChanged(object sender, EventArgs e) { try { if (Convert.ToInt32(this.cmbLogo.SelectedValue) > 0) { int logoid = Convert.ToInt32(this.cmbLogo.SelectedValue); ServiceResultEntity srematnr = DoAsync(() => { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_PM_3602"; cre.Name = "GetMatnr"; cre.Properties["GOODSCODE"] = this.txtGoodsCode.Text; cre.Properties["LOGOID"] = logoid; return PMModuleProxyNew.Service.HandleRequest(cre); }); if (srematnr != null && srematnr.Data.Tables.Count > 0) { string txtmatnr = srematnr.Data.Tables[0].Rows[0]["MATERIALCODE"].ToString(); this.txtMATERIALCODE.Text = txtmatnr; } } } catch (Exception ex) { throw ex; } } /// /// 产品选择 /// /// /// private void scbGoods_SearchedItemChanged_1(object sender, EventArgs e) { try { string goodscodevalue = scbGoods.SearchedValue.ToString(); //产品编码赋值 this.txtGoodsCode.Text = goodscodevalue; //查询产品商标 //根据表中GOODSCODE去查找对应的商标 ServiceResultEntity sreByid = DoAsync(() => { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_PM_0102"; cre.Name = "GetLogoInfoByLogoID"; cre.Properties["GOODSCODE"] = "'" + goodscodevalue + "'"; return SystemModuleProxy.Service.DoRequest(cre); }); if (sreByid != null && sreByid.Data.Tables.Count > 0) { DataTable dataTable = sreByid.Data.Tables[0]; this.cmbLogo.ValueMember = "LOGOID"; this.cmbLogo.DisplayMember = "LOGONAME"; this.cmbLogo.DataSource = dataTable; } } catch (Exception ex) { throw ex; } } #endregion } }