Пример #1
0
        private static void Init()
        {
            if (_singleShopDetail != null)
            {
                return;
            }

            lock (_LockObj)
            {
                if (_singleShopDetail != null)
                {
                    return;
                }

                var r = YunClient.Instance.Execute(new SearchShopsRequest {
                    PageNum = 1, PageSize = 1
                }).Shops;
                if (r.Count <= 0)
                {
                    throw new Exception("店铺数据不存在,无法进行网站初始化");
                }

                _singleShopDetail = r[0];
            }
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Location,Members,Shopkeeper,Notes")] ShopDetail shopDetail)
        {
            if (id != shopDetail.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shopDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShopDetailExists(shopDetail.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shopDetail));
        }
Пример #3
0
        public virtual ActionResult Details(int id)
        {
            var viewModel = new ShopDetail();

            viewModel.Product = db.Products
                                .Include(p => p.Category)
                                .Single(p => p.Id == id);
            return(View(viewModel));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Location,Members,Shopkeeper,Notes")] ShopDetail shopDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shopDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shopDetail));
        }
Пример #5
0
        private static void Init()
        {
            if (_singleShopDetail != null) return;

            lock (_LockObj)
            {
                if (_singleShopDetail != null) return;

                var r = YunClient.Instance.Execute(new SearchShopsRequest {PageNum = 1, PageSize = 1}).Shops;
                if (r.Count <= 0) throw new Exception("店铺数据不存在,无法进行网站初始化");

                _singleShopDetail = r[0];
            }
        }
Пример #6
0
        public IActionResult AddShopDetail([FromBody] ShopDetail sp)
        {
            //定义变量总条数
            int data1 = bll.AddShopDetail(sp);

            if (data1 > 0)
            {
                return(Ok(data1));
            }
            else
            {
                return(Ok(0));
            }
        }
Пример #7
0
        public static ShopInSql ConvertShopInSql(ShopDetail model)
        {
            if (model != null)
            {
                var r = new ShopInSql();

                //映射处理
                var map = new TypeMapping<ShopDetail, ShopInSql>();
                map.AutoMap();
                map.CopyLeftToRight(model, r);

                r.AreaId = r.Areas.Select(e => e.Key).ToList();

                return r;
            }

            return null;
        }
Пример #8
0
        public ActionResult Detail(int?id)
        {
            //拿到属性为ID的产品属性
            ProductProperty pp = db.ProductProperties.Where(x => x.ProperID == id).First();
            //通过属性id来获取此属性的上一级产品编号
            ProductType pt = db.ProductTypes.Where(x => x.TypeID == pp.TypeID).First();
            //把需要前台赋值的内容拿到
            ShopDetail sd = new ShopDetail()
            {
                TypeName = pt.TypeName,
                Price    = pp.Price.ToString(),
                ProName  = pp.ProperName,
                Quantity = pp.Quantity.ToString(),
                IMG      = pp.IMG,
                Desc     = pp.Description
            };

            //传给Model 在页面上调用强类型打点就可以用
            ViewData.Model = sd;
            var result = db.ProductProperties.Where(x => x.TypeID == pt.TypeID);

            ViewBag.ps = result.AsEnumerable();
            return(View());
        }
Пример #9
0
        //添加订单表
        public int AddShopDetail(ShopDetail sp)
        {
            string sql = $"insert into ShopDetail values('{sp.DboId}','{sp.Dtime}','{sp.LoginId}','{sp.Moneys}','{sp.Depay}','{sp.DeScourceId}','{sp.DeStateId}','{sp.confirm}')";

            return(conn.Execute(sql));
        }
        public async Task <IActionResult> GetAllData()
        {
            //Url id 1-298 (292 items)
            for (int id = 1; id <= 300; id++)
            {
                var url = "http://2007rshelp.com/shops.php?id=" + id;

                var web = new HtmlWeb();
                var doc = await web.LoadFromWebAsync(url);

                var htmlNodesContent = doc.DocumentNode.SelectNodes("//div[@id='content']/div[@class='boxbottom']//td");

                var htmlNodesItemData = htmlNodesContent.First().SelectNodes("//td[@class='tablebottom']");
                var htmlTableColum    = htmlNodesContent.First().SelectNodes("//th[@class='tabletop']");

                if (htmlNodesItemData == null || htmlTableColum == null)
                {
                    continue;
                }

                //var htmltd = htmlNodesContent.First().SelectNodes("//td");
                //var nodes3 = htmlNodes.CssSelect("div#wrapper").ToList();

                var itemDataList = new List <string>();
                foreach (var node in htmlNodesItemData)
                {
                    itemDataList.Add(node.InnerText);
                }

                var shopItemList = new List <ShopItem>();
                if (htmlTableColum.Count == 3)
                {
                    for (int i = 0; i < itemDataList.Count; i += 3)
                    {
                        int    price       = 0;
                        string priceString = itemDataList[i + 1];
                        char[] trimList    = { 'g', 'p', ' ', ',', '.' };
                        if (priceString.Contains("gp"))
                        {
                            var testPrice = priceString.Trim(trimList).Replace(",", "");
                            price = Convert.ToInt32(testPrice);
                        }

                        var shopItem = new ShopItem()
                        {
                            Id           = id * 100 + (i / 3),
                            Item         = itemDataList[i],
                            DisplayPrice = itemDataList[i + 1],
                            Price        = price,
                            DefaultStock = Convert.ToInt32(itemDataList[i + 2].Trim(' ')),
                        };
                        shopItemList.Add(shopItem);

                        if (!_context.ShopItems.Any(x => x.Id == id * 100 + (i / 3)))
                        {
                            _context.Add(shopItem);
                        }
                        else
                        {
                            _context.Update(shopItem);
                        }

                        _context.Database.OpenConnection();
                        try
                        {
                            _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopItems ON");
                            _context.SaveChanges();
                            _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopItems OFF");
                        }
                        finally
                        {
                            _context.Database.CloseConnection();
                        }
                    }
                }
                else if (htmlTableColum.Count == 2)
                {
                    for (int i = 0; i < itemDataList.Count; i += 2)
                    {
                        int    price       = 0;
                        string priceString = itemDataList[i + 1];
                        char[] trimList    = { ',', 'g', 'p', ' ' };
                        if (priceString.Contains("gp"))
                        {
                            var testPrice = priceString.Trim(trimList).Replace(",", "");
                            price = Convert.ToInt32(testPrice);
                        }

                        var shopItem = new ShopItem()
                        {
                            Id           = id * 100 + (i / 2),
                            Item         = itemDataList[i],
                            DisplayPrice = itemDataList[i + 1],
                            Price        = price,
                            DefaultStock = 0,
                        };
                        shopItemList.Add(shopItem);

                        if (!_context.ShopItems.Any(x => x.Id == id * 100 + (i / 2)))
                        {
                            _context.Add(shopItem);
                        }
                        else
                        {
                            _context.Update(shopItem);
                        }

                        _context.Database.OpenConnection();
                        try
                        {
                            _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopItems ON");
                            _context.SaveChanges();
                            _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopItems OFF");
                        }
                        finally
                        {
                            _context.Database.CloseConnection();
                        }
                    }
                }
                else
                {
                    continue;
                }

                var shopDetails = new ShopDetail()
                {
                    Id         = id,
                    Name       = htmlNodesContent[0].InnerText.Remove(htmlNodesContent[0].InnerText.Count() - 6),
                    Location   = htmlNodesContent[3].InnerText,
                    Members    = (htmlNodesContent[5].InnerText == "Yes") ? true : false,
                    Shopkeeper = htmlNodesContent[7].InnerText,
                    Notes      = htmlNodesContent[9].InnerText,
                    ShopItems  = shopItemList,
                };

                if (!_context.ShopDetails.Any(x => x.Id == id))
                {
                    _context.Add(shopDetails);
                }
                else
                {
                    _context.Update(shopDetails);
                }

                _context.Database.OpenConnection();
                try
                {
                    _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopDetails ON");
                    _context.SaveChanges();
                    _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ShopDetails OFF");
                }
                finally
                {
                    _context.Database.CloseConnection();
                }
            }

            return(Ok("Data has been saved to the database!"));
        }
Пример #11
0
        private static void Init()
        {
            if (_singleShopDetail != null) return;

            lock (_LockObj)
            {
                if (_singleShopDetail != null) return;

                if (!string.IsNullOrWhiteSpace(_shopId) && _shopId.TryTo(0) > 0)
                {
                    _singleShopDetail = YunClient.Instance.Execute(new GetShopRequest {ShopId = _shopId.TryTo(0)}).Shop;
                }
                else
                {
                    var r = YunClient.Instance.Execute(new SearchShopsRequest {PageNum = 1, PageSize = 1}).Shops;
                    if (r.Count <= 0) throw new Exception("店铺数据不存在,无法进行网站初始化");

                    _singleShopDetail = r[0];
                }
            }
        }
Пример #12
0
 //添加订单表
 public int AddShopDetail(ShopDetail sp)
 {
     return(dal.AddShopDetail(sp));
 }