public static bool addExpense(Expense addExpenses) { try { using (var writer = new StreamWriter(Functions.FilePath, true)) { writer.WriteLine(addExpenses); }; return true; } catch(Exception) { return false; } }
protected void button_Click(object sender, EventArgs e) { var addingExpenses = new Expense( double.Parse(this.price.Text), this.addProductName.Text, this.addDateTime.Text ); if(Functions.addExpense(addingExpenses)) { this.message.Text = "Well done!"; } else { this.message.ForeColor = System.Drawing.Color.Red; this.message.Text = "An error occured"; } }