/*******************************************************************************
* 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
{
///
/// 注浆明细条码绑定
///
public partial class F_PM_0108 : DKFormBase
{
#region 成员变量
private bool _isSave = false; // 保存标识
#endregion
#region 构造函数
///
/// 构造函数
///
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 属性
///
/// 窗体状态
///
public Constant.FormMode FormMode
{
get;
set;
}
///
/// 注浆登记ID
///
public DataRow DrRow
{
get;
set;
}
#endregion
#region 事件
///
/// 窗体加载
///
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);
}
}
///
/// 窗体首次显示事件
///
///
///
private void F_PM_0108_Shown(object sender, EventArgs e)
{
if (FormMode == Constant.FormMode.Add)
{
scbGroutingLine.ShowSearchForm();
}
}
///
/// 提交选择列内容的修改
///
///
///
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);
}
}
///
/// 排序后设置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
{
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);
}
}
///
/// 清空条码
///
///
///
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)
{
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);
}
}
///
/// 成型线改变事件
///
///
///
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);
}
}
///
/// 关闭窗体
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 窗体关闭事件
///
///
///
private void F_PM_0108_FormClosing(object sender, FormClosingEventArgs e)
{
if (_isSave)
{
DialogResult = DialogResult.OK;
}
}
#endregion
#region 私有方法
///
/// 取得注浆日报信息
///
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
}
}