Beispiel #1
0
        //removes and deletes if last one
        public void RemoveOldOrderFromList()
        {
            //if its the last one
            //delete the file


            var orderToFind = SalesDayOrderList.Where(o => o.OrderNumber == OrderToEdit.OrderNumber).First();

            DateOfOrderToRemove = orderToFind.OrderDate;

            if (SalesDayOrderList.Count() == 1)
            {
                string filename = ConvertDateToFileName(SalesDayOrderList[0].OrderDate);

                string path = FolderPath + filename;
                File.Delete(path);
                return;
            }


            else
            {
                SalesDayOrderList.Remove(orderToFind);
                WriteListToFile(DateOfOrderToRemove);
            }



            return;
        }
Beispiel #2
0
        public void AddUpdatedOrderToList(Order updatedOrder)
        {
            SalesDayOrderList.Add(updatedOrder);



            return;
        }
Beispiel #3
0
        public Order GetOrderFromList(int orderNumber)
        {
            Order result = new Order();

            result = SalesDayOrderList.Where(o => o.OrderNumber == orderNumber).First();

            return(result);
        }
Beispiel #4
0
        public void AddUpdatedOrderToList(Order updatedOrder)
        {
            SalesDayOrderList.Add(updatedOrder);
            WriteListToFile(updatedOrder.OrderDate);


            return;
        }
Beispiel #5
0
        public void RemoveOldOrderFromList()
        {
            //findit and remove
            var orderToFind = SalesDayOrderList.Where(o => o.OrderNumber == OrderToEdit.OrderNumber).First();

            SalesDayOrderList.Remove(orderToFind);


            return;
        }
Beispiel #6
0
        //** method param is a filename that has previously been
        //verified to exist in the file system.
        //method extracts a date from file format "Orders_06132020.txt"
        // and converts it to a useable format "06/13/2020"
        //this allows a dateTime object to be parsed from the
        //string input and later saved to the OrderDate
        //field in the target object

        //will take the orders from the file
        // create a local copy and add it to SalesDayOrderList

        //changed to public for testing
        public void ReadOrderByDate(string filename)
        {
            //ex: Orders_06132020.txt

            ProductRepository p = new ProductRepository();

            // will need to extract date from filename
            string s = filename.Remove(0, 7);

            string[] stringArray   = s.Split('.');
            string   date          = stringArray[0];
            string   formattedDate = date.Substring(0, 2) + "/" + date.Substring(2, 2) + "/" + date.Substring(4);


            //this will read one file and add all orders in the file to the
            //SalesDayOrderList
            try
            {
                string[] rows = File.ReadAllLines(_folderpath + filename);
                for (int i = 1; i < rows.Length; i++)
                {
                    string[] columns = rows[i].Split(',');
                    Order    o       = new Order();
                    o.OrderDate              = DateTime.Parse(formattedDate);
                    o.OrderNumber            = Int32.Parse(columns[0]);
                    o.CustomerName           = columns[1];
                    o.State                  = ConvertToStateEnum(columns[2]); //convert to enum
                    o.TaxRate                = Decimal.Parse(columns[3]);
                    o.ProductType            = columns[4];
                    o.Area                   = Decimal.Parse(columns[5]);
                    o.CostPerSquareFoot      = Decimal.Parse(columns[6]);
                    o.LaborCostPerSquareFoot = Decimal.Parse(columns[7]);
                    o.MaterialCost           = Decimal.Parse(columns[8]);
                    o.LaborCost              = Decimal.Parse(columns[9]);
                    o.Tax     = Decimal.Parse(columns[10]);
                    o.Total   = Decimal.Parse(columns[11]);
                    o.Product = p.ProductList.Where(x => x.ProductType == o.ProductType).First();

                    SalesDayOrderList.Add(o);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("There was a error the File System (ReadOrderFile), Contact IT");
                Console.WriteLine(e.Message);
                Console.WriteLine("Press Any Key to Exit");
                Console.ReadKey();
                return;
                //System.Environment.Exit(0);
            }
        }
Beispiel #7
0
        //REFACTOR TO

        //This One: edits, but does not delete file
        public void EditRemoveOldOrderFromList()
        {
            //if its the last one
            //delete the file


            var orderToFind = SalesDayOrderList.Where(o => o.OrderNumber == OrderToEdit.OrderNumber).First();

            //DateOfOrderToRemove = orderToFind.OrderDate;

            SalesDayOrderList.Remove(orderToFind);
            //WriteListToFile(DateOfOrderToRemove);
        }
Beispiel #8
0
        public int CalculateOrderNumber(Order o)
        {
            if (!SalesDayOrderList.Any())
            {
                o.OrderNumber = 1;
            }

            else
            {
                o.OrderNumber = SalesDayOrderList.MaxBy(x => x.OrderNumber).First().OrderNumber + 1;
            }

            return(o.OrderNumber);
        }
Beispiel #9
0
        //*****EDIT Methods*****

        public bool DoesOrderExistInList(int number)
        {
            var orderToFind = SalesDayOrderList.Where(o => o.OrderNumber == number);

            if (!orderToFind.Any())
            {
                return(false);
            }

            else
            {
                OrderToEdit = orderToFind.First();
                return(true);
            }
        }
Beispiel #10
0
        //FROM DisplayOrderManager

        public Response CheckIfOrderGroupExists(DateTime d) //also used in edit functions
        {
            Response response = new Response();

            var CheckOrderDates = SalesDayOrderList.Where(x => x.OrderDate == d);


            if (!CheckOrderDates.Any())
            {
                response.Success = false;
                response.Message = String.Format("Error: There were no orders for the date given: {0}", d.ToString("MM/dd/yyyy"));
            }

            else
            {
                response.Success = true;

                response.Message = String.Format("An order file for {0} has been found", d.ToString("MM/dd/yyyy"));
            }

            return(response);
        }
Beispiel #11
0
        public int CalculateOrderNumber(Order o)
        {
            //does a file exist with the date entered
            string filename = ConvertDateToFileName(o); //returns a filename
            string path     = FolderPath + filename;


            if (!File.Exists(path))
            {
                o.OrderNumber = 1;
            }

            else
            { //if the file does exists load the file to the order repository
                ReadOrderByDate(filename);


                o.OrderNumber = SalesDayOrderList.MaxBy(x => x.OrderNumber).First().OrderNumber + 1;
            }

            return(o.OrderNumber);
        }
Beispiel #12
0
 public void SaveAddedOrder(Order o)
 {
     SalesDayOrderList.Add(o);
 }