Exemplo n.º 1
0
        //Add to stock operation
        private static void AddToStock(string filepath, string logFilePath)
        {
            Console.WriteLine("Enter Item Code");
            string itemCode = Console.ReadLine();

            Console.WriteLine("Enter Item Name");
            string itemName = Console.ReadLine();

            Console.WriteLine("Enter Item Quantity");

            //try catch for user entry of quantity - can't enter string

            try
            {
                int quantity = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Enter Item Price");

                //try catch for user entry of Price - can't enter string


                try
                {
                    float        price    = float.Parse(Console.ReadLine());
                    DateTime     time     = DateTime.Now;
                    stockManager stockMgr = new stockManager();

                    stockMgr.AddItem(new stockItem(itemCode, itemName, price, quantity));

                    try
                    {
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filepath, true))
                        {
                            file.WriteLine(itemCode + "," + itemName + "," + quantity + "," + price);
                        }
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@logFilePath, true))
                        {
                            file.WriteLine(itemCode + "," + itemName + "," + price + "," + "Added to stock" + "," + time);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("ERROR: PLEASE ENTER A VALID PRICE");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("ERROR: PLEASE ENTER AN INTEGER FOR QUANTITY");
            }
        }
Exemplo n.º 2
0
 public mainMenu(stockManager sm, transactionLogManager lm)
 {
     this.stkMgr = sm;
     this.lgMgr  = lm;
 }