예제 #1
0
        public bool InsertJifenbang(Jifenbang jifenbang)
        {
            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 Jifenbang(
liansai,
paiming,
qiudui,
yisai,
sheng,
ping,
fu,
deqiu,
shiqiu ,
jingshengqiu,
junde,
junshi,
shenglv,
pinglv,
fulv,
jifen,
operator,
operatetime
)
values
(
?liansai,
?paiming,
?qiudui,
?yisai,
?sheng,
?ping,
?fu,
?deqiu,
?shiqiu ,
?jingshengqiu,
?junde,
?junshi,
?shenglv,
?pinglv,
?fulv,
?jifen,
?operator,
?operatetime
)

";

                    mySqlCom.CommandText = sqlStr;
                    mySqlCom.Parameters.AddWithValue("?liansai", jifenbang.Liansai);
                    mySqlCom.Parameters.AddWithValue("?paiming", jifenbang.Paiming);
                    mySqlCom.Parameters.AddWithValue("?qiudui", jifenbang.Qiudui);
                    mySqlCom.Parameters.AddWithValue("?yisai", jifenbang.Yisai);
                    mySqlCom.Parameters.AddWithValue("?sheng", jifenbang.Sheng);
                    mySqlCom.Parameters.AddWithValue("?ping", jifenbang.Ping);
                    mySqlCom.Parameters.AddWithValue("?fu", jifenbang.Fu);
                    mySqlCom.Parameters.AddWithValue("?deqiu", jifenbang.Deqiu);
                    mySqlCom.Parameters.AddWithValue("?shiqiu", jifenbang.Shiqiu);
                    mySqlCom.Parameters.AddWithValue("?jingshengqiu", jifenbang.Jingshengqiu);
                    mySqlCom.Parameters.AddWithValue("?junde", jifenbang.Junde);
                    mySqlCom.Parameters.AddWithValue("?junshi", jifenbang.Junshi);
                    mySqlCom.Parameters.AddWithValue("?shenglv", jifenbang.Shenglv);
                    mySqlCom.Parameters.AddWithValue("?pinglv", jifenbang.Pinglv);
                    mySqlCom.Parameters.AddWithValue("?fulv", jifenbang.Fulv);
                    mySqlCom.Parameters.AddWithValue("?jifen", jifenbang.Jifen);
                    mySqlCom.Parameters.AddWithValue("?operator", jifenbang.Operator);
                    mySqlCom.Parameters.AddWithValue("?operatetime", jifenbang.Operatetime);

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

            return total == 0 ? true : false;
        }
예제 #2
0
        private void btnImportJifen_Click(object sender, EventArgs e)
        {
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            //document.LoadHtml(html);
            string fileName = "html/积分榜日职联.html";
            switch (comLiansai.Text)
            {
                case "日职联":
                    fileName = "html/积分榜日职联.html";
                    break;
                case "日职乙":
                    fileName = "html/积分榜日职乙.html";
                    break;

            }

            document.Load(fileName, Encoding.UTF8);
            
            HtmlNode rootNode = document.DocumentNode;

            HtmlNodeCollection trs = rootNode.SelectNodes(@"//tbody[@id='jq_rank_tbody']/tr");

            foreach (HtmlNode tr in trs)
            {
                //MessageBox.Show(node.InnerHtml);
                //foreach (HtmlNode td in table.ChildNodes)
                //{
                //    MessageBox.Show(td.InnerHtml);
                //}
                HtmlNodeCollection tds = tr.SelectNodes("./td");
                //foreach (HtmlNode td in tds)
                //{
                //    MessageBox.Show(td.InnerHtml);
                //}

                Jifenbang jifenbang = new Jifenbang();
                jifenbang.Liansai = comLiansai.Text;
                jifenbang.Paiming = Convert.ToInt32(tds[0].InnerText);
                jifenbang.Qiudui = tds[1].InnerText;
                jifenbang.Yisai = Convert.ToInt32(tds[2].InnerText);
                jifenbang.Sheng = Convert.ToInt32(tds[3].InnerText);
                jifenbang.Ping = Convert.ToInt32(tds[4].InnerText);
                jifenbang.Fu = Convert.ToInt32(tds[5].InnerText);
                string deshiqiu = tds[6].InnerText;
                string[] qiu = deshiqiu.Split('/');

                jifenbang.Deqiu = Convert.ToInt32(qiu[0]);
                jifenbang.Shiqiu = Convert.ToInt32(qiu[1]);
                jifenbang.Jingshengqiu = Convert.ToInt32(tds[7].InnerText);
                jifenbang.Junde = Convert.ToDouble(tds[8].InnerText);
                jifenbang.Junshi = Convert.ToDouble(tds[9].InnerText);
                jifenbang.Shenglv = Convert.ToDouble(tds[10].InnerText);
                jifenbang.Pinglv = Convert.ToDouble(tds[11].InnerText);
                jifenbang.Fulv = Convert.ToDouble(tds[12].InnerText);
                jifenbang.Jifen = Convert.ToInt32(tds[13].InnerText);
                jifenbang.Operator = "吴林";
                jifenbang.Operatetime = DateTime.Now;

                new JifenbangDAL().InsertJifenbang(jifenbang);

            }
            MessageBox.Show("导入联赛积分榜成功!");


        }