private void comboBoxMaterials_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxMaterials.SelectedIndex == -1) { txtQuotes.Text = ""; } else { Desk.SurfaceMaterial material = EnumUtil.ParseEnum <Desk.SurfaceMaterial>(comboBoxMaterials.SelectedValue.ToString()); var sb = new StringBuilder(); foreach (DeskQuote deskQuote in deskQuotes) { if (deskQuote.Desk.Material == material) { sb.AppendLine(deskQuote.ToString()); } } if (sb.Length != 0) { txtQuotes.Text = DeskQuote.CSVHeader() + "\n" + sb.ToString(); } else { txtQuotes.Text = sb.ToString(); } } }
private void WriteToFile() { // First time adding text to the file if (!File.Exists(FILE_PATH)) { string header = DeskQuote.CSVHeader(); File.WriteAllText(FILE_PATH, header + Environment.NewLine + deskQuote.ToString() + Environment.NewLine); } // This text is always added, making the file longer over time // if it is not deleted. File.AppendAllText(FILE_PATH, deskQuote.ToString() + Environment.NewLine); }