private void addQuoteButton_Click(object sender, EventArgs e) { int spaceIndex = nameInput.Text.IndexOf(' '); string tempfName = nameInput.Text.Substring(0, spaceIndex); string tempLName = nameInput.Text.Substring(spaceIndex + 1); Desk desk = new Desk(Int32.Parse(widthInput.Text), Int32.Parse(depthInput.Text), Int32.Parse(drawersInput.Text)); desk.setMaterial(materialComboBox.Text); DeskQuote quote = new DeskQuote(tempfName, tempLName, Int32.Parse(rushComboBox.Text), DateTime.Now); quote.setQuote(quote.calcRushPrice(desk.getWidth(), desk.getDepth()) + desk.calcDeskPrice()); quote.outputToFile("C:\\Users\\Brad\\source\\repos\\MegaDesk1.1-BradKellogg\\MegaDesk-3-BradKellogg\\quotes.txt"); var mainMenu = (MainMenu)Tag; mainMenu.Show(); Close(); }
public void outputToFile(string filePath, DeskQuote quote) { string output = quote.CustomerName + '\t' + quote.QuoteAmount + '\t' + quote.newDesk.deskMaterial + '\t' + quote.QuoteDate + '\t' + quote.newDesk.getWidth() + '\t' + quote.newDesk.getDepth() + '\t' + quote.newDesk.getNumDrawers() + '\t' + quote.RushDays + '\n'; if (!File.Exists(filePath)) { File.Create(filePath); System.IO.File.AppendAllText(filePath, output); } else if (File.Exists(filePath)) { System.IO.File.AppendAllText(@filePath, output); } }
public void outputToJson(string filePath, DeskQuote desk) { List <DeskQuote> listBoi = new List <DeskQuote> { desk }; // Assisted Attempt string jsonFile = JsonConvert.SerializeObject(listBoi, Formatting.Indented); if (!File.Exists(filePath)) { using (StreamWriter sw = File.CreateText(@filePath)) { // done } } using (StreamWriter sw = File.AppendText(@filePath)) { sw.WriteLine(jsonFile); } }