Ejemplo n.º 1
0
        /// <summary>
        /// Local Function to Add Stock
        /// </summary>
        public static void AddStock()
        {
            ProductBusiness productBusinessLogic  = new ProductBusiness();
            MenuPrensentor  wareHousePresentation = new MenuPrensentor();

            StockBusinessLogicLayer stockBusinessLogicLayer = new StockBusinessLogicLayer(); // creation stockBusinessLogic object
            Stock stock = new Stock();                                                       //creation of stock object of entite Layer
            bool  check = false;

            try
            {
                System.Console.WriteLine("Enter StockID");
                stock.StockID = System.Console.ReadLine();


                do
                {
                    try
                    {
                        bool check1 = false;
                        System.Console.WriteLine("Enter WareHouseID");
                        System.Console.WriteLine("It should not contain spaces and length be exactly 6");
                        stock.WareHouseID = System.Console.ReadLine();
                        if (wareHousePresentation.CheckWareHouseId(stock.WareHouseID) == true)//checking whether the Warehouse Id is present in the list of warehouse
                        {
                            do
                            {
                                try
                                {
                                    check = true;
                                    System.Console.WriteLine("Enter Address ID");
                                    System.Console.WriteLine("It should not contain spaces or Special Characters and length should be exactly 4");
                                    stock.AddressID = System.Console.ReadLine();
                                    if (wareHousePresentation.CheckAddressId(stock.AddressID))//checking whether the warehouse address is present in list of warehouse adress
                                    {
                                        bool check2 = false;
                                        check1 = true;
                                        do
                                        {
                                            try
                                            {
                                                System.Console.WriteLine("Enter Product ID");
                                                System.Console.WriteLine("Product ID Should not NULL and ProductID Should Start with PID and 0-9 number and length should be 6");
                                                stock.ProductID = System.Console.ReadLine();
                                                if (productBusinessLogic.CheckProductID(stock.ProductID))//checking whether product is available in the list or not
                                                {
                                                    check2 = true;

                                                    System.Console.WriteLine("Enter no of Quantities u want to add");
                                                    stock.Quantity = System.Convert.ToInt32(System.Console.ReadLine());

                                                    stockBusinessLogicLayer.AddStock(stock);
                                                    Console.WriteLine("Stock Added Sucessfully!!");
                                                }
                                            }

                                            catch (StockException e)
                                            {
                                                System.Console.WriteLine(e.Message);
                                            }
                                        } while (check2 == false);
                                    }
                                }
                                catch (StockException e)
                                {
                                    System.Console.WriteLine(e.Message);
                                }
                            } while (check1 == false);
                        }
                    }
                    catch (StockException e)
                    {
                        System.Console.WriteLine(e.Message);
                    }
                } while (check == false);
            }
            catch (StockException e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void menu()
        {
            int  choice;
            bool b;

            do
            {
                System.Console.WriteLine("1. Add Product");
                System.Console.WriteLine("2. Show product");
                System.Console.WriteLine("3. Show Product By ID");
                System.Console.WriteLine("4. Delete Product");
                System.Console.WriteLine("5. Update Prroduct");
                System.Console.WriteLine("6. Exit");

                b = int.TryParse(System.Console.ReadLine(), out choice);

                if (b == true)
                {
                    switch (choice)
                    {
                    case 1:
                        AddProduct();     // calling AddProduct Method declared Locally
                        break;

                    case 2:
                        DisplayProducts();    // calling DisplayProducts Method declared Locally
                        break;

                    case 3: GetProductByID(); break;   // calling GetProductByID Method declared Locally

                    case 4: RemoveProduct(); break;    // calling RemoveProduct Method declared Locally

                    case 5:
                        UpdateProduct();     // calling update Method declared Locally
                        break;

                    default:
                        System.Console.WriteLine("Please Enter the Correct Option");
                        break;
                    }
                }
                else
                {
                    System.Console.WriteLine("Please Enter the only digits");
                }
            } while (choice != 6);



            //local function to add products into List
            void AddProduct()
            {
                Product         product = new Product();         // creating the object for Product class
                ProductBusiness pb      = new ProductBusiness(); // Creating thhe object for ProductBusiness class
                bool            check1  = false;

                do
                {
                    try
                    {
                        System.Console.WriteLine("enter the ProductId");
                        System.Console.WriteLine("Product ID must start with PID and should be less than 6");
                        product.ProductID = System.Console.ReadLine();


                        if (pb.CheckProductID(product.ProductID) == false) //checking whether the productId avaliable in the list or not to enter unique productId into list
                        {
                            check1 = true;
                            System.Console.WriteLine("enter the ProductName:");
                            System.Console.WriteLine("ProductName must Contain only alphabets");
                            product.ProductName = System.Console.ReadLine();
                            System.Console.WriteLine("enter the Productprice:");
                            product.Price = System.Convert.ToDouble(System.Console.ReadLine());
                            pb.AddProducts(product); //adding the products into the List
                            System.Console.WriteLine("Product Added Sucessfully!!!");
                        }
                    }
                    catch (ProductException e)
                    {
                        System.Console.WriteLine(e.Message);
                    }
                } while (check1 == false);
            }

            // Local Function to Dispaly Product Details
            void DisplayProducts()
            {
                ProductBusiness pb     = new ProductBusiness();// Creating object for ProductBusiness class
                List <Product>  prodts = pb.DispalyProducts();

                System.Console.WriteLine("===============Product Details=============");
                System.Console.WriteLine("ProductName" + "   " + "ProductID" + "  " + "ProductPrice");
                System.Console.WriteLine("-----------------------------------------------------------------------");

                foreach (Product item in prodts)
                {
                    System.Console.WriteLine(item.ProductName + "    " + item.ProductID + "     " + item.Price);// Displaying the products
                }
            }

            // Local function to remove a Product form List
            void RemoveProduct()
            {
                Product         Product = new Product();         // creating the object fro Product class
                ProductBusiness pb      = new ProductBusiness(); // Creating object for ProductBusiness class
                bool            check1  = false;

                do
                {
                    try
                    {
                        System.Console.Write("Enter the ProductID to be Deleted:");
                        System.Console.WriteLine("Product ID must start with PID and should be less than 6");
                        string id = System.Console.ReadLine();
                        if (pb.CheckProductID(id) == true)//checking whether the productId avaliable in the list or not

                        {
                            check1 = true;
                            pb.RemoveProduct(id);
                            System.Console.WriteLine("Product Removed");
                        }
                        else
                        {
                            System.Console.WriteLine("ProductID does not Exixts");
                        }
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine(e.Message);
                    }
                } while (check1 == false);
            }

            // local Function to get details of Product by Id
            void GetProductByID()
            {
                ProductBusiness pb     = new ProductBusiness(); // Creating  object for ProductBusiness class
                bool            check1 = false;

                do
                {
                    try
                    {
                        System.Console.Write("Enter the ProductID: ");
                        System.Console.WriteLine("Product ID must start with PID and should be less than 6");
                        string productID = System.Console.ReadLine();
                        if (pb.CheckProductID(productID))
                        {
                            check1 = true;
                            Product pe = pb.GetProductByProductID(productID);
                            System.Console.WriteLine(pe.ProductID + "     " + pe.ProductName + "      " + pe.Price);
                        }
                        else
                        {
                            throw new ProductException("ProductID Does not Exsits");
                        }
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine(e.Message);
                    }
                } while (check1 == false);
            }

            // local function to update product details
            void UpdateProduct()
            {
                Product         product = new Product();         // creating the object for Product class
                ProductBusiness pb      = new ProductBusiness(); // Creating  object for ProductBusiness class

                System.Console.WriteLine("1. Update Product Name");
                System.Console.WriteLine("2. Update Product Price");


                int option;

                System.Console.Write("enter your Choice: ");
                option = int.Parse(System.Console.ReadLine());

                switch (option)
                {
                case 1:
                    UpdateProductName(); break;

                case 2:
                    UpdateProductPrice(); break;
                }

                // inner function to update a product name by using productID
                void UpdateProductName()
                {
                    bool check1 = false;

                    do
                    {
                        try
                        {
                            System.Console.WriteLine("Enter Existing Product ID");
                            System.Console.WriteLine("Product ID must start with PID and should be less than 6");
                            product.ProductID = System.Console.ReadLine();
                            if (pb.CheckProductID(product.ProductID))//checking whether the productId avaliable in the list or not
                            {
                                check1 = true;
                                System.Console.WriteLine("Enter new name for Product");
                                System.Console.WriteLine("ProductName must Contain only alphabets");
                                product.ProductName = System.Console.ReadLine();

                                pb.UpdateProductName(product);
                                System.Console.WriteLine("ProductName updated!!");
                            }
                            else
                            {
                                throw new ProductException("ProductID does not Exixts");
                            }
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine(e.Message);
                        }
                    } while (check1 == false);
                }

                // inner function to update a product price by using ProductID
                void UpdateProductPrice()
                {
                    bool check1 = false;

                    do
                    {
                        try
                        {
                            System.Console.WriteLine("Enter Existing Product ID");
                            System.Console.WriteLine("Product ID must start with PID and should be less than 6");
                            product.ProductID = System.Console.ReadLine();
                            if (pb.CheckProductID(product.ProductID))//checking whether the productId avaliable in the list or not
                            {
                                check1 = true;
                                System.Console.WriteLine("Enter new Price for Product");
                                product.Price = System.Convert.ToDouble(System.Console.ReadLine());

                                pb.UpdateProductPrice(product);
                                System.Console.WriteLine("Product Price Updated Sucessfully!!!");
                            }
                            else
                            {
                                throw new ProductException("ProductID does not Exixts");
                            }
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine(e.Message);
                        }
                    } while (check1 == false);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// used to update the stock of the product
        /// </summary>
        public void UpdateStockQuantity()
        {
            StockBusinessLogicLayer stockBusinessLogicLayer = new StockBusinessLogicLayer();
            Stock           stock = new Stock();
            ProductBusiness productBusinessLogic  = new ProductBusiness();
            MenuPrensentor  wareHousePresentation = new MenuPrensentor();
            bool            check = false;

            do
            {
                try
                {
                    System.Console.WriteLine("enter to which WarehouseId you want to update the quantity:");
                    System.Console.WriteLine("It should not contain spaces and length be exactly 6");
                    stock.WareHouseID = System.Console.ReadLine();
                    if (wareHousePresentation.CheckWareHouseId(stock.WareHouseID)) //checking whether the Warehouse Id is present in the list of warehouse
                    {
                        bool check1 = false;
                        check = true;
                        do
                        {
                            try
                            {
                                System.Console.WriteLine("enter to which WarehouseAddress you want to update the quantity:");
                                System.Console.WriteLine("It should not contain spaces or Special Characters and length should be exactly 4");
                                stock.AddressID = System.Console.ReadLine();
                                if (wareHousePresentation.CheckAddressId(stock.AddressID))//checking whether the warehouse address is present in list of warehouse adress

                                {
                                    bool check2 = false;
                                    check1 = true;
                                    do
                                    {
                                        try
                                        {
                                            System.Console.WriteLine("enter to which ProductID you want to update the quantity");
                                            System.Console.WriteLine("Product ID Should not NULL and ProductID Should Start with PID and 0-9 number and length should be 6");
                                            stock.ProductID = System.Console.ReadLine();
                                            if (productBusinessLogic.CheckProductID(stock.ProductID))//checking whether product is available in the list or not
                                            {
                                                check2 = true;
                                                System.Console.WriteLine("enter the quantity to be updated:");
                                                stock.Quantity = System.Convert.ToInt32(System.Console.ReadLine());

                                                stockBusinessLogicLayer.UpdateStockQuantity(stock);
                                                System.Console.WriteLine("Stock quntity Updated Sucessfully");
                                            }
                                        }
                                        catch (StockException e)
                                        {
                                            System.Console.WriteLine(e.Message);
                                        }
                                    } while (check2 == false);
                                }
                            }
                            catch (StockException e)
                            {
                                System.Console.WriteLine(e.Message);
                            }
                        } while (check1 == false);
                    }
                }
                catch (StockException e)
                {
                    System.Console.WriteLine(e.Message);
                }
            } while (check == false);
        }