コード例 #1
0
ファイル: AddQuote.cs プロジェクト: sjkendall88/MegaDesk2
        private void DisplayQuote_Click(object sender, EventArgs e)
        {
            DeskQuote testQuote = new DeskQuote();

            testQuote.firstName = FirstName.Text;
            testQuote.lastName  = LastName.Text;
            testQuote.address   = address.Text;
            testQuote.city      = city.Text;
            testQuote.state     = state.Text;
            testQuote.phone     = phone.Text;
            testQuote.orderDate = DateTime.Today;

            Desk testDesk = new Desk();

            //if depth or width empty, set as minimum values
            if (DeskWidth.Text == "")
            {
                DeskWidth.Text = "24";
            }

            if (DeskDepth.Text == "")
            {
                DeskDepth.Text = "12";
            }
            testDesk.Depth        = Single.Parse(DeskDepth.Text);
            testDesk.Width        = Single.Parse(DeskWidth.Text);
            testDesk.NumOfDrawers = (float)NumOfDrawers.SelectedIndex;
            testDesk.DeskType     = DeskMaterials.Text;
            testDesk.RushDays     = RushDelivery.Text;

            DisplayQuotes viewDisplayQuotes = new DisplayQuotes();

            viewDisplayQuotes.Tag = this;
            viewDisplayQuotes.Show(this);
            Hide();



            try
            {
                DeskQuote.DeskCost(ref testDesk, ref testQuote, ref viewDisplayQuotes);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + exception.StackTrace);
            }
        }
コード例 #2
0
        public static void DeskCost(ref Desk testDesk, ref DeskQuote testQuote, ref DisplayQuotes viewDisplayQuotes)
        {
            // Variables
            float    squareInch, feeRush = 0, matFee = 0, exDays = 0, drawFee, topfee = 0, deskCost, width, depth, drawers, baseDeskPrice = (float)MegaConst.BaseDeskPrice;
            string   fName, lName, addrss, cty, rush, materials, stte, phone;
            DateTime orderDate, expDate = default;

            int[,] rushFee = new int[3, 3];

            //Assignment
            fName     = testQuote.firstName;
            lName     = testQuote.lastName;
            addrss    = testQuote.address;
            cty       = testQuote.city;
            stte      = testQuote.state;
            phone     = testQuote.phone;
            orderDate = testQuote.orderDate;
            depth     = testDesk.Depth;
            width     = testDesk.Width;
            drawers   = testDesk.NumOfDrawers;
            materials = testDesk.DeskType;
            rush      = testDesk.RushDays;


            // Area
            squareInch = depth * width;
            // Drawer fee math
            drawFee = (float)MegaConst.DrawerPrice * drawers;

            // Load rush costs into array
            rushFee = GetRushOrder();

            // Logic
            // Check for Rush
            if (rush != RushDays.Fourteen.ToString())
            {
                (feeRush, exDays) = RushFee(squareInch, rush, rushFee);
            }
            else
            {
                feeRush = 0;
                exDays  = 14;
            }

            // Check material fee
            switch (materials)
            {
            case "Oak":
                matFee = (float)MegaConst.OakPrice;
                break;

            case "Laminate":
                matFee = (float)MegaConst.LaminatePrice;
                break;

            case "Pine":
                matFee = (float)MegaConst.PinePrice;
                break;

            case "Rosewood":
                matFee = (float)MegaConst.RosewoodPrice;
                break;

            case "Veneer":
                matFee = (float)MegaConst.VeneerPrice;
                break;
            }

            // Check square foot fee
            if (squareInch > (float)MegaConst.BaseDeskSize)
            {
                topfee = (squareInch - (float)MegaConst.BaseDeskSize);
            }

            // Expected date math
            switch (rush)
            {
            case "Fourteen":
                expDate = orderDate.AddDays(14);
                break;

            case "Seven":
                expDate = orderDate.AddDays(7);
                break;

            case "Five":
                expDate = orderDate.AddDays(5);
                break;

            case "Three":
                expDate = orderDate.AddDays(3);
                break;
            }

            // Add it all up
            deskCost = feeRush + matFee + drawFee + topfee + baseDeskPrice;

            // Output for DisplayQuotes
            #region Output Display
            viewDisplayQuotes.FirstNameLabel.Text     = fName;
            viewDisplayQuotes.LastNameLabel.Text      = lName;
            viewDisplayQuotes.AddressLabel.Text       = addrss;
            viewDisplayQuotes.CityLabel.Text          = cty + ",";
            viewDisplayQuotes.StateLabel.Text         = stte;
            viewDisplayQuotes.PhoneLabel.Text         = phone;
            viewDisplayQuotes.MaterialLabel.Text      = materials;
            viewDisplayQuotes.WidthLabel.Text         = width.ToString();
            viewDisplayQuotes.DepthLabel.Text         = depth.ToString();
            viewDisplayQuotes.DrawersLabel.Text       = drawers.ToString();
            viewDisplayQuotes.DaysLabel.Text          = exDays.ToString();
            viewDisplayQuotes.BaseDeskPriceLabel.Text = "$" + baseDeskPrice.ToString();
            viewDisplayQuotes.MaterialFeeLabel.Text   = "$" + matFee.ToString();
            viewDisplayQuotes.DrawerFeeLabel.Text     = "$" + drawFee.ToString();
            viewDisplayQuotes.OversizeFeeLabel.Text   = "$" + topfee.ToString();
            viewDisplayQuotes.RushFeeLabel.Text       = "$" + feeRush.ToString();
            viewDisplayQuotes.OrderDate.Text          = orderDate.ToString("MMMM dd yyyy");
            viewDisplayQuotes.ExpectedDateLabel.Text  = expDate.ToString("MMMM dd yyyy");
            viewDisplayQuotes.TotalCostLabel.Text     = "$" + deskCost;
            #endregion

            MegaDeskQuotes megaDeskQuotes = new MegaDeskQuotes();

            megaDeskQuotes.mdFirstName    = fName;
            megaDeskQuotes.mdLastName     = lName;
            megaDeskQuotes.mdAddress      = addrss;
            megaDeskQuotes.mdCity         = cty;
            megaDeskQuotes.mdState        = stte;
            megaDeskQuotes.mdPhone        = phone;
            megaDeskQuotes.mdOrderDate    = orderDate;
            megaDeskQuotes.mdWidth        = width;
            megaDeskQuotes.mdDepth        = depth;
            megaDeskQuotes.mdNumOfDrawers = drawers;
            megaDeskQuotes.mdDeskType     = materials;
            megaDeskQuotes.mdRushDays     = rush;
            megaDeskQuotes.mdTotalCost    = "$" + deskCost.ToString();


            string result = JsonConvert.SerializeObject(megaDeskQuotes);
            string cFile  = @"quotes.json";
            if (!File.Exists(cFile))
            {
                using (StreamWriter sw = File.CreateText(cFile))
                {
                }
            }
            using (StreamWriter sw = File.AppendText(cFile))
            {
                sw.WriteLine(result);
            }
        }