Esempio n. 1
0
        private void bnBook_Click(object sender, EventArgs e)
        {
            // XXX List Books buton is pressed

            while (true)
            {
                try
                {
                    // to capture an exception from SelectedItem/SelectedIndex of listBooksDialog
                    listBooksDialog.ClearDisplayItems();
                    // XXX null is a dummy argument

                    BookShopControl.printBookToBookdialog(listBooksDialog);

                    //listBooksDialog.AddDisplayItems(BookShopControl.listOfBooks.ToArray().ToString());

                    if (listBooksDialog.Display() == DialogReturn.Done)
                    {
                        return;
                    }
                    // select is pressed

                    BookShopControl.updateBookInformationDialog(bookInformationDialog, listBooksDialog);

                    switch (bookInformationDialog.Display())
                    {
                    case DialogReturn.AddToCart:     // Add to Cart
                        // XXX
                        BookShopControl.addBookToCustomerCart(BookShopControl.listOfBooks[listBooksDialog.SelectedIndex].isbn);
                        continue;

                    case DialogReturn.AddToWishList:     // Add to Wishlist
                        // XXX
                        BookShopControl.addBookToCustomerWishList(BookShopControl.listOfBooks[listBooksDialog.SelectedIndex].isbn);
                        continue;

                    case DialogReturn.Done:     // cancel
                        continue;

                    default:
                        return;
                    }
                }
                catch (BookShopException bsex)
                {
                    MessageBox.Show(this, bsex.ErrorMessage);
                    continue;
                }
            }
        }
Esempio n. 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; 
        }