/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PC_0101_1_3.cs
* 2.功能描述:操作时间及备注录入
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/09/25 1.00 新建
*******************************************************************************/
using System;
using System.Windows.Forms;
using System.Data;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
namespace Dongke.IBOSS.PRD.Client.PCModule
{
public partial class F_PC_0101_1_3 : FormBase
{
#region 成员变量
private DataTable _dtBindSource = null;
private string _S_PC_001 = "";
private int _gridIndex = -1;
private DataRowView _currentRow = null;
#endregion
#region 构造函数
public F_PC_0101_1_3(DataTable dtBindSource, string titleStr)
{
InitializeComponent();
_dtBindSource = dtBindSource;
this.Text = titleStr;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString();
}
#endregion
#region 事件
///
/// 保存按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable;
if (this._S_PC_001 == "2")
{
DataRow[] drs = dtName.Select("MouldID is null");
if (drs != null && drs.Length > 0)
{
MessageBox.Show("不是所有成型模具都绑定了条码,请绑定条码模具后再保存。", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
return;
}
}
else if (this._S_PC_001 == "1")
{
DataRow[] drs = dtName.Select("MouldID is null");
if (drs != null && drs.Length > 0)
{
DialogResult dialogResult = MessageBox.Show("不是所有成型模具都绑定了条码,是否继续保存?", this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dialogResult != System.Windows.Forms.DialogResult.Yes)
{
this.txtBarcode.Focus();
return;
}
}
}
dtName.AcceptChanges();
dtName.TableName = "GMouldRecord";
ServiceResultEntity returnRow = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
{
return PCModuleProxy.Service.ChangeGMouldEndGroutingLineDetail(dtName);
}));
if (returnRow != null)
{
if (returnRow.Status == Constant.ServiceResultStatus.Success)
{
MessageBox.Show(this.Text + "成功", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
}
else if (returnRow.OtherStatus == -500)
{
MessageBox.Show("数据已经被修改,请重新编辑", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show(returnRow.Message,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show(this.Text + "失败", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体加载事件
///
///
///
private void F_PC_0101_1_2_Load(object sender, EventArgs e)
{
this.dgvGroutingLineDetail.AutoGenerateColumns = false;
DateTime accountDate = CommonModuleProxy.Service.GetAccountDate();
this.txtDateStart.Value = accountDate;
this.dgvGroutingLineDetail.DataSource = _dtBindSource;
// 设置可输入单元格的颜色
this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
DataSet dsSetting = SystemModuleProxy.Service.GetSystemSettingDataByCode(Constant.SettingType.S_PC_001.ToString());
if (dsSetting != null && dsSetting.Tables[0].Rows.Count > 0)
{
this._S_PC_001 = dsSetting.Tables[0].Rows[0]["SettingValue"].ToString();
}
}
///
/// 取消按钮事件
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 自适应列宽
///
///
///
private void btnAdaptive_Click(object sender, EventArgs e)
{
this.dgvGroutingLineDetail.AutoResizeColumns();
}
///
/// 设置只读
///
///
///
private void dgvGroutingLineDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv == null || dgv.ReadOnly || e.RowIndex < 0)
{
return;
}
try
{
if (string.IsNullOrEmpty(dgv.Rows[e.RowIndex].Cells["MouldID"].Value + ""))
{
// 自动生成模具
dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = false;
dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = false;
}
else
{
// 模具档案
dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = true;
dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = true;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 选择改变
///
///
///
private void dgvGroutingLineDetail_SelectionChanged(object sender, EventArgs e)
{
if(dgvGroutingLineDetail.CurrentRow == null)
{
return;
}
try
{
this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 验证模具条码
///
///
///
private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.btnAddMouldBarcode_Click(null, null);
}
}
///
/// 添加模具
///
///
///
private void btnAddMouldBarcode_Click(object sender, EventArgs e)
{
if (this.txtGMouldCode.Text == "" || this._gridIndex == -1 || this._currentRow == null)
{
MessageBox.Show("没有选择模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtGMouldCode.Focus();
return;
}
string barcode = this.txtBarcode.Text.Trim();
if (barcode == "")
{
MessageBox.Show("没有输入模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
return;
}
try
{
string gMouldCode = this.txtGMouldCode.Text;
DataTable dtInfo = _dtBindSource;
DataRow[] dr = dtInfo.Select("GroutingMouldCode <> '" + gMouldCode + "' and NewMouldBarcode = '" + barcode + "'");
if (dr.Length > 0)
{
MessageBox.Show("存在相同的模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
this.txtBarcode.SelectAll();
return;
};
// 验证模具条码状态
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "PC_Mould";
cre.Name = "GetMouldData";
cre.Properties["MouldBarcode"] = barcode;
ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
if (sre == null || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0)
{
MessageBox.Show("无效模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
this.txtBarcode.SelectAll();
return;
}
DataRow item = sre.Data.Tables["InfoData"].Rows[0];
int mouldStatus = Convert.ToInt32(item["MouldStatus"]);
if (mouldStatus != 1 && mouldStatus != 3)
{
MessageBox.Show("此模具当前状态为【" + item["MouldStatusName"] + "】,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
this.txtBarcode.SelectAll();
return;
}
// 验证产品型号
if (this._currentRow["GOODSID"] + "" != item["GOODSID"] + "")
{
MessageBox.Show("此模具产品型号为【" + item["GOODSCODE"] + "】,与当前产品型号不同,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
this.txtBarcode.SelectAll();
return;
}
int outputCount = Convert.ToInt32(item["OutputCount"]);
if (outputCount == 1)
{
// 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
if (this._currentRow["MOULDID"] != DBNull.Value)
{
//int oldMouldID = Convert.ToInt32(this._currentRow["MOULDID"]);
DataRow[] rows = dtInfo.Select("MOULDID=" + this._currentRow["MOULDID"]);
if (rows.Length > 1)
{
foreach (DataRow row in rows)
{
row["MouldSource"] = "0";
row["MOULDID"] = DBNull.Value;
row["MOULDCODE"] = DBNull.Value;
row["NewMouldBarcode"] = DBNull.Value;
row["GROUTINGCOUNT"] = 0;
row["MouldOutputNo"] = DBNull.Value;
row.EndEdit();
}
}
}
this._currentRow["MouldSource"] = "1";
this._currentRow["MOULDID"] = item["MOULDID"];
this._currentRow["MOULDCODE"] = item["MOULDCODE"];
this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
this._currentRow["MouldOutputNo"] = DBNull.Value;
this._currentRow["GOODSID"] = item["GOODSID"];
this._currentRow["GOODSNAME"] = item["GOODSNAME"];
this._currentRow["GOODSCODE"] = item["GOODSCODE"];
this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
this._currentRow["GROUTINGCOUNT"] = item["GroutingNums"];
this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
//this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "]";
this._currentRow.EndEdit();
}
else
{
// 一模多产时,必须绑定连续成型模具编号。 add by chenxy 2018-10-29
string minGMouldCode = this.txtGMouldCode.Text;
int maxIndex = Convert.ToInt32(minGMouldCode.Substring(minGMouldCode.Length - 3)) + outputCount;
string maxGMouldCode = this.txtGroutingLineCode.Text + "-" + maxIndex.ToString("000");
DataRow[] grows = dtInfo.Select("goodsid="+ this._currentRow["GOODSID"]+" And GroutingMouldCode>='" + minGMouldCode + "' and GroutingMouldCode<'" + maxGMouldCode + "'");
if (grows.Length != outputCount)
{
MessageBox.Show("此模具的产出数量为【" + outputCount + "】,当前成型模具数量不足或编号不连续,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtBarcode.Focus();
this.txtBarcode.SelectAll();
return;
}
//foreach (DataRow row in grows)
for (int i = 0; i < grows.Length; i++)
{
DataRow row = grows[i];
DataRow itemOutput = sre.Data.Tables["InfoData"].Rows[i];
// 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
if (row["MOULDID"] != DBNull.Value)
{
DataRow[] rows = dtInfo.Select("MOULDID=" + row["MOULDID"]);
if (rows.Length > 1)
{
foreach (DataRow crow in rows)
{
crow["MouldSource"] = "0";
crow["MOULDID"] = DBNull.Value;
crow["MOULDCODE"] = DBNull.Value;
crow["NewMouldBarcode"] = DBNull.Value;
crow["GROUTINGCOUNT"] = 0;
crow["MouldOutputNo"] = DBNull.Value;
crow.EndEdit();
}
}
}
row["MouldSource"] = "1";
row["MOULDID"] = item["MOULDID"];
row["MOULDCODE"] = item["MOULDCODE"];
row["NewMouldBarcode"] = item["MOULDBarcode"];
row["GOODSID"] = item["GOODSID"];
row["GOODSNAME"] = item["GOODSNAME"];
row["GOODSCODE"] = item["GOODSCODE"];
row["GoodsSpecification"] = item["GoodsSpecification"];
row["GROUTINGCOUNT"] = itemOutput["GroutingNum"];
row["MouldOutputNo"] = itemOutput["OutputNo"];
row["StandardGroutingCount"] = item["StandardGroutingNum"];
row.EndEdit();
}
}
this.txtBarcode.Clear();
this.txtBarcode.Focus();
//if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
//{
// this._gridIndex++;
//}
//else
//{
// this._gridIndex = 0;
//}
if (this._gridIndex + outputCount < this.dgvGroutingLineDetail.Rows.Count)
{
this._gridIndex += outputCount;
}
else
{
this._gridIndex = 0;
}
this.dgvGroutingLineDetail.CurrentCell =
this.dgvGroutingLineDetail.Rows[this._gridIndex].Cells[this.dgvGroutingLineDetail.CurrentCell.ColumnIndex];
this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
}
catch (Exception ex)
{
//_ShowFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
}
}