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; decimal totalWeight = 0; private Entity.xl_recipe pmt_Recipe = null; private string _curRecipeID = null; public FrmRecipMag() { InitializeComponent(); } 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; 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, "1")) { MessageBox.Show("新配方的名称重复!请使用其他名称", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #region 配方及物料信息写入数据库 if (_actionType == ActionType.Add) { if (RecipeHelper.IsExists(this.txtRecipeName.Text, "1")) { 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; this.txtTotalWeight.Text = totalWeight.ToString("f3"); this.txtTotalError.Text = totalError.ToString("f3"); this.textRecipeCode.Text = recipeCode; this.txtRemark.Text = remark; //if (pmt_Recipe.Recipe_Verify == 1) //{ // checkBox1.Checked = true; //} //else //{ // checkBox1.Checked = false; //} // this.chcIsEnable.Checked = true; this.checkBox1.Checked = true; //this.chcWeight.Checked= true; } #region 向数据库中插入新配方数据 /// /// 向数据库中插入新配方数据 /// 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 = "1"; 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; } if (chcIsEnable.Checked) { pmt_Recipe.Total_Error = Convert.ToDecimal(this.txtTotalError.Text); } else { pmt_Recipe.Total_Error = 0; } 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) { } private void chcWeight_CheckedChanged(object sender, EventArgs e) { if (chcWeight.Checked) { txtTotalWeight.Enabled = true; } else { txtTotalWeight.Enabled = false; } } } }