private void GetQuoteButton_Click(object sender, EventArgs e) { Desk desk = new Desk { Width = (int)widthNumericUpDown.Value, Depth = (int)depthNumericUpDown.Value, NumberOfDrawers = (int)numberOfDrawersNumericUpDown.Value, SurfaceMaterial = (Desk.DesktopSurfaceMaterial)surfaceMaterialSelectionComboBox.SelectedItem }; DeskQuote deskQuote = new DeskQuote { Desk = desk, CustomerName = customerNameTextBox.Text, ShippingSpeed = GetRushShippingChoice(), QuoteDate = DateTime.Now }; totalPriceAmountLabel.Text = $@"${deskQuote.CalculateQuote()}"; shippingPriceLabel.Text = $@"${deskQuote.GetShippingPrice()}"; WriteQuoteToFile(deskQuote); DisplayQuote(); }
private void GetQuoteButton_Click(object sender, EventArgs e) { try { Desk desk = new Desk { Width = (int)widthNumericUpDown.Value, Depth = (int)depthNumericUpDown.Value, NumberOfDrawers = (int)numberOfDrawersNumericUpDown.Value, SurfaceMaterial = (Desk.DesktopSurfaceMaterial)surfaceMaterialSelectionComboBox.SelectedItem }; DeskQuote deskQuote = new DeskQuote { Desk = desk, CustomerName = customerNameTextBox.Text, ShippingSpeed = GetRushShippingChoice(), QuoteDate = DateTime.Now }; if (string.IsNullOrEmpty(deskQuote.CustomerName)) { throw new InvalidOperationException(@"Please enter your name."); } totalPriceAmountLabel.Text = $@"${deskQuote.CalculateQuote()}"; shippingPriceLabel.Text = $@"${deskQuote.GetShippingPrice()}"; string quotesFile = @"quotes.txt"; if (!File.Exists(quotesFile)) { using (StreamWriter writer = File.CreateText(quotesFile)) { writer.WriteLine( $"{deskQuote.QuoteDate}," + $"{deskQuote.CustomerName}," + $"{deskQuote.Desk.Width}," + $"{deskQuote.Desk.Depth}," + $"{deskQuote.Desk.NumberOfDrawers}," + $"{deskQuote.Desk.SurfaceMaterial}," + $"{deskQuote.ShippingSpeed}," + $"{deskQuote.GetShippingPrice()}," + $"{deskQuote.CalculateQuote()}"); writer.Close(); } } else { using (StreamWriter writer = File.AppendText(quotesFile)) { writer.WriteLine( $"{deskQuote.QuoteDate}," + $"{deskQuote.CustomerName}," + $"{deskQuote.Desk.Width}," + $"{deskQuote.Desk.Depth}," + $"{deskQuote.Desk.NumberOfDrawers}," + $"{deskQuote.Desk.SurfaceMaterial}," + $"{deskQuote.ShippingSpeed}," + $"{deskQuote.GetShippingPrice()}," + $"{deskQuote.CalculateQuote()}"); writer.Close(); } } DisplayQuote(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }