/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_0103.cs * 2.功能描述:注浆明细条码绑定 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2015/04/03 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_0103 : DKFormBase { #region 成员变量 // 注浆日报ID private int _dailyId; // 注浆日期 private DateTime _groutingDate = DateTime.Now.Date; private bool _canEdit = true; #endregion #region 构造函数 /// /// 构造函数 /// public F_PM_0103() : this(0) { } /// /// 构造函数 /// /// 注浆日报ID public F_PM_0103(int dailyID) { this.InitializeComponent(); this._dailyId = dailyID; this.InitializeControls(); } #endregion #region 属性 /// /// 注浆登记ID /// public List GroutingDailyIDs { get; private set; } #endregion #region 事件 /// /// 窗体加载 /// private void F_PM_0103_Load(object sender, EventArgs e) { try { this.lblGroutingDateValue.Text = string.Empty; DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo(); if (logoInfo != null && logoInfo.Tables.Count > 0) { this.cmbLogo.DataSource = logoInfo.Tables[0]; this.cmbLogo.DisplayMember = "LogoNameCode"; this.cmbLogo.ValueMember = "LogoID"; this.collogo.DataSource = logoInfo.Tables[0].Copy(); this.collogo.DisplayMember = "LogoNameCode"; this.collogo.ValueMember = "LogoID"; } // 设置列表未注浆原因选项数据源 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.GroutingDate = this._groutingDate; 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); } //else if ("BarCode".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)) { // 未绑定时,如果是改变了损坯标识,则对绑定条码进行控制输入 object obarCode = dataGridViewRow.Cells["colOBarCode"].Value; if (obarCode == null || obarCode == DBNull.Value || string.IsNullOrWhiteSpace(obarCode.ToString())) { // 选择了损坯 if (((int)Constant.GroutingScrapFlag.Yes).ToString() == dataGridViewRow.Cells["ScrapFlag"].Value.ToString()) { dataGridViewRow.Cells["BarCode"].ReadOnly = true; dataGridViewRow.Cells["BarCode"].Value = DBNull.Value; } else { if (_canEdit) { dataGridViewRow.Cells["BarCode"].ReadOnly = false; } else { dataGridViewRow.Cells["BarCode"].ReadOnly = true; } } 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 (txtBarCodeStart.ReadOnly || !_canEdit) { return; } if (e.KeyChar == Constant.SYSTEM_KEYBOARD_ENTER_VALUE) { this.btnBindBarCode_Click(sender, e); } } /// /// 绑定条码 /// /// /// private void btnBindBarCode_Click(object sender, EventArgs e) { if (!_canEdit) { return; } try { string barcodeBegin = this.txtBarCodeStart.Text.Trim(); if (barcodeBegin.Length <= 0) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_003, this.lblBarCodeStart.Text); this.txtBarCodeStart.Focus(); return; } System.Text.RegularExpressions.Match mc = System.Text.RegularExpressions.Regex.Match(barcodeBegin, @"^([a-zA-Z]*|[a-zA-Z0-9]*[a-zA-Z]+)([0-9]{10,})$"); // 中陶改为不控制条码位数 //if (!mc.Success) //{ // DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_005, barcodeBegin); // this.txtBarCodeStart.Focus(); // return; //} string strLetter = mc.Groups[1].Value; string strDigit = mc.Groups[2].Value; decimal digit = 0; // 如果能转换为数字,则按之前的逻辑绑定条码 if (decimal.TryParse(strDigit, out digit)) { int len = strDigit.Length; foreach (DataGridViewRow row in this.dgvDetail.Rows) { object sf = row.Cells["ScrapFlag"].Value; if (row.Cells["BarCode"].ReadOnly || sf == null || "1" == sf.ToString()) { continue; } string barcode = strLetter + (digit++).ToString().PadLeft(len, '0'); row.Cells["BarCode"].Value = barcode; DataRowView dataRow = row.DataBoundItem as DataRowView; if (dataRow != null) { dataRow.EndEdit(); } } } // 否则把条码赋给第一个注浆明细 else { dgvDetail.Rows[0].Cells["BarCode"].Value = barcodeBegin; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 清空条码 /// /// /// private void btnClearBarCode_Click(object sender, EventArgs e) { try { this.txtBarCodeStart.Clear(); foreach (DataGridViewRow row in this.dgvDetail.Rows) { if (!row.Cells["BarCode"].ReadOnly) { row.Cells["BarCode"].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 { // 验证条码重复 DataTable dtGROUTINGDAILYDETAIL = this.DataSource.Tables[1]; foreach (DataRow row in dtGROUTINGDAILYDETAIL.Rows) { string barcode = row["Barcode"].ToString().Trim(); if (string.IsNullOrWhiteSpace(barcode)) { row["Barcode"] = DBNull.Value; continue; } else { row["Barcode"] = barcode; } DataRow[] drs = dtGROUTINGDAILYDETAIL.Select("Barcode = '" + barcode + "' AND GROUTINGDAILYDETAILID <> " + row["GROUTINGDAILYDETAILID"]); if (drs != null && drs.Length > 0) { MessageBox.Show("注浆信息中有重复条码【" + barcode + "】", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.SetFPM0103Data(this.DataSource); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002); 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.txtGrouting.Text = null; this.txtBarCodeStart.Clear(); this.dgvDetail.DataSource = null; this.btnSave.Enabled = false; return; } if (sre.Status == Constant.ServiceResultStatus.Other) { 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_0103; // 功能按钮文本赋值 //this.tsbtnGrouting.Text = ButtonText.TSBTN_; 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_BINDBARCODE; this.btnClearBarCode.Text = ButtonText.BTN_CLEARBARCODE; this.txtBarCodeStart.ReadOnly = true; this.btnBindBarCode.Enabled = false; this.btnClearBarCode.Enabled = false; } /// /// 取得注浆日报信息 /// private void InitializeData() { try { if (this._dailyId > 0) { this.DataSource = null; this.dgvDetail.DataSource = null; this.txtBarCodeStart.Clear(); //this.txtGrouting.Clear(); this.txtGrouting.Text = null; // 获取成型线类型数据并绑定到控件上 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; } _canEdit = ((int)sre.Result == 1); 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); if (_canEdit) { this.txtGrouting.Text = string.Format("{0}({1})", lineDataRow["GroutingLineCode"], lineDataRow["MouldQuantity"]); this.txtGrouting.ForeColor = System.Drawing.Color.Black; } else { this.txtGrouting.Text = string.Format("{0}({1}) {2}", lineDataRow["GroutingLineCode"], lineDataRow["MouldQuantity"], sre.Message); this.txtGrouting.ForeColor = System.Drawing.Color.Red; } this.dgvDetail.DataSource = sre.Data.Tables[1]; this.SetEditGrid(); if (_canEdit) { this.btnBindBarCode.Enabled = true; this.txtBarCodeStart.ReadOnly = false; } else { this.btnBindBarCode.Enabled = false; this.txtBarCodeStart.ReadOnly = true; } this.btnClearBarCode.Enabled = true; this.btnSave.Enabled = true; this.txtBarCodeStart.Focus(); } } catch (Exception ex) { throw ex; } } /// /// 编辑模式下设置Grid编辑状态 /// private void SetEditGrid() { foreach (DataGridViewRow row in this.dgvDetail.Rows) { // 未注浆的,不能编辑 object groutingFlag = row.Cells["GroutingFlag"].Value; if (groutingFlag == null || ((int)Constant.GroutingFlag.Yes).ToString() != groutingFlag.ToString()) { row.Cells["BarCode"].ReadOnly = true; row.Cells["ScrapFlag"].ReadOnly = true; //row.Cells["Remarks"].ReadOnly = true; //row.Cells["colLogo"].ReadOnly = true; continue; } // 交坯后,不能编辑 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; } //object oscrapFlag = row.Cells["colOScrapFlag"].Value; //if (oscrapFlag != null && ((int)Constant.GroutingScrapFlag.Yes).ToString() == oscrapFlag.ToString()) //{ // row.ReadOnly = true; // row.Cells["Remarks"].ReadOnly = false; //} // 损坯后,不能编辑 if (((int)Constant.GroutingScrapFlag.Yes).ToString() == row.Cells["ScrapFlag"].Value.ToString()) { row.Cells["BarCode"].Value = DBNull.Value; row.Cells["BarCode"].ReadOnly = true; continue; } if (!_canEdit) { row.Cells["BarCode"].ReadOnly = true; continue; } row.Cells["BarCode"].ReadOnly = false; } this.dgvDetail.IsSetInputColumnsColor = true; } #endregion private void btnNGRSetting_Click(object sender, EventArgs e) { if (this.cmbLogo.SelectedIndex < 0) { return; } try { foreach (DataGridViewRow row in this.dgvDetail.Rows) { if (!row.Cells["colLogo"].ReadOnly) { row.Cells["colLogo"].Value = this.cmbLogo.SelectedValue; DataRowView dataRow = row.DataBoundItem as DataRowView; if (dataRow != null) { dataRow.EndEdit(); } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 一键绑定条码功能 /// /// /// private void btnQuickBindBarCode_Click(object sender, EventArgs e) { try { DataTable dtDetail = dgvDetail.DataSource as DataTable; if (dtDetail == null || dtDetail.Rows.Count == 0) { return; } // 异步处理,获取信息 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_PM_0108"; cre.Name = "GetBarcodeDraft"; cre.Properties["groutingdate"] = _groutingDate; // 调用服务器端获取数据集 ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxyNew.Service.HandleRequest(cre); })); if (sre.Data != null && sre.Data.Tables.Count > 0) { DataRow[] drBarcodeDraft = null; foreach (DataRow row in dtDetail.Rows) { drBarcodeDraft = sre.Data.Tables[0].Select("groutinglinecode = '" + row["groutinglinecode"] + "' AND groutingbatchno = " + row["groutingbatchno"] + " AND groutingmouldcode = '" + row["groutingmouldcode"] + "'"); if (drBarcodeDraft.Length > 0 && (row["GroutingFlag"]+"") == "1" && (row["ScrapFlag"]+"") == "0") { row["Barcode"] = drBarcodeDraft[0]["Barcode"]; } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }