Exemplo n.º 1
0
        public void button2_Click(object sender, EventArgs e) // Retrieve Button on click event
        {
            // selecting or typing a valid order id and displaying the results
            try
            {
                int    orderID = Convert.ToInt32(cborderId.Text);
                Orders myOrder = OrdersDB.GetOrders(orderID);
                List <OrderDetails> myOrderDetails = OrderDetailsDB.GetOrderDetails(orderID);

                if (Object.Equals(myOrder, null)) // if ordr id not valid, show the follofing message
                {
                    MessageBox.Show("No matching Order Id's found, please provide a valid Order ID", "Order ID Error");
                }
                else // else display all the fields and read only order details data grid form
                {
                    displayOrder(myOrder);
                    displayOrderDetails(myOrderDetails);
                    calculateTotalprice();
                }
            }
            catch (FormatException) // catching the wrong format order id exception, in case user types an alphabet or anything other than the valid id
            {
                MessageBox.Show("Select from the drop down list and Retrieve.", "Input Error");
            }
        }
Exemplo n.º 2
0
        private void calculateTotalprice() // calculating the total price for all the orders associated with one order id
        {
            int orderID = Convert.ToInt32(cborderId.Text);
            List <OrderDetails> myOrderDetails = OrderDetailsDB.GetOrderDetails(orderID);

            double totalPrice = 0;
            double UnitPrice  = 0;
            int    Quantity   = 0;
            double Discount   = 0;

            foreach (OrderDetails d in myOrderDetails) // calculating by going through each order details rows
            {
                UnitPrice   = d.UnitPrice;
                Quantity    = d.Quantity;
                Discount    = d.Discount;
                totalPrice += UnitPrice * (1 - Discount) * Quantity;
            }
            lblTotalPrice.Text = totalPrice.ToString("c"); // displaying the result in the text field in a currency format
        }