| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- /*******************************************************************************
- * 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
- {
- /// <summary>
- /// 注浆明细条码绑定
- /// </summary>
- public partial class F_PM_0103 : DKFormBase
- {
- #region 成员变量
- // 注浆日报ID
- private int _dailyId;
- // 注浆日期
- private DateTime _groutingDate = DateTime.Now.Date;
- private bool _canEdit = true;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_PM_0103()
- : this(0)
- {
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="dailyID">注浆日报ID</param>
- public F_PM_0103(int dailyID)
- {
- this.InitializeComponent();
- this._dailyId = dailyID;
- this.InitializeControls();
- }
- #endregion
- #region 属性
- /// <summary>
- /// 注浆登记ID
- /// </summary>
- public List<int> GroutingDailyIDs
- {
- get;
- private set;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 选择注浆登记信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 提交选择列内容的修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 损坯时,不能绑定条码
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 排序后设置Grid状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDetail_Sorted(object sender, EventArgs e)
- {
- this.SetEditGrid();
- }
- /// <summary>
- /// 自动列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- /// <summary>
- /// 页面关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- /// <summary>
- /// 绑定条码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 绑定条码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 清空条码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 保存数据
- /// </summary>
- 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<ServiceResultEntity>(() =>
- {
- 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<int>();
- }
- 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);
- }
- }
- /// <summary>
- /// 关闭窗体
- /// </summary>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 初始化控件
- /// </summary>
- 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;
- }
- /// <summary>
- /// 取得注浆日报信息
- /// </summary>
- 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<ServiceResultEntity>(() =>
- {
- 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;
- }
- }
- /// <summary>
- /// 编辑模式下设置Grid编辑状态
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 一键绑定条码功能
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- }
|