public void CreateNewOrder(CustomerInput custIn, DateTime date)
        {
            Order orderData             = new Order();
            OrderFileRepository newFile = new OrderFileRepository();

            orderData.CustomerName = custIn.CustName;
            orderData.State        = custIn.State;
            orderData.ProductType  = custIn.ProductType;
            orderData.Area         = custIn.Area;
            orderData.OrderNumber  = custIn.OrderNumber;

            string[] stateTaxData = File.ReadAllLines(@"Data\Taxes.txt");

            for (int i = 1; i < stateTaxData.Length; i++)
            {
                if (stateTaxData[i].Contains(custIn.State))
                {
                    string taxRateLine = stateTaxData[i];
                    orderData.TaxRate = decimal.Parse(taxRateLine.Substring(3, taxRateLine.Length - 3));
                }
            }
            string[] productData = File.ReadAllLines(@"Data\Products.txt");

            for (int i = 1; i < productData.Length; i++)
            {
                string[] productDataSplit = productData[i].Split(',');

                if (productDataSplit[0].ToUpper() == custIn.ProductType.ToUpper())
                {
                    orderData.CostPerSquareFoot = decimal.Parse(productDataSplit[1]);
                }
                if (productDataSplit[0].ToUpper() == custIn.ProductType.ToUpper())
                {
                    orderData.LaborCostPerSquareFoot = decimal.Parse(productDataSplit[2]);
                }
            }

            orderData.MaterialCost = orderData.Area * orderData.CostPerSquareFoot;

            orderData.LaborCost = orderData.Area * orderData.LaborCostPerSquareFoot;

            orderData.Tax = Math.Round((orderData.TaxRate / 100M) * (orderData.MaterialCost + orderData.LaborCost), 2);

            orderData.Total = orderData.MaterialCost + orderData.LaborCost + orderData.Tax;

            if (date == default(DateTime))
            {
                newFile.CheckAndSaveNewFile(orderData);
            }
            else
            {
                newFile.CheckAndSaveEditedFile(orderData, date);
            }
        }
예제 #2
0
        public void CreateOrderTest()
        {
            Order myOrder = new Order()
            {
                CustomerName = "Big Bird", Area = 500M
            };

            OrderFileRepository repository = new OrderFileRepository();

            repository.CheckAndSaveNewFile(myOrder);

            Assert.AreEqual(500M, myOrder.Area);
            Assert.AreEqual("Big Bird", myOrder.CustomerName);
        }