Exemple #1
0
        /// <summary>
        /// initialize a new computer depending on the selection of the radiobuttons, then loop through the items
        /// in the selected add-ons listbox, and on each iteration wrap the previous object to a new object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBuy_Click(object sender, EventArgs e)
        {
            IComputer computer;

            if (laptopButton.Checked)
            {
                computer = new Laptop();
            }
            else if (TablePCButton.Checked)
            {
                computer = new TablePC();
            }
            else
            {
                MessageBox.Show("Choose a computer type!");
                return;
            }

            foreach (string item in selectedAddons.Items)
            {
                switch (item.ToString())
                {
                case "ExternalHD":
                    computer = new ExternalHD(computer);
                    break;

                case "Keyboard":
                    computer = new Keyboard(computer);
                    break;

                case "Mouse":
                    computer = new Mouse(computer);
                    break;

                case "Screen":
                    computer = new Screen(computer);
                    break;
                }
            }
            MessageBox.Show("Item bought!\nTotal price: " + computer.getPrice() + "\nDescription: " + computer.getDescription());
        }
Exemple #2
0
        /// <summary>
        /// initialize a new computer depending on the selection of the radiobuttons, then loop through the items
        /// in the selected add-ons listbox, and on each iteration wrap the previous object to a new object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBuy_Click(object sender, EventArgs e)
        {
            IComputer computer;

            if (laptopButton.Checked)
            {
                computer = new Laptop();
            }
            else if (TablePCButton.Checked)
            {
                computer = new TablePC();
            }
            else
            {
                MessageBox.Show("Choose a computer type!");
                return;
            }

            foreach (string item in selectedAddons.Items)
            {
                switch (item.ToString())
                {
                    case "ExternalHD":
                        computer = new ExternalHD(computer);
                        break;
                    case "Keyboard":
                        computer = new Keyboard(computer);
                        break;
                    case "Mouse":
                        computer = new Mouse(computer);
                        break;
                    case "Screen":
                        computer = new Screen(computer);
                        break;
                }
            }
            MessageBox.Show("Item bought!\nTotal price: " + computer.getPrice() + "\nDescription: " + computer.getDescription());
        }