Esempio n. 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(IngredientUnit).Name)
            {
                throw new ArgumentException();
            }

            foreach (var item in xml.Elements(typeof(IngredientUnit).Name))
            {
                IngredientUnit unit = IngredientUnit.Parse(item);
                if (dictionary.ContainsKey(unit.Id))
                {
                    throw new Exception(string.Format("发现重复的单位名称【{0}】!", unit.Name));
                }

                dictionary.Add(unit.Id, unit);
            }
        }
        private bool TryAdd()
        {
            string name = this.txtName.Text.Trim();

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

            var unit = new IngredientUnit()
            {
                Name = name
            };
            IDictionary <Guid, IngredientUnit> unitDict = IngredientUnit.GetAll();
            var result = from item in unitDict.Values
                         where item.Name == unit.Name
                         select item;

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

            unitDict.Add(unit.Id, unit);
            IngredientUnit.SaveDatabase(typeof(IngredientUnit).Name);

            return(true);
        }
        void FormNewIngredientUnit_Load(object sender, EventArgs e)
        {
            IDictionary <Guid, IngredientUnit> unitDict = IngredientUnit.GetAll();
            var list = from item in unitDict.Values
                       select item;

            foreach (var item in list)
            {
                this.lstUnit.Items.Add(item);
            }
        }
Esempio n. 4
0
        public FormUpdateIngredientUnit(IngredientUnit unit)
        {
            InitializeComponent();

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

            this.unit         = unit;
            this.txtName.Text = unit.Name;
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var selectedItem = this.lstUnit.SelectedItem;

            if (selectedItem != null)
            {
                if (MessageBox.Show(string.Format("是否确认删除【{0}】单位名称?(这将同步删除使用此单位名称的食材和使用这些食材的菜品!)", selectedItem), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    // 删除category
                    var unit = selectedItem as IngredientUnit;
                    IDictionary <Guid, IngredientUnit> categoryDict = IngredientUnit.GetAll();
                    categoryDict.Remove(unit.Id);
                    // 删除关联到unit的食材ingredient
                    IDictionary <Guid, Ingredient> ingredientDict = Ingredient.GetAll();
                    var toBeDeletedIngredients = (from item in ingredientDict.Values
                                                  where item.Unit.Id == unit.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);
                    }

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

                    this.lstUnit.Items.Remove(selectedItem);
                    MessageBox.Show("已删除此单位名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Esempio n. 6
0
        private void ReloadIngredientUnit()
        {
            this.cmbUnit.Items.Clear();
            IDictionary <Guid, IngredientUnit> dict = IngredientUnit.GetAll();
            var list = from item in dict.Values
                       select item;

            foreach (var item in list)
            {
                this.cmbUnit.Items.Add(item);
            }
            {
                this.cmbUnit.Items.Add(newOne);
            }
        }
Esempio n. 7
0
        private bool TryAdd()
        {
            string name = this.txtName.Text.Trim();

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

            this.unit.Name = this.txtName.Text.Trim();
            IngredientUnit.SaveDatabase(typeof(IngredientUnit).Name);

            return(true);
        }
Esempio n. 8
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
            });
        }
Esempio n. 9
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");
        }