// submit the quote.
        private void SubmitQuote_Click(object sender, EventArgs e)
        {
            try
            {
                CustomerName = userName.Text;
                DeskWidth    = int.Parse(userWidth.Text);
                DeskDepth    = int.Parse(userDepth.Text);
                Drawers      = int.Parse(userDrawers.Text);
                Finish       = (Materials)materialComboBox.SelectedValue;
                RushDays     = int.Parse(userSpeed.Text);

                // instantiate new deskQuote
                DeskQuote NewQuote = new DeskQuote(DeskWidth, DeskDepth, Drawers, Finish, RushDays, CustomerName);
                // Save the Quote Price
                QuotePrice = NewQuote.CalculateQuotePrice();

                // store the user input, the quote amount, and the date of the quote
                // create CSV string
                string csvString = CustomerName + "," + DeskWidth + "," + DeskDepth + "," + Drawers + "," +
                                   Finish + "," + RushDays + "," + QuotePrice + "," + DateTime.Now;
                string csvFile = @"quotes.txt";
                // check if file exists. If no, create file
                if (!File.Exists(csvFile))
                {
                    using (StreamWriter sw = File.CreateText(csvFile))
                    {
                        sw.WriteLine(csvString);
                    }
                }
                // if yes, append to file
                else
                {
                    using (StreamWriter sw = File.AppendText(csvFile))
                    {
                        sw.WriteLine(csvString);
                    }
                }
                // output the price quote to the screen along with the original user input
                DisplayQuote displayQuote = new DisplayQuote(NewQuote)
                {
                    Tag = this
                };
                displayQuote.Show(this);
                Hide();
            }
            catch (Exception)
            {
                MessageBox.Show("Please fill in all fields.");
                // validate fields
                if (CustomerName == "")
                {
                    userName.BackColor = Color.LightPink;
                }
                if (DeskWidth == 0)
                {
                    userWidth.BackColor = Color.LightPink;
                }
                if (DeskDepth == 0)
                {
                    userDepth.BackColor = Color.LightPink;
                }
                if (userSpeed.Text == "")
                {
                    userSpeed.BackColor = Color.LightPink;
                }
                this.Show();
            }

            {
            }
        }
Ejemplo n.º 2
0
 public DisplayQuote(DeskQuote newQuote)
 {
     InitializeComponent();
     this.newQuote = newQuote;
 }