/*******************************************************************************
* Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PC_1002.cs
* 2.功能描述:新建、编辑模具档案
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2017/12/11 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.PCModule
{
///
/// 新建、编辑模具档案
///
public partial class F_PC_1002 : DKFormBase
{
#region 成员变量
///
/// 模具ID
///
private int _mouldID = 0;
#endregion
#region 构造函数
///
/// 构造函数
///
public F_PC_1002(int mouldID)
{
InitializeComponent();
//this.txtWeight.Number = new Dongke.WinForm.Controls.DNumber(5, 2);
//this.txtCost.Number = new Dongke.WinForm.Controls.DNumber(5, 2);
//this.txtStandardGroutingNum.Number = new Dongke.WinForm.Controls.DNumber(6, 0);
//txtOutputCount.Number = new Dongke.WinForm.Controls.DNumber(3, 0);
this.txtWeight.Number = new Point(5, 2);
this.txtCost.Number = new Point(5, 2);
this.txtStandardGroutingNum.Number = new Point(6, 0);
txtOutputCount.Number = new Point(3, 0);
this._mouldID = mouldID;
if (this._mouldID > 0)
{
this.Text = "编辑模具档案";
this.txtBarcode.ReadOnly = true;
this.scbGoods.EditReadOnly = true;
this.scbGoods.Enabled = false;
}
else
{
this.Text = "新建模具档案";
}
}
#endregion
#region 事件处理
///
/// 画面加载
///
///
///
private void F_PC_1002_Load(object sender, System.EventArgs e)
{
try
{
if (this._mouldID > 0)
{
chkAutoPrint.Checked = false;
chkAutoPrint.Visible = false;
txtMCount.Visible = false;
lblMCount.Visible = false;
}
this.dtpPDate.Value = DateTime.Now;
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1002";
cre.Name = "GetFPC1002LoadData";
cre.Properties["MouldID"] = this._mouldID;
ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
if (sre == null)
{
this.Close();
return;
}
this.ftcMouldType.DataSource = sre.Data.Tables["MouldType"];
this.ftcSuppliers.DataSource = sre.Data.Tables["Suppliers"];
if (this._mouldID > 0)
{
DataRow item = sre.Data.Tables["InfoData"].Rows[0];
// 编辑
this.txtBarcode.Text = item["MouldBarcode"].ToString();
this.scbGoods.CheckedData = sre.Data.Tables["InfoData"];
this.scbGoods.Text = item["GoodsCode"].ToString();
this.ftcMouldType.InitValue(item["MouldTypeName"].ToString(), item["MouldType"]);
this.ftcSuppliers.InitValue(item["SupplierName"].ToString(), item["materialsupplier"]);
this.dtpPDate.Value = Convert.ToDateTime(item["ProductionDate"]);
this.txtWeight.DataValue = Convert.ToDecimal(item["Weight"]);
this.txtCost.DataValue = Convert.ToDecimal(item["Cost"]);
this.txtStandardGroutingNum.DataValue = Convert.ToDecimal(item["StandardGroutingNum"]);
this.txtOutputCount.DataValue = Convert.ToDecimal(item["OutputCount"]);
this.txtRemarks.Text = item["Remarks"].ToString();
this.dkUserInfo.Text = item["UserCode"].ToString();
this.dkUserInfo.UserCode = item["UserCode"].ToString();
this.dkUserInfo.UserID = Convert.ToInt32(item["UserID"]);
this.txtStandardGroutingNum.ReadOnly = true;
this.txtOutputCount.ReadOnly = true;
}
else
{
//this.txtBarcode.Text = DateTime.Now.ToString("yyMMdd") + "XXXXXX";
this.dkUserInfo.Text = LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode;
this.dkUserInfo.UserCode = LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode;
this.dkUserInfo.UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 关闭画面
///
///
///
private void btnCancel_Click(object sender, System.EventArgs e)
{
if (this._mouldID < 0)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
this.Close();
}
///
/// 保存
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (!this.CheckInput())
{
return;
}
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1002";
cre.Name = "SetFPC1002Data";
cre.Properties["MouldID"] = (this._mouldID > 0 ? this._mouldID : 0);
//cre.Properties["MouldBarcode"] = this.txtBarcode.Text.Trim();
cre.Properties["GoodsID"] = scbGoods.SearchedPKMember;
cre.Properties["GoodsCode"] = scbGoods.SearchedValue;
cre.Properties["MouldType"] = this.ftcMouldType.SelectedValue;
cre.Properties["MaterialSupplier"] = this.ftcSuppliers.SelectedValue;
cre.Properties["ProductionDate"] = this.dtpPDate.Value;
cre.Properties["UserID"] = this.dkUserInfo.UserID;
cre.Properties["UserCode"] = this.dkUserInfo.UserCode;
cre.Properties["Weight"] = this.txtWeight.DataValue;
cre.Properties["Cost"] = this.txtCost.DataValue;
cre.Properties["StandardGroutingNum"] = this.txtStandardGroutingNum.DataValue;
cre.Properties["OutputCount"] = this.txtOutputCount.DataValue;
cre.Properties["Remarks"] = this.txtRemarks.Text;
cre.Properties["MCount"] = this.txtMCount.DataValue;
ServiceResultEntity sre = this.DoAsync(() =>
{
return PCModuleProxyNew.Service.HandleRequest(cre);
});
if (sre != null)
{
if (sre.Status == Constant.ServiceResultStatus.Success)
{
if (this.chkAutoPrint.Checked && sre.Result != null)
{
string[] barcodes = (sre.Result as string).Split(',');
foreach (string item in barcodes)
{
F_MST_013006.PrintBarcode(item, 1, this);
}
}
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
if (this._mouldID > 0)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
this._mouldID = -1;
this.ClearData();
this.txtBarcode.Focus();
}
}
else if (!string.IsNullOrWhiteSpace(sre.Message))
{
MessageBox.Show(sre.Message,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
// 提示信息
MessageBox.Show("保存失败",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 选择产品型号
///
///
///
private void scbGoods_SearchedItemChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.scbGoods.Text))
{
return;
}
try
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "FPC1002";
cre.Name = "GetFPC1002GoodsData";
cre.Properties["GoodsCode"] = scbGoods.SearchedValue;
ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
if (sre == null)
{
return;
}
DataRow item = sre.Data.Tables[0].Rows[0];
if (item["MouldWeight"] != DBNull.Value)
{
this.txtWeight.DataValue = Convert.ToDecimal(item["MouldWeight"]);
}
if (item["MouldCost"] != DBNull.Value)
{
this.txtCost.DataValue = Convert.ToDecimal(item["MouldCost"]);
}
if (item["StandardGroutingNum"] != DBNull.Value)
{
this.txtStandardGroutingNum.DataValue = Convert.ToDecimal(item["StandardGroutingNum"]);
}
if (item["MouldOutputCount"] != DBNull.Value)
{
this.txtOutputCount.DataValue = Convert.ToDecimal(item["MouldOutputCount"]);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
/////
///// 选择产品型号
/////
/////
/////
//private void dkGoodsCode_GoodsValueChanged(object sender, Controls.SearchTextBox.dkGoodsCodeSearchBox.TextChangeEventArgs e)
//{
// if (string.IsNullOrEmpty(this.scbGoods.Text))
// {
// return;
// }
// try
// {
// ClientRequestEntity cre = new ClientRequestEntity();
// cre.NameSpace = "FPC1002";
// cre.Name = "GetFPC1002GoodsData";
// cre.Properties["GoodsCode"] = scbGoods.SearchedValue;
// ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
// if (sre == null)
// {
// return;
// }
// DataRow item = sre.Data.Tables[0].Rows[0];
// if (item["MouldWeight"] != DBNull.Value)
// {
// this.txtWeight.DataValue = Convert.ToDecimal(item["MouldWeight"]);
// }
// if (item["MouldCost"] != DBNull.Value)
// {
// this.txtCost.DataValue = Convert.ToDecimal(item["MouldCost"]);
// }
// }
// catch (Exception ex)
// {
// // 对异常进行共通处理
// ExceptionManager.HandleEventException(this.ToString(),
// MethodBase.GetCurrentMethod().Name, this.Text, ex);
// }
//}
#endregion
#region 私有方法
///
/// 清除画面数据
///
private void ClearData()
{
this.txtBarcode.Clear();
//this.dkGoodsCode.Text = null;
//this.dkGoodsCode.GoodsID = null;
//this.dkGoodsCode.GoodsCode = null;
//this.ftcMouldType.ClearValue();
//this.ftcSuppliers.ClearValue();
//this.dtpPDate.ClearValue();
//this.txtWeight.Clear();
//this.txtCost.Clear();
//this.txtStandardGroutingNum.Clear();
//this.txtRemarks.Clear();
//this.dkUserInfo.Text = null;
//this.dkUserInfo.UserCode = null;
//this.dkUserInfo.UserID = null;
}
///
/// 保存前画面数据验证
///
///
private bool CheckInput()
{
if (this._mouldID <= 0)
{
//if (string.IsNullOrEmpty(this.txtBarcode.Text.Trim()))
//{
// MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具条码"),
// this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
// MessageBoxDefaultButton.Button1);
// this.txtBarcode.Focus();
// return false;
//}
if (this.scbGoods.SearchedPKMember == 0)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品型号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.scbGoods.Focus();
return false;
}
}
if (this.ftcMouldType.SelectedValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具类型"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.ftcMouldType.Focus();
return false;
}
if (this.ftcSuppliers.SelectedValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "材料供应商"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.ftcSuppliers.Focus();
return false;
}
if (this.txtWeight.DataValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具重量"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.txtWeight.Focus();
return false;
}
if (this.txtCost.DataValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具成本"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.txtCost.Focus();
return false;
}
if (this.dkUserInfo.UserID == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "生产工号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.dkUserInfo.Focus();
return false;
}
if (this.txtStandardGroutingNum.DataValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "标准注浆次数"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.txtStandardGroutingNum.Focus();
return false;
}
if (this.txtOutputCount.DataValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具产出数量"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
this.txtOutputCount.Focus();
return false;
}
return true;
}
#endregion
private void txtOutputCount_TextChanged(object sender, EventArgs e)
{
try
{
int mouldOutputCount = (this.txtOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtOutputCount.DataValue) : 1);
int standardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
this.txtStandardGroutingSum.DataValue = mouldOutputCount * standardGroutingNum;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
}
}