Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// 移出一个产品配方
        /// </summary>
        /// <param name="categoty"></param>
        /// <param name="recipeID"></param>
        /// <returns></returns>
        public IJFRecipe RemoveRecipe(string categoty, string recipeID)
        {
            if (string.IsNullOrEmpty(categoty))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(recipeID))
            {
                return(null);
            }

            IJFRecipe ret = GetRecipe(categoty, recipeID);

            if (ret == null) //已已存在同名Recipe
            {
                return(ret);
            }

            Dictionary <string, JFCommonRecipe> dctInMmry = _dctRecipes[categoty];

            dctInMmry.Remove(recipeID);
            if (dctInMmry.Count == 0)
            {
                _dctRecipes.Remove(categoty);
            }


            JFXmlDictionary <string, List <string[]> > dctRecipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >;
            List <string[]> lstIDAndTxt = dctRecipesInCfg[categoty];

            for (int i = 0; i < lstIDAndTxt.Count; i++)
            {
                if (lstIDAndTxt[i][0] == recipeID)
                {
                    lstIDAndTxt.RemoveAt(i);
                    break;
                }
            }

            if (lstIDAndTxt.Count == 0)
            {
                dctRecipesInCfg.Remove(categoty);
                List <string> lstCatesInCfg = _cfg.GetItemValue("Categoties") as List <string>;
                lstCatesInCfg.Remove(categoty);
            }
            return(ret);
        }
        /// <summary>
        /// 删除当前所选Recipe
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItemDelRecipe_Click(object sender, EventArgs e)
        {
            if (_mgr == null)
            {
                MessageBox.Show("无效操作:RecipeManager未设置");
                return;
            }

            if (!_mgr.IsInitOK)
            {
                MessageBox.Show("无效操作:RecipeManager未初始化,Error:" + _mgr.GetInitErrorInfo());
                return;
            }


            if (toolStripCbRecipeIDs.SelectedIndex < 0)
            {
                MessageBox.Show("请先选择一个需要删除的RecipeID");
                return;
            }
            string categoty = toolStripCbCategoty.Text;
            string recipeID = toolStripCbRecipeIDs.Text;

            if (DialogResult.OK != MessageBox.Show("确定要删除Categoty: " + categoty + " RecipeID: " + recipeID + "?", "删除警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
            {
                return;
            }


            IJFRecipe deled = _mgr.RemoveRecipe(categoty, recipeID);

            if (deled != null)
            {
                _mgr.Save();
                MessageBox.Show("Categoty:" + categoty + " RecipeID:" + recipeID + " 已删除");
                toolStripCbRecipeIDs.SelectedIndex = -1;
                return;
            }
        }