Ejemplo n.º 1
0
        private void AddIngredientsToDish(ListView.SelectedListViewItemCollection items)
        {
            foreach (var item in items)
            {
                var obj        = item as ListViewItem;
                var ingredient = obj.Tag as Ingredient;
                if (!this.selectedIngredientList.Contains(ingredient.Id))
                {
                    Guid categoryId = ingredient.Category.Id;
                    if (!this.groups.ContainsKey(categoryId))
                    {
                        var group = new ListViewGroup(ingredient.Category.Name);
                        this.groups.Add(categoryId, group);
                        this.lstSelectedIngredient.Groups.Add(group);
                    }

                    var weighted = new WeightedIngredient()
                    {
                        Ingredient = ingredient, Weight = 0
                    };
                    var listViewItem = new ListViewItem(weighted.ToString(), this.groups[categoryId])
                    {
                        Tag = weighted
                    };
                    listViewItem.ForeColor = ingredient.ForeColor;
                    this.lstSelectedIngredient.Items.Add(listViewItem);
                    this.selectedIngredientList.Add(ingredient.Id);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static Dish Parse(XElement xml)
        {
            if (xml == null || xml.Name != typeof(Dish).Name)
            {
                throw new ArgumentException();
            }

            Guid id = new Guid(xml.Attribute(strId).Value);

            string name = xml.Attribute(strName).Value;

            int priority = 0;
            {
                XAttribute attr = xml.Attribute(strPriority);
                if (attr != null)
                {
                    priority = int.Parse(attr.Value);
                }
            }
            Dish result = new Dish(id)
            {
                Name = name, Priority = priority
            };

            foreach (var item in xml.Elements(typeof(WeightedIngredient).Name))
            {
                WeightedIngredient ingredient = WeightedIngredient.Parse(item);
                result.weightedIngredientList.Add(ingredient);
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static List <ChunkBase> GetChunkList(List <WeightedIngredient> list, int tableCount, Font font)
        {
            var result = new List <ChunkBase>();

            var groupedIngredients = from item in list
                                     group item by item.Ingredient.Category into g
                                     select g;

            foreach (var group in groupedIngredients)
            {
                {
                    string str   = string.Format("{0}:", group.Key.Name);
                    var    chunk = new StringChunk(str, font)
                    {
                        Tag = group.Key
                    };
                    result.Add(chunk);
                    result.Add(new NewLineChunk());
                }
                WeightedIngredient last = null;
                foreach (var weighted in group)
                {
                    string str = string.Format(
                        "{0}:{1:0.##}{2}, ",
                        weighted.Ingredient.Name, weighted.Weight * tableCount, weighted.Ingredient.Unit);
                    var chunk = new StringChunk(str, font)
                    {
                        Tag = weighted
                    };
                    result.Add(chunk);
                    last = weighted;
                }
                if (last != null)
                {
                    string str = string.Format(
                        "{0}:{1:0.##}{2}。",
                        last.Ingredient.Name, last.Weight * tableCount, last.Ingredient.Unit);
                    var chunk = new StringChunk(str, font)
                    {
                        Tag = last
                    };
                    result.RemoveAt(result.Count - 1);
                    result.Add(chunk);
                }
                result.Add(new NewLineChunk());
            }

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="weightedIngredient"></param>
        public FormUpdateWeightedIngrendient(WeightedIngredient weightedIngredient)
        {
            InitializeComponent();

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

            this.weighted = weightedIngredient;

            this.FillView(weightedIngredient.Ingredient);

            this.txtWeight.Text = weightedIngredient.Weight.ToString();
        }
Ejemplo n.º 5
0
        private static void Calculate(Dictionary <string, WeightedIngredient> ingredientDict, WeightedDish weightedDish, int tableCount)
        {
            int count = weightedDish.Count;

            foreach (var weightedIngredient in weightedDish.Dish.WeightedIngredientList)
            {
                WeightedIngredient current;
                if (ingredientDict.TryGetValue(weightedIngredient.Ingredient.Name, out current))
                {
                    current.Weight += (tableCount * count * weightedIngredient.Weight);
                }
                else
                {
                    current = new WeightedIngredient()
                    {
                        Ingredient = weightedIngredient.Ingredient, Weight = tableCount * count * weightedIngredient.Weight
                    };
                    ingredientDict.Add(current.Ingredient.Name, current);
                }
            }
        }