Exemplo n.º 1
0
        private void mnuItemAddDebit_Click(object sender, EventArgs e)
        {
            //Retrieve selected customer from grid
            Data.Customer selectedCustomer = (Data.Customer)gvwCustomers.SelectedRows[0].DataBoundItem;

            //Pass customer name to a new transaction form along with a new debit transaction
            using (frmTransaction transactionForm = new frmTransaction())
            {
                transactionForm.TransactionData = new Data.Transaction(Data.Transaction.TransactionType.Debit);
                transactionForm.CustomerName    = selectedCustomer.Name;
                transactionForm.ShowDialog();
                if (transactionForm.DialogResult == DialogResult.OK)
                {
                    //Add transaction to the customer's transactions
                    if (selectedCustomer.Transactions is null)
                    {
                        selectedCustomer.Transactions = new List <Data.Transaction>();
                    }
                    selectedCustomer.Transactions.Add(transactionForm.TransactionData);
                    selectedCustomer.UpdateToDatabase();
                    RefreshCustomers();
                }
            }
        }