示例#1
0
        public static void DisplayOrder(string filename, int ordernumber)
        {
            LoadOrders   O      = new LoadOrders();
            List <Order> Orders = O.ParseFileData(filename);

            if (Orders == null)
            {
                Console.WriteLine("no orders found");
                return;
            }
            Order selected = Orders.Where(o => o.OrderNumber == ordernumber).FirstOrDefault();

            if (selected != null)
            {
                Console.WriteLine($"Order Number:  {selected.OrderNumber}");
                Console.WriteLine($"Customer Name: {selected.CustomerName}");
                Console.WriteLine($"State:  {selected.State}");
                Console.WriteLine($"Product:  {selected.Product}");
                Console.WriteLine($"Cost of Materials:  {selected.MaterialCost:C}");
                Console.WriteLine($"Cost of Labor:  {selected.LaborCost:C}");
                Console.WriteLine($"Tax:  {selected.Tax:C}");
                Console.WriteLine($"Total:  {selected.Total:C}");
            }
            else
            {
                Console.WriteLine("No order with that number was found for this date");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Press any key to continue");
        }
示例#2
0
        public static void PrintOrders(string filename)
        {
            LoadOrders O    = new LoadOrders();
            string     path = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename;

            if (File.Exists(path))
            {
                List <Order> Orders = O.ParseFileData(filename);
                foreach (Order order in Orders)
                {
                    Console.WriteLine($"Order Number:  {order.OrderNumber}");
                    Console.WriteLine($"Customer Name: {order.CustomerName}");
                    Console.WriteLine($"State:  {order.State}");
                    Console.WriteLine($"Product:  {order.Product}");
                    Console.WriteLine($"Cost of Materials:  {order.MaterialCost}");
                    Console.WriteLine($"Cost of Labor:  {order.LaborCost:C}");
                    Console.WriteLine($"Tax:  {order.Tax:C}");
                    Console.WriteLine($"Total:  {order.Total:C}");
                    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                }
                Console.WriteLine("Press any key to continue");
            }
            else
            {
                Console.WriteLine("No orders found for that date");
                Console.WriteLine("Press any key to continue");
            }
        }
示例#3
0
        public void CanParseOrders()
        {
            LoadOrders   O      = new LoadOrders();
            List <Order> Orders = O.ParseFileDataFromPath(directory + @"Orders_06012013.txt");

            Assert.AreEqual(1, Orders.Count);
            Assert.AreEqual(1, Orders[0].OrderNumber);
        }
示例#4
0
        public static void DisplayCurrentOrderFiles()
        {
            Console.Clear();
            List <string> allfiles = FileIO.GetCurrentOrderFiles();
            LoadOrders    o        = new LoadOrders();

            foreach (string file in allfiles)
            {
                int    x           = file.Length;
                string sub         = file.Substring(77, 8);
                string output      = sub.Substring(0, 2) + "/" + sub.Substring(2, 2) + "/" + sub.Substring(4, 4);
                int    OrderNumber = o.GetHigestOrderNumberinFile(file);
                Console.WriteLine($"File Date: {output}  Final order number:  {OrderNumber}");
                Console.WriteLine("--------------------------------------------------------------------------------------------------");
            }
            Console.WriteLine($"The highest order number is {o.GetHighestOrderNumber(allfiles)}");
        }
示例#5
0
        public static void Displaydictionary()
        {
            Console.WriteLine("Dictionary Load Test");

            LoadOrders o = new LoadOrders();
            Dictionary <int, Order> OrderDirectory = o.ParseOrderFilestodictionary();

            try
            {
                var Toprint = OrderDirectory.Where(d => d.Key > 0);
                foreach (var print in Toprint)
                {
                    Console.WriteLine($"Order Number: {print.Value.OrderNumber}\nEntry Key:{print.Key}\nCustomer name: {print.Value.CustomerName}, Order date {print.Value.OrderDate}\nProduct: {print.Value.Product}, Sales Zone: {print.Value.State}");
                    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                }
            }
            catch
            {
                Console.WriteLine("Could not access or generate database, please contact IT");
                return;
            }
        }
示例#6
0
        public static void InspectOrder()
        {
            UserIO.DisplayCurrentOrderFiles();
            OrderManager manager       = new OrderManager();
            string       orderdate     = manager.PseudoDateSelect();
            string       filename      = "Orders_" + orderdate + ".txt";
            List <Order> CurrentOrders = new List <Order>();

            try
            {
                LoadOrders current = new LoadOrders();
                CurrentOrders = current.ParseFileData(filename);
            }
            catch
            {
                Console.WriteLine("Could not open specified file");
                return;
            }
            Console.Clear();
            Console.WriteLine($"Orders on {orderdate}");
            Console.WriteLine("Order#, Customer name, State, product type, area, total cost");
            if (CurrentOrders != null)
            {
                foreach (Order order in CurrentOrders)
                {
                    Console.WriteLine($"{order.OrderNumber}, {order.CustomerName}, {order.State}, {order.Product}, {order.Area}, {order.Total:C}");
                }

                Console.WriteLine("Enter the order number");
                int ordernumber = UserIO.GetIntegerFromUser();
                UserIO.DisplayOrder(filename, ordernumber);
            }
            else
            {
                Console.WriteLine("No orders to display\nPress any key to continue");
            }
            Console.ReadKey();
        }
示例#7
0
        //-------------------------------------------------------------------------------------------------------------------------------------
        public void RemoveOrder()
        {
            string       date          = PseudoDateSelect();
            string       filename      = "Orders_" + date + ".txt";
            string       path          = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename;
            List <Order> CurrentOrders = new List <Order>();

            if (!File.Exists(path))
            {
                Console.WriteLine("Invalid date");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                return;
            }
            try
            {
                LoadOrders current = new LoadOrders();
                CurrentOrders = current.ParseFileData(filename);
            }
            catch
            {
                Console.WriteLine("Could not open specified file");
                return;
            }
            Console.Clear();
            Console.WriteLine($"Orders on {date}");
            Console.WriteLine("Order#, Customer name, State, product type, area, total cost");
            foreach (Order order in CurrentOrders)
            {
                Console.WriteLine($"{order.OrderNumber}, {order.CustomerName}, {order.State}, {order.Product}, {order.Area}, {order.Total:C}");
            }
            bool GoodOrder      = false;
            int  todelete       = 0;
            int  maxOrderNumber = CurrentOrders[CurrentOrders.Count - 1].OrderNumber;

            while (!GoodOrder)
            {
                Console.WriteLine("Please enter the order number of the order you wish to delete");
                int selection = UserIO.GetIntegerFromUser();
                if (selection > maxOrderNumber || selection < 1)
                {
                    GoodOrder = false;
                    Console.WriteLine("Please enter a valid order number");
                }
                else
                {
                    GoodOrder = true;
                    todelete  = selection;
                    break;
                }
            }
            foreach (Order order in CurrentOrders)
            {
                if (order.OrderNumber == todelete)
                {
                    CurrentOrders.Remove(order);
                    break;
                }
            }
            if (CurrentOrders.Count < 1)
            {
                File.Delete(path);
                Console.WriteLine("Date file deleted");
            }
            else
            {
                try
                {
                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total");
                        foreach (Order MyOrder in CurrentOrders)
                        {
                            sw.WriteLine($"{MyOrder.OrderNumber},\"{MyOrder.CustomerName}\",{MyOrder.State},{MyOrder.TaxRate},{MyOrder.Product},{MyOrder.Area},{MyOrder.CostPerSquareFoot},{MyOrder.LaborCostPerSquareFoot},{MyOrder.MaterialCost},{MyOrder.LaborCost},{MyOrder.Tax},{MyOrder.Total}");
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Could not write updated order to file");
                    return;
                }
            }
            Console.WriteLine("Order deleted");
            Console.ReadLine();
        }
示例#8
0
        //--------------------------------------------------------------------------------------------------------------------------------------
        public void EditOrder()
        {
            List <Product> Products = new List <Product>();

            try
            {
                Products = LoadProducts.LoadAllProducts();
            }
            catch
            {
                Console.WriteLine("Could not load product data");
            }
            List <State> States = new List <State>();

            try
            {
                States = LoadStates.LoadAllStates();
            }
            catch
            {
                Console.WriteLine("Could not load sales tax data");
            }
            string       date          = PseudoDateSelect();
            string       filename      = "Orders_" + date + ".txt"; //enusre write-ability
            string       path          = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename;
            List <Order> CurrentOrders = new List <Order>();

            if (!File.Exists(path))
            {
                Console.WriteLine("Invalid date");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                return;
            }
            try
            {
                LoadOrders current = new LoadOrders();
                CurrentOrders = current.ParseFileData(filename);
            }
            catch
            {
                Console.WriteLine("Could not open specified file");
                return;
            }
            Console.Clear();
            Console.WriteLine($"Orders on {date}");
            Console.WriteLine("Order#, Customer name, State, product type, area, total cost");
            foreach (Order order in CurrentOrders)
            {
                Console.WriteLine($"{order.OrderNumber}, {order.CustomerName}, {order.State}, {order.Product}, {order.Area}, {order.Total:C}");
            }

            bool  GoodOrder   = false;
            Order OrderToEdit = new Order();

            while (!GoodOrder)
            {
                Console.WriteLine("Please enter the order number of the order you wish to edit");
                int   selection = UserIO.GetIntegerFromUser();
                Order chosen    = CurrentOrders.Where(o => o.OrderNumber == selection).FirstOrDefault();
                if (chosen != null)
                {
                    OrderToEdit = chosen;
                    GoodOrder   = true;
                    break;
                }
                else
                {
                    Console.WriteLine("Enter a valid order number");
                }
            }
            Console.WriteLine($"The current Customer name is {OrderToEdit.CustomerName}");
            Console.WriteLine("Enter a new name, or leave the field blank to retain the current name");
            string namechange = Console.ReadLine();  // will need this to be better, maybe seperate into change name function

            if (namechange != "")
            {
                if (namechange[0].ToString() != " ")
                {
                    OrderToEdit.CustomerName = namechange;
                    Console.WriteLine($"Customer name changed to {OrderToEdit.CustomerName}");
                }
                else
                {
                    Console.WriteLine($"Customer name reamins {OrderToEdit.CustomerName}");
                }
            }
            else
            {
                Console.WriteLine($"Customer name remains {OrderToEdit.CustomerName}");
            }
            Console.WriteLine($"The current state is {OrderToEdit.State}");

            UserIO.DisplayStates();
            Console.WriteLine("Please enter the number associated with the customer's updated state");
            string statechange = Console.ReadLine();
            State  Mystate     = null;

            if (statechange != "")
            {
                if (statechange[0].ToString() != " ")
                {
                    Mystate             = EditState(States, statechange);
                    OrderToEdit.State   = Mystate.StateCode;
                    OrderToEdit.TaxRate = Mystate.TaxRate;
                }
                else
                {
                    Console.WriteLine($"State remains {OrderToEdit.State}");
                    Mystate = GetState(OrderToEdit.State, States);
                }
            }
            else
            {
                Console.WriteLine($"State remains {OrderToEdit.State}");
                Mystate = GetState(OrderToEdit.State, States);
            }
            Console.Clear();
            UserIO.DisplayProducts();
            Console.WriteLine($"The current product selected is {OrderToEdit.Product}");
            Console.WriteLine("please enter the new product, or leave the field empty to continue");
            Product changedproduct = null;
            string  productchange  = Console.ReadLine();

            if (productchange != "")
            {
                if (productchange[0].ToString() != " ")
                {
                    bool isFinished         = false;
                    int  productchangeIndex = 0;
                    while (!isFinished)
                    {
                        bool goodInt = int.TryParse(productchange, out productchangeIndex);

                        if (goodInt)
                        {
                            changedproduct      = GetProductByIndex(productchangeIndex, Products);
                            OrderToEdit.Product = changedproduct.ProductName;
                            OrderToEdit.LaborCostPerSquareFoot = changedproduct.LaborCost;
                            OrderToEdit.CostPerSquareFoot      = changedproduct.CostperSquare;
                            Console.WriteLine($"The product has been updated to {OrderToEdit.Product} with a material cost of of {OrderToEdit.CostPerSquareFoot:C}/ft^2, \nand a labor cost of {OrderToEdit.LaborCostPerSquareFoot:C}");
                            isFinished = true;
                        }
                        else
                        {
                            Console.WriteLine($"Please enter a valid index number in the range of 1 to {Products.Count}");
                            productchange = Console.ReadLine();
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"Product remains {OrderToEdit.Product}");
                    changedproduct = GetMyProduct(OrderToEdit.Product, Products);
                }
            }
            else
            {
                Console.WriteLine($"Product remains {OrderToEdit.Product}");
                changedproduct = GetMyProduct(OrderToEdit.Product, Products);
            }
            Console.WriteLine($"The current area is {OrderToEdit.Area}");
            Console.WriteLine("please enter the new area, or leave the field empty to continue");
            string areachange = Console.ReadLine();

            if (areachange != "")
            {
                if (areachange[0].ToString() != " ")
                {
                    OrderToEdit.Area = GetArea(areachange);
                    Console.WriteLine($"The new area is {OrderToEdit.Area}");
                }
                else
                {
                    Console.WriteLine($"The area remains {OrderToEdit.Area}");
                }
            }
            else
            {
                Console.WriteLine($"The area remains {OrderToEdit.Area}");
            }
            OrderToEdit.ComputOrderValues(changedproduct, Mystate);
            Console.WriteLine($"The order now stands at:\n{ OrderToEdit.CustomerName}, in {OrderToEdit.State}, for {OrderToEdit.Area}ft^2 {OrderToEdit.Product} for a total of {OrderToEdit.Total:C}");
            Console.WriteLine("Do you wish to save these these changes?");
            Console.WriteLine("enter \'N\' to discard changes or any other key to keep changes?");
            string SaveChoice = Console.ReadLine().ToUpper();

            if (SaveChoice == "N")
            {
                Console.WriteLine("Changes Discared");
                return;
            }
            else
            {
                try
                {
                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total");
                        foreach (Order MyOrder in CurrentOrders)
                        {
                            sw.WriteLine($"{MyOrder.OrderNumber},\"{MyOrder.CustomerName}\",{MyOrder.State},{MyOrder.TaxRate},{MyOrder.Product},{MyOrder.Area},{MyOrder.CostPerSquareFoot},{MyOrder.LaborCostPerSquareFoot},{MyOrder.MaterialCost},{MyOrder.LaborCost},{MyOrder.Tax},{MyOrder.Total}");
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Could not write updated order to file");
                    return;
                }
                Console.WriteLine("Order edited");
            }
        }
示例#9
0
        //--------------------------------------------------------------------------------------------------------------------------------------
        public void AddOrder()
        {
            List <Product> Products = new List <Product>();

            try
            {
                Products = LoadProducts.LoadAllProducts();
            }
            catch
            {
                Console.WriteLine("Could not load product data");
            }
            List <State> States = new List <State>();

            try
            {
                States = LoadStates.LoadAllStates();
            }
            catch
            {
                Console.WriteLine("Could not load sales tax data");
            }

            int          ordernumber   = FileIO.ReturnHighestOrderNumber() + 1;
            string       date          = DateSelect();
            string       filename      = "Orders_" + date + ".txt";
            string       path          = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename;
            List <Order> CurrentOrders = new List <Order>();

            if (File.Exists(path))
            {
                LoadOrders current = new LoadOrders();
                CurrentOrders = current.ParseFileData(filename);
            }
            if (!File.Exists(path))
            {
                using (StreamWriter sw = new StreamWriter(path, true))
                {
                    sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total");
                }
            }
            string name = GetName();

            Console.Clear();
            Console.WriteLine("Please enter the number associated with the customer's sales zone");
            UserIO.DisplayStates();
            State state = GetStateByIndex(States);

            Console.Clear();
            UserIO.DisplayProducts();
            Product myProduct = GetProductByIndex(Products);
            decimal area      = GetArea();
            Order   MyOrder   = new Order(ordernumber, name, state, myProduct, area, date);

            Console.WriteLine($"The order for {name} in {state.StateName} is {area}ft^2 of {myProduct.ProductName}");
            Console.WriteLine($"The cost/ft^2 for material is{MyOrder.CostPerSquareFoot}, and the labor cost/ft^2 is{MyOrder.LaborCostPerSquareFoot}");
            Console.WriteLine($"Total material cost: {MyOrder.MaterialCost:C} \nTotal labor cost: {MyOrder.LaborCost:C}\nTaxes: {MyOrder.Tax:C}\nTotal cost: {MyOrder.Total:C}");
            Console.WriteLine("Do you wish to submit this order?  Enter \"n\" to discard order");
            string input = Console.ReadLine().ToUpper();

            if (input != "N")
            {
                try
                {
                    using (StreamWriter sw = new StreamWriter(path, true))
                    {
                        sw.WriteLine($"{MyOrder.OrderNumber},{MyOrder.CustomerName},{MyOrder.State},{MyOrder.TaxRate},{MyOrder.Product},{MyOrder.Area},{MyOrder.CostPerSquareFoot},{MyOrder.LaborCostPerSquareFoot},{MyOrder.MaterialCost},{MyOrder.LaborCost},{MyOrder.Tax},{MyOrder.Total}");
                    }
                }
                catch
                {
                    Console.WriteLine("System Error: order not submitted");
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Order terminated");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Order entry complete");
        }