예제 #1
0
파일: Model.cs 프로젝트: kristena11/store
        public void AddChocolateInList(Chocolate chocolate)
        {
            ChocolateList.Add(chocolate);

            if (ChocolateAdded != null)
            {
                ChocolateAdded(chocolate);
            }
            Console.WriteLine("chocolate added!");
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //set variables to create new object in Chocolate class
            Console.WriteLine("flavor selected : " + comboBoxChocolateSelection.SelectedItem.ToString());
            //adding new chocolate to list;
            decimal quantity        = numericUpDown1.Value;
            string  chocolateFlavor = comboBoxChocolateSelection.SelectedItem.ToString();
            string  darkChocolate   = "Dark Chocolate";
            string  whiteChocolate  = "White Chocolate";

            //conditional to based on which selection from the flavor drop down
            if (chocolateFlavor.Contains(darkChocolate))
            {
                //choloate object created
                Chocolate newChocolate = new Chocolate(chocolateFlavor, 9.50, quantity);
                //add object to list in the model class
                m_model.AddChocolateInList(newChocolate);
                //hide current form
                this.Hide();
                //pass model information to new main screen... midel info will be reset if we reutrn back to the origional model
                MainNavigation aMainNavigation = new MainNavigation(m_model);
                aMainNavigation.Closed += (s, args) => this.Close();
                aMainNavigation.Show();
            }
            else if (chocolateFlavor.Contains(whiteChocolate))
            {
                Chocolate newChocolate = new Chocolate(chocolateFlavor, 5.00, quantity);
                m_model.AddChocolateInList(newChocolate);

                this.Hide();
                MainNavigation aMainNavigation = new MainNavigation(m_model);
                aMainNavigation.Closed += (s, args) => this.Close();
                aMainNavigation.Show();
            }
            else
            {
                Chocolate newChocolate = new Chocolate(chocolateFlavor, 7.60, quantity);
                m_model.AddChocolateInList(newChocolate);

                this.Hide();
                MainNavigation aMainNavigation = new MainNavigation(m_model);
                aMainNavigation.Closed += (s, args) => this.Close();
                aMainNavigation.Show();
            }
        }