private void timer1_Tick(object sender, EventArgs e) { var ucc = ""; httpservice httpservice = new httpservice(); string url = "http://www.17500.cn/widget/ssq/surveyload.html?issue="; var db = new Model(); //取数据库最新的一条 var ite = db.T_DrawPrize.OrderByDescending(x => x.Lssue).FirstOrDefault(); //判断是否今年最后一期 if (ite.Lssue.Substring(0, 4) == DateTime.Now.Year.ToString()) { ucc = (int.Parse(ite.Lssue) + 1).ToString(); } else { ucc = DateTime.Now.Year.ToString() + "001"; } HttpItem HttpItem = new HttpItem() { URL = url + ucc }; var ss = httpservice.GetHtml(HttpItem); JObject json = (JObject)JsonConvert.DeserializeObject(ss.Html); var str = json["award"].ToString().Split(','); if (str[0] == "-") { return; } db.T_DrawPrize.Add(new T_DrawPrize() { Lssue = ucc, number1 = int.Parse(str[0]), number2 = int.Parse(str[1]), number3 = int.Parse(str[2]), number4 = int.Parse(str[3]), number5 = int.Parse(str[4]), number6 = int.Parse(str[5]), number7 = int.Parse(str[6]), }); this.textBox1.AppendText("正在同步第 " + ucc + " 期" + json["award"].ToString() + "\r\n"); db.SaveChanges(); ViewBind(); }
private void 开始同步ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("已经整体同步过了,现在是自动同步哟!"); return; httpservice httpservice = new httpservice(); //string url = "http://www.17500.cn/widget/ssq/surveyload.html?issue=2003001"; string url = "http://www.17500.cn/widget/ssq/surveyload.html?issue="; var db = new Model(); //计算一年开奖多少次 var yers = GetYearWeekCount(); foreach (var item in yers) { for (var i = 1; i <= item.Value; i++) { string cc = i.ToString("D3"); HttpItem HttpItem = new HttpItem() { URL = url + item.Key.ToString() + cc }; var ss = httpservice.GetHtml(HttpItem); JObject json = (JObject)JsonConvert.DeserializeObject(ss.Html); var str = json["award"].ToString().Split(','); db.T_DrawPrize.Add(new T_DrawPrize() { Lssue = item.Key.ToString() + cc, number1 = int.Parse(str[0]), number2 = int.Parse(str[1]), number3 = int.Parse(str[2]), number4 = int.Parse(str[3]), number5 = int.Parse(str[4]), number6 = int.Parse(str[5]), number7 = int.Parse(str[6]), }); this.textBox1.AppendText("正在同步:" + item.Key + " 年,第 " + cc + " 期" + json["award"].ToString() + "\r\n"); } db.SaveChanges(); ViewBind(); } }