-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
135 lines (106 loc) · 4.73 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HtmlAgilityPack;
using System.Net;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using LotteryDb;
using LotteryReader.Utils;
namespace LotteryReader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btSSQ_Click(object sender, EventArgs e)
{
string urlBase = "http://trend.lecai.com/ssq/redBaseTrend.action?startPhase={0}&endPhase={1}&phaseOrder=up&coldHotOrder=number&onlyBody=true";
// string url = "http://trend.lecai.com/ssq/redBaseTrend.action?startPhase=2014000&endPhase=2015000&phaseOrder=up&coldHotOrder=number&onlyBody=true";
int min = 2003000;
int max = (DateTime.Now.Year + 1) * 1000;
using (LotteryEntities db = new LotteryEntities())
{
string sMax = db.ShuangSeQius.Max(q => q.Phase);
if (!string.IsNullOrEmpty(sMax))
min = int.Parse(sMax) + 1;
}
for (int i = min; i < max; i = (i + 1000) / 1000 * 1000)
{
string uri = string.Format(urlBase, i, i + 1000);
string content = HtmlHelper.HtmlRequest(uri);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
SSQ ssq = new SSQ(doc);
DataTable balls = ssq.getBallsTable();
string connection = ConfigurationManager.ConnectionStrings["LotteryConnectionString"].ConnectionString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
{
bulkCopy.DestinationTableName = "dbo.ShuangSeQiu";
bulkCopy.ColumnMappings.Add("R1", "R1");
bulkCopy.ColumnMappings.Add("R2", "R2");
bulkCopy.ColumnMappings.Add("R3", "R3");
bulkCopy.ColumnMappings.Add("R4", "R4");
bulkCopy.ColumnMappings.Add("R5", "R5");
bulkCopy.ColumnMappings.Add("R6", "R6");
bulkCopy.ColumnMappings.Add("B1", "B1");
bulkCopy.ColumnMappings.Add("Phase", "Phase");
bulkCopy.BulkCopyTimeout = 0;
bulkCopy.WriteToServer(balls);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btDLT_Click(object sender, EventArgs e)
{
string urlBase = "http://trend.lecai.com/dlt/redBaseTrend.action?startPhase={0}&endPhase={1}&phaseOrder=up&coldHotOrder=number&onlyBody=yes";
int min = 7000;
int max = (DateTime.Now.Year % 2000 + 1) * 1000;
using (LotteryEntities db = new LotteryEntities())
{
string sMax = db.DLTs.Max(q => q.Phase);
if (!string.IsNullOrEmpty(sMax))
{
min = int.Parse(sMax) - 2000000 +1;
}
}
for (int i = min; i < max; i = (i + 1000) / 1000 * 1000)
{
string start = i < 10000 ? "0" + i : ""+i;
int iEnd = i + 1000;
string end = iEnd < 10000 ? "0" + iEnd : "" + iEnd;
string uri = string.Format(urlBase, start, end);
string content = HtmlHelper.HtmlRequest(uri);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
DltUtils dlt = new DltUtils(doc);
DataTable balls = dlt.getBallsTable();
string connection = ConfigurationManager.ConnectionStrings["LotteryConnectionString"].ConnectionString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
{
bulkCopy.DestinationTableName = "dbo.DLT";
bulkCopy.ColumnMappings.Add("R1", "R1");
bulkCopy.ColumnMappings.Add("R2", "R2");
bulkCopy.ColumnMappings.Add("R3", "R3");
bulkCopy.ColumnMappings.Add("R4", "R4");
bulkCopy.ColumnMappings.Add("R5", "R5");
bulkCopy.ColumnMappings.Add("B1", "B1");
bulkCopy.ColumnMappings.Add("B2", "B2");
bulkCopy.ColumnMappings.Add("Phase", "Phase");
bulkCopy.BulkCopyTimeout = 0;
bulkCopy.WriteToServer(balls);
}
}
}
}
}