Example #1
0
        // Zdarzenie usuwania zaznaczonych produktów z koszyka
        private void uiBtnDelete_Click(object sender, EventArgs e)
        {
            for (int i = uiClbShopingCard.CheckedItems.Count - 1; i >= 0; i--)
            {
                if (uiClbShopingCard.CheckedItems[i] is IPizza)
                {
                    IPizza pizza = uiClbShopingCard.CheckedItems[i] as IPizza;
                    _orderCost -= pizza.Price();
                    uiClbShopingCard.Items.RemoveAt(uiClbShopingCard.Items.IndexOf(uiClbShopingCard.CheckedItems[i]));
                }
                else if (uiClbShopingCard.CheckedItems[i] is IDrink)
                {
                    IDrink drink = uiClbShopingCard.CheckedItems[i] as IDrink;
                    _orderCost -= drink.Price();
                    uiClbShopingCard.Items.RemoveAt(uiClbShopingCard.Items.IndexOf(uiClbShopingCard.CheckedItems[i]));
                }
                else if (uiClbShopingCard.CheckedItems[i] is ISoup)
                {
                    ISoup soup = uiClbShopingCard.CheckedItems[i] as ISoup;
                    _orderCost -= soup.Price();
                    uiClbShopingCard.Items.RemoveAt(uiClbShopingCard.Items.IndexOf(uiClbShopingCard.CheckedItems[i]));
                }
                else if (uiClbShopingCard.CheckedItems[i] is IMainDish)
                {
                    IMainDish mainDish = uiClbShopingCard.CheckedItems[i] as IMainDish;
                    _orderCost -= mainDish.Price();
                    uiClbShopingCard.Items.RemoveAt(uiClbShopingCard.Items.IndexOf(uiClbShopingCard.CheckedItems[i]));
                }
            }

            uiTxtOrderCost.Text = _orderCost.ToString("C", _cultureInfo);
        }
Example #2
0
        // Zdarzenie obsługujące tworzenie obiektu zupa
        private void SoupClickEvent(object sender, EventArgs e)
        {
            Button button = sender as Button;
            ISoup  soup   = SoupFactory.CreateSoup(button.Tag as FoodInformation);

            uiClbShopingCard.Items.Add(soup);
            _orderCost         += soup.Price();
            uiTxtOrderCost.Text = _orderCost.ToString("C", _cultureInfo);
        }
Example #3
0
        public static ISoup CreateSoup(FoodInformation foodInformation)
        {
            ISoup soup = null;

            switch (foodInformation.Name.ToUpper())
            {
            case "POMIDOROWA":
                soup = new TomatoSoup(foodInformation.ID, foodInformation.Name, foodInformation.Price);
                break;

            case "ROSÓŁ":
                soup = new ChickenSoup(foodInformation.ID, foodInformation.Name, foodInformation.Price);
                break;
            }

            return(soup);
        }
Example #4
0
 public void ChangeDinner(ISoup soup, IMainCourse maainCourse, IDrink drink)
 {
     this._soup       = soup;
     this._mainCourse = maainCourse;
     this._drink      = drink;
 }
Example #5
0
        static void Main(string[] args)
        {
            try
            {
                #region 普通方法
                Console.WriteLine("*******************普通方法************************");
                {
                    PoHuPangYuTou menu = new PoHuPangYuTou();
                    menu.Show();
                }
                #endregion
                #region 简单工厂
                Console.WriteLine("*******************简单工厂************************");
                {
                    //Console.WriteLine("说明:请输入1-4:1、鄱湖胖鱼头 2、庐山石鸡 3、四星望月 4、藜蒿炒腊肉");
                    //while (true)
                    //{
                    //    Console.WriteLine("请点菜:");
                    //    int type = int.Parse(Console.ReadLine());
                    //    IMenuName menu = ObjectFactory.CreateInstance((MenuType)type);
                    //    menu.Show();
                    //    Console.WriteLine("是否继续点菜?(是:y,否:n)");
                    //    string str = Console.ReadLine();
                    //    if (str=="y")
                    //    {
                    //        continue;
                    //    }
                    //    else if (str=="n")
                    //    {
                    //        break;
                    //    }
                    //    else
                    //    {
                    //        Console.WriteLine("指令无效");
                    //    }
                    //}
                }
                #endregion
                #region 简单工厂+反射+配置文件
                Console.WriteLine("*******************简单工厂+反射+配置文件************************");
                {
                    IMenuName menuName = ObjectFactory.CreateInstance();
                    menuName.Show();
                }
                #endregion
                #region 工厂方法
                Console.WriteLine("*******************工厂方法************************");
                {
                    Factory.FactoryMethod.IMenu menu1 = new LiHaoChaoLaRouFactory();
                    IMenuName menuName1 = menu1.CreateInstance();
                    menuName1.Show();

                    Factory.FactoryMethod.IMenu menu2 = new SiXingWangYueFactory();
                    IMenuName menuName2 = menu2.CreateInstance();
                    menuName2.Show();
                }
                #endregion
                #region 抽象工厂
                Console.WriteLine("*******************抽象工厂************************");
                {
                    AbstractFactory factory    = new AHunanCuisineFactory();
                    IMenuName       menuName_1 = factory.CreateMenu_1();
                    menuName_1.Show();
                    IMenuName menuName_2 = factory.CreateMenu_2();
                    menuName_2.Show();
                    IMenuName menuName_3 = factory.CreateMenu_3();
                    menuName_3.Show();
                    ISapleFood sapleFood = factory.CreateSapleFood();
                    sapleFood.Show();
                    ISoup soup = factory.CreateSoup();
                    soup.Show();
                }
                #endregion
                #region 点菜系统
                Console.WriteLine("*******************点菜系统************************");
                {
                    //List<AbstractFood> foodList = new List<AbstractFood>() {
                    //new Homework_4.OrderSystem.Service.LiHaoChaoLaRou(){Id=1,Name="藜蒿炒腊肉",Price=23,Desc="江西鄱阳特产"},
                    //new Homework_4.OrderSystem.Service.LuShanShiJi(){Id=2,Name="庐山石鸡",Price=23,Desc="江西鄱阳特产"},
                    //new Homework_4.OrderSystem.Service.PoHuPangYuTou(){Id=3,Name="鄱湖胖鱼头",Price=23,Desc="江西鄱阳特产"}
                    //};
                    //string jsonData = JsonHelper.ObjectToJson(foodList);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }