You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
7.1 KiB
C#

using DevExpress.XtraRichEdit.Fields.Expression;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Technical.XlRecipe
{
public partial class FrmRecipMag : Form
{
private ActionType _actionType = ActionType.Add; //操作类型0-为添加1-为修改
string selectRecipeID = string.Empty;
string recipeCode = string.Empty;
string recipeName = string.Empty;
string version = string.Empty;
string remark = string.Empty;
decimal totalError = 0;
1 year ago
decimal totalWeight = 0;
private Entity.xl_recipe pmt_Recipe = null;
private string _curRecipeID = null;
public FrmRecipMag()
{
InitializeComponent();
}
1 year ago
public FrmRecipMag(ActionType actionType,string _selectRecipeID, string _recipeCode, string _recipeName, string _version, string _remark, decimal _totalWeight, decimal _totalError)
{
InitializeComponent();
_actionType = actionType;
pmt_Recipe=new xl_recipe();
selectRecipeID = _selectRecipeID;
recipeCode = _recipeCode;
recipeName = _recipeName;
version = _version;
remark = _remark;
1 year ago
totalWeight = _totalWeight;
totalError = _totalError;
pmt_Recipe = RecipeHelper.GetRecipeByName(selectRecipeID);
if (pmt_Recipe.Recipe_Verify == 1)
{
checkBox1.Checked = true;
}
else
{
checkBox1.Checked = false;
}
}
public FrmRecipMag(ActionType actionType)
{
InitializeComponent();
_actionType = actionType;
pmt_Recipe = new xl_recipe
{
ID = Guid.NewGuid().ToString("N")
};
}
private void btnOk_Click(object sender, EventArgs e)
{
#region 信息验证
if (String.IsNullOrEmpty(this.txtRecipeName.Text))
{
MessageBox.Show("请输入新配方的名称!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (String.IsNullOrEmpty(this.cmbRecipeVersion.Text))
{
MessageBox.Show("请选择新配方的版本!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (String.IsNullOrEmpty(this.textRecipeCode.Text))
{
MessageBox.Show("请添加新配方编码!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#endregion
if (_actionType == ActionType.Add && RecipeHelper.IsExistsName(this.txtRecipeName.Text, this.cmbRecipeVersion.Text))
{
MessageBox.Show("新配方的名称重复!请使用其他名称", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#region 配方及物料信息写入数据库
if (_actionType == ActionType.Add)
{
if (RecipeHelper.IsExists(this.txtRecipeName.Text, this.cmbRecipeVersion.Text))
{
MessageBox.Show("新配方的版本已存在,请修改.", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
this.NewRecipeAdd(); //新配方数据插入数据库
}
else if (_actionType == ActionType.Modify)
{
this.NewRecipeAdd(); //更新配方数据到数据库
}
#endregion
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void FrmRecipMag_Load(object sender, EventArgs e)
{
this.txtRecipeName.Text = recipeName;
this.cmbRecipeVersion.Text = version;
1 year ago
this.txtTotalWeight.Text = totalWeight.ToString("f3");
this.txtTotalError.Text = totalError.ToString("f3");
this.textRecipeCode.Text = recipeCode;
this.txtRemark.Text = remark;
1 year ago
//if (pmt_Recipe.Recipe_Verify == 1)
//{
// checkBox1.Checked = true;
//}
//else
//{
// checkBox1.Checked = false;
//}
1 year ago
// this.chcIsEnable.Checked = true;
this.checkBox1.Checked = true;
//this.chcWeight.Checked= true;
}
#region 向数据库中插入新配方数据
/// <summary>
/// 向数据库中插入新配方数据
/// </summary>
public void NewRecipeAdd()
{
pmt_Recipe.Recipe_Code = textRecipeCode.Text;
pmt_Recipe.Recipe_Name = txtRecipeName.Text;
pmt_Recipe.Equip_Code = ConfigurationManager.AppSettings["EquipCode"];
pmt_Recipe.Version = this.cmbRecipeVersion.Text;
pmt_Recipe.GroupBags = null;
pmt_Recipe.Remark = txtRemark.Text;
pmt_Recipe.End_datetime = DateTime.Now.ToString();
if (checkBox1.Checked)
{
pmt_Recipe.Recipe_Verify = 1;
}
else
{
pmt_Recipe.Recipe_Verify = 0;
}
1 year ago
if (chcIsEnable.Checked)
{
pmt_Recipe.Total_Error = Convert.ToDecimal(this.txtTotalError.Text);
}
else
{
pmt_Recipe.Total_Error = 0;
}
1 year ago
if (chcWeight.Checked)
{
pmt_Recipe.Total_Weight =Convert.ToDecimal(this.txtTotalWeight.Text);
}
else
{
pmt_Recipe.Total_Weight = 0;
}
_curRecipeID = RecipeHelper.InsertRecipe(pmt_Recipe);
}
#endregion
private void chcIsEnable_CheckedChanged(object sender, EventArgs e)
{
if (chcIsEnable.Checked)
{
txtTotalError.Enabled = true;
}
else
{
txtTotalError.Enabled = false;
}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void txtTotalError_TextChanged(object sender, EventArgs e)
{
}
1 year ago
private void chcWeight_CheckedChanged(object sender, EventArgs e)
{
if (chcWeight.Checked)
{
txtTotalWeight.Enabled = true;
}
else
{
txtTotalWeight.Enabled = false;
}
}
}
}