Пример #1
0
            chickenstripTypes.SelectedItem = null;

            // Beverage Tab
            beverageTypes.ClearSelected();

        }

        /* ORDER LIST ( SINGLE CLICK EVENT )
         * 
         * Loads an object from the ' OrderList ' based on the index value.  This will
         * repopulate the form with the values contained within the object.  The user
         * can change the values on the form and then resubmit them into the array.
         * 
                           _           _     _     _   
              ___  _ __ __| | ___ _ __| |   (_)___| |_ 
             / _ \| '__/ _` |/ _ \ '__| |   | / __| __|
            | (_) | | | (_| |  __/ |  | |___| \__ \ |_ 
             \___/|_|  \__,_|\___|_|  |_____|_|___/\__|

             ____  _             _         ____ _ _      _    
            / ___|(_)_ __   __ _| | ___   / ___| (_) ___| | __
            \___ \| | '_ \ / _` | |/ _ \ | |   | | |/ __| |/ /
             ___) | | | | | (_| | |  __/ | |___| | | (__|   < 
            |____/|_|_| |_|\__, |_|\___|  \____|_|_|\___|_|\_\

        */
        private void orderList_SingleClick(object sender, EventArgs e)
        {
            
            // Check validity on the selected item
            if (orderList.SelectedItem != null)
            {
                editMode = true;
                addOrderButton.Text = "Add ( Edit Mode )";

                // Get the name of the class that is contained within the ' OrderList ' list array by index
                string className = NewOrder.OrderList[orderList.SelectedIndex].GetType().Name;

                // To manipulate the object, convert it back into a child class object
                switch (className)
                {
                    case "Pizza":
                        pizza = (Pizza)orderList.SelectedItem;
                        // Disable unneeded tabs
                        tabControl.TabPages.Remove(otherTab);
                        tabControl.TabPages.Remove(beverageTab);
                        // Populate the form with the values from the object in the orderList
                        pizzaTypes.SelectedIndex = pizzaTypes.FindString(pizza.PizzaType.ToString());
                        pizzaSizes.SelectedIndex = pizzaSizes.FindString(pizza.PizzaSize.ToString());
                        crustTypes.SelectedIndex = crustTypes.FindString(pizza.CrustType.ToString());
                        sauceTypes.SelectedIndex = sauceTypes.FindString(pizza.SauceType.ToString());
                        setToppingsList(pizza._PizzaToppings);
                        // Clear the topping array to ensure it's empty. Other variables will overwrite
                        pizza._PizzaToppings = null;

                        break;
                    case "Wings":
                        wings = (Wings)orderList.SelectedItem;
                        // Disable unneeded tabs
                        tabControl.TabPages.Remove(pizzaTab);
                        tabControl.TabPages.Remove(beverageTab);
                        // Populate the form
                        wingTypes.SelectedIndex = wingTypes.FindString(wings.WingType.ToString());
                        break;
                    case "Chickenstrips":
                        chickenstrips = (Chickenstrips)orderList.SelectedItem;
                        // Disable unneeded tabs
                        tabControl.TabPages.Remove(pizzaTab);
                        tabControl.TabPages.Remove(beverageTab);
                        // Populate the form
                        chickenstripTypes.SelectedIndex = chickenstripTypes.FindString(chickenstrips.ChickenstripType.ToString());
                        break;
                    case "Breadsticks":
                        breadsticks = (Breadsticks)orderList.SelectedItem;
                        // Disable unneeded tabs
                        tabControl.TabPages.Remove(pizzaTab);
                        tabControl.TabPages.Remove(beverageTab);
                        // Populate the form
                        breadstickTypes.SelectedIndex = breadstickTypes.FindString(breadsticks.BreadStickType.ToString());
                        break;
                    case "Beverage":
                        beverages = (Beverage)orderList.SelectedItem;
                        // Disable unneeded tabs
                        tabControl.TabPages.Remove(pizzaTab);
                        tabControl.TabPages.Remove(otherTab);
                        // Populate the form
                        beverageTypes.SelectedIndex = beverageTypes.FindString(beverages.BeverageType.ToString());
Пример #2
0
        {
            foreach(string topping in toppings) 
            {
                toppingsList.SetItemChecked(toppingsList.FindString(topping), true);
            }
        }

        /*
                       _     _  ___          _           ____        _   _              
              __ _  __| | __| |/ _ \ _ __ __| | ___ _ __| __ ) _   _| |_| |_ ___  _ __  
             / _` |/ _` |/ _` | | | | '__/ _` |/ _ \ '__|  _ \| | | | __| __/ _ \| '_ \ 
            | (_| | (_| | (_| | |_| | | | (_| |  __/ |  | |_) | |_| | |_| || (_) | | | |
             \__,_|\__,_|\__,_|\___/|_|  \__,_|\___|_|  |____/ \__,_|\__|\__\___/|_| |_|

        */
        private void addOrderButton_Click(object sender, EventArgs e)
        {
            
            /*
                       _     _ __  __           _      
              __ _  __| | __| |  \/  | ___   __| | ___ 
             / _` |/ _` |/ _` | |\/| |/ _ \ / _` |/ _ \
            | (_| | (_| | (_| | |  | | (_) | (_| |  __/
             \__,_|\__,_|\__,_|_|  |_|\___/ \__,_|\___|
 
            */
            if (!editMode)
            {

                /*** VALIDATE SOME CONTRAINTS ***/

                if (tabControl.SelectedTab == tabControl.TabPages["pizzaTab"])
                {
                    // User selected a 'Type' but did not select a 'Size'
                    if (pizzaTypes.SelectedItem == null)
                    {
                        orderFormMessageArea.Text = "ERROR: Please choose a ' Pizza Type '";
                    }

                    else if (pizzaSizes.SelectedItem == null)
                    {
                        orderFormMessageArea.Text = "ERROR: Please choose a ' Pizza Size '";

                    }

                    else
                    {

                        /*** PULL ALL VALUES ***/

                        // Pizza Tab - Temp variables to use when creating the pizza instance
                        Pizza.PizzaTypes pizzaType = (Pizza.PizzaTypes)pizzaTypes.SelectedItem;
                        Pizza.PizzaSizes pizzaSize = (Pizza.PizzaSizes)pizzaSizes.SelectedItem;
                        Pizza.SauceTypes sauceType = (Pizza.SauceTypes)sauceTypes.SelectedItem;
                        Pizza.CrustTypes crustType = (Pizza.CrustTypes)crustTypes.SelectedItem;
                        Pizza.PizzaToppings[] toppingsList = new Pizza.PizzaToppings[this.toppingsList.CheckedItems.Count];
                        int index = 0;
                        // REF: https://social.msdn.microsoft.com/Forums/windows/en-US/1c93a1c0-ebbb-4053-b544-210ced41270f/how-to-iterate-through-checkedlistbox-selecteditems-and-storing-it-in-a-string-array?forum=winforms
                        foreach (object item in this.toppingsList.CheckedItems)
                        {
                            toppingsList[index] = (Pizza.PizzaToppings)item;
                            ++index;
                        }


                        pizza = new Pizza(pizzaType, sauceType, crustType, toppingsList, pizzaSize);
                        //pizza.ProductType.Insert(0, "Pizza: ");
                        newOrder.OrderList.Add(pizza);
                        clearAllFields();
                        
                        // Enable the 'Save Order' Button
                        if (!saveOrderButton.Enabled) { saveOrderButton.Enabled = true; }
                        // Enable the 'Reset Order' Button on the 'MainForm'
                        if (!mainForm.ResetButtonEnable) { mainForm.ResetButtonEnable = true; }

                        if (MainForm.DEBUG) { Console.Write(pizza.displayDetails(toppingsList)); }

                    }
                }
                else if (tabControl.SelectedTab == tabControl.TabPages["otherTab"])
                {
                    if (wingTypes.SelectedItem == null && breadstickTypes.SelectedItem == null && chickenstripTypes.SelectedItem == null)
                    {
                        orderFormMessageArea.Text = "ERROR: Please select an option before adding";
                    }
                    // Other Tab
                    if (wingTypes.SelectedItem != null)
                    {
                        // Pull the value
                        Wings.WingTypes wingType = (Wings.WingTypes)wingTypes.SelectedItem;
                        // Create the instance
                        wings = new Wings(wingType);
                        // Store it in the 'Product' array
                        NewOrder.OrderList.Add(wings);
                        clearAllFields();
                        // Enable the 'Save Order' Button
                        if (!saveOrderButton.Enabled) { saveOrderButton.Enabled = true; }
                        // Enable the 'Reset Order' Button on the 'MainForm'
                        if (!mainForm.ResetButtonEnable) { mainForm.ResetButtonEnable = true; }
                    }
                    if (breadstickTypes.SelectedItem != null)
                    {
                        Breadsticks.BreadstickTypes breadstickType = (Breadsticks.BreadstickTypes)breadstickTypes.SelectedItem;
                        breadsticks = new Breadsticks(breadstickType);
                        NewOrder.OrderList.Add(breadsticks);
                        clearAllFields();
                        // Enable the 'Save Order' Button
                        if (!saveOrderButton.Enabled) { saveOrderButton.Enabled = true; }
                        // Enable the 'Reset Order' Button on the 'MainForm'
                        if (!mainForm.ResetButtonEnable) { mainForm.ResetButtonEnable = true; }

                    }
                    if (chickenstripTypes.SelectedItem != null)
                    {
                        Chickenstrips.ChickenstripTypes chickenstripType = (Chickenstrips.ChickenstripTypes)chickenstripTypes.SelectedItem;
                        chickenstrips = new Chickenstrips(chickenstripType);
                        NewOrder.OrderList.Add(chickenstrips);
                        clearAllFields();
                        // Enable the 'Save Order' Button
                        if (!saveOrderButton.Enabled) { saveOrderButton.Enabled = true; }
                        // Enable the 'Reset Order' Button on the 'MainForm'
                        if (!mainForm.ResetButtonEnable) { mainForm.ResetButtonEnable = true; }
                    }


                }
                else if (tabControl.SelectedTab == tabControl.TabPages["beverageTab"])
                {

                    if (beverageTypes.SelectedItem != null)
                    {
                        Beverage.BeverageTypes beverageType = (Beverage.BeverageTypes)beverageTypes.SelectedItem;
                        beverages = new Beverage(beverageType);
                        NewOrder.OrderList.Add(beverages);
                        orderFormMessageArea.Text = "SUCCESS: Your order has been added!";
                        clearAllFields();
                        // Enable the 'Save Order' Button
                        if (!saveOrderButton.Enabled) { saveOrderButton.Enabled = true; }
                        // Enable the 'Reset Order' Button on the 'MainForm'
                        if (!mainForm.ResetButtonEnable) { mainForm.ResetButtonEnable = true; }
                    }
                    else
                    {
                        orderFormMessageArea.Text = "ERROR: Please select a beverage before adding";
                    }
                }

                /*** CLEAR ALL FIELDS ***/

                


            } // END: Add mode


            /*
                          _ _ _   __  __           _      
                  ___  __| (_) |_|  \/  | ___   __| | ___ 
                 / _ \/ _` | | __| |\/| |/ _ \ / _` |/ _ \
                |  __/ (_| | | |_| |  | | (_) | (_| |  __/
                 \___|\__,_|_|\__|_|  |_|\___/ \__,_|\___|

            */
            else
            {
                if (tabControl.TabPages.Contains(pizzaTab))
                {
                    // Pull and assign the new values
                    pizza.ProductType = pizzaTypes.SelectedItem.ToString();
                    pizza.PizzaType = (Pizza.PizzaTypes)pizzaTypes.SelectedItem;
                    pizza.PizzaSize = (Pizza.PizzaSizes)pizzaSizes.SelectedItem;
                    pizza.SauceType = (Pizza.SauceTypes)sauceTypes.SelectedItem;
                    pizza.CrustType = (Pizza.CrustTypes)crustTypes.SelectedItem;

                    // Create and assign the 'toppingList' variable.  It was set to 'null' in orderList_SingleClick()
                    Pizza.PizzaToppings[] toppingsList = new Pizza.PizzaToppings[this.toppingsList.CheckedItems.Count];
                    pizza._PizzaToppings = toppingsList;

                    int index = 0;
                    foreach (object item in this.toppingsList.CheckedItems)
                    {
                        toppingsList[index] = (Pizza.PizzaToppings)item;
                        ++index;
                    }

                    // Store index, remove previous object and insert new object
                    int productIndex = orderList.SelectedIndex;
                    NewOrder.OrderList.RemoveAt(orderList.SelectedIndex);
                    NewOrder.OrderList.Insert(productIndex, pizza);

                    // Re-enable the tabs
                    tabControl.TabPages.Add(otherTab);
                    tabControl.TabPages.Add(beverageTab);

                    orderFormMessageArea.Text = "SUCCESS: Update complete";
                    if (MainForm.DEBUG) { Console.Write(pizza.displayDetails(toppingsList)); }
                }
                else if (tabControl.TabPages.Contains(otherTab))
                {
                    if (wingTypes.SelectedItem != null)
                    {
                        wings.ProductType = wingTypes.SelectedItem.ToString();
                        //newOrder.OrderList.SetItem(orderList.SelectedIndex, wings);

                        // Store index, remove previous object and insert new object
                        int productIndex = orderList.SelectedIndex;
                        NewOrder.OrderList.RemoveAt(orderList.SelectedIndex);
                        NewOrder.OrderList.Insert(productIndex, wings);
                    }
                    if (breadstickTypes.SelectedItem != null)
                    {
                        // Pull the new value
                        breadsticks.ProductType = breadstickTypes.SelectedItem.ToString();

                        // Store index, remove previous object and insert new object
                        int productIndex = orderList.SelectedIndex;
                        NewOrder.OrderList.RemoveAt(orderList.SelectedIndex);
                        NewOrder.OrderList.Insert(productIndex, breadsticks);
                    }
                    if (chickenstripTypes.SelectedItem != null)
                    {
                        // Pull the new value
                        chickenstrips.ProductType = chickenstripTypes.SelectedItem.ToString();

                        // Store index, remove previous object and insert new object
                        int productIndex = orderList.SelectedIndex;
                        NewOrder.OrderList.RemoveAt(orderList.SelectedIndex);
                        NewOrder.OrderList.Insert(productIndex, chickenstrips);
                    }

                    // Re-enable the tabs
                    tabControl.TabPages.Remove(otherTab);
                    // Had to do this to get the right order
                    tabControl.TabPages.Add(pizzaTab);
                    tabControl.TabPages.Add(otherTab);
                    tabControl.TabPages.Add(beverageTab);

                    orderFormMessageArea.Text = "SUCCESS: Update complete";
                }
                else if (tabControl.TabPages.Contains(beverageTab))
                {
                    // Pull the new value
                    beverages.ProductType = beverageTypes.SelectedItem.ToString();

                    // Store index, remove previous object and insert new object
                    int productIndex = orderList.SelectedIndex;
                    NewOrder.OrderList.RemoveAt(orderList.SelectedIndex);
                    NewOrder.OrderList.Insert(productIndex, beverages);

                    // Re-enable the tabs
                    tabControl.TabPages.Remove(beverageTab);
                    // Had to do this to get the right order
                    tabControl.TabPages.Add(pizzaTab);
                    tabControl.TabPages.Add(otherTab);
                    tabControl.TabPages.Add(beverageTab);

                    orderFormMessageArea.Text = "SUCCESS: Update complete";
                }