Beispiel #1
0
        static void checkLab4()
        {
            ShopService logic = new ShopService();

            logic.InitializeDAO("dao2.ini");

            Shop shop1 = logic.AddShop("Пятерочка");
            Shop shop2 = logic.AddShop("Заря");
            Shop shop3 = logic.AddShop("Юнион");

            AProduct prod1 = logic.AddProduct("Шоколадка", "Аленка");
            AProduct prod2 = logic.AddProduct("Молоко", "Простоквашино");
            AProduct prod3 = logic.AddProduct("Колбаса", "Докторская");

            logic.SetProductPrice(shop2, prod2, 60);
            logic.SetProductPrice(shop3, prod2, 55);
            logic.SetProductPrice(shop1, prod1, 40);

            logic.SupplyShop(shop1, prod1, 20);
            logic.SupplyShop(shop3, prod2, 15);

            logic.SetProductPrice(shop3, prod1, 45);
            logic.SetProductPrice(shop1, prod2, 60);

            logic.SupplyShop(shop1, prod2, 10);
            logic.SupplyShop(shop3, prod1, 20);

            var pair = logic.FindCheapest(prod1);

            Console.WriteLine("{0}, {1}, {2}", pair.First.Name, pair.Second.Name, pair.Second.Price.ToString());
            pair = logic.FindCheapest(prod2);
            Console.WriteLine("{0}, {1}, {2}", pair.First.Name, pair.Second.Name, pair.Second.Price.ToString());

            List <AProduct> list = new List <AProduct>();

            list.Add(prod1);
            list.Add(prod2);
            List <int> amounts = new List <int>();

            amounts.Add(15);
            amounts.Add(5);
            check = true;
            logic.BuyProduct(shop1, list, amounts);

            list.RemoveAt(0);
            amounts.RemoveAt(0);
            Console.WriteLine("This {0}", logic.FindCheapestAmount(list, amounts).First.Name);
            logic.SupplyShop(shop1, prod2, 20);
            amounts[0] = 20;
            Console.WriteLine("This {0}", logic.FindCheapestAmount(list, amounts).First.Name);

            DataBase db = logic.GetData();

            logic.InitializeDAO("dao1.ini", db);
        }
Beispiel #2
0
        /// <summary>
        /// 点击更新店铺
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnDownload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WaitDialogForm waitFrm = null;

            try
            {
                Alading.Entity.Shop focusShop = gridViewShop.GetFocusedRow() as Alading.Entity.Shop;
                if (focusShop == null)//未选中
                {
                    XtraMessageBox.Show("请先选中更新的店铺", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                waitFrm = new WaitDialogForm(Constants.WAIT_LOAD_DATA);
                ShopRsp shopRsp = TopService.ShopGet(focusShop.nick);
                string  session = SystemHelper.GetSessionKey(focusShop.nick);
                UserRsp userRsp = TopService.UserGet(session, focusShop.nick, string.Empty);

                Alading.Entity.Shop shop = new Alading.Entity.Shop();

                if (shopRsp == null || userRsp == null)//从淘宝网未获取到数据
                {
                    waitFrm.Close();
                    XtraMessageBox.Show("未获取到数据", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ShopCopyData((int)shopShowType, shop, shopRsp.Shop, userRsp.User);

                Alading.Entity.Shop oldShop = ShopService.GetShopByNick(shop.nick);

                if (oldShop == null)//不存在时添加
                {
                    ShopService.AddShop(shop);
                }
                else//存在时更新
                {
                    ShopService.UpdateShop(shop);
                }

                LoadShop(shopShowType);//重新刷新界面
                waitFrm.Close();
                XtraMessageBox.Show("更新成功", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                waitFrm.Close();
                XtraMessageBox.Show(ex.Message, Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public ActionResult Create(ShopViewModel model)
        {
            try
            {
                bool result = _shopService.AddShop(model);

                if (result)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!");
                return(View());
            }
        }
Beispiel #4
0
 public void AddShop(Client client)
 {
     ShopService.AddShop(client.position);
     API.sendChatMessageToPlayer(client, "Shop Created");
 }