Пример #1
0
        private void GetPaiMaiPromtInfo(string productId)
        {
            var db      = new jd();
            var product = db.products.FirstOrDefault(a => a.productId == productId);

            if (product?.auctionAvgPrice != null)
            {
                if (product.auctionTopPrice != null)
                {
                    if (product.auctionLowPrice != null)
                    {
                        label1.Text = @"当前:" + (int)(product.price ?? 0) + @"均:" +
                                      (int)product.auctionAvgPrice + @"均差:" +
                                      (int)(product.price == null
                                          ? 0
                                          : product.price - (int)product.auctionAvgPrice) +
                                      @" 高:" + (int)product.auctionTopPrice + @" 低:" + (int)product.auctionLowPrice +
                                      @" 次数:" +
                                      product.auctionEndCount;
                    }
                }

                TBMaxPrice.Text = ((int)product.auctionAvgPrice).ToString();
            }
            else
            {
                label1.Text = @"暂无数据";
            }
        }
Пример #2
0
        private int CalculateProductInfoForBach()
        {
            //查询数据库中,未完成的所有拍卖
            var db = new jd();
            //当前时间减去一分钟,避免时间不同步造成的延迟问题
            var currentTimeStamp = long.Parse((long)ConvertDateTimeInt(DateTime.Now.AddSeconds(-30)) + "000");
            //获取40条,竞拍时间已经结束,但竞拍状态还未重置的数据
            var auctions = db.auctions
                           .Where(a => a.endTime < currentTimeStamp && a.auctionStatus == (int)AuctionStatus.Auctioning).Take(40)
                           .ToList();

            if (auctions.Count == 0)
            {
                return(0);
            }
            //联网查询最新的拍卖数据
            var processlist = auctions.Select(a => new PaimaiItem {
                paimaiId = a.auctionId
            }).ToList();
            var webList = GetPaiMaiDetailListFromWeb(processlist);

            if (webList == null)
            {
                return(-1);
            }

            webList.Where(a => a.auctionStatus == 0).ToList().ForEach(a =>
            {
                var auction           = db.auctions.Single(b => a.paimaiId == b.auctionId);
                auction.auctionStatus = (int)AuctionStatus.ErrorNotFoundAuction;
                //MessageBox.Show("");
            });
            //if()
            db.SaveChanges();
            //处理每一条返回的数据
            var list = webList.Where(a => a.auctionStatus != 0).ToList();

            list.ForEach(CalculateProductInfo);
            return(list.Count);
        }
Пример #3
0
        /// <summary>
        ///     拍卖结束后,求出对应产品的最新成交价格,历史评价价格,最低价,最高价
        /// </summary>
        /// <param name="paimaiItem"></param>
        /// <returns></returns>
        private void CalculateProductInfo(PaimaiItem paimaiItem)
        {
            var price = GetProductPrice(paimaiItem.productId, paimaiItem.paimaiId);

            var db = new jd();

            if ((int)price != 0)
            {
                db.productPrices.Add(new productPrice
                {
                    price      = (decimal)price,
                    productId  = paimaiItem.productId,
                    createTime = DateTime.Now
                });
            }


            //检查产品是否存在
            var productList = db.products.Single(pro => pro.productId == paimaiItem.productId);
            var auction     = db.auctions.Single(pro => pro.auctionId == paimaiItem.paimaiId);

            //productList.auctionEndCount = productList.auctionEndCount + 1;
            if (productList.auctionAvgPrice == null)
            {
                productList.auctionAvgPrice = (decimal)paimaiItem.currentPrice;
            }
            else
            {
                productList.auctionAvgPrice =
                    (productList.auctionEndCount * productList.auctionAvgPrice + (decimal)paimaiItem.currentPrice) /
                    (productList.auctionEndCount + 1);
            }

            if (productList.auctionEndCount == null)
            {
                productList.auctionEndCount = 1;
            }
            else
            {
                productList.auctionEndCount = productList.auctionEndCount + 1;
            }

            if (productList.auctionTopPrice == null)
            {
                productList.auctionTopPrice = (decimal)paimaiItem.currentPrice;
            }
            else if (productList.auctionTopPrice < (decimal)paimaiItem.currentPrice)
            {
                productList.auctionTopPrice = (decimal)paimaiItem.currentPrice;
            }

            if (productList.auctionLowPrice == null)
            {
                productList.auctionLowPrice = (decimal)paimaiItem.currentPrice;
            }
            else if (productList.auctionLowPrice > (decimal)paimaiItem.currentPrice)
            {
                productList.auctionLowPrice = (decimal)paimaiItem.currentPrice;
            }

            if ((int)price != 0)
            {
                productList.price = (decimal)price;
            }

            productList.updateTime = DateTime.Now;
            auction.auctionStatus  = (int)AuctionStatus.EndAuction;
            auction.updateTime     = DateTime.Now;
            auction.currentPrice   = (decimal)paimaiItem.currentPrice;
            auction.bidCount       = paimaiItem.bidCount;
            db.SaveChanges();
        }
Пример #4
0
        /// <summary>
        ///     保存拍卖明细数据
        /// </summary>
        /// <param name="paimaiItem"></param>
        /// <returns></returns>
        private void SavePaimaiDetail(PaimaiItem paimaiItem)
        {
            var db = new jd();

            //检查产品是否存在
            var productList = db.products.Where(pro => pro.productId == paimaiItem.productId);

            //如果不存在则添加
            if (!productList.Any())
            {
                db.products.Add(new product
                {
                    productId    = paimaiItem.productId,
                    name         = paimaiItem.describe,
                    auctionCount = 0,
                    createTime   = DateTime.Now
                });
                db.SaveChanges();
            }
            else
            {
                var oneProduct = productList.Single();
                if (!string.IsNullOrEmpty(paimaiItem.describe) &&
                    string.IsNullOrEmpty(oneProduct.name))
                {
                    oneProduct.name       = paimaiItem.describe;
                    oneProduct.updateTime = DateTime.Now;
                    db.SaveChanges();
                }
            }
            //检查拍卖编号是否存在
            var auction = db.auctions.Where(pro => pro.auctionId == paimaiItem.paimaiId);

            if (!auction.Any())
            {
                db.auctions.Add(new auction
                {
                    currentPrice  = (decimal)paimaiItem.currentPrice,
                    productId     = paimaiItem.productId,
                    auctionId     = paimaiItem.paimaiId,
                    startTime     = paimaiItem.startTime,
                    endTime       = paimaiItem.endTime,
                    bidCount      = paimaiItem.bidCount,
                    auctionStatus = paimaiItem.auctionStatus,
                    createTime    = DateTime.Now
                });
                var product = db.products.First(pro => pro.productId == paimaiItem.productId);
                product.auctionCount = product.auctionCount + 1;
                db.SaveChanges();
            }
            else
            {
                var auctionItem = auction.Single();
                auctionItem.auctionStatus = paimaiItem.auctionStatus;
                auctionItem.currentPrice  = (decimal)paimaiItem.currentPrice;
                auctionItem.endTime       = paimaiItem.endTime;
                auctionItem.startTime     = paimaiItem.startTime;
                auctionItem.bidCount      = paimaiItem.bidCount;
                auctionItem.updateTime    = DateTime.Now;
                db.SaveChanges();
            }
        }