private void CreateQuoteButton_Click(object sender, EventArgs e) { customerNameValue = CustomerName.Text; rushDaysValue = Convert.ToInt32(RushDays.Text); widthValue = (int)Width.Value; depthValue = (int)Depth.Value; numDrawersValue = (int)NumDrawers.Value; surfaceMaterialValue = SurfaceMaterial.Text; DisplayQuote viewDisplayQuote = new DisplayQuote(); viewDisplayQuote.Tag = this.Tag; viewDisplayQuote.Show(); Hide(); }
private void CreateQuoteButton_Click(object sender, EventArgs e) { customerNameValue = CustomerName.Text; rushDaysValue = Convert.ToInt32(RushDays.Text); widthValue = (int)Width.Value; depthValue = (int)Depth.Value; numDrawersValue = (int)NumDrawers.Value; surfaceMaterialValue = SurfaceMaterial.Text; currentDate = DateTime.Now; // saved currentdate in string so the format is nice for the JSON file string orderDate = currentDate.ToString("dd MMMM yyyy"); //rushCostValue = ; Desk customerDesk = new Desk(widthValue, depthValue, numDrawersValue, surfaceMaterialValue); DeskQuote customerQuote = new DeskQuote(customerNameValue, customerDesk, rushDaysValue, orderDate); Program.Quotes.Add(customerQuote); //private static Desk customerDesk = new Desk(widthValue, depthValue, numDrawersValue, surfaceMaterialValue); //private static DeskQuote customerQuote = new DeskQuote(customerNameValue, customerDesk, rushDaysValue); // Saving JSON to text file #region Save Quotes to JSON file / serialize/deserialize var json = ""; try { json = JsonConvert.SerializeObject(Program.Quotes); string fileName = @"quotes.json"; List <DeskQuote> deskOrders = new List <DeskQuote>(); if (File.Exists(fileName)) { using (StreamReader reader = new StreamReader(fileName)) { string quotes = reader.ReadToEnd(); if (quotes.Length > 0) { deskOrders = JsonConvert.DeserializeObject <List <DeskQuote> >(quotes); } deskOrders.Add(customerQuote); } // convert to Json var serializedOrders = JsonConvert.SerializeObject(deskOrders); // save to json File.WriteAllText(fileName, serializedOrders); } else { deskOrders = new List <DeskQuote> { customerQuote }; var serializedOrders = JsonConvert.SerializeObject(deskOrders); // save to json File.WriteAllText(fileName, serializedOrders); } #endregion //File.WriteAllText(@"quotes.json", JsonConvert.SerializeObject(Program.Quotes)); // using (StreamWriter x = File.WriteAllText(fileName)) //{ // x.WriteLine(json); // } } catch (Exception ex) { MessageBox.Show(ex.Message + "Error writing to file."); } DisplayQuote viewDisplayQuote = new DisplayQuote(); viewDisplayQuote.Tag = this.Tag; viewDisplayQuote.Show(); Hide(); }