using ICSharpCode.Core; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity; 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; namespace Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe { public partial class SetCratParamForm : Form { private string recipeId = null; private string materialId = null; private List pmt_Materials = null; private List base_CratParams = null; public SetCratParamForm(string recipeId,string materialId) { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; this.recipeId = recipeId; this.materialId = materialId; this.base_CratParams = new List(); } private void Form_Load(object sender, EventArgs e) { this.InitCombox(); this.InitUi(); this.InitData(); } /// /// 工艺参数下拉框初始化 /// public void InitCombox() { //获取工艺参数 } public void InitUi() { this.btnOk.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnOK")); this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel")); } public void InitData() { //根据配方编号、物料编号获取工艺参数 DataTable dataTable = RecipeHelper.GetCratParamByRecipeAndMaterial(recipeId,""); //先添加好空行 if (dataTable != null && dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { this.DGVMaterialSet.Rows.Add(); //再将数据填入 for (int j = 0; j < this.DGVMaterialSet.ColumnCount; j++) { if (j == 0) { this.DGVMaterialSet.Rows[i].Cells[j].Value = dataTable.Rows[i][0].ToString(); } else if (j == 1) { this.DGVMaterialSet.Rows[i].Cells[j].Value = dataTable.Rows[i][2].ToString(); } else if (j == 2) { this.DGVMaterialSet.Rows[i].Cells[j].Value = dataTable.Rows[i][5].ToString(); } } } } else { this.DGVMaterialSet.Rows.Add(); } } private void DGVMaterialSet_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { this.DGVMaterialSet.Rows.Add(); } private void DGVMaterialSet_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { this.DGVMaterialSet.Refresh(); int newRowNum = this.DGVMaterialSet.RowCount; if (pmt_Materials != null && pmt_Materials.Count > 0) { this.DGVMaterialSet.Rows[newRowNum - 1].Cells[0].Value = newRowNum; foreach (Base_CratParamInfo pmt_Material in pmt_Materials) { (this.DGVMaterialSet.Rows[newRowNum - 1].Cells[1] as DataGridViewComboEditBoxCell).Items.Add(pmt_Material.paramName); } } this.DGVMaterialSet.Rows[newRowNum - 1].HeaderCell.Value = "+"; this.DGVMaterialSet.CurrentCell = this.DGVMaterialSet[1, newRowNum - 1]; } private void btnOk_Click(object sender, EventArgs e) { if (this.GetCratParamList()) { this.SaveCratParam(); } } //获取工艺参数信息 public bool GetCratParamList() { try { base_CratParams.Clear(); for (int i = 0; i < DGVMaterialSet.Rows.Count; i++) { Base_RecipeCratParam base_CratParam = new Base_RecipeCratParam(); base_CratParam.recipeId = this.recipeId; //base_CratParam.materialId = this.materialId; for (int j = 1; j < DGVMaterialSet.ColumnCount; j++) { if (j == 1) { //根据物料名称获取物料ID if (DGVMaterialSet.Rows[i].Cells[j].Value == null) { MessageBox.Show("未选择工艺参数名称,请重新填写!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { string materialNameStr = DGVMaterialSet.Rows[i].Cells[j].Value.ToString(); base_CratParam.paramName = materialNameStr; } //if (pmt_Materials.Exists(x => x.materialName == materialNameStr)) //{ // baseRepiceMaterial.materialId = GetMaterialID(materialNameStr); //} } else if (j == 2) { if (DGVMaterialSet.Rows[i].Cells[j].Value == null) { MessageBox.Show("未填写[" + base_CratParam.paramName + "]工艺参数值,请重新填写!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else base_CratParam.paramValue = DGVMaterialSet.Rows[i].Cells[j].Value.ToString(); } } base_CratParams.Add(base_CratParam); } return true; } catch (Exception ex) { return false; } } /// /// 保存工艺参数 /// public void SaveCratParam() { if (base_CratParams != null && base_CratParams.Count > 0) { //应该判断该配方下的该物料是否存在相同参数 bool HaveDuplicates = base_CratParams.GroupBy(i => i.paramName).Where(g => g.Count() > 1).Count() >= 1; if (!HaveDuplicates) { RecipeHelper.DeleteCratParam(this.recipeId); foreach (Base_RecipeCratParam cratParam in base_CratParams) { cratParam.editUser = "admin"; RecipeHelper.InsertCratParam(cratParam); } this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("已存在相同参数请勿重复添加!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } private void toolStripMenuItemAdd_Click(object sender, EventArgs e) { this.DGVMaterialSet.Rows.Add(); } private void toolStripMenuItemDel_Click(object sender, EventArgs e) { if (this.DGVMaterialSet.CurrentCell != null) { this.DGVMaterialSet.Rows.RemoveAt(this.DGVMaterialSet.CurrentRow.Index); } } } }