예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <OpenCode> list2 = new List <OpenCode>();

            while (true)
            {
                try
                {
                    List <OpenCode> list = JsonHelper.ReadJson();

                    if (list.Count != 0)
                    {
                        arg2value = (int.Parse(list.Max(S => S.issueNo)) + 1).ToString();
                    }
                    else
                    {
                        string y = DateTime.Now.ToString("yy");
                        arg2value = y + "001";
                    }
                    string arg  = arg1 + "&" + arg2key + "=" + arg2value;
                    string json = Post(arg, url);

                    HisModel model = JsonConvert.DeserializeObject <History.HisModel>(json);

                    OpenCode code = new OpenCode();
                    code.issueNo = arg2value;
                    code.Date    = model.openTime;
                    code.Code    = model.openResult.Replace("<i>", "").Replace("</i>", ",");



                    list2.Add(code);
                }
                catch (Exception)
                {
                    break;
                }
                JsonHelper.Insert(list2);
            }



            his();
        }
예제 #2
0
        public static void  caiji()
        {
            Console.WriteLine("开始采集2019年数据");

            string url       = "https://kaijiang.aicai.com/open/historyIssue.do";
            string arg1      = "gameIndex=203";
            string arg2key   = "issueNo";
            string arg2value = "19001";

            int i = 0;


            while (true)
            {
                Console.WriteLine("采集中:" + i);
                try
                {
                    string sql1 = "select max(issno) issno from tb_hiscode";

                    DataRow r1  = SQLiteHelper.ExecuteDataRow(sql1);
                    int     num = r1[0].Equals(DBNull.Value) ? 0 : Convert.ToInt32(r1[0]);
                    if (num != 0)
                    {
                        arg2value = (Convert.ToInt32(r1["issno"]) + 1).ToString();
                    }
                    else
                    {
                        string y = DateTime.Now.ToString("yy");
                        arg2value = y + "001";
                    }
                    string arg  = arg1 + "&" + arg2key + "=" + arg2value;
                    string json = Post(arg, url);

                    HisModel model = JsonConvert.DeserializeObject <CpWinfrom.History.HisModel>(json);

                    string rescode = model.openResult.Replace("<i>", "").Replace("</i>", ",");
                    string n1      = rescode.Split(',')[0];
                    string n2      = rescode.Split(',')[1];
                    string n3      = rescode.Split(',')[2];
                    string n4      = rescode.Split(',')[3];
                    string n5      = rescode.Split(',')[4];

                    string sql2 = @"INSERT INTO [tb_hiscode]
           ([id]
           ,[Date]
           ,[Code]
           ,[IssNo]
           ,[N1]
           ,[N2]
           ,[N3]
           ,[N4]
           ,[N5])
     VALUES
           (null,'" + model.openTime + "','" + rescode + "','" + arg2value + "' ,'" + n1 + "' ,'" + n2 + "' ,'" + n3 + "','" + n4 + "','" + n5 + "')";

                    SQLiteHelper.ExecuteNonQuery(sql2);
                    i = i + 1;
                }
                catch (Exception e)
                {
                    break;
                }
            }

            Console.WriteLine("采集结束,累计:" + i);

            Main(null);
        }