Example #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     Taocan taocan = new Taocan();
     taocan.Qishu = 20140803;
     taocan.Riqi = new DateTime(2014, 8, 3);
     taocan.Huibaolv = 225;
     taocan.Gailv = "80+%";
     taocan.Jiangjin = 500;
     taocan.Lucky = 0;
     taocan.Type = "专家推荐套餐";
     taocan.Remark = "test"; 
     new TaocanDAL().InsertTaocan(taocan);
 }
        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);
                    }
                }
            }
        }
Example #3
0
        public int InsertTaocanVote(Taocan taocan)
        {
            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_vote(qishu,
riqi ,
gailv,
huibaolv,
touru,
jiangjin,
lucky,
type,
zhudui1,
kedui1,
zhudui2,
kedui2,
remark)
VALUES(
?qishu,
?riqi ,
?gailv,
?huibaolv,
?touru,
?jiangjin,
?lucky,
?type,
?zhudui1,
?kedui1,
?zhudui2,
?kedui2,
?remark
);
Select @@IDENTITY;
";
                    //"SELECT COUNT(*) FROM BlogsUsers WHERE BlogsName=?BlogsName";
                    mySqlCom.CommandText = sqlStr;
                    mySqlCom.Parameters.AddWithValue("?qishu", taocan.Qishu);
                    mySqlCom.Parameters.AddWithValue("?riqi", taocan.Riqi);
                    mySqlCom.Parameters.AddWithValue("?gailv", taocan.Gailv);
                    mySqlCom.Parameters.AddWithValue("?huibaolv", taocan.Huibaolv);
                    mySqlCom.Parameters.AddWithValue("?touru", taocan.Touru);
                    mySqlCom.Parameters.AddWithValue("?jiangjin", taocan.Jiangjin);
                    mySqlCom.Parameters.AddWithValue("?lucky", taocan.Lucky);
                    mySqlCom.Parameters.AddWithValue("?type", taocan.Type);
                    mySqlCom.Parameters.AddWithValue("?zhudui1", taocan.Zhudui1);
                    mySqlCom.Parameters.AddWithValue("?kedui1", taocan.Kedui1);
                    mySqlCom.Parameters.AddWithValue("?zhudui2", taocan.Zhudui2);
                    mySqlCom.Parameters.AddWithValue("?kedui2", taocan.Kedui2);
                    mySqlCom.Parameters.AddWithValue("?remark", taocan.Remark);

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

            return total;
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            
            document.Load("HTMLPage4.html", Encoding.UTF8);
            HtmlNode rootNode = document.DocumentNode;

            //<div class="pub_mod_hd">
            HtmlNodeCollection typeList = rootNode.SelectNodes(@"//div[@class='pub_mod_i mt10']");

            HtmlNode temp = null;

            foreach(HtmlNode typeNode in typeList)
            {
                //MessageBox.Show(typeNode.InnerText);
                temp = HtmlNode.CreateNode(typeNode.OuterHtml);
                HtmlNodeCollection strong = temp.SelectNodes("//div[@class='pub_mod_hd']/strong[@class='pub_mod_title yahei']");

                String type = strong[0].InnerText;
                //MessageBox.Show(strong[0].InnerText);

               //HtmlNodeCollection strong  = typeNode.FirstChild.SelectNodes("//div[@class='pub_mod_hd']/strong[@class='pub_mod_title yahei']");
               //MessageBox.Show(strong[0].InnerText);
                //MessageBox.Show(type);

                HtmlNodeCollection voteCodeList = temp.SelectNodes(VoteCode);
                HtmlNode temp2 = null;
                foreach (HtmlNode node in voteCodeList)
                {
                    //MessageBox.Show(node.XPath);
                    //HtmlNodeCollection nodes = node.SelectNodes("/div");
                    //foreach (HtmlNode nd in nodes)
                    //{
                    //    MessageBox.Show(nd.InnerHtml);
                    //}

                    temp2 = HtmlNode.CreateNode(node.OuterHtml);
                    //回报率
                    HtmlNode game_info = temp2.SelectSingleNode(@"//div[@class='game_info']/strong[2]");
                    double huibaolv = Convert.ToDouble(game_info.InnerText);
                    //MessageBox.Show(game_info.InnerText);
                    //获取主队1,客队1,主队2,客队2
                    HtmlNodeCollection duimings = temp2.SelectNodes("//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;


                    //foreach (HtmlNode duiming in duimings)
                    //{
                    //    MessageBox.Show(duiming.InnerText);
                    //}
                    //获取投入和奖金 game_money
                    HtmlNodeCollection gameMoney = temp2.SelectNodes("//div[@class='game_money']/span");
                    int touru = Convert.ToInt32(gameMoney[0].InnerText);
                    double jiangjin = Convert.ToDouble(gameMoney[1].InnerText);


                    Taocan taocan = new Taocan();
                    taocan.Gailv = "88+%";
                    taocan.Huibaolv = huibaolv;
                    taocan.Qishu = GetQishu();
                    taocan.Riqi = DateTime.Now.Date;
                    taocan.Touru = touru;
                    taocan.Jiangjin = jiangjin;
                    taocan.Type = type;
                    taocan.Lucky = 0;
                    taocan.Zhudui1 = zhudui1;
                    taocan.Zhudui1 = zhudui2;
                    taocan.Kedui1 = kedui1;
                    taocan.Kedui2 = kedui2;

                    new TaocanDAL().InsertTaocan(taocan);


                }
            }
            

        }