Example #1
0
        private void AddQuoteToFile(DeskQuote deskQuote)
        {
            var quotesFile = @"quotes.json";
            List <DeskQuote> deskQuotes = new List <DeskQuote>();

            // read existing quotes
            if (File.Exists(quotesFile))
            {
                using (StreamReader reader = new StreamReader(quotesFile))
                {
                    // load existing quotes
                    string quotes = reader.ReadToEnd();

                    if (quotes.Length > 0)
                    {
                        // deserialize quotes
                        deskQuotes = JsonConvert.DeserializeObject <List <DeskQuote> >(quotes);
                    }

                    // add a new quote
                    deskQuotes.Add(deskQuote);
                }

                // save to file
                SaveQuotes(deskQuotes);
            }
            else
            {
                // create quote list
                deskQuotes = new List <DeskQuote> {
                    deskQuote
                };

                // save to file
                SaveQuotes(deskQuotes);
            }
        }
Example #2
0
        public decimal CreateQuoteTotal(DeskQuote deskQuote)
        {
            //define required area vars
            int surfaceAreaCost;
            int surfaceArea = deskQuote.Desk.Depth * deskQuote.Desk.Width;
            int costOfDrawers;
            int materialCost;
            int rushOrderCost = 0;

            //calculate surface area cost
            if (surfaceArea > SIZE)
            {
                surfaceAreaCost = (surfaceArea - SIZE) * PRICE_PER_SURFACEAREA;
            }
            else
            {
                surfaceAreaCost = 0;
            }

            //calculate drawer cost
            costOfDrawers = deskQuote.Desk.NumberOfDrawers * PRICE_PER_DRAWER;

            //calculate material cost
            switch (deskQuote.Desk.Material)
            {
            case Material.laminate:
                materialCost = 100;
                break;

            case Material.oak:
                materialCost = 200;
                break;

            case Material.pine:
                materialCost = 50;
                break;

            case Material.veneer:
                materialCost = 125;
                break;

            case Material.rosewood:
                materialCost = 300;
                break;

            default:
                materialCost = -1;     // error flag
                break;
            }

            //calculate rush order

            if (deskQuote.RushDays == RUSH1)
            {
                RushDayPrices = GetRushOrderPrices();

                if (surfaceArea < SIZE)
                {
                    rushOrderCost = RushDayPrices[0, 0];
                }
                else if (surfaceArea <= RUSH)
                {
                    rushOrderCost = RushDayPrices[0, 1];
                }
                else
                {
                    rushOrderCost = RushDayPrices[0, 2];
                }
            }
            if (deskQuote.RushDays == RUSH2)
            {
                if (surfaceArea < SIZE)
                {
                    rushOrderCost = RushDayPrices[1, 0];
                }
                else if (surfaceArea <= RUSH)
                {
                    rushOrderCost = RushDayPrices[1, 1];
                }
                else
                {
                    rushOrderCost = RushDayPrices[1, 2];
                }
            }
            if (deskQuote.RushDays == RUSH3)
            {
                if (surfaceArea < SIZE)
                {
                    rushOrderCost = RushDayPrices[2, 0];
                }
                else if (surfaceArea <= RUSH)
                {
                    rushOrderCost = RushDayPrices[2, 1];
                }
                else
                {
                    rushOrderCost = RushDayPrices[2, 2];
                }
            }

            return(BASE_PRICE + surfaceAreaCost + costOfDrawers + materialCost + rushOrderCost);
        }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            var desk = new Desk
            {
                Depth           = Int32.Parse(textBox4.Text),
                Width           = Int32.Parse(textBox5.Text),
                NumberOfDrawers = (int)comboBox1.SelectedValue
            };

            switch (comboBox2.SelectedItem)
            {
            case "laminate":
                desk.Material = Material.laminate;
                break;

            case "oak":
                desk.Material = Material.oak;
                break;

            case "pine":
                desk.Material = Material.pine;
                break;

            case "rosewood":
                desk.Material = Material.rosewood;
                break;

            case "veneer":
                desk.Material = Material.veneer;
                break;
            }

            var deskQuote = new DeskQuote
            {
                Desk         = desk,
                CustomerName = textBox1.Text,
                QuoteDate    = DateTime.Now
            };

            if (radioButton1.Checked)
            {
                deskQuote.RushDays = 0;
            }
            else if (radioButton2.Checked)
            {
                deskQuote.RushDays = 3;
            }
            else if (radioButton3.Checked)
            {
                deskQuote.RushDays = 5;
            }
            else if (radioButton4.Checked)
            {
                deskQuote.RushDays = 7;
            }
            else
            {
                MessageBox.Show("error with rush days baby");
            }

            try
            {
                // get quote amount
                var quote = deskQuote.CreateQuoteTotal(deskQuote);

                // add amount to quote
                deskQuote.QuoteAmount = quote;

                // add quote to file
                AddQuoteToFile(deskQuote);

                // show 'DisplayQuote' form
                DisplayQuote displayQuote = new DisplayQuote(deskQuote);
                displayQuote.Tag = this;
                displayQuote.Show(this);
                Hide();
            }
            catch (Exception err)
            {
                MessageBox.Show("There was an error creating the quote. {0}", err.Message);
            }
        }