private void OpenDetails() { if (dataGridView.Rows.Count < 1) { return; } var selectedTransaction = dataGridView.SelectedRows[0].Cells[0].Value; var transactions = this._transactions .SingleOrDefault(_ => _.Id == Guid.Parse(selectedTransaction.ToString())); var form = new frmIncomeExpense(transactions); form.ShowDialog(); if (!form.isCancelled) { dataGridView.SelectedRows[0].Cells[2].Value = form.Transaction.BeginningBalance.ToString("#,##0.00"); dataGridView.SelectedRows[0].Cells[3].Value = form.Transaction.EndingBalance.ToString("#,##0.00"); dataGridView.SelectedRows[0].Cells[4].Value = form.Transaction.GetTotalIncome().ToString("#,##0.00"); dataGridView.SelectedRows[0].Cells[5].Value = form.Transaction.GetTotalExpense().ToString("#,##0.00"); dataGridView.SelectedRows[0].Cells[6].Value = form.Transaction.Profit.ToString("#,##0.00"); dataGridView.SelectedRows[0].Cells[7].Value = form.Transaction.Notes; this._transactions.Remove(transactions); this._transactions.Add(form.Transaction); Filter(); } }
private void BtnNew_Click(object sender, EventArgs e) { var formDate = new frmDate(); formDate.ShowDialog(); if (!formDate.IsCancelled) { var transaction = new Transaction { Id = Guid.NewGuid(), Date = formDate.Date }; var form = new frmIncomeExpense(transaction); form.ShowDialog(); if (!form.isCancelled) { //Check if date is exists var data = this._transactions.SingleOrDefault(_ => _.Date.Year == form.Transaction.Date.Year && _.Date.Month == form.Transaction.Date.Month && _.Date.Day == form.Transaction.Date.Day); if (data == null) { this._transactions.Add(form.Transaction); Filter(); } else { MessageBox.Show(ErrorMessages.DateIsAlreadyExists); } } } }