using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using Mesnac.Action.Base; using System.Text; using System.Windows.Forms; using Mesnac.Action.Feeding.Technology; namespace Mesnac.Action.Feeding.ProducingPlan { public partial class FrmPlan : Form { private int _actionType = 0; //操作类型,0-为添加,1-为修改 //private string _recipeMaterialName = String.Empty; //组合物料名称 private SimplePmtRecipe _recipe = null; //物料对象 #region 构造方法 public FrmPlan() { InitializeComponent(); } /// /// 构造方法 /// /// 操作类型,0-为添加,1-为修改 public FrmPlan(int actionType) { InitializeComponent(); this._actionType = actionType; } /// /// 构造方法 /// /// 操作类型,0-为添加,1-为修改 /// 初始份数 //public FrmPlan(int actionType, int planNum, string recipeMaterialName) //{ // InitializeComponent(); // this._actionType = actionType; // this.txtPlanNum.Text = planNum.ToString(); // this._recipeMaterialName = recipeMaterialName; //} /// /// 构造方法 /// /// 操作类型,0-为添加,1-为修改 /// 初始份数 /// 配方物料 public FrmPlan(int actionType, int planNum, SimplePmtRecipe recipe) { InitializeComponent(); this._actionType = actionType; this.txtPlanNum.Text = planNum.ToString(); this._recipe = recipe; } #endregion #region 初始化工作 #region 初始化界面文本 /// /// 初始化界面文本 /// public void InitUI() { if (this._actionType == 0) { //添加 this.Text = LanguageService.Instance.Read(115); this.btnOk.Text = LanguageService.Instance.Read(117); } else { //修改 this.Text = LanguageService.Instance.Read(116); this.btnOk.Text = LanguageService.Instance.Read(118); } this.btnSelect.Text = LanguageService.Instance.Read(159); //筛选 this.btnCancel.Text = LanguageService.Instance.Read(119); this.label1.Text = LanguageService.Instance.Read(120); this.label2.Text = LanguageService.Instance.Read(121); } #endregion #region 初始化配方列表 public void InitData() { List lst = null; //判断是网络版还是单机版 DatabaseAction action = new DatabaseAction(); if (action.NetType == BaseAction.NetTypes.Net) { //网络版 lst = PlanCommon.GetNetRecipeMaterialList(action.CurrEquipCode, 1); } else { //单机版 lst = PlanCommon.GetLocalRecipeMaterialList(action.CurrEquipCode, 1); } foreach (SimplePmtRecipe r in lst) { this.cmbRecipeMaterial.Items.Add(r); } this.cmbRecipeMaterial.SelectedIndex = 0; //默认定位到第一项 if (this._actionType == 1) { bool flag = false; foreach (SimplePmtRecipe r in this.cmbRecipeMaterial.Items) { if (r.ObjID == this._recipe.ObjID) { this.cmbRecipeMaterial.SelectedItem = r; flag = true; break; } } if (!flag) { this.cmbRecipeMaterial.Text = this._recipe.Content; } this.cmbRecipeMaterial.Enabled = false; } } #endregion private void FrmPlan_Load(object sender, EventArgs e) { this.InitUI(); this.InitData(); } #endregion private void btnOk_Click(object sender, EventArgs e) { SimplePmtRecipe recipe = this.cmbRecipeMaterial.SelectedItem as SimplePmtRecipe; int planNum = 0; if (recipe == null || string.IsNullOrEmpty(recipe.ObjID)) { MessageBox.Show(LanguageService.Instance.Read(123), LanguageService.Instance.Read(1), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (String.IsNullOrEmpty(this.txtPlanNum.Text)) { MessageBox.Show(LanguageService.Instance.Read(124), LanguageService.Instance.Read(1), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!int.TryParse(this.txtPlanNum.Text, out planNum)) { MessageBox.Show(LanguageService.Instance.Read(125), LanguageService.Instance.Read(1), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (planNum <= 0) { MessageBox.Show(LanguageService.Instance.Read(126), LanguageService.Instance.Read(1), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this._recipe = recipe; this._planNum = planNum; this.DialogResult = System.Windows.Forms.DialogResult.OK; } #region 属性定义 //private SimplePmtRecipe _recipe; private int _planNum; /// /// 物料信息 /// public SimplePmtRecipe Recipe { get { return this._recipe; } } /// /// 份数 /// public int PlanNum { get { return this._planNum; } } #endregion private void btnSelect_Click(object sender, EventArgs e) { SimplePmtRecipe selectedRecipe = null; FrmRecipeFinder recipeFinder = new FrmRecipeFinder(0); recipeFinder.ShowDialog(this); if (recipeFinder.DialogResult == System.Windows.Forms.DialogResult.OK) { selectedRecipe = recipeFinder.SelectedRecipe; } recipeFinder.Dispose(); if (selectedRecipe != null) { foreach (SimplePmtRecipe r in this.cmbRecipeMaterial.Items) { if (r.ObjID == selectedRecipe.ObjID) { this.cmbRecipeMaterial.SelectedItem = r; break; } } } } } }