public static void editExpenses(expenseModel expense, int expenseID) { using (IDbConnection cnn = new SQLiteConnection(loadConnectionString())) { cnn.Execute("update expenseTable set Name = @Name, Amount = @Amount, Date = @Date where expenseID = " + expenseID, expense); } }
public static void saveExpenses(expenseModel expense) { using (IDbConnection cnn = new SQLiteConnection(loadConnectionString())) { cnn.Execute("insert into expenseTable (Name, Amount, Date) values (@Name, @Amount, @Date)", expense); } }
private void expenseButton_Click(object sender, EventArgs e) { try { expenseModel em = new expenseModel(); double tempAmount = Convert.ToDouble(txtAmount.Text); double finalAmount = 0; if (tempAmount > 0) { finalAmount = tempAmount * -1; } else { finalAmount = tempAmount; } em.Name = txtName.Text; em.Amount = finalAmount; em.Date = datePicker.Value.ToString("MM/dd/yyy"); if (expenseID == -1) { SQLiteDataAccess.saveExpenses(em); } else { SQLiteDataAccess.editExpenses(em, expenseID); } loadExpenseList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }