public static bool AddInfo(Info infoToAdd) { try { using (StreamWriter writer = new StreamWriter(Operation.FilePath, true)) { writer.WriteLine(infoToAdd); } return true; } catch (Exception) { return false; } }
protected void addButton_Click(object sender, EventArgs e) { var infoToAdd = new Info( DateTime.Parse(this.dateTextBox.Text), this.expenseTextBox.Text, double.Parse(this.priceTextBox.Text)); if (Operation.AddInfo(infoToAdd)) { this.labelMessage.Text = "Successfully added"; this.dateTextBox.Text = string.Empty; this.expenseTextBox.Text = string.Empty; this.priceTextBox.Text = string.Empty; } else { this.labelMessage.Text = "Error occured"; } }
public static List<Info> TakeInfoFromTheBase() { var listOfDate = new List<Info>(); using (var reader = new StreamReader(Operation.FilePath)) { var currentDateLine = reader.ReadLine(); while (currentDateLine != null) { var currentDate = currentDateLine.Split('|'); var date = new Info( DateTime.Parse(currentDate[0].Trim()), currentDate[1].Trim(), double.Parse(currentDate[2].Trim())); listOfDate.Add(date); currentDateLine = reader.ReadLine(); } } return listOfDate; }