Пример #1
0
        public void createSale()
        {
            Console.Clear();
            System.Console.WriteLine("New Sale\n\n");

            SaleBO  sale  = new SaleBO();
            SaleBLL saleB = new SaleBLL();

            int id = saleB.readId();

            System.Console.WriteLine("Sales ID: " + id);

            DateTime thisDay = DateTime.Today;

            System.Console.WriteLine("Sales Date: " + thisDay.ToString("dd/MM/yyyy"));

            System.Console.Write("Enter CustomerID: ");
            int    custid;
            String c = System.Console.ReadLine();

            if (c.Length != 0)
            {
                custid = int.Parse(c);
            }
            else
            {
                custid = 0;
            }

            CustomerBLL custB  = new CustomerBLL();
            CustomerBO  custO  = custB.find(custid);
            int         choice = 0;

            if (custO.Custid != 0)
            {
                List <SaleLineItemBO> lineList = new List <SaleLineItemBO>();

                SaleLineItemBLL lineBI    = new SaleLineItemBLL(); //I-initial
                SaleLineItemBO  lineitemI = makenewSale();



                if (lineitemI.Itemid != 0)
                {
                    lineitemI.Lineid = lineBI.readId();

                    lineitemI.Orderid = id;
                    lineitemI.Amount  = lineBI.calculatesubTotal(lineitemI);
                    System.Console.WriteLine("Sub-Total: Rs." + lineitemI.Amount);
                    lineList.Add(lineitemI);
                }


                while (choice != 4)
                {
                    System.Console.WriteLine("\nPress 1 to Enter New Item");
                    System.Console.WriteLine("Press 2 to End Sale");
                    System.Console.WriteLine("Press 3 to Remove an existing Item from the current sale");
                    System.Console.WriteLine("Press 4 to Cancel Sale");
                    System.Console.WriteLine("Choose from option 1 – 4:");

                    System.Console.Write("Enter Choice: ");
                    c = System.Console.ReadLine();

                    if (c.Length != 0)
                    {
                        choice = int.Parse(c);
                    }
                    else
                    {
                        choice = 0;
                    }

                    while (choice < 1 || choice > 4)
                    {
                        System.Console.Write("InValid Choice! Enter again: ");
                        c = System.Console.ReadLine();

                        if (c.Length != 0)
                        {
                            choice = int.Parse(c);
                        }
                        else
                        {
                            choice = 0;
                        }
                    }

                    if (choice == 1)
                    {
                        SaleLineItemBLL lineB    = new SaleLineItemBLL();
                        SaleLineItemBO  lineitem = makenewSale();


                        if (lineitem.Itemid != 0)
                        {
                            lineitem.Lineid = lineB.readId();

                            lineitem.Orderid = id;
                            lineitem.Amount  = lineB.calculatesubTotal(lineitem);
                            System.Console.WriteLine("Sub-Total: Rs." + lineitem.Amount);

                            lineList.Add(lineitem);
                        }
                    }
                    else if (choice == 2)
                    {
                        SaleLineItemBLL lineB = new SaleLineItemBLL();
                        if (lineList.Count > 0)
                        {
                            sale.Orderid = id;
                            sale.Date    = thisDay.ToString("dd/MM/yyyy");
                            sale.Custid  = custO.Custid;
                            sale.Total   = saleB.calculateTotal(lineList);

                            if (saleB.checkSaleLimit(sale))
                            {
                                lineB.save(lineList);
                                saleB.save(sale);

                                displayInvoice(sale, lineList);
                            }
                            else
                            {
                                Console.Clear();
                                System.Console.WriteLine("\n\n\n\n\n\n ***Error! Sale Limit Exceeded***");
                                System.Threading.Thread.Sleep(2000);
                            }
                        }

                        break;
                    }
                    else if (choice == 3)
                    {
                        int itemid; bool flag = true;
                        System.Console.Write("\nEnter ItemID to be removed: ");
                        c = System.Console.ReadLine();
                        if (c.Length != 0)
                        {
                            itemid = int.Parse(c);
                        }
                        else
                        {
                            itemid = 0;
                        }

                        List <SaleLineItemBO> removeList = new List <SaleLineItemBO>();
                        foreach (var line in lineList)
                        {
                            if (line.Itemid == itemid)
                            {
                                removeList.Add(line);
                                flag = false;
                            }
                        }

                        foreach (var line in removeList)
                        {
                            lineList.Remove(line);
                        }

                        if (flag)
                        {
                            System.Console.WriteLine("Error! Item not included in sale");
                        }
                    }
                }
            }
            else
            {
                Console.Clear();
                System.Console.WriteLine("\n\n\n\n\n\n ***Error! Customer Not Found***");
                System.Threading.Thread.Sleep(2000);
            }
        }
Пример #2
0
        public SaleLineItemBO makenewSale()
        {
            SaleLineItemBO lineItem = new SaleLineItemBO();

            System.Console.Write("\nItem Id: ");
            int    itemid;
            String c = System.Console.ReadLine();

            if (c.Length != 0)
            {
                itemid = int.Parse(c);
            }
            else
            {
                itemid = 0;
            }
            ItemBLL itemB = new ItemBLL();
            ItemBO  itemO = itemB.find(itemid);
            int     q     = 0;

            if (itemO.Itemid != 0)
            {
                System.Console.WriteLine("\nDescription: " + itemO.Description);
                System.Console.WriteLine("Price: Rs." + itemO.Price + ".00");
                System.Console.Write("Quantity: ");

                c = System.Console.ReadLine();
                if (c.Length != 0)
                {
                    q = int.Parse(c);
                }
                else
                {
                    q = 0;
                }

                while (q < 0)
                {
                    System.Console.Write("InValid Quantity! Enter again: ");
                    c = System.Console.ReadLine();
                    if (c.Length != 0)
                    {
                        q = int.Parse(c);
                    }
                    else
                    {
                        q = 0;
                    }
                }

                if (q <= itemO.Quantity)
                {
                    lineItem.Itemid   = itemO.Itemid;
                    lineItem.Quantity = q;
                    lineItem.Amount   = itemO.Price; //sets unit price of item
                }
                else
                {
                    System.Console.WriteLine("Stock quantity Not Available");
                }
            }
            else
            {
                System.Console.WriteLine("Error! Item not found");
            }


            return(lineItem);
        }
Пример #3
0
 public double calculatesubTotal(SaleLineItemBO lineitem)
 {
     return(lineitem.Quantity * lineitem.Amount);
 }