Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        public static void LoadDatabase(string filename)
        {
            if (!File.Exists(filename))
            {
                return;
            }

            XElement xml = XElement.Load(filename);

            if (xml == null || xml.Name != typeof(IngredientCategory).Name)
            {
                throw new ArgumentException();
            }

            foreach (var item in xml.Elements(typeof(IngredientCategory).Name))
            {
                IngredientCategory category = IngredientCategory.Parse(item);
                if (dictionary.ContainsKey(category.Id))
                {
                    throw new Exception(string.Format("发现重复的食材类别【{0}】!", category.Name));
                }

                dictionary.Add(category.Id, category);
            }
        }
Пример #2
0
        private bool TryAdd()
        {
            string name = this.txtName.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("食材类别的名称不能为空!");
                return(false);
            }

            IDictionary <Guid, IngredientCategory> ingredientDict = IngredientCategory.GetAll();
            var result = from item in ingredientDict.Values
                         where item.Name == this.newCatetory.Name
                         select item;

            if (result.Count() > 0)
            {
                MessageBox.Show(string.Format("已存在名为【{0}】的食材类别!", name), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            for (int i = 0; i < this.lstCategory.Items.Count; i++)
            {
                var obj = this.lstCategory.Items[i] as IngredientCategory;
                obj.Priority = i;
            }

            ingredientDict.Add(this.newCatetory.Id, this.newCatetory);
            IngredientCategory.SaveDatabase(typeof(IngredientCategory).Name);

            return(true);
        }
        public FormUpdateIngredientCategory(IngredientCategory category)
        {
            InitializeComponent();

            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            this.category     = category;
            this.txtName.Text = category.Name;
        }
Пример #4
0
        private bool TryAdd()
        {
            for (int i = 0; i < this.lstCategory.Items.Count; i++)
            {
                var obj = this.lstCategory.Items[i] as IngredientCategory;
                obj.Priority = i;
            }

            IngredientCategory.SaveDatabase(typeof(IngredientCategory).Name);

            return(true);
        }
Пример #5
0
        void FormNewIngredientCategory_Load(object sender, EventArgs e)
        {
            IDictionary <Guid, IngredientCategory> ingredientDict = IngredientCategory.GetAll();
            var list = from item in ingredientDict.Values
                       orderby item.Priority ascending
                       select item;

            foreach (var item in list)
            {
                this.lstCategory.Items.Add(item);
            }
        }
Пример #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var selectedItem = this.lstCategory.SelectedItem;

            if (selectedItem != null)
            {
                if (MessageBox.Show(string.Format("是否确认删除【{0}】类别?(这将同步删除使用此类别的食材和使用这些食材的菜品!)", selectedItem), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    // 删除category
                    var category = selectedItem as IngredientCategory;
                    IDictionary <Guid, IngredientCategory> categoryDict = IngredientCategory.GetAll();
                    categoryDict.Remove(category.Id);
                    // 删除关联到category的食材ingredient
                    IDictionary <Guid, Ingredient> ingredientDict = Ingredient.GetAll();
                    var toBeDeletedIngredients = (from item in ingredientDict.Values
                                                  where item.Category.Id == category.Id
                                                  select item.Id).ToList();
                    foreach (var id in toBeDeletedIngredients)
                    {
                        ingredientDict.Remove(id);
                    }
                    // 删除关联到食材ingredient的菜品dish
                    IDictionary <Guid, Dish> dishDict = Dish.GetAll();
                    var toBeDeletedDishes             = new List <Dish>();
                    foreach (var dish in dishDict.Values)
                    {
                        foreach (var weightedIngredient in dish.WeightedIngredientList)
                        {
                            if (toBeDeletedIngredients.Contains(weightedIngredient.Ingredient.Id))
                            {
                                toBeDeletedDishes.Add(dish);
                                break;
                            }
                        }
                    }
                    foreach (var dish in toBeDeletedDishes)
                    {
                        dishDict.Remove(dish.Id);
                    }

                    IngredientCategory.SaveDatabase(typeof(IngredientCategory).Name);
                    Ingredient.SaveDatabase(typeof(Ingredient).Name);
                    Dish.SaveDatabase(typeof(Dish).Name);

                    this.lstCategory.Items.Remove(selectedItem);
                    MessageBox.Show("已删除此类别!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private bool TryAdd()
        {
            string name = this.txtName.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("食材类别的名称不能为空!");
                return(false);
            }

            this.category.Name = this.txtName.Text.Trim();
            IngredientCategory.SaveDatabase(typeof(IngredientCategory).Name);

            return(true);
        }
Пример #8
0
        private void ReloadIngredientCategory()
        {
            this.cmbCategory.Items.Clear();
            IDictionary <Guid, IngredientCategory> dict = IngredientCategory.GetAll();
            var list = from item in dict.Values
                       orderby item.Priority ascending
                       select item;

            foreach (var item in list)
            {
                this.cmbCategory.Items.Add(item);
            }
            {
                this.cmbCategory.Items.Add(newOne);
            }
        }
Пример #9
0
        void FormNewIngredientCategory_Load(object sender, EventArgs e)
        {
            IDictionary <Guid, IngredientCategory> ingredientDict = IngredientCategory.GetAll();
            var list = from item in ingredientDict.Values
                       orderby item.Priority ascending
                       select item;

            foreach (var item in list)
            {
                this.lstCategory.Items.Add(item);
            }
            {
                var category = new IngredientCategory()
                {
                    Name = strNewCategory, Priority = 10000
                };
                this.lstCategory.Items.Add(category);
                this.newCatetory  = category;
                this.txtName.Text = strNewCategory;
            }
        }
Пример #10
0
        public static Ingredient Parse(XElement xml)
        {
            if (xml == null || xml.Name != typeof(Ingredient).Name)
            {
                throw new ArgumentException();
            }

            Guid               id       = new Guid(xml.Attribute(strId).Value);
            string             name     = xml.Attribute(strName).Value;
            IngredientCategory category = IngredientCategory.Select(new Guid(xml.Attribute(strCategory).Value));
            IngredientUnit     unit     = IngredientUnit.Select(new Guid(xml.Attribute(strUnitName).Value));
            Color              color;
            var colorAttr = xml.Attribute(strForeColor);

            if (colorAttr != null)
            {
                string[] parts = colorAttr.Value.Split(',');
                int      r = int.Parse(parts[0]), g = int.Parse(parts[1]), b = int.Parse(parts[2]);
                color = Color.FromArgb(r, g, b);
            }
            else
            {
                color = Color.Black;
            }
            float price = float.Parse(xml.Attribute(strPrice).Value);

            int priority = 0;

            {
                XAttribute attr = xml.Attribute(strPriority);
                if (attr != null)
                {
                    priority = int.Parse(attr.Value);
                }
            }
            return(new Ingredient(id)
            {
                Name = name, Category = category, Unit = unit, ForeColor = color, Price = price, Priority = priority
            });
        }
Пример #11
0
        public FormMain()
        {
            InitializeComponent();

            this.CurrentPartyProject = new PartyProject();
            this.grayBrush           = new SolidBrush(Color.LightGray);

            this.CurrentFont  = new Font("宋体", 32, GraphicsUnit.Pixel);
            this.CurrentBrush = new SolidBrush(Color.Black);
            this.CurrentPen   = new Pen(this.CurrentBrush);

            foreach (PaperSize item in this.printDocument1.PrinterSettings.PaperSizes)
            {
                if (item.PaperName.Equals("A4"))
                {
                    this.printDocument1.DefaultPageSettings.PaperSize = item;
                    break;
                }
            }
            IngredientCategory.LoadDatabase(typeof(IngredientCategory).Name + ".xml");
            IngredientUnit.LoadDatabase(typeof(IngredientUnit).Name + ".xml");
            Ingredient.LoadDatabase(typeof(Ingredient).Name + ".xml");
            Dish.LoadDatabase(typeof(Dish).Name + ".xml");
        }