コード例 #1
0
        private void BtnSaveQuote_Click(object sender, EventArgs e)
        {
            Desk userDesk = new Desk();

            userDesk.Width           = (int)(NumDeskWidth.Value);
            userDesk.Depth           = (int)(NumDeskDepth.Value);
            userDesk.NumberOfDrawers = (int)(NumNumberOfDrawers.Value);
            userDesk.DesktopMaterial = (DesktopMaterial)ComDesktopMaterial.SelectedItem;
            DeskQuote userQuote = new DeskQuote();

            userQuote.CustomerName   = TxtCustomerName.Text;
            userQuote.DaysToComplete = (DaysToComplete)(ComDaysToComplete.SelectedValue);
            // OutputBox.Text = userQuote.DaysToComplete.ToString();
            userQuote.Desk = userDesk;
            userQuote.getRushOrderPrices();
            userQuote.CalculateQuotePrice();

            var quotesFile = @"quotes.json";
            var finalJson  = " ";

            using (StreamReader reader = new StreamReader(quotesFile))
            {
                string quotes = reader.ReadToEnd();
                var    list   = (JsonConvert.DeserializeObject <List <DeskQuote> >(quotes));
                list.Add(userQuote);
                finalJson = JsonConvert.SerializeObject(list, Formatting.Indented);
            }

            using (StreamWriter writer = new StreamWriter(quotesFile))
            {
                writer.Write(finalJson);
            }

            this.Hide();
            this.mainMenu.Show();
        }