private void bPlaceOrder_Click(object sender, EventArgs e) { double grandTotal = 0.00; double result1 = 0; double subTotal = 0; double priceTemp = 0; if (double.TryParse(tBItem1Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem1Price.Text); } if (double.TryParse(tBItem2Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem2Price.Text); } if (double.TryParse(tBItem3Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem3Price.Text); } if (double.TryParse(tBItem4Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem4Price.Text); } if (double.TryParse(tBItem5Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem5Price.Text); } if (double.TryParse(tBItem6Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem6Price.Text); } if (double.TryParse(tBItem7Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem7Price.Text); } if (double.TryParse(tBItem8Price.Text, out priceTemp)) { subTotal = subTotal + double.Parse(tBItem8Price.Text); } int count = 0; /*calculate tax on items in menuDataArray with itemTax value being greater than 1, add that value to grandTotal and loop through menuDataArray */ while (count < menuDataArray.Length) { double totalPrice = 0; if (count == 0) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem1Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 1) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem2Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 2) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem3Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 3) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem4Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 4) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem5Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 5) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem6Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 6) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem7Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } if (count == 7) { totalPrice = menuDataArray[count].itemPrice * double.Parse(nUDItem8Qty.Value.ToString()); if (menuDataArray[count].itemTax > 1) { result1 = totalPrice * menuDataArray[count].itemTax; grandTotal = result1 + grandTotal; } else { result1 = totalPrice; grandTotal = grandTotal + result1; } } count++; } if (grandTotal == 0) { MessageBox.Show("Please select an item"); return; } //create instance of global class called TransferData(contains list) //TransferData globalClass = new TransferData(); OrderData[] orderArray = new OrderData[8]; List<OrderData> orderlist = new List<OrderData>(); if (nUDItem1Qty.Value > 0) { //pass data into constructor (in Program.cs) and save to 'record1' OrderData record1 = new OrderData(menuDataArray[0].itemName,menuDataArray[0].itemPrice,int.Parse(nUDItem1Qty.Value.ToString())); //orderArray[0] = record1; orderlist.Add(record1); } if (nUDItem2Qty.Value > 0) { OrderData record2 = new OrderData(menuDataArray[1].itemName, menuDataArray[1].itemPrice, int.Parse(nUDItem2Qty.Value.ToString())); orderlist.Add(record2); } if (nUDItem3Qty.Value > 0) { OrderData record3 = new OrderData(menuDataArray[2].itemName, menuDataArray[2].itemPrice, int.Parse(nUDItem3Qty.Value.ToString())); orderlist.Add(record3); } if (nUDItem4Qty.Value > 0) { OrderData record4 = new OrderData(menuDataArray[3].itemName, menuDataArray[3].itemPrice, int.Parse(nUDItem4Qty.Value.ToString())); orderlist.Add(record4); } if (nUDItem5Qty.Value > 0) { OrderData record5 = new OrderData(menuDataArray[4].itemName, menuDataArray[4].itemPrice, int.Parse(nUDItem5Qty.Value.ToString())); orderlist.Add(record5); } if (nUDItem6Qty.Value > 0) { OrderData record6 = new OrderData(menuDataArray[5].itemName, menuDataArray[5].itemPrice, int.Parse(nUDItem6Qty.Value.ToString())); orderlist.Add(record6); } if (nUDItem7Qty.Value > 0) { OrderData record7 = new OrderData(menuDataArray[6].itemName, menuDataArray[6].itemPrice, int.Parse(nUDItem7Qty.Value.ToString())); orderlist.Add(record7); } if (nUDItem8Qty.Value > 0) { OrderData record8 = new OrderData(menuDataArray[7].itemName, menuDataArray[7].itemPrice, int.Parse(nUDItem8Qty.Value.ToString())); orderlist.Add(record8); } //pass user input through constructor into element of list //MoveToNewForm ian instance of OrderConfirmation and passes info through orderlist OrderConfirmation MoveToNewForm = new OrderConfirmation(orderlist, grandTotal); MoveToNewForm.Show(); this.Hide(); { } }
private void OrderConfirmation_Load(object sender, EventArgs e) { tBGrandTotal.Text = "$"+Convert.ToString(grandTotalGlobal); lDateTimeFuncton.Text = DateTime.Now.ToString(); int count = 0; OrderData[] orderDataArray = new OrderData[orderListGlobal.Count]; foreach (OrderData data in orderListGlobal) // Loop through List with foreach { //Console.WriteLine(prime); orderDataArray[count] = data; count++; } if (orderDataArray[0].itemName != null) { lItemOrder1.Text = orderDataArray[0].itemName.ToString(); lItemQty1.Text = orderDataArray[0].quantity.ToString(); lItemPrice1.Text = orderDataArray[0].itemPrice.ToString("c"); } if (count >= 2) { lItemOrder2.Text = orderDataArray[1].itemName; lItemQty2.Text = orderDataArray[1].quantity.ToString(); lItemPrice2.Text = orderDataArray[1].itemPrice.ToString("c"); } if (count >= 3) { lItemOrder3.Text = orderDataArray[2].itemName; lItemQty3.Text = orderDataArray[2].quantity.ToString(); lItemPrice3.Text = orderDataArray[2].itemPrice.ToString("c"); } if (count >= 4) { lItemOrder4.Text = orderDataArray[3].itemName; lItemQty4.Text = orderDataArray[3].quantity.ToString(); lItemPrice4.Text = orderDataArray[3].itemPrice.ToString("c"); } if (count >= 5) { lItemOrder5.Text = orderDataArray[4].itemName; lItemQty5.Text = orderDataArray[4].quantity.ToString(); lItemPrice5.Text = orderDataArray[4].itemPrice.ToString("c"); } if (count >= 6) { lItemOrder6.Text = orderDataArray[5].itemName; lItemQty6.Text = orderDataArray[5].quantity.ToString(); lItemPrice6.Text = orderDataArray[5].itemPrice.ToString("c"); } if (count >= 7) { lItemOrder7.Text = orderDataArray[6].itemName; lItemQty7.Text = orderDataArray[6].quantity.ToString(); lItemPrice7.Text = orderDataArray[6].itemPrice.ToString("c"); } if (count >= 8) { lItemOrder8.Text = orderDataArray[7].itemName; lItemQty8.Text = orderDataArray[7].quantity.ToString(); lItemPrice8.Text = orderDataArray[7].itemPrice.ToString("c"); } if (lItemQty1.Text == "label1") { lItemQty1.Visible = false; lItemPrice1.Visible = false; lItemOrder1.Visible = false; } if (lItemQty2.Text == "label2") { lItemQty2.Visible = false; lItemPrice2.Visible = false; lItemOrder2.Visible = false; } if (lItemQty3.Text == "label3") { lItemQty3.Visible = false; lItemPrice3.Visible = false; lItemOrder3.Visible = false; } if (lItemQty4.Text == "label4") { lItemQty4.Visible = false; lItemPrice4.Visible = false; lItemOrder4.Visible = false; } if (lItemQty5.Text == "label5") { lItemQty5.Visible = false; lItemPrice5.Visible = false; lItemOrder5.Visible = false; } if (lItemQty6.Text == "label6") { lItemQty6.Visible = false; lItemPrice6.Visible = false; lItemOrder6.Visible = false; } if (lItemQty7.Text == "label7") { lItemQty7.Visible = false; lItemPrice7.Visible = false; lItemOrder7.Visible = false; } if (lItemQty8.Text == "label8") { lItemQty8.Visible = false; lItemPrice8.Visible = false; lItemOrder8.Visible = false; } }