public DisplayQuote(DeskQuote deskQuote) { InitializeComponent(); _deskQuote = deskQuote; lblCustomerName.Text = deskQuote.CustomerName; lblWidth.Text = deskQuote.Desk.Width.ToString(); lblDepth.Text = deskQuote.Desk.Depth.ToString(); lblDrawers.Text = deskQuote.Desk.NumberOfDrawers.ToString(); lblMaterial.Text = deskQuote.Desk.SurfaceMaterial.ToString(); lblShipping.Text = deskQuote.Shipping.ToString(); quotePriceLabel.Text = _deskQuote.QuotePrice.ToString("c"); }
private void AddQuoteToFile(DeskQuote deskQuote) { var quotesFile = @"quotes.json"; List <DeskQuote> deskQuotes = new List <DeskQuote>(); if (File.Exists(quotesFile)) { using (StreamReader reader = new StreamReader(quotesFile)) { string quotes = reader.ReadToEnd(); if (quotes.Length > 0) { deskQuotes = System.Text.Json.JsonSerializer.Deserialize <List <DeskQuote> >(quotes); } } } deskQuotes.Add(deskQuote); SaveQuotes(deskQuotes); }
private void btnSaveQuote_Click(object sender, EventArgs e) { // when clicking Save Quote button, will create a new desk using the // new Desk() method var desk = new Desk { Depth = numericUpDownDepth.Value, Width = numericUpDownWidth.Value, NumberOfDrawers = (int)numericUpDownDrawers.Value, SurfaceMaterial = (SurfaceMaterial)comboBoxMaterial.SelectedValue }; // create a desk quote var deskQuote = new DeskQuote { Desk = desk, CustomerName = txtCustomerName.Text, QuoteDate = DateTime.Now, Shipping = (Shipping)comboBoxShipping.SelectedValue }; var price = deskQuote.GetQuotePrice(); // set quote price deskQuote.QuotePrice = deskQuote.GetQuotePrice(); // add to quote deskQuote.QuotePrice = price; AddQuoteToFile(deskQuote); //code block to create form, add reference to AddQuote, show new form, and hide AddQuote DisplayQuote frmDisplayQuote = new DisplayQuote(deskQuote); frmDisplayQuote.Show(); this.Hide(); }