Esempio n. 1
0
        //private List<Order> myVar = Orders;
        public void Execute()
        {
            CommonIO.ShowHeader("Lookup an order");

            List <Order> _allOrders = new List <Order>();
            DateTime     OrderDate  = ConsoleIO.AskForOrderDate();

            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders = _manager.LoadOrders(OrderDate);

            _allOrders = AllOrders.Orders;

            Console.Clear();

            if (AllOrders.Success)
            {
                foreach (Order OneOrder in _allOrders)
                {
                    ConsoleIO.DisplayOrderDetails(OneOrder);
                }
                CommonIO.Continue();
            }
            else
            {
                CommonIO.MessageToUserInBlue(AllOrders.Message);
            }
        }
Esempio n. 2
0
        public Order LoadOrder(DateTime DateLookup, int OrderNumber)
        {
            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders  = LoadOrders(DateLookup);
            _allOrders = AllOrders.Orders;

            if (!AllOrders.Success)
            {
                return(null);
            }
            //Order orderCk = _allOrders.FirstOrDefault(a => a.OrderDate == DateLookup);
            Order orderCk = AllOrders.Orders.FirstOrDefault(a => a.OrderNumber == OrderNumber);

            //if (orderCk == null)
            //{
            //    return orderCk;
            //}
            //else
            //{
            //    orderCk = _allOrders.FirstOrDefault(o => o.OrderNumber == OrderNumber);
            //}

            return(orderCk);
        }
Esempio n. 3
0
        public void SaveOrderToList(Order newOrder)
        {
            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders = _manager.LoadOrders(newOrder.OrderDate);
            String userConfirm = ConsoleIO.RequireYorN("Would you like to save this order? (y=yes, n=no)");

            _orders = AllOrders.Orders;

            if (userConfirm == "Y")
            {
                int   orderNumToReplace = newOrder.OrderNumber;
                Order OldOrder          = _orders.FirstOrDefault(o => o.OrderNumber == newOrder.OrderNumber);

                int indexToReplace = (_orders.IndexOf(OldOrder));

                _orders[indexToReplace] = newOrder;
                _manager.SaveOrders(newOrder.OrderDate, _orders);

                userConfirm = userConfirm.ToUpper();
                CommonIO.MessageToUserInBlue($"New order ID {newOrder.OrderNumber} has been saved.");
                CommonIO.Continue();
            }
            else if (userConfirm == "N")
            {
                CommonIO.MessageToUserInBlue($"New order ID {newOrder.OrderNumber} was NOT saved.");
                CommonIO.Continue();
            }
        }
Esempio n. 4
0
        public OrdrLkpResponses LoadOrders(DateTime FileDate)
        {
            //DateTime FileDate = new DateTime(2018, 5, 26);

            string fileName = "Orders_" + FileDate.ToString("MMddyyyy") + ".txt";

            fileName = fileName.Replace("/", "");
            string path = @"C:\Users\steve\OneDrive\Work\sGuild\Week05\Code\Flooring_Orders\Flooring_Orders\bin\Debug\Files\" + fileName;

            OrdrLkpResponses ResponsesFromFile = new OrdrLkpResponses();

            List <Order> OrdersFromFile = new List <Order>();
            Order        OneFileOrder   = new Order();

            FileLookupResponse response = null;

            string[] readText = null;

            try
            {
                readText = File.ReadAllLines(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                string exceptionType  = ex.GetType().ToString();
                string fileNotFoundEx = "System.IO.FileNotFoundException";
                if (exceptionType == fileNotFoundEx)
                {
                    ResponsesFromFile.Success = false;
                    ResponsesFromFile.Message = "No file found for date " + FileDate;
                    return(ResponsesFromFile);
                }
                else
                {
                    throw ex;
                }
            }

            bool isHeader = true;

            foreach (string line in readText)
            {
                if (!isHeader)
                {
                    OneFileOrder = MapToOrders(FileDate, line);
                    OrdersFromFile.Add(OneFileOrder);
                }
                isHeader = false;
            }
            _allOrders = OrdersFromFile;

            ResponsesFromFile.Success = true;
            ResponsesFromFile.Message = "Orders successfully Loaded";
            ResponsesFromFile.Orders  = OrdersFromFile;

            return(ResponsesFromFile);
        }
Esempio n. 5
0
        public void Execute()
        // The construct doesn't get executed when a method is static.
        // But, without having this static makes it difficult to count orders
        // AND diffiuclt to get the next order number.
        {
            Order orderFromUsr = new Order();

            CommonIO.ShowHeader("Add an order");

            orderFromUsr = ConsoleIO.GetNewOrder();

            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders = _manager.LoadOrders(orderFromUsr.OrderDate);

            if (AllOrders.Success)
            {
                _orders = AllOrders.Orders;
            }
            else
            {
                Console.WriteLine("An error occurred: ");
                Console.WriteLine(AllOrders.Message);
            }

            orderFromUsr = CalcRestofOrder(orderFromUsr);
            //DateTime OrderDate = orderFromUsr.OrderDate;
            CommonIO.MessageToUserInBlue("Order entry is complete.");
            CommonIO.Continue();

            ConsoleIO.DisplayOrderDetails(orderFromUsr);

            String userConfirm = ConsoleIO.RequireYorN("Would you like to save this information? (y=Yes, n=No.)");

            if (userConfirm.ToUpper() == "Y")
            {
                //List<Order> AllOrders = _manager.LoadOrders(DateTime.Now);

                _manager.SaveOrder(orderFromUsr);
                //manager.SaveOrders(AllOrders);
                CommonIO.MessageToUserInBlue($"New order ID {orderFromUsr.OrderNumber} has been saved.");
                CommonIO.Continue();
            }
            else
            {
                CommonIO.MessageToUserInBlue($"New order ID {orderFromUsr.OrderNumber} was NOT saved.");
                CommonIO.Continue();
            }
        }
Esempio n. 6
0
        public OrdrLkpResponses LoadOrders(DateTime FileDate)
        {
            //_allOrders = Orders;

            OrdrLkpResponses AllResponses = new OrdrLkpResponses();

            AllResponses.Orders = _allOrders.Where(o => o.OrderDate == FileDate).ToList();

            if (AllResponses.Orders.Count > 0)
            {
                AllResponses.Success = true;
            }
            else
            {
                AllResponses.Success = false;
            }
            return(AllResponses);
        }
Esempio n. 7
0
        public Order LoadOrder(DateTime orderDate, int orderNum)
        {
            //            List<Order> Orders = new List<Order>();

            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders = LoadOrders(orderDate);
            //_allOrders = AllOrders.Orders;

            if (!AllOrders.Success)
            {
                return(null);
            }

            Order orderCk = AllOrders.Orders.FirstOrDefault(a => a.OrderNumber == orderNum);


            return(orderCk);
        }
        public void Execute()
        {
            CommonIO.ShowHeader("Delete Order");
            DateTime OrderDateToDelete = ConsoleIO.AskForOrderDate();

            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders = _manager.LoadOrders(OrderDateToDelete);

            if (AllOrders.Success)
            {
                _orders = AllOrders.Orders;
                int orderNumtoDelete = CommonIO.GetIntFromUser(1, 999, 0, "What order number would you like to delete?");
                DeleteOrder(OrderDateToDelete, orderNumtoDelete);
            }
            else
            {
                CommonIO.MessageToUserInBlue(AllOrders.Message);
            }
        }
Esempio n. 9
0
            //expects fail since this is not a valid date

            public void LookupOrderFileTest
                (int orderYr, int orderMnth, int orderDay, bool expectedResult)
            {
                DateTime testDate = new DateTime();

                testDate = new DateTime(orderYr, orderMnth, orderDay);

                ////// ////// ////// ////// ////// //////
                ////// Call the method being tested /////

                //OrderManager manager = new OrderManager(new OrderTestRepo2());
                OrderTestRepo2 Repo = new OrderTestRepo2();

                OrdrLkpResponses GetOrders = new OrdrLkpResponses();

                GetOrders = Repo.LoadOrders(testDate);

                bool actualResult = GetOrders.Success;

                Assert.AreEqual(expectedResult, actualResult);
            }
Esempio n. 10
0
        public int NextOrderID(DateTime OrderDate)
        {
            /// Should go in Repo
            /// ///
            List <Order> ListOfOrders = new List <Order>();

            OrdrLkpResponses AllOrders = new OrdrLkpResponses();

            AllOrders    = LoadOrders(OrderDate);
            ListOfOrders = AllOrders.Orders;

            int maxOrderNum = 0;

            foreach (Order order in ListOfOrders)
            {
                if (order.OrderNumber > maxOrderNum)
                {
                    maxOrderNum = order.OrderNumber;
                }
            }

            return(maxOrderNum + 1);
        }
Esempio n. 11
0
        public OrdrLkpResponses LoadOrders(DateTime OrderDate)
        {
            AllLkupResponses = _orderRepository.LoadOrders(OrderDate);

            return(AllLkupResponses);
        }