Пример #1
0
        private void bnPendingTransactions_Click(object sender, EventArgs e)
        {
            // XXX List Pending Transactions button event handl

            while (true)
            {
                try
                {  // to capture an exception from SelectedIndex/SelectedItem of listPendingTransactionsDialog
                    listPendingTransactionsDialog.ClearDisplayItems();
                    //listPendingTransactionsDialog.AddDisplayItems(null);  // null is a dummy argument
                    foreach (Transaction tran in BookShopControl.listOfPendingTransactions)
                    {
                        //TODO move into new method
                        listPendingTransactionsDialog.AddDisplayItems(tran.customerName.userName + " : " + tran.ToString());
                    }
                    if (listPendingTransactionsDialog.Display() == DialogReturn.Done)
                    {
                        return;
                    }
                    // select button is pressed

                    while (true)
                    {
                        try
                        {  // to capture an exception from SelectedItem/SelectedTransaction of showPendingTransactionDialog
                            showPendingTransactionDialog.ClearDisplayItems();
                            //showPendingTransactionDialog.AddDisplayItems(null); // null is a dummy argument

                            BookShopControl.listTransactionDetails((SelectDialog)showPendingTransactionDialog, BookShopControl.listOfPendingTransactions[listPendingTransactionsDialog.SelectedIndex]);

                            switch (showPendingTransactionDialog.Display())
                            {
                            case DialogReturn.Approve:      // Transaction Processed
                                // XXX
                                BookShopControl.approveTransaction(BookShopControl.listOfPendingTransactions[listPendingTransactionsDialog.SelectedIndex]);
                                if (BookShopControl.amountOfPendingTransactions <= 0)
                                {
                                    return;
                                }
                                break;

                            case DialogReturn.ReturnBook:     // Return Book
                                // XXX
                                BookShopControl.listOfPendingTransactions[listPendingTransactionsDialog.SelectedIndex].
                                removeSubTransaction(BookShopControl.listOfPendingTransactions[listPendingTransactionsDialog.SelectedIndex].itemsPurchased[showPendingTransactionDialog.SelectedIndex].purchaseBook.isbn, 1);
                                continue;

                            case DialogReturn.Remove:     // Remove transaction
                                // XXX
                                BookShopControl.removeTransactionFromPending(BookShopControl.listOfPendingTransactions[listPendingTransactionsDialog.SelectedIndex]);
                                break;
                            }
                            break; //for "transaction processed"
                        }
                        catch (BookShopException bsex)
                        {
                            MessageBox.Show(this, bsex.ErrorMessage);
                            return;
                        }
                    }
                }
                catch (BookShopException bsex)
                {
                    MessageBox.Show(this, bsex.ErrorMessage);
                    continue;
                }
            }
        }