示例#1
0
        public bool InsertTaocanDetailVote(TaocanDetail taocandetail)
        {
            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 taocan_detail_vote(
taocanid,zhudui1,zhuduiluck1,zhuduishengfu1,zhudui2,zhuduiluck2,zhuduishengfu2,beishu,jiangjin,lucky,operator,operatedate
)
VALUES
(
?taocanid,?zhudui1,?zhuduiluck1,?zhuduishengfu1,?zhudui2,?zhuduiluck2,?zhuduishengfu2,?beishu,?jiangjin,?lucky,?operator,?operatedate
)

";
                        //"SELECT COUNT(*) FROM BlogsUsers WHERE BlogsName=?BlogsName";
                        mySqlCom.CommandText = sqlStr;
                        mySqlCom.Parameters.AddWithValue("?taocanid", taocandetail.TaocanID);
                        mySqlCom.Parameters.AddWithValue("?zhudui1", taocandetail.Zhudui1);
                        mySqlCom.Parameters.AddWithValue("?zhuduiluck1", taocandetail.Zhuduilucky1);
                        mySqlCom.Parameters.AddWithValue("?zhuduishengfu1", taocandetail.Zhuduishengfu1);
                        mySqlCom.Parameters.AddWithValue("?zhudui2", taocandetail.Zhudui2);
                        mySqlCom.Parameters.AddWithValue("?zhuduiluck2", taocandetail.Zhuduilucky2);
                        mySqlCom.Parameters.AddWithValue("?zhuduishengfu2", taocandetail.Zhuduishengfu2);
                        mySqlCom.Parameters.AddWithValue("?beishu", taocandetail.Beishu);
                        mySqlCom.Parameters.AddWithValue("?jiangjin", taocandetail.Jiangjin);
                        mySqlCom.Parameters.AddWithValue("?lucky", taocandetail.Lucky);
                        mySqlCom.Parameters.AddWithValue("?operator", taocandetail.Operator);
                        mySqlCom.Parameters.AddWithValue("?operatedate", taocandetail.OperateTime);


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

                return total == 0 ? true : false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return false;
        }
        private void btnImportCurrentTaocan_Click(object sender, EventArgs e)
        {
            DateTime importdate = DateTime.Now.Date;

            DateTime importDate = importdate;
            string uri = @"http://www.aicai.com/pages/lotnew/zq/index_vote.shtml";
            string htmlData = GetHtmlFromUrl(uri);
            // MessageBox.Show(htmlData);

            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            document.LoadHtml(htmlData);
            HtmlNode rootNode = document.DocumentNode;
            HtmlNodeCollection typeList = rootNode.SelectNodes(@"//div[@class='pub_mod_i mt10']");
            foreach (HtmlNode typeNode in typeList)
            {
                HtmlNode strong =
                    typeNode.SelectSingleNode("./div[@class='pub_mod_hd']/strong[@class='pub_mod_title yahei']");
                String type = strong.InnerText;
                HtmlNodeCollection voteCodeList =
                    typeNode.SelectNodes(@"./div[@class='pub_mod_bd pub_hc_wzj  clearfix']");
                HtmlNodeCollection voteCodeList2 =
                    typeNode.SelectNodes(@"./div[@class='pub_mod_bd pub_hc_wzj mt20 clearfix']");
                if (voteCodeList2 != null)
                {
                    foreach (HtmlNode vCode in voteCodeList2)
                    {
                        voteCodeList.Add(vCode);
                    }
                }

                foreach (HtmlNode node in voteCodeList)
                {
                    //概率
                    HtmlNode gailv = node.SelectSingleNode(@"./div/div[@class='pstCell']");
                    string gailvStr = gailv.InnerText;
                    //回报率
                    HtmlNode game_info = node.SelectSingleNode(@"./div/div[@class='game_info']/strong[2]");
                    double huibaolv = Convert.ToDouble(game_info.InnerText);
                    //获取主队1,客队1,主队2,客队2
                    HtmlNodeCollection duimings = node.SelectNodes("./div/div[@class='game_dz']/span");
                    string zhudui1 = duimings[0].InnerText;
                    string kedui1 = duimings[1].InnerText;
                    string zhudui2 = duimings[2].InnerText;
                    string kedui2 = duimings[3].InnerText;
                    HtmlNode gameMoney1 = node.SelectSingleNode("./div/div[@class='game_money']");
                    int touru = 0;
                    double jiangjin = 0.0;
                    touru = Convert.ToInt32(gameMoney1.ChildNodes[1].InnerText);
                    if (gameMoney1.ChildNodes[3].NodeType == HtmlNodeType.Comment)
                    {
                        string comment = gameMoney1.ChildNodes[3].InnerText;
                        int startIndex = comment.IndexOf("\">");
                        int endIndex = comment.IndexOf("</span>");
                        string strJiangjin = comment.Substring(startIndex + 2, endIndex - startIndex - 2);
                        jiangjin = Convert.ToDouble(strJiangjin);
                    }
                    else
                    {
                        jiangjin = Convert.ToDouble(gameMoney1.ChildNodes[3].InnerText);
                    }
                    //foreach(HtmlNode child in gameMoney1.ChildNodes)
                    //{

                    //    MessageBox.Show(child.InnerHtml);
                    //}
                    ////获取投入和奖金 game_money
                    //HtmlNodeCollection gameMoney = node.SelectNodes("./div/div[@class='game_money']/span");
                    //int touru = Convert.ToInt32(gameMoney[0].InnerText);
                    //double jiangjin = Convert.ToDouble(gameMoney[1].InnerText);
                    //是否中奖
                    //<div class="bs_select yahei fs22">中奖金额</div>
                    //<div class="bs_select yahei fs22 c999 pt10">已截止</div>
                    HtmlNode jiezhi = node.SelectSingleNode("./div/div[@class='bs_select yahei fs22 c999 pt10']");
                    HtmlNode zhongjiang = node.SelectSingleNode("./div/div[@class='bs_select yahei fs22']");
                    int lucky = 0;
                    if (jiezhi != null)
                    {
                        lucky = 0;
                    }
                    if (zhongjiang != null)
                    {
                        lucky = 1;
                    }
                    Taocan taocan = new Taocan();
                    taocan.Gailv = gailvStr;
                    taocan.Huibaolv = huibaolv;
                    taocan.Qishu = GetQishu(importDate);
                    taocan.Riqi = importdate.Date;
                    taocan.Touru = touru;
                    taocan.Jiangjin = jiangjin;
                    taocan.Type = type;
                    taocan.Lucky = lucky;
                    taocan.Zhudui1 = zhudui1;
                    taocan.Zhudui2 = zhudui2;
                    taocan.Kedui1 = kedui1;
                    taocan.Kedui2 = kedui2;
                    int taocanID = new TaocanDAL().InsertTaocanVote(taocan);

                    HtmlNode xiangqing = node.SelectSingleNode("./div/div/span/div[@class='tcxq_box']");
                    HtmlNodeCollection details = xiangqing.SelectNodes("./table/tbody/tr");
                    foreach (HtmlNode detailNode in details)
                    {
                        TaocanDetail detail = new TaocanDetail();
                        detail.TaocanID = taocanID;
                        HtmlNodeCollection tds = detailNode.SelectNodes("./td");
                        HtmlNode td = tds[1];
                        HtmlNodeCollection spans = td.SelectNodes("./span");
                        if (spans[0].Attributes["class"].Value == "red")
                        {
                            detail.Zhuduilucky1 = 1;
                        }
                        else
                        {
                            detail.Zhuduilucky1 = 0;
                        }

                        if (spans[1].Attributes["class"].Value == "red")
                        {
                            detail.Zhuduilucky2 = 1;
                        }
                        else
                        {
                            detail.Zhuduilucky2 = 0;
                        }

                        String str1 = td.ChildNodes[0].InnerText;
                        string str2 = td.ChildNodes[1].InnerText;
                        string str3 = td.ChildNodes[2].InnerText.Substring(12);
                        string str4 = td.ChildNodes[3].InnerText;


                        detail.Zhudui1 = str1;
                        detail.Zhuduishengfu1 = str2;
                        detail.Zhudui2 = str3;
                        detail.Zhuduishengfu2 = str4;
                        detail.Beishu = Convert.ToInt32(tds[3].Attributes["unitmult"].Value);
                        detail.Jiangjin = Convert.ToDouble(tds[4].Attributes["unitprize"].Value);
                        detail.Operator = "吴林";
                        detail.OperateTime = DateTime.Now;
                        new TaocanDetailDAL().InsertTaocanDetailVote(detail);
                    }
                }
            }
        }