Example #1
0
        private void saveTransactionToDatabase(DataGridViewRow dirtyRow)
        {
            Transaction transaction = new Transaction();

            transaction.Account = account;

            long transactionId;
            if (dirtyRow.Cells["id"].Value != null &&
                long.TryParse(dirtyRow.Cells["id"].Value.ToString(), out transactionId))
            {
                transaction.Id = transactionId;
            }

            if (isTransactionDataComplete(dirtyRow))
            {
                transaction.Date = DateTime.Parse(dirtyRow.Cells["date"].Value.ToString());
                transaction.Amount = (decimal)dirtyRow.Cells["amount"].Value;
                transaction.Remarks = dirtyRow.Cells["remarks"].Value.ToString();
                transaction.Save(DatabaseFactory.Default);
                dirtyRow.Cells["id"].Value = transaction.Id;
                withChanges = true;
            }
        }
Example #2
0
 void transactionsGrid_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     DialogResult result = MessageBox.Show("Are you sure you want to delete this transaction?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
     if (result == DialogResult.OK)
     {
         long transactionId;
         if (e.Row.Cells["id"].Value != null &&
             long.TryParse(e.Row.Cells["id"].Value.ToString(), out transactionId))
         {
             Transaction transaction = new Transaction();
             transaction.Id = transactionId;
             transaction.Remove(DatabaseFactory.Default);
         }
     }
     else
     {
         e.Cancel = true;
     }
 }