Exemple #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;
                }
            }
        }
Exemple #2
0
        void initial_Load()
        {
            //temporary variables
            //TODO change this to work directly with the class
            List<Customer> listOfCustomers = new List<Customer>();
            List<Book> listOfBooks = new List<Book>();
            List<Transaction> listOfPendingTransactions = new List<Transaction>();
            List<Transaction> listOfCompleteTransactions = new List<Transaction>();


        OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "BookStore Data Files|*.bdf";
            openFileDialog.InitialDirectory = Application.StartupPath;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                TextReader trs = new StreamReader(openFileDialog.FileName);
                string s;
                List<string> words;
                int stringIndex;

                while (((s = trs.ReadLine()) != null) && (s != ""))
                {
                    words = new List<string>();
                    while (true)
                    {
                        if ((stringIndex = s.IndexOf('#')) == -1) break;
                        words.Add(s.Substring(0, stringIndex).Trim());
                        s = s.Substring(stringIndex + 1);
                    }
                    if (words.Count > 0)
                    {
                        try
                        { // to catprue an exception from getInt( ) getDecimal
                            switch (words[0])
                            {
                                case "AddBook":
                                    decimal price = getDecimal(words[5]);
                                    int stock = getInt(words[7]);
                                    // XXX use words[1]~words[4], price, words[6], and stock to register a book
                                    ControlShop.listOfBooks.Add(new Book(words[1], words[2], words[3], words[4], price, words[6], stock));
                                    break;
                                case "AddCustomer":
                                    // XXX use words[1]~words[7] to register a customer
                                    ControlShop.listOfCustomers.Add(new Customer(words[1], words[2], words[3], words[4], words[5], words[6], words[7]));
                                    //ControlShop.addCustomerTodictionary(words[3], );
                                    break;
                                case "Login":
                                    // XXX use words[1] and words[2] to login a customer
                                    ControlShop.findCustomerLogin(words[1], words[2]);
                                    customerWindow.updateLabel = ControlShop.LoggedinCustomer.userName;
                                    break;
                                case "AddBookToWishList":
                                    // XXX use words[1] (ISBN) to register the book in the current customer's wishlist
                                    ControlShop.addBookToCustomerWishList(words[1]);
                                    break;
                                case "AddBookToCart":
                                    // XXX use words[1] (ISBN) to add the book in the current customer's cart
                                    ControlShop.addBookToCustomerCart(words[1]);
                                    break;
                                case "CheckOut":
                                    // XXX check out the current customer's cart
                                    ControlShop.checkOutCustomer(); 
                                    break;
                                case "ProcessPendingTransaction":
                                    // XXX use words[1] (index of the pending transactions) to identify the pending
                                    // transaction to approve
                                    ControlShop.approveTransaction(ControlShop.listOfPendingTransactions[Int32.Parse(words[1])]);
                                    break;
                                default:
                                    MessageBox.Show(this, "Unknown Operation : " + words[0]);
                                    break;
                            }
                        }
                        catch (BookShopException ex)
                        {
                            MessageBox.Show(this, ex.ErrorMessage);
                        }
                    }
                }
                
            }
            //ControlShop.updateObject(listOfCustomers, listOfBooks, listOfPendingTransactions, listOfCompleteTransactions);
            //ControlShop.LoggedinCustomer = null; 
        }