/// <summary> /// 加载产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnLoadProduct_Click(object sender, EventArgs e) { string Errstring = ""; if (lbxProductCategory.SelectedIndex == -1) { return; } btnLoadProduct.Enabled = false; string pdt = null; pdt = lbxProductCategory.SelectedValue.ToString(); btnLoadProduct.Enabled = true; Form_Wait.ShowForm(); await Task.Run(new Action(() => { try { //需要加载当前产品相关的参数 _operation = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", pdt) as JFDLAFProductRecipe; if (_operation == null) { HTUi.TipError("Recipe Manager中不存在配方:" + pdt); return; } if (Errstring == "") { HTLog.Info("加载产品完成."); HTUi.TipHint("加载产品完成"); if (_operation.MgzIdx == -1) { HTLog.Error("注意:当前产品未选择料盒型号,开始流程需要选择料盒型号."); } } else { HTLog.Error("加载产品失败!!!" + Errstring); HTUi.TipError("加载产品失败"); HTUi.PopWarn("产品加载失败\n" + Errstring); } } catch (Exception EXP) { HTLog.Error(String.Format("{0}加载新产品失败\n", EXP.ToString())); HTUi.TipError("加载新产品失败"); } })); if (_operation != null) { SetupUI(); } JFHubCenter.Instance.SystemCfg.SetItemValue("CurrentID", pdt); JFHubCenter.Instance.SystemCfg.Save(); Form_Wait.CloseForm(); }
/// <summary> /// 删除产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, EventArgs e) { var pdt = lbxProductCategory.SelectedValue; if (!HTUi.PopYesNo("是否删除选中产品?")) { return; } if (!DeleteProduct((string)pdt)) { HTUi.PopWarn("不能删除已激活的产品!"); } //删除Recipe Manager中配方信息 JFHubCenter.Instance.RecipeManager.RemoveRecipe("Product", (string)pdt); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Box", (string)pdt); JFHubCenter.Instance.RecipeManager.Save(); lbxProductCategory.DataSource = GetProductList(); }
/// <summary> /// 重命名产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRename_Click(object sender, EventArgs e) { string souce = (string)lbxProductCategory.SelectedValue; if (souce == (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) { HTUi.PopError("当前产品名称不可修改"); return; } String newname = ""; if (!MSG.Inputbox("new", "rename", out newname)) { return; } if (newname == string.Empty) { HTUi.PopWarn("命名错误,名字不能为空"); return; } var pdtlist = GetProductList(); foreach (var pdt in pdtlist) { if (pdt == newname) { HTUi.PopWarn("命名冲突,当前产品已存在"); return; } } //重新命名Recipe manager中recipe ID JFDLAFProductRecipe jFDLAFProductRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)souce) as JFDLAFProductRecipe; if (jFDLAFProductRecipe == null) { HTUi.PopWarn("Recipe Manager中不存在recipe:" + souce); return; } jFDLAFProductRecipe.Categoty = "Product"; jFDLAFProductRecipe.ID = newname; JFDLAFBoxRecipe jFDLAFBoxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)souce) as JFDLAFBoxRecipe; if (jFDLAFBoxRecipe == null) { HTUi.PopWarn("Recipe Manager中不存在recipe:" + souce); return; } jFDLAFBoxRecipe.Categoty = "Box"; jFDLAFBoxRecipe.ID = newname; JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFProductRecipe.Categoty, jFDLAFProductRecipe.ID, jFDLAFProductRecipe as IJFRecipe); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFBoxRecipe.Categoty, jFDLAFBoxRecipe.ID, jFDLAFBoxRecipe as IJFRecipe); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Product", souce); JFHubCenter.Instance.RecipeManager.RemoveRecipe("Box", souce); JFHubCenter.Instance.RecipeManager.Save(); ChangeProdcutName(newname, souce); HTUi.TipHint("重命名成功!"); lbxProductCategory.DataSource = GetProductList(); return; }
/// <summary> /// 创建产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreateProduct_Click(object sender, EventArgs e) { String newfile = ""; if (!MSG.Inputbox("Copy&New", "请输入新的产品名", out newfile)) { return; } if (newfile == string.Empty) { HTUi.PopWarn("命名错误,名字不能为空"); return; } //新增Product Recipe到recipe Dictionary中 JFDLAFProductRecipe jFDLAFProductRecipe = new JFDLAFProductRecipe(); if (JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null) { jFDLAFProductRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone(); } jFDLAFProductRecipe.ID = newfile; jFDLAFProductRecipe.Categoty = "Product"; jFDLAFProductRecipe.SaveParamsToCfg(); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFProductRecipe.Categoty, jFDLAFProductRecipe.ID, jFDLAFProductRecipe as IJFRecipe); ////新增Box Recipe到recipe Dictionary中 JFDLAFBoxRecipe jFDLAFBoxRecipe = new JFDLAFBoxRecipe(); if (JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null) { jFDLAFBoxRecipe = ((JFDLAFBoxRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone(); } jFDLAFBoxRecipe.MagezineBox = jFDLAFProductRecipe.MagezineBox; jFDLAFBoxRecipe.MgzIdx = jFDLAFProductRecipe.MgzIdx; jFDLAFBoxRecipe.ID = newfile; jFDLAFBoxRecipe.Categoty = "Box"; jFDLAFBoxRecipe.SaveParamsToCfg(); JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFBoxRecipe.Categoty, jFDLAFBoxRecipe.ID, jFDLAFBoxRecipe as IJFRecipe); //此处后面需要保存 JFHubCenter.Instance.RecipeManager.Save(); var pdtlist = GetProductList(); foreach (var pdt in pdtlist) { if (pdt == newfile) { HTUi.PopWarn("无法新建,当前产品已存在"); return; } } string souce = (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"); if (!CreateProduct(souce, newfile)) { HTUi.PopWarn("产品创建失败!"); return; } HTLog.Info("产品创建成功!"); HTUi.TipHint("产品创建成功!"); lbxProductCategory.DataSource = GetProductList(); return; }