/// <summary> /// 将配置数据转化为内存对象 /// </summary> /// <param name="errorInfo"></param> /// <returns></returns> bool _load(out string errorInfo) { _dctRecipes.Clear(); JFXmlDictionary <string, List <string[]> > cateRecipeInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; foreach (KeyValuePair <string, List <string[]> > cr in cateRecipeInCfg) { if (!_dctRecipes.ContainsKey(cr.Key)) { _dctRecipes.Add(cr.Key, new Dictionary <string, JFCommonRecipe>()); } Dictionary <string, JFCommonRecipe> dctInCate = _dctRecipes[cr.Key]; foreach (string[] idAndTxt in cr.Value) { JFCommonRecipe recipe = new JFCommonRecipe(); recipe.Categoty = cr.Key; recipe.ID = idAndTxt[0]; try { recipe.Dict = JFFunctions.FromXTString(idAndTxt[1], recipe.Dict.GetType()) as JFXmlDictionary <string, object>; } catch (Exception ex) { errorInfo = "Categoty = " + cr.Key + ", RecipeID = " + idAndTxt[0] + " FromXTString() Exception:" + ex.Message; return(false); } dctInCate.Add(idAndTxt[0], recipe); } } errorInfo = "Success"; return(true); }
List <Button> _lstDeleteItemButtons = new List <Button>(); //删除单个数据项的按钮 public void SetRecipe(JFCommonRecipe recipe) { _recipe = recipe; if (Created) { AdjustRecipe2View(); } }
/// <summary> /// 添加一个产品/配方 /// </summary> /// <param name="categoty"></param> /// <param name="recipeID"></param> /// <param name="recipe"></param> public bool AddRecipe(string categoty, string recipeID, IJFRecipe recipe = null) { if (string.IsNullOrEmpty(categoty)) { return(false); } if (string.IsNullOrEmpty(recipeID)) { return(false); } if (recipe != null && recipe.GetType() != typeof(JFCommonRecipe)) { return(false); } if (GetRecipe(categoty, recipeID) != null) //已已存在同名Recipe { return(false); } JFCommonRecipe cmRecipe = recipe as JFCommonRecipe; if (null == cmRecipe) { cmRecipe = new JFCommonRecipe(); } cmRecipe.ID = recipeID; cmRecipe.Categoty = categoty; List <string> lstCatesInCfg = _cfg.GetItemValue("Categoties") as List <string>; if (!lstCatesInCfg.Contains(categoty)) { lstCatesInCfg.Add(categoty); } JFXmlDictionary <string, List <string[]> > dctRecipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; if (!dctRecipesInCfg.ContainsKey(categoty)) { dctRecipesInCfg.Add(categoty, new List <string[]>()); } List <string[]> lstIDAndTxt = dctRecipesInCfg[categoty]; lstIDAndTxt.Add(new string[] { recipeID, cmRecipe.Dict.ToString() }); if (!_dctRecipes.ContainsKey(categoty)) { _dctRecipes.Add(categoty, new Dictionary <string, JFCommonRecipe>()); } Dictionary <string, JFCommonRecipe> dctInMmry = _dctRecipes[categoty]; dctInMmry.Add(recipeID, cmRecipe); return(true); }
/// <summary> /// RecipeID选择改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripCbRecipeIDs_SelectedIndexChanged(object sender, EventArgs e) { if (toolStripCbRecipeIDs.SelectedIndex == -1) { toolStripMenuItemEditSave.Enabled = false; _recipeEdit.SetRecipe(null); return; } toolStripMenuItemEditSave.Enabled = true; JFCommonRecipe recipe = _mgr.GetRecipe(toolStripCbCategoty.Text, toolStripCbRecipeIDs.Text) as JFCommonRecipe; _recipeEdit.SetRecipe(recipe); return; }
private void btOK_Click(object sender, EventArgs e) { if (null == _mgr) { MessageBox.Show("无效操作,RecipeManager未设置"); return; } if (!_mgr.IsInitOK) { MessageBox.Show("无效操作,RecipeManager未初始化,ErrorInfo:" + _mgr.GetInitErrorInfo()); return; } if (string.IsNullOrWhiteSpace(cbGenCate.Text)) { MessageBox.Show("参数项 Categoty 不能为空值!"); return; } if (string.IsNullOrWhiteSpace(tbGenID.Text)) { MessageBox.Show("参数项 RecipeID 不能为空值!"); return; } string[] existIDs = _mgr.AllRecipeIDsInCategoty(cbGenCate.Text); if (null != existIDs && existIDs.Contains(tbGenID.Text)) { MessageBox.Show("添加Recipe失败,Categoty = " + cbGenCate.Text + "已包含当前RecipeID = " + tbGenID.Text); return; } JFCommonRecipe newRecipe = new JFCommonRecipe(); newRecipe.Categoty = cbGenCate.Text; newRecipe.ID = tbGenID.Text; if (chkCopy.Checked) //以拷贝的方式创建新的Recipe { if (string.IsNullOrEmpty(cbCopyCate.Text)) { MessageBox.Show("请选择待拷贝的Categoty!"); return; } if (string.IsNullOrEmpty(cbCopyID.Text)) { MessageBox.Show("请选择待拷贝的RecipeID!"); return; } JFCommonRecipe recipe = _mgr.GetRecipe(cbCopyCate.Text, cbCopyID.Text) as JFCommonRecipe; string xmlTxt; string typeTxt; JFFunctions.ToXTString(recipe.Dict, out xmlTxt, out typeTxt); newRecipe.Dict = JFFunctions.FromXTString(xmlTxt, typeTxt) as JFXmlDictionary <string, object>; } _mgr.AddRecipe(cbGenCate.Text, tbGenID.Text, newRecipe); _mgr.Save(); DialogResult = DialogResult.OK; }