Пример #1
0
 private void BtnViewReceipt_Click(object sender, RoutedEventArgs e)
 {
     if (selectedIndex != -1)
     {
         if (receipt != null)
         {
             string           msg       = "Are you sure you want to view this receipt: " + receipt.ReceiptID.ToString("00000");
             MessageBoxResult boxResult = MessageBox.Show(msg, "Select Receipt", MessageBoxButton.YesNo,
                                                          MessageBoxImage.Question);
             if (boxResult == MessageBoxResult.Yes)
             {
                 if (customer != null)
                 {
                     Window WReceiptWindow = new ReceiptWindow(customer, receipt);
                     WReceiptWindow.Show();
                     Close();
                 }
                 else
                 {
                     Window WindowReceiptWindow = new ReceiptWindow(user, receipt);
                     WindowReceiptWindow.Show();
                     Close();
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("No receipt selected", "Please Select");
     }
 }
        private void BtnConfirmCart_Click(object sender, RoutedEventArgs e)
        {
            if (listOfP.Count != 0) //!= null?
            {
                string           msg       = "Are you sure you CONFIRM your cart?";
                MessageBoxResult boxResult = MessageBox.Show(msg, "Confirmation", MessageBoxButton.YesNo);
                if (boxResult == MessageBoxResult.Yes)
                {
                    //Confirm cart /Add to SQL(Create Receipt, Create Product List) /Go to receipt.
                    try
                    {
                        date = DateTime.Now;
                        receiptCart.ReceiptDate = date;
                        decimal total  = receiptCart.ReceiptTotal;
                        int     userid = customer.UserId;
                        receiptCart.UserId = userid;
                        int receiptid = Extras.CreateReceipt(userid, total, date);
                        receiptCart.ReceiptID = receiptid;
                        foreach (Product p in listOfP)
                        {
                            Extras.CreateProductInOrder(receiptid, userid, p.ProductName, p.ProductPrice, p.ProductQuantity, p.ProductTax);
                        }

                        Window WindowReceipt = new ReceiptWindow(customer, receiptCart);
                        WindowReceipt.Show();
                        Close();
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
                }
            }
            else
            {
                BtnGoBack.Visibility = Visibility.Hidden;
                MessageBox.Show("No items in your cart.", "Add items.");
            }
        }