Beispiel #1
0
 /*
  * Event Handler for Clear Button in Sale Windows
  */
 private void ClearButton_Click(object sender, EventArgs e)
 {
     CartFlowLayoutPanel.Controls.Clear();
     ProductsFlowLayoutPanel.Controls.Clear();
     CurrentCartProducts.Clear();
     TotalItems           = 0;
     GrandTotal           = 0;
     TotalItemsLabel.Text = "";
     GrandTotalLabel.Text = "";
 }
Beispiel #2
0
        //====================== END OF UI FUNCATIONALITY BUTTONS  =========================



        //====================== START OF SALE FUNCATIONALITY METHODS  =========================

        /*
         * Event Handler for Order Button in Sale Windows
         */
        private void OrderButton_Click(object sender, EventArgs e)
        {
            StreamWriter FileWriter;
            string       Reciept = "", CurrentLine, Seperator = "_", Message = "";

            //Generating Dynamic Confirmation Message Based on Cart Items
            Message = "Please Confirm the below order:\n\n";
            foreach (CartList CartItems in CartFlowLayoutPanel.Controls)
            {
                Message = Message + "\nProduct Name: " + CartItems.ProdName +
                          "\nQuantity(s)      : " + CartItems.ProdQuantity + Environment.NewLine;
            }
            Message = Message + "\n\nYou will have to pay €" + GrandTotal.ToString() + " for " + TotalItems.ToString() + " items.";
            Message = Message + "\n\nDo you want to confirm the order?";

            DialogResult DR = MessageBox.Show(Message, "Confirm the Order", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (DR == DialogResult.Yes)
            {
                foreach (CartList CartItems in CartFlowLayoutPanel.Controls)
                {
                    int i;
                    // Modifying Original Stock ProductList
                    // Substracting Cart Quantities from stock
                    for (i = 0; i < ProductList.Count; i++)
                    {
                        if (ProductList[i].ProductQuantity > 0)
                        {
                            if (CartItems.ProdID == ProductList[i].ProductID)
                            {
                                ProductList[i].ProductQuantity -= CartItems.ProdQuantity;
                                break;
                            }
                        }
                    }
                    // Adding quantities into Sold Product List
                    //Adding Cart Quantities from stock
                    for (i = 0; i < SaleProductIDs.Count; i++)
                    {
                        if (CartItems.ProdID == SaleProductIDs[i].ProductID)
                        {
                            SaleProductIDs[i].ProductQuantity += CartItems.ProdQuantity;
                            break;
                        }
                    }
                    CurrentLine = CartItems.ProdCat + Seperator + CartItems.ProdName + Seperator + CartItems.ProdQuantity + Seperator + CartItems.ProdTotal;
                    if (Reciept == "")
                    {
                        Reciept = CurrentLine;
                    }
                    else
                    {
                        Reciept = Reciept + Seperator + CurrentLine;
                    }
                }
                TodaysSaleTotal += GrandTotal;
                //Writing current Transaction to file
                try
                {
                    FileWriter = File.AppendText(TRANSACTIONDATABASEFILENAME);
                    FileWriter.WriteLine(TransactionIDLabel.Text);
                    FileWriter.WriteLine(DateTime.Today.ToShortDateString());
                    FileWriter.WriteLine(TotalItems.ToString());
                    FileWriter.WriteLine(GrandTotal.ToString());
                    FileWriter.WriteLine(Reciept);
                    FileWriter.Close();

                    MessageBox.Show("Transaction " + TransactionIDLabel.Text + " completed successfully");

                    CartFlowLayoutPanel.Controls.Clear();
                    ProductsFlowLayoutPanel.Controls.Clear();
                    CurrentCartProducts.Clear();
                    TotalItems           = 0;
                    GrandTotal           = 0;
                    TotalItemsLabel.Text = "";
                    GrandTotalLabel.Text = "";
                }
                catch
                {
                    MessageBox.Show("Some Error Occured while Completing your order. Try again Later", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }