Пример #1
0
        /// <summary>
        ///     从主要链接查询开奖号码 昨天/今天
        /// </summary>
        /// <param name="IsToday"></param>
        /// <returns></returns>
        private List <HuBei11x5Entity> GetDocByMainUrl(bool IsToday = true)
        {
            var list = new List <HuBei11x5Entity>();

            try
            {
                var time = DateTime.Now;
                var arg  = new OpenCaiApiArg
                {
                    code = EnumHelper.GetLotteryCode(SCCLottery.HuBei11x5),
                    // rows = int.Parse(GetPeriodsNumberToDay(time, IsToday)),
                    date = time.ToString("yyyy-MM-dd")
                };
                if (!IsToday)
                {
                    arg.date = time.AddDays(-1).ToString("yyyy-MM-dd");
                }
                var data = OpenCaiApiServices.GetOpenCaiApiData(arg);
                if (data == null)
                {
                    return(list);
                }


                if (data.data != null)
                {
                    if (data.data.Count == 0)
                    {
                        return(list);
                    }

                    for (var i = 0; i < data.data.Count; i++)
                    {
                        var tmp = new HuBei11x5Entity
                        {
                            Id       = int.Parse(data.data[i].GetTermStr()),
                            OpenCode = data.data[i].GetOpenCodeStr(),
                            OpenTime = DateTime.Parse(data.data[i].opentime)
                        };
                        list.Add(tmp);
                    }

                    var checkDataHelper = new CheckDataHelper();
                    var dbdata          = services.GetListIn(currentLottery, IsToday)
                                          .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                    checkDataHelper.CheckData(dbdata, list.ToDictionary(w => w.Id.ToString(), w => w.OpenCode),
                                              Config.Area, currentLottery);
                }
            }
            catch (Exception ee)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message));
            }

            return(list);
        }
Пример #2
0
        /// <summary>
        ///     插入单条
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool SaveRecord(HuBei11x5Entity data)
        {
            var model = new OpenCode5Model();

            model.Term = Convert.ToInt64(data.Id); //期号
            var haoMaArray = data.OpenCode.Split(',');

            model.OpenCode1 = Convert.ToInt32(haoMaArray[0]);
            model.OpenCode2 = Convert.ToInt32(haoMaArray[1]);
            model.OpenCode3 = Convert.ToInt32(haoMaArray[2]);
            model.OpenCode4 = Convert.ToInt32(haoMaArray[3]);
            model.OpenCode5 = Convert.ToInt32(haoMaArray[4]);
            model.OpenTime  = data.OpenTime;
            if (services.AddOpen5Code(currentLottery, model))
            {
                GetMaxPeriodNum((int)model.Term);  //添加成功存放期数
                return(true);
            }

            return(false);
        }
Пример #3
0
        /// <summary>
        ///     通过备用站点抓取开奖数据 今天/昨天
        /// </summary>
        private List <HuBei11x5Entity> GetDocByBackUrl(bool IsToday = true)
        {
            var list = new List <HuBei11x5Entity>();

            try
            {
                var day = 1;
                if (!IsToday)
                {
                    day = 2;
                }
                var HtmlResource = NetHelper.GetUrlResponse(string.Format(Config.BackUrl, day)); //Config.MainUrl
                if (HtmlResource == null)
                {
                    return(list);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(HtmlResource);

                var rootnode   = doc.DocumentNode;
                var xpath      = "//*[@id=\"ZstTable\"]/tbody/[@class=\"datainfo\"]";
                var xpath2     = "//*[@id=\"ZstTable\"]";
                var collection = rootnode.SelectNodes(xpath2);
                var data       = collection[0].ChildNodes;
                if (HtmlResource == null)
                {
                    return(list);
                }
                for (var i = 0; i < data.Count; i++)
                {
                    if (data[i].GetAttributeValue("class", " ") == "datainfo")
                    {
                        var periodnum = data[i].ChildNodes[0].InnerText;
                        var code1     = data[i].ChildNodes[1].InnerText;
                        var code2     = data[i].ChildNodes[2].InnerText;
                        var code3     = data[i].ChildNodes[3].InnerText;
                        var code4     = data[i].ChildNodes[4].InnerText;
                        var code5     = data[i].ChildNodes[5].InnerText;
                        var tmp       = new HuBei11x5Entity
                        {
                            Id       = int.Parse(periodnum),
                            OpenCode = CommonHelper.TRHandleCode(string.Format("{0},{1},{2},{3},{4}", code1, code2,
                                                                               code3, code4, code5)),
                            OpenTime = GetOpenTimeByPeriodNum(int.Parse(periodnum))
                        };
                        list.Add(tmp);
                    }
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListIn(currentLottery, IsToday)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, list.ToDictionary(w => w.Id.ToString(), w => w.OpenCode), Config.Area,
                                          currentLottery);
            }
            catch (Exception ee)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message));
            }

            return(list);
        }