| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PM_0108.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.Basics.Library;
- 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_0108 : DKFormBase
- {
- #region 成员变量
- private bool _isSave = false; // 保存标识
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_PM_0108()
- {
- this.InitializeComponent();
- // 功能按钮文本赋值
- 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.btnBindBarCode.Text = ButtonText.BTN_BINDBARCODE;
- this.btnClearBarCode.Text = ButtonText.BTN_CLEARBARCODE;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 窗体状态
- /// </summary>
- public Constant.FormMode FormMode
- {
- get;
- set;
- }
- /// <summary>
- /// 注浆登记ID
- /// </summary>
- public DataRow DrRow
- {
- get;
- set;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载
- /// </summary>
- private void F_PM_0108_Load(object sender, EventArgs e)
- {
- try
- {
- // 设置列表未注浆原因选项数据源
- 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 F_PM_0108_Shown(object sender, EventArgs e)
- {
- if (FormMode == Constant.FormMode.Add)
- {
- scbGroutingLine.ShowSearchForm();
- }
- }
- /// <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>
- /// 排序后设置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 (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)
- {
- 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 = Convert.ToDecimal(strDigit);
- int len = strDigit.Length;
- foreach (DataGridViewRow row in this.dgvDetail.Rows)
- {
- string barcode = strLetter + (digit++).ToString().PadLeft(len, '0');
- row.Cells["BarCode"].Value = barcode;
- 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 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)
- {
- try
- {
- // 验证条码重复
- DataTable dtDetail = dgvDetail.DataSource as DataTable;
- if (dtDetail == null || dtDetail.Rows.Count == 0)
- {
- MessageBox.Show(string.Format(Messages.W_CMN_C_006, "没有任何数据"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- return;
- }
- DataRow[] drs = null;
- foreach (DataRow row in dtDetail.Rows)
- {
- string barcode = row["Barcode"].ToString().Trim();
- if (string.IsNullOrWhiteSpace(barcode))
- {
- row["Barcode"] = DBNull.Value;
- continue;
- }
- else
- {
- row["Barcode"] = barcode;
- }
- drs = dtDetail.Select("Barcode = '" + barcode + "' AND groutinglinedetailid <> " + row["groutinglinedetailid"]);
- if (drs != null && drs.Length > 0)
- {
- MessageBox.Show("有重复条码【" + barcode + "】",
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- return;
- }
- }
- // 异步处理,获取信息
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "F_PM_0108";
- cre.Name = "SaveBarcodeDraft";
- cre.Properties["groutingdate"] = dtpGroutingDate.Value;
- cre.Properties["groutinglineid"] = scbGroutingLine.SearchedPKMember;
- cre.Properties["groutingbatchno"] = txtGroutingBatchno.Text.Trim();
- cre.Data = new DataSet();
- cre.Data.Tables.Add(dtDetail.Copy());
- // 调用服务器端获取数据集
- ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxyNew.Service.HandleRequest(cre);
- }));
- if (sre.OtherStatus > 0)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, Text, "保存"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- _isSave = true;
- if (FormMode == Constant.FormMode.Add)
- {
- txtGroutingBatchno.Text = (cre.Properties["groutingbatchno"].ToNullableInt32() + 1) + "";
- txtBarCodeStart.Text = string.Empty;
- foreach (DataRow row in dtDetail.Rows)
- {
- row["Barcode"] = DBNull.Value;
- }
- }
- else
- {
- Close();
- }
- }
- else if (sre.OtherStatus < 0 && !string.IsNullOrEmpty(sre.Message))
- {
- // 提示未查找到数据
- MessageBox.Show(string.Format(Messages.W_CMN_C_006, sre.Message),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- }
- else
- {
- // 提示未查找到数据
- MessageBox.Show(Messages.MSG_CMN_W007,
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- }
- }
- catch (Exception ex)
- {
- //this.SetEditGrid();
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 成型线改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void scbGroutingLine_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
- {
- try
- {
- dgvDetail.DataSource = null;
- if (scbGroutingLine.SearchedPKMember != 0)
- {
- // 异步处理,获取信息
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "F_PM_0108";
- cre.Name = "GetGroutingLineByGroutingID";
- cre.Properties["groutinglineid"] = scbGroutingLine.SearchedPKMember;
- cre.Properties["groutingdate"] = dtpGroutingDate.Value;
- // 调用服务器端获取数据集
- ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxyNew.Service.HandleRequest(cre);
- }));
- if (sre.Data != null && sre.Data.Tables.Count > 0)
- {
- dgvDetail.DataSource = sre.Data.Tables[0];
- txtGroutingBatchno.Text = sre.Result + "";
- }
- }
- }
- 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.Close();
- }
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_PM_0108_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (_isSave)
- {
- DialogResult = DialogResult.OK;
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 取得注浆日报信息
- /// </summary>
- private void InitializeData()
- {
- try
- {
- if (FormMode == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_PM_0107_ADD;
- dtpGroutingDate.Value = DateTime.Now.Date.AddDays(1);
- dtpGroutingDate.MinDate = DateTime.Now.Date;
- }
- else if (FormMode == Constant.FormMode.Edit)
- {
- this.Text = FormTitles.F_PM_0107_EDIT;
- dtpGroutingDate.Value = Convert.ToDateTime(DrRow["groutingdate"]);
- scbGroutingLine.Text = DrRow["GroutingLineCode"] + "";
- scbGroutingLine.SearchedPKMember = Convert.ToInt32(DrRow["groutinglineid"]);
- txtGroutingBatchno.Text = DrRow["GroutingBatchno"] + "";
- dtpGroutingDate.Enabled = false;
- scbGroutingLine.Enabled = false;
- txtGroutingBatchno.ReadOnly = true;
- // 异步处理,获取信息
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "F_PM_0108";
- cre.Name = "GetBarcodeDraft";
- cre.Properties["groutinglineid"] = DrRow["groutinglineid"];
- cre.Properties["groutingbatchno"] = DrRow["groutingbatchno"];
- cre.Properties["groutingdate"] = DrRow["groutingdate"];
- // 调用服务器端获取数据集
- ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxyNew.Service.HandleRequest(cre);
- }));
- if (sre.Data != null && sre.Data.Tables.Count > 0)
- {
- dgvDetail.DataSource = sre.Data.Tables[0];
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|