/******************************************************************************* * Copyright(c) 2018 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_2702.cs * 2.功能描述:新建/编辑成型报损信息窗体 * 编辑履历: * 作者 日期 版本 修改内容 * 周兴 2018/03/27 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.Library; using Dongke.IBOSS.PRD.WCF.DataModels; namespace Dongke.IBOSS.PRD.Client.PMModule { /// /// 新建编辑成型报损信息窗体 /// public partial class F_PM_2702 : FormBase { #region 成员变量 //窗体模式ID private Constant.FormMode _formType; //修改产品报损信息ID private string _barCode; //报损信息ID private int _editSPId; //是否允许审批 private bool _isScrap = false; //报损原因 private DataTable _scrapReasonTable = null; //产品条码信息 private DataRow _barCodeRow = null; // 编辑时不根据工号加载员工信息 private bool _isLoadStaff = true; #endregion #region 构造函数 /// /// 窗体构造 /// public F_PM_2702(Constant.FormMode formType, string BarCode, int EditSPId, bool isScrap) { InitializeComponent(); this._formType = formType; this._barCode = BarCode; this._editSPId = EditSPId; this._isScrap = isScrap; if (formType == Constant.FormMode.Add) { this.Text = FormTitles.F_PM_2702_ADD; } else { this.Text = FormTitles.F_PM_2702_EDIT; } this.btnViewApprover.Text = ButtonText.BTN_VIEWAPPROVER; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; } #endregion #region 事件 /// /// 窗体加载 /// /// /// private void F_PM_2702_Load(object sender, EventArgs e) { try { // 损坯原因 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "MST_ScrapReason"; cre.Name = "GetScrapReasonData"; ServiceResultEntity result = new ServiceResultEntity(); result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.DoBarCodePrint(cre); })); // 没有数据时,直接返回 if (result == null || result.Data == null || result.Data.Tables.Count <= 0) { return; } _scrapReasonTable = result.Data.Tables[0]; this.cboRreason.DisplayMember = "ScrapReason"; this.cboRreason.ValueMember = "ScrapReasonID"; this.chkScrapTypeOne.Checked = false; //绑定损坯状态 DataTable dtAuditStatus = new DataTable(); dtAuditStatus.Columns.Add("AuditStatusID"); dtAuditStatus.Columns.Add("AuditStatusValue"); // 目前只需要审核通过 DataRow dr = dtAuditStatus.NewRow(); dr["AuditStatusID"] = 1; dr["AuditStatusValue"] = "审核通过"; dtAuditStatus.Rows.Add(dr); //dr["AuditStatusID"] = 0; //dr["AuditStatusValue"] = "待审核"; //dtAuditStatus.Rows.Add(dr); //if (this._isScrap) //{ // dr = dtAuditStatus.NewRow(); // dr["AuditStatusID"] = 1; // dr["AuditStatusValue"] = "损坯通过"; // dtAuditStatus.Rows.Add(dr); // dr = dtAuditStatus.NewRow(); // dr["AuditStatusID"] = 2; // dr["AuditStatusValue"] = "损坯驳回"; // dtAuditStatus.Rows.Add(dr); //} this.cboAuditStatus.DisplayMember = "AuditStatusValue"; this.cboAuditStatus.ValueMember = "AuditStatusID"; this.cboAuditStatus.DataSource = dtAuditStatus; if (this._formType == Constant.FormMode.Edit) { BindEntity(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 条码输入完毕后 /// /// /// private void txtBarCode_Validating(object sender, System.ComponentModel.CancelEventArgs e) { try { string BarCode = this.txtBarCode.Text.Trim(); if (!string.IsNullOrWhiteSpace(BarCode)) { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GroutingScrapProduct"; cre.Name = "GetGroutingDailyDetail"; cre.Properties["BarCode"] = this.txtBarCode.Text.Trim(); ServiceResultEntity result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxyNew.Service.HandleRequest(cre); })); if (result == null || result.Data == null || result.Data.Tables.Count == 0 || result.Data.Tables[0].Rows.Count == 0) { MessageBox.Show("未查询到该产品信息,请确认该产品是否已经进行注浆!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); //this.txtBarCode.Text = ""; this.txtBarCode.Focus(); return; } _barCodeRow = result.Data.Tables[0].Rows[0]; // 判断是否进行了注浆 if ("0".Equals(_barCodeRow["GroutingFlag"])) { MessageBox.Show("该产品还未进行注浆!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); //this.txtBarCode.Text = ""; this.txtBarCode.Focus(); return; } // 判断是否进行了交坯 if ("1".Equals(_barCodeRow["DeliverFlag"])) { MessageBox.Show("该产品已经交坯!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); //this.txtBarCode.Text = ""; this.txtBarCode.Focus(); return; } // 判断是否已经报损 if ("1".Equals(_barCodeRow["ScrapFlag"])) { MessageBox.Show("该产品已经报损!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); //this.txtBarCode.Text = ""; this.txtBarCode.Focus(); return; } this.txtGoodsCode.Text = _barCodeRow["GoodsCode"] + ""; this.txtGroutingLine.Text = _barCodeRow["GroutingLineCode"] + ""; this.txtMouldCode.Text = _barCodeRow["GroutingMouldCode"] + ""; this.txtGroutingUser.Text = _barCodeRow["GroutingUserCode"] + ""; } else { // 如果产品条码是空,那么就清空相关信息 this.txtGoodsCode.Clear(); this.txtGroutingLine.Clear(); this.txtMouldCode.Clear(); this.txtGroutingUser.Clear(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 切换报损类型,联动更换报损原因 /// /// /// private void chkScrapTypeOne_CheckedChanged(object sender, EventArgs e) { try { string scrapType = this.chkScrapTypeOne.Checked ? "0" : "1"; if (_scrapReasonTable != null && _scrapReasonTable.Rows.Count > 0) { _scrapReasonTable.DefaultView.RowFilter = "ScrapType = '" + scrapType + "'"; DataTable returnTable = _scrapReasonTable.DefaultView.ToTable(); _scrapReasonTable.DefaultView.RowFilter = string.Empty; this.cboRreason.DataSource = returnTable; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 提交操作 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { this.btnSave.Focus(); // 校验数据 if (!IsValidData()) { return; } // 给实体赋值 ClientRequestEntity cre = SetEntity(); ServiceResultEntity result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxyNew.Service.HandleRequest(cre); })); int resultRow = (int)result.Result; if (resultRow > Constant.INT_IS_ZERO) { //成功 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成型报损", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else if (resultRow == -99) { MessageBox.Show(string.Format(Messages.W_CMN_C_006, "未查询到该产品信息,请确认该产品是否已经进行注浆"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (resultRow == -100) { MessageBox.Show(string.Format(Messages.W_CMN_C_006, "该产品还未进行注浆"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (resultRow == -101) { MessageBox.Show(string.Format(Messages.W_CMN_C_006, "该产品已经交坯"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (resultRow == -102) { MessageBox.Show(string.Format(Messages.W_CMN_C_006, "该产品已经报损"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { //失败 MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "成型报损", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 察看审批意见 /// /// /// private void btnViewApprover_Click(object sender, EventArgs e) { try { string barCode = this.txtBarCode.Text; F_PM_1103 frmFPM1103 = new F_PM_1103(barCode, 1, _editSPId); DialogResult dialogresult = frmFPM1103.ShowDialog(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 选择工号改变 /// /// /// //private void dkUser_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e) //{ // try // { // if (this.sbxUser.UserID != null && _isLoadStaff) // { // if (this.sbxUser.Text != "") // { // this.dgvResponsible.AutoGenerateColumns = false; // DataSet dsUser = (DataSet)DoAsync(new BaseAsyncMethod(() => // { // return HRModuleProxy.Service.SearchHrStaffInfo(Convert.ToInt32(this.sbxUser.UserID)); // })); // if (dsUser != null && dsUser.Tables.Count > 0) // { // DataTable returnTable = dsUser.Tables[0]; // if (!returnTable.Columns.Contains("UserSelected")) // { // returnTable.Columns.Add("UserSelected", typeof(int)); // } // foreach (DataRow row in returnTable.Rows) // { // row["UserSelected"] = 1; // } // this.dgvResponsible.DataSource = returnTable; // } // } // else // { // this.dgvResponsible.DataSource = null; // this.sbxUser.ClearControl(); // } // } // else // { // this.dgvResponsible.DataSource = null; // } // } // catch (Exception ex) // { // // 对异常进行共通处理 // ExceptionManager.HandleEventException(this.ToString(), // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); // } //} /// /// 窗体关闭 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 私有方法 /// /// 加载数据 /// private void BindEntity() { try { //条码控件不可用 this.txtBarCode.Enabled = false; ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GroutingScrapProduct"; cre.Name = "GetGroutingScrapProduct"; cre.Properties["ScrapProductID"] = this._editSPId; cre.Properties["IsSearchStaff"] = true; ServiceResultEntity result = PMModuleProxyNew.Service.HandleRequest(cre); // 给控件赋值 if (result != null && result.Data != null && result.Data.Tables.Count > 0 && result.Data.Tables[0].Rows.Count > 0) { _isLoadStaff = false; DataRow row = result.Data.Tables[0].Rows[0]; this.txtBarCode.Text = row["BarCode"] + ""; this.txtGoodsCode.Text = row["GoodsCode"] + ""; this.txtGroutingLine.Text = row["GroutingLineCode"] + ""; this.txtMouldCode.Text = row["GroutingMouldCode"] + ""; this.txtGroutingUser.Text = row["GroutingUserCode"] + ""; this.dtpScrapDate.Value = Convert.ToDateTime(row["ScrapDate"]); //this.sbxUser.Text = row["ResponUserCode"] + ""; //this.sbxUser.UserName = row["ResponUserName"] + ""; //this.sbxUser.UserID = Convert.ToInt32(row["ResponUserID"]); //this.sbxUser.UserCode = row["ResponUserCode"] + ""; scbUser.SearchedPKMember = Convert.ToInt32(row["ResponUserID"]); scbUser.InitValue(row["ResponUserName"] + "", row["ResponUserCode"] + ""); this.cboAuditStatus.SelectedValue = Convert.ToInt32(row["AuditStatus"]); // 报损类型 if ("0".Equals(row["ScrapType"])) { this.chkScrapTypeOne.Checked = true; } this.cboRreason.SelectedValue = Convert.ToInt32(row["ScrapRreasonID"]); if (result.Data.Tables.Count > 1 && result.Data.Tables[1].Rows.Count > 0) { this.dgvResponsible.DataSource = result.Data.Tables[1]; } _isLoadStaff = true; } } catch (Exception ex) { throw ex; } } /// /// 保存前校验数据 /// /// private bool IsValidData() { try { // 产品条码 if (string.IsNullOrWhiteSpace(this.txtBarCode.Text)) { MessageBox.Show(string.Format(Messages.W_CMN_C_003, "产品条码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.txtBarCode.Focus(); return false; } // 责任工号 if (scbUser.SearchedPKMember == 0) { MessageBox.Show(string.Format(Messages.W_CMN_C_003, "责任工号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.scbUser.Focus(); return false; } // 损坯原因 if (string.IsNullOrWhiteSpace(this.cboRreason.SelectedValue + "")) { MessageBox.Show(string.Format(Messages.W_CMN_C_003, "损坯原因"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.cboRreason.Focus(); return false; } // 责任员工 如果责任员工不输入给出提示 DataTable returnTable = this.dgvResponsible.DataSource as DataTable; if (returnTable == null || returnTable.Rows.Count == 0) { MessageBox.Show(string.Format(Messages.W_CMN_C_003, "责任员工"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.dgvResponsible.Focus(); return false; } else { DataRow[] dataRows = returnTable.Select("UserSelected = 1"); if (dataRows.Length == 0) { MessageBox.Show(string.Format(Messages.W_CMN_C_003, "责任员工"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.dgvResponsible.Focus(); return false; } } return true; } catch (Exception ex) { throw ex; } } /// /// 保存之前给实体赋值 /// /// private ClientRequestEntity SetEntity() { try { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GroutingScrapProduct"; cre.Name = "SaveGroutingScrapProduct"; if (_formType == Constant.FormMode.Add) { // 产品条码 cre.Properties["BarCode"] = _barCodeRow["BarCode"]; // 产品ID cre.Properties["GoodsID"] = _barCodeRow["GoodsID"]; // 产品编码 cre.Properties["GoodsCode"] = _barCodeRow["GoodsCode"]; // 产品名称 cre.Properties["GoodsName"] = _barCodeRow["GoodsName"]; // 注浆日报ID cre.Properties["GroutingDailyID"] = _barCodeRow["GroutingDailyID"]; // 注浆日报明细ID cre.Properties["GroutingDailyDetailID"] = _barCodeRow["GroutingDailyDetailID"]; // 注浆日期 cre.Properties["GroutingDate"] = _barCodeRow["GroutingDate"]; // 成型生产线ID cre.Properties["GroutingLineID"] = _barCodeRow["GroutingLineID"]; // 成型生产线编码 cre.Properties["GroutingLineCode"] = _barCodeRow["GroutingLineCode"]; // 成型生产线名称 cre.Properties["GroutingLineName"] = _barCodeRow["GroutingLineName"]; // 成型线类型ID cre.Properties["GMouldTypeID"] = _barCodeRow["GMouldTypeID"]; // 成型生产线明细ID cre.Properties["GroutingLineDetailID"] = _barCodeRow["GroutingLineDetailID"]; // 注浆模具编号 cre.Properties["GroutingMouldCode"] = _barCodeRow["GroutingMouldCode"]; // 模具编号 cre.Properties["MouldCode"] = _barCodeRow["MouldCode"]; // 注浆工号ID cre.Properties["GroutingUserID"] = _barCodeRow["GroutingUserID"]; // 注浆工号编码 cre.Properties["GroutingUserCode"] = _barCodeRow["GroutingUserCode"]; // 注浆次数 cre.Properties["GroutingNum"] = _barCodeRow["GroutingNum"]; } else { // 报损ID cre.Properties["ScrapProductID"] = _editSPId; // 产品条码 cre.Properties["BarCode"] = this.txtBarCode.Text.Trim(); } // 报损类型 cre.Properties["ScrapType"] = this.chkScrapTypeOne.Checked ? "0" : "1"; // 损坯日期 cre.Properties["ScrapDate"] = this.dtpScrapDate.Value.ToString("yyyy-MM-dd"); // 报损原因 cre.Properties["ScrapRreasonID"] = this.cboRreason.SelectedValue; // 责任工号ID cre.Properties["ResponUserID"] = scbUser.SearchedPKMember; // 责任工号编码 cre.Properties["ResponUserCode"] = scbUser.SearchedValue; // 备注 cre.Properties["Remarks"] = this.txtRemarks.Text.Trim(); // 审核状态 cre.Properties["AuditStatus"] = this.cboAuditStatus.SelectedValue; // 责任员工 DataTable returnTable = this.dgvResponsible.DataSource as DataTable; returnTable.AcceptChanges(); returnTable = returnTable.Copy(); returnTable.DefaultView.RowFilter = "UserSelected = 1"; returnTable = returnTable.DefaultView.ToTable(); cre.Data = new DataSet(); cre.Data.Tables.Add(returnTable); return cre; } catch (Exception ex) { throw ex; } } #endregion /// /// 选择工号改变 /// /// /// private void scbUser_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e) { try { if (scbUser.SearchedPKMember != 0 && _isLoadStaff) { if (this.scbUser.Text != "") { this.dgvResponsible.AutoGenerateColumns = false; DataSet dsUser = (DataSet)DoAsync(new BaseAsyncMethod(() => { return HRModuleProxy.Service.SearchHrStaffInfo(scbUser.SearchedPKMember); })); if (dsUser != null && dsUser.Tables.Count > 0) { DataTable returnTable = dsUser.Tables[0]; if (!returnTable.Columns.Contains("UserSelected")) { returnTable.Columns.Add("UserSelected", typeof(int)); } foreach (DataRow row in returnTable.Rows) { row["UserSelected"] = 1; } this.dgvResponsible.DataSource = returnTable; } } else { this.dgvResponsible.DataSource = null; this.scbUser.ClearValue(); } } else { this.dgvResponsible.DataSource = null; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }