public decimal CalculateAdded(ArrayList arr, string size) { decimal sizeModifier = (size == "family") ? 1.5M : 1; List <decimal> list = new List <decimal>(); foreach (string added in arr) { string[] tokens = added.Split('-'); decimal addPrice = PriceCatalog.GetValue(tokens[0]) * sizeModifier; list.Add(addPrice); } Console.WriteLine(list.Sum()); return(list.Sum()); }
public void CalculatePizzas(string id, string navn, string size, int antal, decimal added) { int idPrice = PriceCatalog.GetValue(id); decimal sizeModifier = (size == "family") ? 1.5M : 1; string key = id; decimal subtotal = (idPrice * antal * sizeModifier) + (added * antal); if (PizzaSum.ContainsKey(key)) // TODO : make unnessecasry { PizzaSum[key] += subtotal; // total += subtotal; } else { PizzaSum.Add(key, subtotal); } total += subtotal; // TODO : correct me! // PizzaSum.ToList().ForEach(Console.WriteLine); }
private void BeregnButton1_Click(object sender, EventArgs e) { ArrayList order = new ArrayList(); var panels = this.Controls.OfType <Panel>(); foreach (Panel panel in panels) { GroupBox panelGrpBox1 = panel.Controls.OfType <GroupBox>().FirstOrDefault(l => l.Name.EndsWith(panel.Name + "GroupBox1")); GroupBox panelGrpBox2 = panel.Controls.OfType <GroupBox>().FirstOrDefault(l => l.Name.EndsWith(panel.Name + "GroupBox2")); GroupBox panelGrpBox3 = panel.Controls.OfType <GroupBox>().FirstOrDefault(l => l.Name.EndsWith(panel.Name + "GroupBox3")); foreach (TextBox tBox in panelGrpBox1.Controls.OfType <TextBox>()) { ArrayList orderline = OrderLine(tBox, (string)panel.Name, panelGrpBox1.Text, out bool abort); if (abort) { return; } ArrayList added = new ArrayList(); foreach (CheckBox chkBox in panelGrpBox2.Controls.OfType <CheckBox>()) { if (chkBox.Checked) { added.Add(chkBox.Name + "-" + chkBox.Text); } } orderline.Add(added); if (tBox.Enabled && orderline.Count > 0) { order.Add(orderline); } } foreach (TextBox tBox in panelGrpBox3.Controls.OfType <TextBox>()) { foreach (Label label in panelGrpBox3.Controls.OfType <Label>()) { Console.WriteLine((string)tBox.Text); int value; if (int.TryParse(tBox.Text, out value) && value > 1 && value < 11) { decimal i = PriceCatalog.GetValue(tBox.Name); Console.WriteLine(i); decimal value2 = 0; if (value != 0) { if (label.Name == Constants.KCAL_SLICE_NAME) { label.Text = Constants.KCAL_SLICE_TEXT + (i / value).ToString("##.##") + "KCal\n" + " Kalorier (family): " + ((i / value) * 1.5M).ToString("##.##") + "KCal"; } } else if (tBox.Text != "") { System.Windows.Forms.MessageBox.Show("Indtast 2 til 10 antal skiver"); return; } Console.WriteLine(value2); } else if (tBox.Text != "") { System.Windows.Forms.MessageBox.Show("Indtast 2 til 10 antal skiver"); return; } } } } PizzaOrder pizzaOrder = new PizzaOrder(order); Console.WriteLine(pizzaOrder.DisplayPizzaOrder()); foreach (Panel panel in panels) // add to subtotal { panel.Controls.OfType <Label>().FirstOrDefault(l => l.Name.EndsWith(Constants.SUBTOTAL_NAME)).Text = Constants.SUBTOTAL_TEXT + pizzaOrder.DisplayPizzaSubTotal(panel.Name); } this.Controls["totalLabel"].Text = "Total: " + pizzaOrder.total.ToString(); if (pizzaOrder.total > 0) { PendingOrder pizzaCounter = new PendingOrder(pizzaOrder.DisplayPizzaOrder()); this.Controls["bestillingsNummerLabel"].Text = "Dit bestillingsnummer er: " + pizzaCounter.GetCounter(); this.Controls["bestilButton"].Enabled = true; } // TODO : Tilføj klokkeslet }