using DevExpress.Utils.Drawing.Helpers; using ICSharpCode.Core; using Mesnac.Action.ChemicalWeighing.Entity; using Mesnac.Action.ChemicalWeighing.Technical; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Mesnac.Action.ChemicalWeighing.Technical; using Mesnac.Action.ChemicalWeighing.Technical.XlRecipe; namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan { public partial class FrmXl : Form { #region 字段定义 private ActionType _actionType = ActionType.Add; //操作类型,0-为添加,1-为修改 private int _planNum; //计划数 private SimplePmtRecipe _recipe = null; //配方对象 #endregion #region 构造方法 public FrmXl() { InitializeComponent(); } /// /// 构造方法 /// /// 操作类型,0-为添加,1-为修改 public FrmXl(ActionType actionType) { InitializeComponent(); this._actionType = actionType; } /// /// 构造方法 /// /// 操作类型,0-为添加,1-为修改 /// 初始份数 /// 配方物料 public FrmXl(ActionType actionType, int planNum, SimplePmtRecipe recipe) { InitializeComponent(); this._actionType = actionType; this._planNum = planNum; this._recipe = recipe; this.txtPlanNum.Text = planNum.ToString(); } #endregion #region 属性定义 /// /// 物料信息 /// public SimplePmtRecipe Recipe { get { return this._recipe; } } public string RecipeVersion { get { return this.cmbRecipeVersion.SelectedItem as string; } } /// /// 计划数 /// public int PlanNum { get { return this._planNum; } } #endregion #region 方法定义 /// /// 初始化界面文本 /// public void InitUI() { if (this._actionType == ActionType.Add) { this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_Text_Add")); //添加新计划 } else if (this._actionType == ActionType.Modify) { this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_Text_Modify")); //修改计划 } this.label1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_label1_Text")); //配方名称 this.label2.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_label2_Text")); //配方版本 this.label3.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_label3_Text")); //份 数 this.btnOk.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnOK")); this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel")); } /// /// 初始化配方列表 /// public void InitData() { List lst = null; lst = TechnicalHelper.GetXlRecipeMaterialListPY(); this.cmbRecipeMaterial.Items.Clear(); foreach (SimplePmtRecipe r in lst) { this.cmbRecipeMaterial.Items.Add(r); } cmbRecipeMaterial.DisplayMember = "Recipe_Name"; cmbRecipeMaterial.ValueMember = "ID"; if (this._actionType == ActionType.Modify) { bool flag = false; foreach (SimplePmtRecipe r in this.cmbRecipeMaterial.Items) { if (r.MaterialGUID == this._recipe.MaterialGUID) { this.cmbRecipeMaterial.SelectedItem = r; flag = true; break; } } if (!flag) { this.cmbRecipeMaterial.Text = this._recipe.Content; } this.cmbRecipeMaterial.Enabled = false; this.cmbRecipeVersion.SelectedItem = this._recipe.Version; this.cmbRecipeVersion.Enabled = false; } } /// /// 初始化选中的配方版本数据 /// public void InitRecipeVersionData() { if (this.cmbRecipeMaterial.SelectedItem != null) { SimplePmtRecipe recipe = this.cmbRecipeMaterial.SelectedItem as SimplePmtRecipe; List recipeVersionList = TechnicalHelper.GetXlRecipeVersionList(recipe.Recipe_Name); this.cmbRecipeVersion.DataSource = recipeVersionList; } } #endregion #region 事件处理 private void FrmXl_Load(object sender, EventArgs e) { this.InitUI(); this.InitData(); } private void FrmXl_Activated(object sender, EventArgs e) { if (this._actionType == ActionType.Modify) { this.txtPlanNum.Focus(); } else { this.cmbRecipeMaterial.Focus(); } } /// /// 自动完成实现 /// /// /// private void cmbRecipeMaterial_TextUpdate(object sender, EventArgs e) { this.InitData(); //设置光标位置,否则光标位置始终保持在第一列,造成输入关键词的倒序排列 this.cmbRecipeMaterial.SelectionStart = this.cmbRecipeMaterial.Text.Length; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置。 Cursor = Cursors.Default; //自动弹出下拉框 this.cmbRecipeMaterial.DroppedDown = true; } /// /// 配方名称更改 /// /// /// private void cmbRecipeMaterial_SelectedIndexChanged(object sender, EventArgs e) { this.InitRecipeVersionData(); } private void btnOk_Click(object sender, EventArgs e) { SimplePmtRecipe recipe = this.cmbRecipeMaterial.SelectedItem as SimplePmtRecipe; var list = TechnicalHelper.GetRecipeMaterialListPY(); if (recipe == null) { MessageBox.Show("没有找到该配方!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var recipe2 = list.FirstOrDefault(d=>d.Recipe_Name== recipe.Recipe_Name); int planNum = 0; if (recipe == null || string.IsNullOrEmpty(recipe2.ID)) { string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg1")); //请选择配方名称! MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cmbRecipeMaterial.Focus(); return; } if (String.IsNullOrEmpty(this.cmbRecipeVersion.SelectedItem as string)) { string msg1_1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg1_1")); //请选择配方版本! MessageBox.Show(msg1_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cmbRecipeVersion.Focus(); return; } if (String.IsNullOrEmpty(this.txtPlanNum.Text)) { string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg2")); //请输入份数! MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!int.TryParse(this.txtPlanNum.Text, out planNum)) { string msg3 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg3")); //份数只能为整型数字! MessageBox.Show(msg3, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (planNum <= 0) { string msg4 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg4")); //份数必须大于0! MessageBox.Show(msg4, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //if (string.IsNullOrEmpty(this.combPlanClass.Text)) //{ // string msg5 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg5")); //请选择班次 // MessageBox.Show(msg5, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if (string.IsNullOrEmpty(this.mcPlanDate.Text)) //{ // string msg6 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_FrmPlan_msg6")); //请选择时间 // MessageBox.Show(msg6, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} recipe.ID = recipe2.ID; recipe.Version= this.cmbRecipeVersion.SelectedItem as string; this._recipe = recipe; this._planNum = planNum; this.DialogResult = System.Windows.Forms.DialogResult.OK; } #endregion } }