/// <summary> /// 将此彩种指定期号和开奖号码保存至数据库 /// </summary> /// <param name="QiHao">期号</param> /// <param name="OpenCode">开奖号码(形如01,02,03)</param> /// <param name="IsYesterdayRecord">是否是保存昨天的记录</param> /// <returns></returns> private bool SaveRecord(HeNanK3Enitity data) { var model = new OpenCode3Model(); model.Term = Convert.ToInt64(data.QiHao); //期号 var haoMaArray = data.KaiJiangHao.Split(','); model.OpenCode1 = Convert.ToInt32(haoMaArray[0]); model.OpenCode2 = Convert.ToInt32(haoMaArray[1]); model.OpenCode3 = Convert.ToInt32(haoMaArray[2]); model.OpenTime = data.OpenTime; if (services.AddOpen3Code(currentLottery, model)) { GetMaxPeriodNum((int)model.Term); //添加成功存放期数 return(true); } return(false); }
/// 从主站抓取开奖数据 昨天/今天 /// </summary> /// <param name="IsToday"></param> /// <returns></returns> private List <HeNanK3Enitity> GetDocByMainUrl(bool IsToday = true) { var list = new List <HeNanK3Enitity>(); try { var day = CommonHelper.SCCSysDateTime.ToString("yyyyMMdd"); if (!IsToday) { day = CommonHelper.SCCSysDateTime.AddDays(-1).ToString("yyyyMMdd"); } var url = string.Format(Config.MainUrl, day); //@"http://www.henanfucai.com/Kuaikai/Kuai3Zoushi.html?selectDate=20171208"; var HtmlResource = NetHelper.GetUrlResponse(url); if (HtmlResource == null) { return(list); } if (!string.IsNullOrWhiteSpace(HtmlResource)) { var doc = new HtmlDocument(); doc.LoadHtml(HtmlResource); var data = doc.DocumentNode.SelectNodes("//*[@id=\"content\"]"); if (data == null) { return(list); } if (data != null) { foreach (var item in data[0].ChildNodes) { var qihao = ""; var opencode = new List <string>(); if (item.Name == "tr" && item.GetAttributeValue("class", "") == "xunhuan") { foreach (var item2 in item.ChildNodes) { if (item2.GetAttributeValue("class", "") == "td_1") { qihao = item2.InnerText; } if (item2.GetAttributeValue("class", "") == "td_2") { opencode.Add(item2.InnerText.Trim()); } } } if (opencode.Count == 3) { var num = qihao.Substring(2).Remove(6, 1); var tmp = new HeNanK3Enitity { QiHao = num, KaiJiangHao = string.Join(",", opencode), OpenTime = GetOpenTimeByPeriodNum(int.Parse(num)) }; 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.QiHao, w => w.KaiJiangHao), Config.Area, currentLottery); } } } catch (Exception ee) { log.Error(GetType(), string.Format("【{0}】通过站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message)); } return(list); }
/// <summary> /// 抓取站点开奖数据 /// </summary> /// <param name="url">备用站点</param> /// <returns></returns> private List <HeNanK3Enitity> GetDocByBackUrl(bool IsToday = true) { var list = new List <HeNanK3Enitity>(); try { var day = DateTime.Now.ToString("yyyyMMdd"); if (!IsToday) { day = DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); } var url = string.Format(Config.BackUrl, day); //" http://kaijiang.500.com/static/info/kaijiang/xml/bjk3/20171124.xml?_A=YLQMBVJT1511764350898"; //string url = @"http://www.bwlc.net/bulletin/prevqck3.html?page=3"; var HtmlResource = NetHelper.GetUrlResponse(url); if (string.IsNullOrWhiteSpace(HtmlResource)) { return(list); } var doc = new XmlDocument(); doc.LoadXml(HtmlResource); var records = doc.SelectNodes("//row"); if (records == null) { return(list); } foreach (XmlNode xmlnode in records) { if (xmlnode.Attributes["expect"] == null || string.IsNullOrWhiteSpace(xmlnode.Attributes["expect"].Value) || xmlnode.Attributes["opencode"] == null || string.IsNullOrWhiteSpace(xmlnode.Attributes["opencode"].Value)) { continue; } var num = xmlnode.Attributes["expect"].Value; var opencode = xmlnode.Attributes["opencode"].Value; var opentime = xmlnode.Attributes["opentime"].Value; var tmp = new HeNanK3Enitity { QiHao = num.Substring(2), KaiJiangHao = opencode, OpenTime = DateTime.Parse(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.QiHao, w => w.KaiJiangHao), Config.Area, currentLottery); } catch (Exception ex) { log.Error(GetType(), string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message)); } return(list); }