Beispiel #1
0
        private void ImportBifa(DateTime importDate)
        {
            string bifaUrl = "http://live.aicai.com/jsbf/timelyscore!dynamicBfDataFromPage.htm?lotteryType=zc&issue=" + importDate.ToString("yyyyMMdd");
            //string bifaUrl = "http://live.aicai.com/jsbf/timelyscore!dynamicBfDataFromPage.htm?lotteryType=zc&issue=20150628";
            string result = GetHtmlFromUrl(bifaUrl);

            BifaJsonEntity bifaJsonEntity = JsonConvert.DeserializeObject<BifaJsonEntity>(result);
            //MessageBox.Show(bifaJsonEntity.result.bf_page);

            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            document.LoadHtml(bifaJsonEntity.result.bf_page);

            HtmlNode rootNode = document.DocumentNode;

            SuperBifa bifa = new SuperBifa();
            bifa.riqi = importDate.ToString("yyyy-MM-dd");
            //HtmlNode parentNode = rootNode.SelectSingleNode(@"//div[@id='jq_bf_refresh_time_div']");
            HtmlNodeCollection bifaNodes = rootNode.SelectNodes("./div[@class='md_data_box css_league']");

            foreach (HtmlNode bifaNode in bifaNodes)
            {
                //HtmlNode div = bifaNode.SelectSingleNode("./div[@class='md_data_box css_league']");
                //HtmlNode div2 = bifaNode.SelectSingleNode("./div/div");
                //HtmlNode div3 = bifaNode.SelectSingleNode("./div/div/span");
                //HtmlNode div4 = bifaNode.SelectSingleNode("./div/div/span/span[@class='c_yellow']");

                string xingqiandbianhao = bifaNode.SelectSingleNode(@"./div/span/span[@class='c_yellow']").InnerText;
                string liansai = bifaNode.SelectSingleNode(@"./div/span[@class='c_dgreen']").InnerText;
                //这里得增加一个判断,比分是否有值,没有的话以 -1:-1为默认值
                string zhudui = "";
                string bifen = "";
                string kedui = "";
                if (bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span").Count == 3)
                {
                    zhudui = bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span")[0].InnerText;
                    bifen = bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span")[1].InnerText;
                    kedui = bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span")[2].InnerText;
                }
                else
                {
                    zhudui = bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span")[0].InnerText;
                    bifen = "-1:-1";
                    kedui = bifaNode.SelectNodes(@"./div/span[@class='c_yellow']/span")[1].InnerText;
                }
              

                string bisaishijian = bifaNode.SelectSingleNode("./div/span[@class='md_ks_time']/span").InnerText;

                HtmlNode tbody = bifaNode.SelectSingleNode("./div/div/table/tbody");
                HtmlNode tr1 = tbody.SelectNodes("./tr")[0];
                HtmlNodeCollection tds1 = tr1.SelectNodes("./td");
                string bifajiawei_sheng = tds1[1].InnerText;
                string bifazhishu_sheng = tds1[2].InnerText;
                string baijiaoupei_sheng = tds1[3].InnerText;

                HtmlNode tr2 = tbody.SelectNodes("./tr")[1];
                HtmlNodeCollection tds2 = tr2.SelectNodes("./td");
                string bifajiawei_ping = tds2[1].InnerText;
                string bifazhishu_ping = tds2[2].InnerText;
                string baijiaoupei_ping = tds2[3].InnerText;

                HtmlNode tr3 = tbody.SelectNodes("./tr")[2];
                HtmlNodeCollection tds3 = tr3.SelectNodes("./td");
                string bifajiawei_fu = tds3[1].InnerText;
                string bifazhishu_fu = tds3[2].InnerText;
                string baijiaoupei_fu = tds3[3].InnerText;

                string chengjiaoliang = bifaNode.SelectSingleNode("./div/div/div[@class='proba_total']/p/strong[@class='c_orange']").InnerText;

                string sheng = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_orange']")[0].InnerText;
                string ping = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_green']")[0].InnerText;
                string fu = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_blue']")[0].InnerText;

                string dae_sheng = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_orange']")[1].InnerText;
                string dae_ping = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_green']")[1].InnerText;
                string dae_fu = bifaNode.SelectNodes("./div/div/div[@class='proba_data']/p/span[@class='c_blue']")[1].InnerText;


                bifa.xingqi = GetXingqiFromData(xingqiandbianhao);
                bifa.bianhao = GetBianhaoFromData(xingqiandbianhao);

                bifa.liansai = liansai;
                bifa.zhudui = zhudui;
                bifa.kedui = kedui;
                bifa.bifen = bifen;
                bifa.kaisaishijian = bisaishijian;
                bifa.bifajiawei_sheng = Convert.ToDouble(bifajiawei_sheng);
                bifa.bifajiawei_ping = Convert.ToDouble(bifajiawei_ping);
                bifa.bifajiawei_fu = Convert.ToDouble(bifajiawei_fu);

                bifa.bifazhishu_sheng = Convert.ToDouble(bifazhishu_sheng);
                bifa.bifazhishu_ping = Convert.ToDouble(bifazhishu_ping);
                bifa.bifazhishu_fu = Convert.ToDouble(bifazhishu_fu);

                bifa.baijiaoupei_sheng = Convert.ToDouble(baijiaoupei_sheng);
                bifa.baijiaoupei_ping = Convert.ToDouble(baijiaoupei_ping);
                bifa.baijiaoupei_fu = Convert.ToDouble(baijiaoupei_fu);

                bifa.chengjiaoe = Convert.ToInt32(chengjiaoliang);

                bifa.sheng = Convert.ToDouble(sheng.Substring(0, sheng.Length - 1));
                bifa.ping = Convert.ToDouble(ping.Substring(0, ping.Length - 1));
                bifa.fu = Convert.ToDouble(fu.Substring(0, fu.Length - 1));

                bifa.dae_sheng = Convert.ToDouble(dae_sheng.Substring(0, dae_sheng.Length - 1));
                bifa.dae_ping = Convert.ToDouble(dae_ping.Substring(0, dae_ping.Length - 1));
                bifa.dae_fu = Convert.ToDouble(dae_fu.Substring(0, dae_fu.Length - 1));

                bifa.inserttime = DateTime.Now;

                string[] bifens = bifa.bifen.Split(':');
                int zhuScore = Convert.ToInt32(bifens[0]);
                int keScore = Convert.ToInt32(bifens[1]);

                if (zhuScore > keScore)
                {
                    //int prize_rank = GetRank(bifa.sheng, bifa.ping, bifa.fu);
                    //int dae_prize_rank = GetRank(bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                    int prize_rank = GetRank(3, bifa.sheng, bifa.sheng, bifa.ping, bifa.fu);
                    int dae_prize_rank = GetRank(3, bifa.dae_sheng, bifa.dae_sheng,bifa.dae_ping, bifa.dae_fu);
                    bifa.prize_rank = prize_rank;
                    bifa.dae_prize_rank = dae_prize_rank;
                }
                else if(zhuScore == keScore)
                {
                    //int prize_rank = GetRank(bifa.ping, bifa.sheng, bifa.fu);
                    //int dae_prize_rank = GetRank(bifa.dae_ping, bifa.dae_sheng, bifa.dae_fu);
                    int prize_rank = GetRank(1, bifa.ping, bifa.sheng, bifa.ping, bifa.fu);
                    int dae_prize_rank = GetRank(1, bifa.dae_ping, bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                    bifa.prize_rank = prize_rank;
                    bifa.dae_prize_rank = dae_prize_rank;
                }
                else
                {
                    //int prize_rank = GetRank(bifa.fu, bifa.ping, bifa.sheng);
                    //int dae_prize_rank = GetRank(bifa.dae_fu, bifa.dae_ping, bifa.dae_sheng);
                    int prize_rank = GetRank(0, bifa.fu, bifa.sheng, bifa.ping, bifa.fu);
                    int dae_prize_rank = GetRank(0, bifa.dae_fu, bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                    bifa.prize_rank = prize_rank;
                    bifa.dae_prize_rank = dae_prize_rank;
                }
                //获取赔率

                Kaijiang kaijiang = new KaijiangDAL().GetKaijiangByRiqiAndBianhao(bifa.riqi, bifa.bianhao);

                if (kaijiang != null)
                {
                    //MessageBox.Show("数据有错!");
                    bifa.first_sp = GetFirstSp(kaijiang, bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                    bifa.second_sp = GetSecondSp(kaijiang, bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                    bifa.third_sp = GetThirdSp(kaijiang, bifa.dae_sheng, bifa.dae_ping, bifa.dae_fu);
                }
                else
                {
                    bifa.first_sp = 0.0;
                    bifa.second_sp = 0.0;
                    bifa.third_sp = 0.0;
                }
                
                new SuperBifaDAL().InsertSuperBifa(bifa);

            }
        }
Beispiel #2
0
        public bool InsertSuperBifa(SuperBifa bifa)
        {
            try
            {


                int total = 0;
                string conStr = "server=localhost;User Id=root;database=aicai;" +
                               "Password=root;Character Set=utf8;";
                using (MySqlConnection mySqlCon = new MySqlConnection(conStr))
                {
                    mySqlCon.Open();
                    using (MySqlCommand mySqlCom = mySqlCon.CreateCommand())
                    {
                        //这里需要注意的是在 Sql 语句中有一个参数是 ?BlogsName 
                        //很明显,这个参数有点古怪,和我们一直使用的 @ 不一样, 
                        //这是因为在 MySql 以前的提供的 .NET Connector 中 
                        //都是采用 ? 来标志一个参数的,而现在的 .NET Connector 呢, 
                        //您既可以采用 ? 来标志一个参数,您也可以使用一个 @ 符号来标志一个参数 
                        //新版的 .NET Connector 对此都是支持的 
                        string sqlStr = @"insert into superbifa(riqi,xingqi,bianhao,liansai,zhudui,kedui,bifen,kaisaishijian,bifajiawei_sheng,bifajiawei_ping,bifajiawei_fu,bifazhishu_sheng,bifazhishu_ping,
bifazhishu_fu,baijiaoupei_sheng,baijiaoupei_ping,baijiaoupei_fu,chengjiaoe,sheng,ping,fu,dae_sheng,dae_ping,dae_fu,inserttime,prize_rank,dae_prize_rank,first_sp,second_sp,third_sp)
values(?riqi,?xingqi,?bianhao,?liansai,?zhudui,?kedui,?bifen,?kaisaishijian,?bifajiawei_sheng,?bifajiawei_ping,?bifajiawei_fu,?bifazhishu_sheng,?bifazhishu_ping,
?bifazhishu_fu,?baijiaoupei_sheng,?baijiaoupei_ping,?baijiaoupei_fu,?chengjiaoe,?sheng,?ping,?fu,?dae_sheng,?dae_ping,?dae_fu,?inserttime,?prize_rank,?dae_prize_rank,?first_sp,?second_sp,?third_sp)
";
                        //"SELECT COUNT(*) FROM BlogsUsers WHERE BlogsName=?BlogsName";
                        mySqlCom.CommandText = sqlStr;
                        mySqlCom.Parameters.AddWithValue("?riqi", bifa.riqi);
                        mySqlCom.Parameters.AddWithValue("?xingqi", bifa.xingqi);
                        mySqlCom.Parameters.AddWithValue("?bianhao", bifa.bianhao);
                        mySqlCom.Parameters.AddWithValue("?liansai", bifa.liansai);
                        mySqlCom.Parameters.AddWithValue("?zhudui", bifa.zhudui);
                        mySqlCom.Parameters.AddWithValue("?kedui", bifa.kedui);
                        mySqlCom.Parameters.AddWithValue("?bifen", bifa.bifen);
                        mySqlCom.Parameters.AddWithValue("?kaisaishijian", bifa.kaisaishijian);
                        mySqlCom.Parameters.AddWithValue("?bifajiawei_sheng", bifa.bifajiawei_sheng);
                        mySqlCom.Parameters.AddWithValue("?bifajiawei_ping", bifa.bifajiawei_ping);
                        mySqlCom.Parameters.AddWithValue("?bifajiawei_fu", bifa.bifajiawei_fu);
                        mySqlCom.Parameters.AddWithValue("?bifazhishu_sheng", bifa.bifazhishu_sheng);
                        mySqlCom.Parameters.AddWithValue("?bifazhishu_ping", bifa.bifazhishu_ping);
                        mySqlCom.Parameters.AddWithValue("?bifazhishu_fu", bifa.bifazhishu_fu);
                        mySqlCom.Parameters.AddWithValue("?baijiaoupei_sheng", bifa.baijiaoupei_sheng);
                        mySqlCom.Parameters.AddWithValue("?baijiaoupei_ping", bifa.baijiaoupei_ping);
                        mySqlCom.Parameters.AddWithValue("?baijiaoupei_fu", bifa.baijiaoupei_fu);
                        mySqlCom.Parameters.AddWithValue("?chengjiaoe", bifa.chengjiaoe);
                        mySqlCom.Parameters.AddWithValue("?sheng", bifa.sheng);
                        mySqlCom.Parameters.AddWithValue("?ping", bifa.ping);
                        mySqlCom.Parameters.AddWithValue("?fu", bifa.fu);
                        mySqlCom.Parameters.AddWithValue("?dae_sheng", bifa.dae_sheng);
                        mySqlCom.Parameters.AddWithValue("?dae_ping", bifa.dae_ping);
                        mySqlCom.Parameters.AddWithValue("?dae_fu", bifa.dae_fu);
                        mySqlCom.Parameters.AddWithValue("?inserttime", bifa.inserttime);
                        mySqlCom.Parameters.AddWithValue("?prize_rank", bifa.prize_rank);
                        mySqlCom.Parameters.AddWithValue("?dae_prize_rank", bifa.dae_prize_rank);
                        mySqlCom.Parameters.AddWithValue("?first_sp", bifa.first_sp);
                        mySqlCom.Parameters.AddWithValue("?second_sp", bifa.second_sp);
                        mySqlCom.Parameters.AddWithValue("?third_sp", bifa.third_sp);

                        total = Convert.ToInt32(mySqlCom.ExecuteScalar());
                    }
                }

                return total == 0 ? true : false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return false;
        }