private void RefreshShoppingList() { LvShopping.Items.Clear(); List <OrderList> list = db.GetOrderListbyId(currentOrderId); if (list != null) { total = 0.0m; totalTax = 0.0m; foreach (OrderList l in list) { foreach (InStock ins in productList) { if (l.ProductId == ins.Id) { string name = ins.ProductName; decimal subtotal = l.Quantity * l.UnitPrice; total = total + subtotal; decimal tax = subtotal * 0.15m; totalTax = totalTax + tax; Shopping s = new Shopping(l.ProductId, name, l.Quantity, l.UnitPrice, l.Discount, subtotal, tax); LvShopping.Items.Add(s); } } } } SubTotal(); }
private void ButtonDelete_Click(object sender, RoutedEventArgs e) { int index = LvShopping.SelectedIndex; if (index < 0) { MessageBox.Show("Please select Item", "Warning", MessageBoxButton.OK, MessageBoxImage.Information); return; } Shopping s = (Shopping)LvShopping.Items[index]; try { if (s.Quantity > 1) { QCounts[s.ID - 1] = s.Quantity - 1; OrderList o = new OrderList(currentOrderId, s.ID, QCounts[s.ID - 1], s.UnitPrice, 0.1m); db.UpdateOrderList(o); RefreshShoppingList(); SubTotal(); return; } db.DeleteOrderListById(s.ID); QCounts[s.ID - 1] = 0; RefreshShoppingList(); SubTotal(); } catch (SqlException ex) { Console.WriteLine(ex.StackTrace); MessageBox.Show("Database query error " + ex.Message); } }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { currentItemText = LvItems.SelectedValue.ToString(); currentItemIndex = LvItems.SelectedIndex; Shopping s = new Shopping(currentItemText, 1, 3, 4, 3, 1); LvShopping.Items.Add(s); int quantity = 0; switch (currentItemText) { case "Coffee": quantity++; break; case "Green Tea": break; case "Tea": break; case "Hot Chocolate": break; case "Cafe Latte": break; case "Cappuccino": break; } }
private void DeductProduct() { for (int i = 0; i < LvShopping.Items.Count; i++) { Shopping s = (Shopping)LvShopping.Items[i]; db.DeductProductById(s.ID, s.Quantity); if (db.ProductStockById(s.ID)) { MessageBox.Show(s.ProductName + " needs reload !!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Information); } } }
private void ButtonChekOut_Click(object sender, RoutedEventArgs e) { if (total == 0m) { return; } doc.Blocks.Clear(); string theDate = DpDate.Text; //.ToString("yyyy-MM-dd"); string itemPurchasedInfo = ""; string invoiceNoText = Convert.ToString(DpDate.SelectedDate.Value.Year) + Convert.ToString(DpDate.SelectedDate.Value.Month) + Convert.ToString(DpDate.SelectedDate.Value.Day) + Convert.ToString(currentOrderId); int invoiceNo; Int32.TryParse(invoiceNoText, out invoiceNo); itemPurchasedInfo = "=============================" + "\r\n" + "Mike & Elmira's Company" + "\r\n" + "=============================" + "\r\n" + "" + "Address:" + "\r\n" + "John Abbot College" + "\r\n" + "Phone: 514- 543 74 89" + "\r\n" + "INVOICE NO: " + invoiceNo + "\t\t" + "Date: " + theDate + "\r\n" + "=============================" + "\r\n"; for (int i = 0; i < LvShopping.Items.Count; i++) { Shopping s = (Shopping)LvShopping.Items[i]; itemPurchasedInfo += "Product Name: " + s.ProductName + "\r\n Quantity: " + s.Quantity + "\r\n Unit Price: " + String.Format("{0:C}", s.UnitPrice) + "\r\n\r\n"; } itemPurchasedInfo += "====================" + "\r\n"; itemPurchasedInfo += "Tax: " + totalTaxCost.Text + "\r\n"; itemPurchasedInfo += "Balance: " + BalancePriceTb.Text + "\r\n"; itemPurchasedInfo += "Paid: " + PaidTextBox.Text + "\r\n"; itemPurchasedInfo += "Method Of Payment: " + ComboCard.Text; itemPurchasedInfo += "\r\n" + "*****************************" + "\r\n" + "Thank you for Shoping at Mike & Elmira's Company"; Paragraph p = new Paragraph(new Run(itemPurchasedInfo)); doc.Blocks.Add(p); FdViewer.Document = doc; Order o = new Order(currentOrderId, EmpId, DpDate.SelectedDate.Value.Date, CustomerId, total, ComboCard.Text, invoiceNo); db.AddOrder(o); DeductProduct(); currentOrderId++; TabControl.SelectedIndex = 1; total = 0.0m; }
public Shopping GetProductbyId(int CategoryId, int ProductId) { using (SqlCommand command = new SqlCommand( "SELECT * FROM Products where CategoryId=" + CategoryId + " and productId=" + ProductId, conn)) using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { string name = (string)reader["productName"]; decimal price = (decimal)reader["unitprice"]; int Id = (int)reader["productId"]; Shopping p = new Shopping(Id, name, 1, price, 4, 3, 1); return(p); } return(null); } }