private void transactionClicked(object sender, DataGridViewCellMouseEventArgs e) { var id = int.Parse(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()); AddNewTransactionView addNewTransactionView = new AddNewTransactionView(); using (DataBase.DBContainer db = new DataBase.DBContainer()) { var transaction = (from Transactions in db.Transactions where id == Transactions.Id select Transactions).FirstOrDefault(); if (transaction != null) { // contact Models.Contact _contact = new Models.Contact(); if (transaction.Contact != null) { var selectedContact = (from Contacts in db.Contacts where Contacts.Id == transaction.Contact.Id select Contacts).FirstOrDefault(); _contact.Id = selectedContact.Id; _contact.FirstName = selectedContact.FirstName; _contact.LastName = selectedContact.LastName; _contact.Description = selectedContact.Description; } // category var selectedCategory = (from Categories in db.Categories where Categories.Id == transaction.Category.Id select Categories).FirstOrDefault(); Models.Category _category = new Models.Category(); _category.Id = selectedCategory.Id; _category.Name = selectedCategory.Name; if (selectedCategory.TransactionType == "Expense") { _category.Type = Models.TransactionType.Expense; } else { _category.Type = Models.TransactionType.Income; } // transaction Models.Transaction _transaction = new Models.Transaction(); _transaction.Id = id; _transaction.Amount = transaction.Amount; _transaction.DateTime = transaction.DateTime; _transaction.Category = _category; _transaction.Contact = _contact; if (transaction.TransactionType == "Expense") { _transaction.TransactionType = Models.TransactionType.Expense; } else { _transaction.TransactionType = Models.TransactionType.Income; } addNewTransactionView.isUpdating = true; addNewTransactionView.Text = "Update transaction"; addNewTransactionView.updatingTransaction = _transaction; addNewTransactionView.ShowDialog(); } } }
private void addNewTransaction(object sender, EventArgs e) { AddNewTransactionView addNewTransactionView = new AddNewTransactionView(); addNewTransactionView.ShowDialog(); }