Пример #1
0
        /// <summary>
        /// Event-handler when user clicks "Confirm Order"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConfirmOrderButton_Click(object sender, EventArgs e)
        {
            // check if the user added something to the cart
            if (TotalAmount == 0m)
            {
                MessageBox.Show("Please add book(s) to the order first");
                BookList.Focus();
            }
            else if (BookList.SelectedItem != null)
            {
                DialogResult dialogResult = MessageBox.Show("Please confirm your order", "Confirm your order", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    int     CurrQty            = 0;
                    int     CurrBookID         = 0;
                    int     CurrCustID         = 0;
                    decimal CurrSubtotalAmount = 0;
                    decimal CurrTaxAmount      = 0;
                    decimal CurrTotalAmount    = 0;
                    string  tempStr            = null;
                    int     MaxOrderID         = 0;


                    //InsertIntoOrdersTable(CurrCustID, SubtotalAmount, TaxAmount, TotalAmount);


                    foreach (DataGridViewRow row in OrderSummarydataGridView.Rows)
                    {
                        CurrCustID = Convert.ToInt32(row.Cells["Customer_ID"].Value);

                        tempStr = row.Cells["Price"].Value.ToString();
                        tempStr = tempStr.Replace("$", "");

                        CurrSubtotalAmount = Convert.ToDecimal(row.Cells["Quantity"].Value) * Convert.ToDecimal(tempStr);
                        CurrTaxAmount      = Math.Round(CurrSubtotalAmount * 0.1m, 2);
                        CurrTotalAmount    = CurrSubtotalAmount + CurrTaxAmount;
                        CurrBookID         = Convert.ToInt32(row.Cells["Book_ID"].Value);
                        CurrQty            = Convert.ToInt32(row.Cells["Quantity"].Value);

                        InsertIntoOrdersTable(CurrCustID, CurrSubtotalAmount, CurrTaxAmount, CurrTotalAmount);
                        MaxOrderID = MAX_ID_FROM_ORDER_TABLE();
                        InsertIntoOrderDetailsTable(MaxOrderID, CurrBookID, CurrQty, CurrSubtotalAmount);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }
        }
Пример #2
0
        private void AddToCart_Click(object sender, System.EventArgs e)
        {
            if (BookList.SelectedItem == null || CustomerList.SelectedItem == null)
            {
                // user has not chosen a book
                MessageBox.Show("Please choose a book and a customer first");
                BookList.Focus();
            }
            else if (QuantityBox.Value == 0 && (BookList.SelectedItem != null && CustomerList.SelectedItem != null))
            {
                // user has not chosen the quantity (it is still 0)
                MessageBox.Show("Please set \"Quantity\" to a non-zero positive value");
                QuantityBox.Focus();
            }
            else if (Math.Round(QuantityBox.Value) == 0 ||
                     QuantityBox.Value / Math.Round(QuantityBox.Value) != 1
                     )
            {
                // user has chosen 0 books
                MessageBox.Show("Please set \"Quantity\" to a whole number");
                QuantityBox.Focus();
                QuantityBox.Value = 0;
            }
            else
            {
                string  selectedTitle    = RetrievedBooks.Tables[0].Rows[BookList.SelectedIndex]["title"].ToString();
                decimal selectedPrice    = decimal.Parse(RetrievedBooks.Tables[0].Rows[BookList.SelectedIndex]["price"].ToString());
                int     selectedCustID   = Convert.ToInt32(CustomerIDStorage[CustomerList.SelectedIndex]);
                string  selectedCustName = RetrievedCustomers.Tables[0].Rows[CustomerList.SelectedIndex]["first_name"].ToString() + " " + RetrievedCustomers.Tables[0].Rows[CustomerList.SelectedIndex]["last_name"].ToString();
                int     selectedBookID   = Convert.ToInt32(BookIDStorage[BookList.SelectedIndex]);

                // calculate amount fields
                SubtotalAmount += Math.Round(QuantityBox.Value * selectedPrice, 2); // calculate subtotal field
                TaxAmount       = Math.Round(0.1m * SubtotalAmount, 2);             //  calculate tax. 10% of SubtotalAmount
                TotalAmount     = SubtotalAmount + TaxAmount;                       // calculate the total amount. SubtotalAmount + TaxAmount

                // update amount fields
                UpdateAmountFields(SubtotalAmount, TaxAmount, TotalAmount);

                // add selected book and QTY to the DataGridView
                OrderSummarydataGridView.Rows.Add(selectedBookID, selectedTitle, QuantityBox.Value, "$" + selectedPrice, "$" + QuantityBox.Value * selectedPrice, selectedCustID, selectedCustName);
            }
        }
Пример #3
0
 /// <summary>
 /// Event-handler when user clicks "Confirm Order"
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ConfirmOrderButton_Click(object sender, EventArgs e)
 {
     // check if the user added something to the cart
     if (TotalAmount == 0m)
     {
         MessageBox.Show("Please add book(s) to the order first");
         BookList.Focus();
     }
     else if (BookList.SelectedItem != null)
     {
         DialogResult dialogResult = MessageBox.Show("Please confirm your order", "Confirm your order", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             // write the order summary to the orders.txt file within the same directory
             WriteOrderSummaryToFile();
         }
         else if (dialogResult == DialogResult.No)
         {
             //do something else
         }
     }
 }
Пример #4
0
        private static void AddBook()
        {
            Console.Write("Enter the title of your book: ");
            string title = Console.ReadLine();

            while (title.Trim() == "")
            {
                Console.Write("Enter the correct title for your book: ");
                title = Console.ReadLine();
            }

            Console.Write("Enter the price of your book (Leave blank or type some ohter values to set the price as 0 dollars) : ");
            try {
                double price = Convert.ToDouble(Console.ReadLine());

                Book book = new Book(title, price);
                BookList.AddBook(book);
            } catch (Exception) {
                Book book = new Book(title);
                BookList.AddBook(book);
            }
        }
Пример #5
0
        private void AddToCart_Click(object sender, System.EventArgs e)
        {
            if (BookList.SelectedItem == null)
            {
                // user has not chosen a book
                MessageBox.Show("Please choose the book first");
                BookList.Focus();
            }
            else if (QuantityBox.Value == 0 && BookList.SelectedItem != null)
            {
                // user has not chosen the quantity (it is still 0)
                MessageBox.Show("Please set \"Quantity\" to a non-zero positive value");
                QuantityBox.Focus();
            }
            else if (Math.Round(QuantityBox.Value) == 0 ||
                     QuantityBox.Value / Math.Round(QuantityBox.Value) != 1
                     )
            {
                // user has chosen 0 books
                MessageBox.Show("Please set \"Quantity\" to a whole number");
                QuantityBox.Focus();
                QuantityBox.Value = 0;
            }
            else
            {
                // calculate amount fields
                SubtotalAmount += Math.Round(QuantityBox.Value * Books[BookList.SelectedIndex].Price, 2); // calculate subtotal field
                TaxAmount       = Math.Round(0.1m * SubtotalAmount, 2);                                   //  calculate tax. 10% of SubtotalAmount
                TotalAmount     = SubtotalAmount + TaxAmount;                                             // calculate the total amount. SubtotalAmount + TaxAmount

                // update amount fields
                UpdateAmountFields(SubtotalAmount, TaxAmount, TotalAmount);

                // add selected book and QTY to the DataGridView
                OrderSummarydataGridView.Rows.Add(Books[BookList.SelectedIndex].Title, QuantityBox.Value, "$" + Books[BookList.SelectedIndex].Price, "$" + QuantityBox.Value * Books[BookList.SelectedIndex].Price);
            }
        }
Пример #6
0
 private static void DisplayBooks()
 {
     BookList.DisplayBooks();
 }