/// <summary> /// 插入期号 /// 每天09:02 - 09:07 第一期 /// 23:52-23:57 最后一期 /// </summary> /// <param name="qihao"></param> /// <param name="starttime"></param> /// <param name="qishu"></param> /// <returns></returns> public string InsertQiHao(string qihao, DateTime starttime, int qishu) { DAL.QihaoinfoDAL qhdal = new DAL.QihaoinfoDAL() { ConnStr = ConnStr }; StringBuilder sb = new StringBuilder(); int success = 0; int exists = 0; for (int i = 0; i < qishu; i++) { if (i != 0) { qihao = (long.Parse(qihao) + 1).ToString(); if (starttime.ToString("HH:mm") == "23:52") { //已经是当天最后一天了,下一个开始时间是明天的09:00 starttime = DateTime.Parse(starttime.AddDays(1).ToString("yyyy-MM-dd 09:02")); } else { starttime = starttime.AddMinutes(5); } } int czid = 23; string czname = "北京PK拾"; DateTime endtime = starttime.AddMinutes(4); DateTime kjtime = starttime.AddMinutes(5); if (qhdal.CalcCount($"qihao='{qihao}'") == 0) { qhdal.Add(new Qihaoinfo() { qihao = qihao, createtime = DateTime.Now, czid = czid, czname = czname, starttime = starttime, endtime = endtime, kjtime = kjtime, }); success++; } else { exists++; } } sb.Append($"成功插入{success}期期号,{exists}期期号已存在"); return(sb.ToString()); }
public ActionResult Add(Model.Qihaoinfo m) { try { if (m.id == 0) { dal.Add(m); return(Json(new { code = 0, msg = "新增成功!" })); } else { dal.Update(m); return(Json(new { code = 0, msg = "编辑成功!" })); } } catch (Exception ex) { return(Json(new { code = 1, msg = $"出错:{ex.Message}" })); } }
public async Task <string> InsertKJCodeAsync(bool onlyfirst = false, string url = "http://www.bwlc.net/bulletin/trax.html?page=1") { var config = Configuration.Default.WithDefaultLoader(); var address = url; StringBuilder sb = new StringBuilder(); DAL.QihaoinfoDAL qhdal = new DAL.QihaoinfoDAL() { ConnStr = ConnStr }; int czid = 5; string czname = "北京PK拾"; using (var document = await BrowsingContext.New(config).OpenAsync(address)) { string allhtml = document.QuerySelector("body").InnerHtml; // Util.Log.Info($"开始抓取开奖号,远程返回的HTML:{allhtml} <br /> \r\n"); var cellSelector = "table.tb tr"; var cells = document.QuerySelectorAll(cellSelector); foreach (var item in cells) { string qihao = ""; string kjcode = ""; string kjtime = ""; if (item.InnerHtml.Contains("td")) { qihao = item.QuerySelector("td:nth-child(1)").TextContent; kjcode = item.QuerySelector("td:nth-child(2)").TextContent; kjtime = item.QuerySelector("td:nth-child(3)").TextContent; Model.Qihaoinfo qihaoinfo = qhdal.GetModelByCond($"qihao='{qihao}' and czid={czid}"); if (qihaoinfo != null && !string.IsNullOrEmpty(qihaoinfo.kjcode)) { sb.Append($"期号:{qihao}<span style='color:red;'>已存在</span><br /> \r\n"); if (onlyfirst) { break; } continue; } DateTime d = DateTime.Parse(kjtime); if (qihaoinfo == null) { qhdal.Add(new Qihaoinfo() { czid = czid, czname = czname, createtime = DateTime.Now, kjtime = d, starttime = d.AddMinutes(-5), endtime = d.AddMinutes(-1), qihao = qihao, kjcode = kjcode, }); } else { //期号存在,开奖号为空,修改 qihaoinfo.kjcode = kjcode; qhdal.Update(qihaoinfo); } sb.Append($"[{czname}],期号:{qihao},开奖号:{kjcode},开奖时间 :{kjtime} <span style='color:green'>已插入</span><br /> \r\n"); #region 兑奖 sb.Append($"兑奖结果:<br />\r\n"); //List<Model.Xiazhuinfo> list_xiazhu = xzdal.GetListArray($"czid=1 and qihao='{qihao}'", "id"); //foreach (var xz in list_xiazhu) //{ // try // { // string str = this.DuiJiang(xz.id); // // sb.Append(str + "<br />\r\n"); 前台用户也能采集,不显示每张跟单的兑奖结果 // } // catch (Exception ex) // { // // sb.Append($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); // // Util.Log.Error($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); // } //} #endregion if (onlyfirst) { break; } } } //document.Close(); //document.Dispose(); } return(sb.ToString()); }
public async Task <string> InsertKJCodeAsync(bool onlyfirst = false, string url = "http://bwlc.net/bulletin/prevkeno.html") { var config = Configuration.Default.WithDefaultLoader(); var address = url; StringBuilder sb = new StringBuilder(); DAL.XiazhuinfoDAL xzdal = new DAL.XiazhuinfoDAL() { ConnStr = ConnStr }; DAL.QihaoinfoDAL qhdal = new DAL.QihaoinfoDAL() { ConnStr = ConnStr }; int czid = 1; string czname = "北京28"; #region 北京福彩网的抓取规则 using (var document = await BrowsingContext.New(config).OpenAsync(address)) { string allhtml = document.QuerySelector("body").InnerHtml; // Util.Log.Info($"开始抓取开奖号,远程返回的HTML:{allhtml} <br /> \r\n"); var cellSelector = "table.tb tr"; var cells = document.QuerySelectorAll(cellSelector); foreach (var item in cells) { string qihao = ""; string kjcode = ""; string kjtime = ""; if (item.InnerHtml.Contains("td")) { qihao = item.QuerySelector("td:nth-child(1)").TextContent; kjcode = item.QuerySelector("td:nth-child(2)").TextContent; kjtime = item.QuerySelector("td:nth-child(4)").TextContent; Model.Qihaoinfo qihaoinfo = qhdal.GetModelByCond($"qihao='{qihao}' and czid={czid}"); if (qihaoinfo != null && !string.IsNullOrEmpty(qihaoinfo.kjcode)) { sb.Append($"期号:{qihao}<span style='color:red;'>已存在</span><br /> \r\n"); if (onlyfirst) { break; } continue; } DateTime d = DateTime.Parse(kjtime); string[] ss = kjcode.Split(','); List <int> arr = new List <int>(); foreach (var s in ss) { arr.Add(int.Parse(s)); } arr.Sort(); int shu1 = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5]; int shu2 = arr[6] + arr[7] + arr[8] + arr[9] + arr[10] + arr[11]; int shu3 = arr[12] + arr[13] + arr[14] + arr[15] + arr[16] + arr[17]; string real_kjcode = (shu1 % 10 + shu2 % 10 + shu3 % 10).ToString(); string remark = $"{shu1 % 10} + {shu2 % 10} + {shu3 % 10}"; if (qihaoinfo == null) { qhdal.Add(new Qihaoinfo() { czid = czid, czname = czname, createtime = DateTime.Now, kjtime = d, starttime = d.AddMinutes(-5), endtime = d.AddMinutes(-2), qihao = qihao, kjcode2 = kjcode, kjcode = real_kjcode, remark = remark, code1 = shu1 % 10, code2 = shu2 % 10, code3 = shu3 % 10 }); } else { //期号存在,开奖号为空,修改 qihaoinfo.kjcode = real_kjcode; qihaoinfo.kjcode2 = kjcode; qihaoinfo.remark = remark; qihaoinfo.code1 = shu1 % 10; qihaoinfo.code2 = shu2 % 10; qihaoinfo.code3 = shu3 % 10; qhdal.Update(qihaoinfo); } sb.Append($"期号:{qihao},开奖号:{kjcode},开奖时间 :{kjtime} <span style='color:green'>已插入</span><br /> \r\n"); #region 兑奖 sb.Append($"兑奖结果:<br />\r\n"); List <Model.Xiazhuinfo> list_xiazhu = xzdal.GetListArray($"czid=1 and qihao='{qihao}'", "id"); foreach (var xz in list_xiazhu) { try { string str = this.DuiJiang(xz.id); // sb.Append(str + "<br />\r\n"); 前台用户也能采集,不显示每张跟单的兑奖结果 } catch (Exception ex) { // sb.Append($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); // Util.Log.Error($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); } } #endregion if (onlyfirst) { break; } } } //document.Close(); //document.Dispose(); } #endregion #region PC2820.com的抓取规则 //address = "https://pc2820.com/"; //using (var document = await BrowsingContext.New(config).OpenAsync(address)) //{ // string allhtml = document.QuerySelector("body").InnerHtml; // // Util.Log.Info($"开始抓取开奖号,远程返回的HTML:{allhtml} <br /> \r\n"); // var firsttable = document.QuerySelector("table"); //第一个表格就是存期号,开奖时间,开奖号的 // var trs = firsttable.QuerySelectorAll("tr"); // foreach (var onetr in trs) // { // if (onetr.InnerHtml.Contains("td")) // { // string qihao = onetr.QuerySelector("td:nth-child(1)").TextContent; // string kjtime = onetr.QuerySelector("td:nth-child(2)").TextContent; // string remark = onetr.QuerySelector("td:nth-child(3)").TextContent; // string code1 = ""; // string code2 = ""; // string code3 = ""; // string kjcode = ""; // Regex reg = new Regex(@"(\d+)\+(\d+)\+(\d+)=(\d+)"); // Match m = reg.Match(remark); // if (m.Success) // { // code1 = m.Groups[1].Value; // code2 = m.Groups[2].Value; // code3 = m.Groups[3].Value; // kjcode = m.Groups[4].Value; // // sb.Append("\r\n期号:" + qihao + ", 开奖时间:" + kjtime + ", 开奖号:" + code1 + " + " + code2 + " + " + code3 + " = " + kjcode); // Model.Qihaoinfo qihaoinfo = qhdal.GetModelByCond($"qihao='{qihao}' and czid={czid}"); // if (qihaoinfo != null && !string.IsNullOrEmpty(qihaoinfo.kjcode)) // { // sb.Append($"期号:{qihao} <span style='color:red;'>已存在</span><br /> \r\n"); // if (onlyfirst) // { // break; // } // continue; // } // DateTime d = DateTime.Parse(kjtime); // if (qihaoinfo == null) // { // qhdal.Add(new Qihaoinfo() // { // czid = czid, // czname = czname, // createtime = DateTime.Now, // kjtime = d, // starttime = d.AddMinutes(-5), // endtime = d.AddMinutes(-2), // qihao = qihao, // kjcode2 = "", // kjcode = kjcode, // remark = remark, // code1 = int.Parse(code1), // code2 = int.Parse(code2), // code3 = int.Parse(code3) // }); // } // else // { // //期号存在,开奖号为空,修改 // qihaoinfo.kjcode = kjcode; // qihaoinfo.kjcode2 = ""; // qihaoinfo.remark = remark; // qihaoinfo.code1 = int.Parse(code1); // qihaoinfo.code2 = int.Parse(code2); // qihaoinfo.code3 = int.Parse(code3); // qhdal.Update(qihaoinfo); // } // sb.Append($"期号:{qihao},开奖号:{kjcode},开奖时间 :{kjtime} <span style='color:green'>已插入</span><br /> \r\n"); // #region 兑奖 // sb.Append($"兑奖结果:<br />\r\n"); // List<Model.Xiazhuinfo> list_xiazhu = xzdal.GetListArray($"czid=1 and qihao='{qihao}'", "id"); // foreach (var xz in list_xiazhu) // { // try // { // string str = this.DuiJiang(xz.id); // // sb.Append(str + "<br />\r\n"); 前台用户也能采集,不显示每张跟单的兑奖结果 // } // catch (Exception ex) // { // // sb.Append($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); // Util.Log.Error($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n"); // } // } // #endregion // if (onlyfirst) // { // break; // } // } // } // } //} #endregion return(sb.ToString()); }