/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_2901.cs * 2.功能描述:开模报损 * 编辑履历: * 作者 日期 版本 修改内容 * 周兴 2018/04/02 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Text; 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.PMModule { /// /// 注浆明细条码绑定 /// public partial class F_PM_2901 : DKFormBase { #region 成员变量 // 注浆日报ID private int _dailyId; // 注浆日期 private DateTime _groutingDate = DateTime.Now.Date; #endregion #region 构造函数 /// /// 构造函数 /// public F_PM_2901() : this(0) { } /// /// 构造函数 /// /// 注浆日报ID public F_PM_2901(int dailyID) { this.InitializeComponent(); this._dailyId = dailyID; this.InitializeControls(); } #endregion #region 属性 /// /// 注浆登记ID /// public List GroutingDailyIDs { get; private set; } #endregion #region 事件 /// /// 窗体加载 /// private void F_PM_2901_Load(object sender, EventArgs e) { try { this.lblGroutingDateValue.Text = string.Empty; // 设置列表 this.InitializeData(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 全线注浆按钮按下,生成该成型班长的所有注浆信息 /// /// /// private void tsbtnGrouting_Click(object sender, EventArgs e) { try { F_PM_0105 frmPM0105 = new F_PM_0105(); frmPM0105.IsBarCodeScrapReasonUseFlag = true; DialogResult dialogResult = frmPM0105.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } this._dailyId = frmPM0105.GroutingDailyID; this.InitializeData(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 提交选择列内容的修改 /// /// /// private void dgvDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e) { try { if (this.dgvDetail.CurrentRow != null && this.dgvDetail.IsCurrentCellDirty) { if ("ScrapFlag".Equals(this.dgvDetail.Columns [this.dgvDetail.CurrentCell.ColumnIndex].Name)) { this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 损坯时,不能绑定条码 /// private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } try { DataGridViewRow dataGridViewRow = this.dgvDetail.Rows[e.RowIndex]; if ("ScrapFlag".Equals(this.dgvDetail.Columns[e.ColumnIndex].Name)) { // 未绑定时,如果是改变了损坯标识,则对绑定条码进行控制输入 if (string.IsNullOrWhiteSpace(dataGridViewRow.Cells["colOBarCode"].Value + "")) { if (Convert.ToBoolean(dataGridViewRow.Cells["ScrapFlag"].EditedFormattedValue)) { dataGridViewRow.Cells["SReasonID"].ReadOnly = false; } else { dataGridViewRow.Cells["SReasonID"].ReadOnly = true; dataGridViewRow.Cells["SReasonID"].Value = DBNull.Value; } this.dgvDetail.IsSetInputColumnsColor = true; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 排序后设置Grid状态 /// /// /// private void dgvDetail_Sorted(object sender, EventArgs e) { this.SetEditGrid(); } /// /// 自动列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 页面关闭 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } /// /// 绑定条码 /// /// /// private void txtBarCodeStart_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Constant.SYSTEM_KEYBOARD_ENTER_VALUE) { this.btnBindBarCode_Click(sender, e); } } /// /// 绑定报损原因 /// /// /// private void btnBindBarCode_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(this.cboSReason.SelectedValue + "")) { int sReasonID = Convert.ToInt32(this.cboSReason.SelectedValue); for (int i = 0; i < this.dgvDetail.Rows.Count; i++) { if (Convert.ToBoolean(this.dgvDetail.Rows[i].Cells["ScrapFlag"].EditedFormattedValue)) { this.dgvDetail.Rows[i].Cells["SReasonID"].Value = sReasonID; } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 清空条码 /// /// /// private void btnClearBarCode_Click(object sender, EventArgs e) { try { foreach (DataGridViewRow row in this.dgvDetail.Rows) { row.Cells["SReasonID"].Value = DBNull.Value; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 保存数据 /// private void btnSave_Click(object sender, EventArgs e) { // 没有注浆数据 if (this.DataSource == null || this._dailyId <= 0) { return; } try { // 校验数据 if (!IsValidData()) { return; } ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GroutingScrapProduct"; cre.Name = "SaveScrapKm"; cre.Data = this.DataSource; ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.HandleRequest(cre); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { if (string.IsNullOrWhiteSpace(sre.Message)) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "开模报损", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("开模报损保存成功,但有部分商品未成功;具体信息如下【" + sre.Message + "】。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } if (this.GroutingDailyIDs == null) { this.GroutingDailyIDs = new List(); } this.GroutingDailyIDs.Add(this._dailyId); //this.DialogResult = DialogResult.OK; //this.Close(); this._dailyId = 0; this.lblGroutingDateValue.Text = string.Empty; this.txtGrouting.Clear(); this.dgvDetail.DataSource = null; this.btnSave.Enabled = false; return; } else if (sre.Status == Constant.ServiceResultStatus.Other) { int resultRow = (int)sre.Result; if (resultRow == -99) { MessageBox.Show(string.Format(Messages.W_CMN_C_006, "未查询到该产品信息,请确认该产品是否已经进行注浆"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); } } this.SetEditGrid(); } catch (Exception ex) { this.SetEditGrid(); // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭窗体 /// private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } #endregion #region 私有方法 /// /// 初始化控件 /// private void InitializeControls() { this.Text = FormTitles.F_PM_2901; // 功能按钮文本赋值 this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnClose.Text = ButtonText.BTN_CLOSE; this.dgvDetail.AutoGenerateColumns = false; this.lblGroutingDateValue.Text = string.Empty; this.btnBindBarCode.Text = ButtonText.BTN_BINDSCRAPREASON; this.btnClearBarCode.Text = ButtonText.BTN_CLEARSCRAPREASON; this.btnBindBarCode.Enabled = false; this.btnClearBarCode.Enabled = false; } /// /// 取得注浆日报信息 /// private void InitializeData() { try { if (this._dailyId > 0) { this.DataSource = null; this.dgvDetail.DataSource = null; this.txtGrouting.Clear(); // 获取成型线类型数据并绑定到控件上 ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.GetFPM0103Data(this._dailyId); } ); if (sre.Status == Constant.ServiceResultStatus.Other) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); return; } if (sre.Status != Constant.ServiceResultStatus.Success) { return; } this.DataSource = sre.Data; DataRow lineDataRow = sre.Data.Tables[0].Rows[0]; this._groutingDate = Convert.ToDateTime(lineDataRow["GroutingDate"]); this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD); this.txtGrouting.Text = string.Format("{0}({1})", lineDataRow["GroutingLineCode"], lineDataRow["MouldQuantity"]); this.dgvDetail.DataSource = sre.Data.Tables[1]; // 获取成型报损原因 if (sre.Data.Tables.Count > 2) { SReasonID.DisplayMember = "ScrapReason"; SReasonID.ValueMember = "ScrapReasonID"; SReasonID.DataSource = sre.Data.Tables[2]; this.cboSReason.DisplayMember = "ScrapReason"; this.cboSReason.ValueMember = "ScrapReasonID"; this.cboSReason.DataSource = sre.Data.Tables[2]; } this.SetEditGrid(); this.btnBindBarCode.Enabled = true; this.btnClearBarCode.Enabled = true; this.btnSave.Enabled = true; } } catch (Exception ex) { throw ex; } } /// /// 编辑模式下设置Grid编辑状态 /// private void SetEditGrid() { foreach (DataGridViewRow row in this.dgvDetail.Rows) { // 报损标识勾上才可以编辑报损原因 if (!Convert.ToBoolean(row.Cells["ScrapFlag"].EditedFormattedValue)) { row.Cells["SReasonID"].ReadOnly = true; } //// 交坯后,不能编辑 //object deliverFlag = row.Cells["DeliverFlag"].Value; //if (deliverFlag != null && "1" == deliverFlag.ToString()) //{ // row.Cells["BarCode"].ReadOnly = true; // row.Cells["ScrapFlag"].ReadOnly = true; // row.Cells["Remarks"].ReadOnly = true; // row.Cells["colLogo"].ReadOnly = true; // continue; //} //// 绑定条码后,不能编辑条码 //object obarCode = row.Cells["colOBarCode"].Value; //if (obarCode != null && !string.IsNullOrWhiteSpace(obarCode.ToString())) //{ // row.Cells["BarCode"].ReadOnly = true; // continue; //} //// 损坯后,不能编辑 //if (((int)Constant.GroutingScrapFlag.No).ToString() == row.Cells["ScrapFlag"].Value.ToString()) //{ // row.Cells["BarCode"].ReadOnly = false; //} //else //{ // row.Cells["BarCode"].Value = DBNull.Value; // row.Cells["BarCode"].ReadOnly = true; //} } this.dgvDetail.IsSetInputColumnsColor = true; } /// /// 校验数据 /// /// private bool IsValidData() { try { for (int j = 0; j < this.dgvDetail.Rows.Count; j++) { // 判断如果勾选上报损标识,那么报损原因必须输入 if (Convert.ToBoolean(this.dgvDetail.Rows[j].Cells["ScrapFlag"].EditedFormattedValue) && string.IsNullOrWhiteSpace(this.dgvDetail.Rows[j].Cells["SReasonID"].EditedFormattedValue + "")) { dgvDetail.CurrentCell = dgvDetail.Rows[j].Cells["ScrapFlag"]; // 增加单元格的错误消息 dgvDetail.Rows[j].ErrorText = string.Format(Messages.W_CMN_S_004, "报损原因为空"); return false; } } return true; } catch (Exception ex) { throw ex; } } #endregion } }