public void writetoFile(Desk desk, DeskQuote quote) { DateTime date = new DateTime(); date = DateTime.Now; StreamWriter writer; writer = new StreamWriter("quotes.txt", append: true); writer.WriteLine("{0},{1},{2},{3},{4},{5},{6},${7}", quote.CustomerName, date, desk.DeskWidth.ToString(), desk.DeskDepth.ToString(), desk.NumberOfDrawers.ToString(), desk.Material, quote.Shipping, quote.QuoteAmount ); writer.Close(); }
public static void Save(DeskQuote quote) { // Make a container for our saved desks List <DeskQuote> quotes = new List <DeskQuote>(); // If a save file already exists, read from and append to it if (File.Exists(SaveFilePath)) { // Load all saves string savedQuotes = File.ReadAllText(SaveFilePath); // Deserialize the saved list of desks quotes = JsonConvert.DeserializeObject <List <DeskQuote> >(savedQuotes); } // Add the current desk to the (possibly empty) list of desks quotes.Add(quote); // JSONify string JSONDesks = JsonConvert.SerializeObject(quotes); // Save our JSON File.WriteAllText(SaveFilePath, JSONDesks); }
private void generateDeskQuoteButton_Click(object sender, EventArgs e) { Desk desk = new Desk(); desk.DeskWidth = Convert.ToInt32(widthInputBox.Text); desk.DeskDepth = Convert.ToInt32(depthInputBox.Text); desk.NumberOfDrawers = Convert.ToInt32(drawerNumberInputForm.Text); switch (materialInputBox.Text) { case "Pine": desk.Material = Desk.DeskMaterial.Pine; break; case "Rosewood": desk.Material = Desk.DeskMaterial.Rosewood; break; case "Oak": desk.Material = Desk.DeskMaterial.Oak; break; case "Laminate": desk.Material = Desk.DeskMaterial.Laminate; break; case "Veneer": desk.Material = Desk.DeskMaterial.Veneer; break; } DeskQuote quote = new DeskQuote(); switch (shippingInputBox.ValueMember.ToString()) { case "Three Day": quote.Shipping = DeskQuote.ShippingSpeed.Three_day; break; case "Five Day": quote.Shipping = DeskQuote.ShippingSpeed.Five_day; break; case "Seven Day": quote.Shipping = DeskQuote.ShippingSpeed.Seven_day; break; default: quote.Shipping = DeskQuote.ShippingSpeed.Fourteen_day; break; } //calculations done here. int calculateDeskArea = desk.DeskWidth * desk.DeskDepth; quote.CustomerName = customerNameBox.Text; quote.QuoteDate = DateTime.Today; quote.QuoteAmount = quote.getDeskPrice(desk, (int)numDesksInputBox.Value, quote.Shipping); // Get the quote amount quote.DeskStruct = desk; // Display the quote price to 2 decimal places priceLabel.Text = "$" + quote.QuoteAmount.ToString("0.00"); // Save the current quote DeskQuote.Save(quote); }