Beispiel #1
0
        //匹配当地所有号段
        void mainWhile(object tel)
        {
            DateTime hdStart = DateTime.Now;
            int      hdnum   = 0;
            string   telStr  = tel.ToString();

            string    strSql   = "select SUBSTRING(Number7,1,3) q3w from TelphoneData where SUBSTRING(Number7,4,4)=" + telStr.Substring(3, 4) + " and city='" + textBox2.Text + "'";
            DataTable returnDt = SqlHelp.bangding(strSql);
            string    telStr8  = telStr.Substring(3, 8);

            for (int i = 0; i < returnDt.Rows.Count; i++)
            {
                string keyword = returnDt.Rows[i][0].ToString() + telStr8;
                int    bl      = CollectRule.MainWhile(search, keyword);
                if (bl == 1)
                {
                    num++;
                    hdnum++;
                }
                else if (bl == -1)
                {
                    MessageBox.Show(DateTime.Now.ToString() + "执行到:" + keyword + "时,当前IP开始被" + search + "屏蔽,未启动VPN!\r\n");
                }
            }
            DateTime hdEnd = DateTime.Now;

            StringHelp.Write(StringHelp.pathError, hdEnd.ToString() + "号码:" + telStr + "执行结束。" + "用时:" + DateHelp.DateDiff(hdEnd, hdStart) + "获取个数:" + hdnum + "\r\n");
        }
Beispiel #2
0
        void mainWhile(object q3Str)
        {
            DateTime hdStart = DateTime.Now;
            int      hdnum   = 0;
            string   txt     = q3Str + z4Str + "0000";
            long     hd      = Convert.ToInt64(txt);

            for (int i = 0; i < 10000; i++)
            {
                string keyword = (hd + i).ToString();
                int    bl      = CollectRule.MainWhile(search, keyword);
                if (bl == 1)
                {
                    num++;
                    hdnum++;
                }
                else if (bl == -1)
                {
                    MessageBox.Show(DateTime.Now.ToString() + "执行到:" + keyword + "时,当前IP开始被" + search + "屏蔽,未启动VPN!\r\n");
                }
            }

            DateTime hdEnd = DateTime.Now;

            StringHelp.Write(StringHelp.pathError, hdEnd.ToString() + " 号段:" + q3Str + "结束。" + "用时:" + DateHelp.DateDiff(hdEnd, hdStart) + "获取个数:" + hdnum + "\r\n");
        }
Beispiel #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < repalys.Length; i++)
            {
                string   url      = "https://club.autohome.com.cn/frontapi/reply/add";
                Encoding encoding = Encoding.GetEncoding("utf-8");
                IDictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("bbs", textBox4.Text);
                parameters.Add("bbsid", textBox5.Text);
                parameters.Add("topicid", textBox6.Text);
                parameters.Add("content", repalys[i]);
                HttpWebResponse response = StringHelp.CreatePostHttpResponse(url, parameters, encoding, textBox8.Text);
                //打印返回值
                Stream       stream   = response.GetResponseStream(); //获取响应的字符串流
                StreamReader sr       = new StreamReader(stream);     //创建一个stream读取流
                string       jsonText = sr.ReadToEnd();               //从头读到尾,放到字符串html


                JObject jo         = (JObject)JsonConvert.DeserializeObject(jsonText); //或者JObject jo = JObject.Parse(jsonText);
                string  returncode = jo["returncode"].ToString();                      //输出 "深圳"
                if (returncode == "0")
                {
                    textBox7.Text += "成功\r\n";
                }
                else
                {
                    textBox7.Text += jo["message"].ToString() + "\r\n";
                }


                Thread.Sleep(3000);//3000毫秒
            }
        }
Beispiel #4
0
 public static DataTable bangding(string sqlsel)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(connStr))
         {
             DataTable      dt = new DataTable();
             SqlDataAdapter da = new SqlDataAdapter(sqlsel, conn);
             da.Fill(dt);
             return(dt);
         }
     }
     catch (SqlException ex)
     {
         DataTable dt;
         do
         {
             StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + sqlsel + ex.Message + "\r\n");
             System.Threading.Thread.Sleep(3 * 1000);
             StringHelp.getState();
             dt = bangding(sqlsel);
         } while (dt == null);
         StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + "重新执行\r\n");
         return(dt);
     }
 }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //C:\Users\Administrator\Documents\Visual Studio 2015\Projects\号码采集系统\号码采集系统\bin\x86\Debug\20170914
            string spath = Environment.CurrentDirectory + "\\" + dateStr;

            if (!Directory.Exists(spath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(spath);
                directoryInfo.Create();
            }
            StringHelp.filePathOut = spath + "\\_360固话万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            StringHelp.pathError   = spath + "\\_360固话万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
            StringHelp.CreateExcel();

            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                MessageBox.Show("号码不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            dt          = DateTime.Now;
            label3.Text = dt + "正在执行……";
            //执行主循环万号
            mainWhile(textBox1.Text.Trim(), textBox2.Text.Trim());
            DateTime end = DateTime.Now;

            StringHelp.Write(StringHelp.pathError, end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "获取个数:" + num + "\r\n");
            label3.Text = end.ToString() + "执行完毕,已将检索结果导出到与导入文件所在的相同目录。";
            MessageBox.Show(end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "。" +
                            "\r\n获取个数:" + num + ", 已将检索结果导出到与导入文件所在的相同目录。\r\n");
        }
Beispiel #6
0
        public static bool MainProc(string search, string keyword, string input)
        {
            bool use = false;

            string title     = "";
            string titleText = "";
            string titleLink = "";
            string remark    = "";

            getReg(search, ref title, ref titleText, ref titleLink, ref remark);

            //标题
            Regex           r = new Regex(title, RegexOptions.IgnoreCase);
            MatchCollection matchCollection = r.Matches(input);
            //简介
            string          abstractReg        = remark;
            MatchCollection abstractCollection = Regex.Matches(input, abstractReg, RegexOptions.IgnoreCase);

            for (int i = 0; i < abstractCollection.Count; i++)
            {
                Match  m           = abstractCollection[i];
                string abstractStr = StringHelp.ReplaceHtmlTag(m.Value.Replace("'", ""));
                if (m.Success && ruleJudge(abstractStr, keyword))
                {
                    //标题
                    string          textReg             = titleText;
                    MatchCollection textMatchCollection = Regex.Matches(matchCollection[i].Value, textReg, RegexOptions.IgnoreCase);
                    Match           match2   = textMatchCollection[0];
                    string          titleStr = "";
                    if (match2.Success)
                    {
                        titleStr = StringHelp.ReplaceHtmlTag(match2.Result("$1"));
                    }
                    //标题链接
                    string          LinkReg             = titleLink;
                    MatchCollection linkMatchCollection = Regex.Matches(matchCollection[i].Value, LinkReg, RegexOptions.IgnoreCase);
                    Match           match3       = linkMatchCollection[0];
                    string          titleLinkStr = "";
                    if (match3.Success)
                    {
                        titleLinkStr = match3.Value.Replace("<a href=", "").Replace("\"", "");
                    }

                    #region 创建采集对象
                    TelCollection tel = new TelCollection();
                    tel.Search    = search;
                    tel.Telphone  = keyword;
                    tel.Title     = titleStr;
                    tel.TitleLink = titleLinkStr;
                    tel.Abstract  = abstractStr;
                    #endregion
                    StringHelp.WriteExcel(tel);
                    use = true;
                    break;
                }
            }
            return(use);
        }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //C:\\Users\\Administrator\\Documents\\Visual Studio 2015\\Projects\\号码采集系统\\号码采集系统\\bin\\Debug
            string spath = Environment.CurrentDirectory + "\\" + dateStr;

            if (!Directory.Exists(spath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(spath);
                directoryInfo.Create();
            }

            StringHelp.filePathOut = spath + "\\_360手机万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            StringHelp.pathError   = spath + "\\_360手机万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
            //创建excel文件
            StringHelp.CreateExcel();

            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                MessageBox.Show("城市或号段不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            dt          = DateTime.Now;
            label3.Text = dt + "正在执行……";
            z4Str       = textBox2.Text;

            ThreadPool.SetMaxThreads(5, 5); //设置最大线程数
            StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + "\r\n--------------------------------" + textBox2.Text + "号段开始-------------------------------------" + "\r\n");

            //string strSql = "select SUBSTRING(Number7,1,3) q3w from TelphoneData where SUBSTRING(Number7,4,4)=" + textBox2.Text.Trim() + " and city='" + textBox1.Text.Trim() + "' AND SUBSTRING(Number7,1,3) NOT IN ('170','171')";
            //DataTable returnDt = SqlHelp.bangding(strSql);
            //for (int i = 0; i < returnDt.Rows.Count; i++)
            //{
            //    ThreadPool.QueueUserWorkItem(new WaitCallback(mainWhile), returnDt.Rows[i][0].ToString());
            //}
            #region 测试代码
            //SELECT max(手机号) '最大尾号',count(1) '个数' FROM _360手机万号采集_6549_20170913110445155 GROUP BY SUBSTRING(手机号, 1, 3)
            //SELECT max(Telphone) '最大尾号',count(1) '个数' FROM TelCollection_0539 GROUP BY begin3
            //DELETE FROM TelCollection_0539 WHERE begin3 NOT IN (135,137)
            //DELETE FROM TelCollection_0539 WHERE SUBSTRING(Telphone, 8, 4) > 204
            //delete FROM TelCollection_0539 WHERE SUBSTRING(Telphone, 8, 4) > 7100 AND begin3 NOT IN (135,137)
            //6539号段
            //int[] q = { 131,134,133,136,150,151,152,158,159,178,182,187,188 };
            //0539号段
            //int[] q = { 131, 132, 133, 134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 153, 155, 156, 157, 158, 159, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189 };
            int[] q = { 155, 156, 157, 158, 159, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189 }; //147, 150, 151, 152, 153,
            for (int i = 0; i < q.Length; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(mainWhile), q[i]);
            }
            #endregion

            //是否结束所有线程
            rhw = ThreadPool.RegisterWaitForSingleObject(new System.Threading.AutoResetEvent(false), CheckThreadPool, null, 5000, false);
        }
Beispiel #8
0
        public static int MainWhile(string search, string keyword)
        {
            string url   = "";
            string error = "";
            string div   = "";

            getSearch(search, ref url, ref error, ref div);

            Regex  r       = new Regex(div, RegexOptions.IgnoreCase);
            string htmlStr = StringHelp.GetHtml2(url, keyword);
            string input   = r.Match(htmlStr).Value;
            int    bl      = 0;

            if (htmlStr.IndexOf(error) > 0)
            {
                Object locker = new Object();
                lock (locker)
                {
                    try
                    {
                        StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + " *************************************当前IP开始被" + search + "屏蔽*************************************" + keyword + "\r\n");
                        do
                        {
                            StringHelp.getChangeIp();
                            htmlStr = StringHelp.GetHtml2(url, keyword);
                        } while (htmlStr.IndexOf(error) > 0);

                        input = r.Match(htmlStr).Value;
                        if (input != "")
                        {
                            MainProc(search, keyword, input);
                        }
                    }
                    catch (Exception ex)
                    {
                        StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + ex + keyword + "当前IP开始被" + search + "屏蔽,未启动VPN!\r\n");
                        bl = -1;
                    }
                }
            }
            else if (input != "")
            {
                if (MainProc(search, keyword, input))
                {
                    bl = 1;
                }
            }
            return(bl);
        }
Beispiel #9
0
        public static string getState()
        {
            Object locker = new Object();

            lock (locker)
            {
                string stateHtml = StringHelp.GetHtml1(@"http://127.0.0.1:8222/getstate/");

                while (stateHtml.IndexOf("<state>11</state>") < 0)
                {
                    Stconnect();
                    stateHtml = StringHelp.GetHtml1(@"http://127.0.0.1:8222/getstate/");
                }
                return(stateHtml);
            }
        }
Beispiel #10
0
        private void CheckThreadPool(object state, bool timeout)
        {
            Object locker = new Object();

            lock (locker)
            {
                int maxWorkerThreads, workerThreads;
                int portThreads;
                ThreadPool.GetMaxThreads(out maxWorkerThreads, out portThreads);
                ThreadPool.GetAvailableThreads(out workerThreads, out portThreads);
                if (maxWorkerThreads - workerThreads == 0)
                {
                    // 走到这里,所有线程都结束了
                    rhw.Unregister(null);
                    DateTime end = DateTime.Now;
                    StringHelp.Write(StringHelp.pathError, end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "获取个数:" + num + "\r\n");
                    label3.Text = end.ToString() + "执行完毕,已将检索结果导出到与导入文件所在的相同目录。";
                    MessageBox.Show(end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "。" +
                                    "\r\n获取个数:" + num + ", 已将检索结果导出到与导入文件所在的相同目录。\r\n");
                }
            }
        }
Beispiel #11
0
        //本文件记录
        void mainWhile0(object tel)
        {
            DateTime hdStart = DateTime.Now;
            int      hdnum   = 0;

            string keyword = tel.ToString();
            int    bl      = CollectRule.MainWhile(search, keyword);

            if (bl == 1)
            {
                num++;
                hdnum++;
            }
            else if (bl == -1)
            {
                MessageBox.Show(DateTime.Now.ToString() + "执行到:" + keyword + "时,当前IP开始被" + search + "屏蔽,未启动VPN!\r\n");
            }

            DateTime hdEnd = DateTime.Now;

            StringHelp.Write(StringHelp.pathError, hdEnd.ToString() + "号码:" + keyword + "执行结束。" + "用时:" + DateHelp.DateDiff(hdEnd, hdStart) + "获取个数:" + hdnum + "\r\n");
        }
Beispiel #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            //C:\Users\Administrator\Documents\Visual Studio 2015\Projects\号码采集系统\号码采集系统\bin\x86\Debug\20170914
            string spath = Environment.CurrentDirectory + "\\" + dateStr;

            if (!Directory.Exists(spath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(spath);
                directoryInfo.Create();
            }
            StringHelp.filePathOut = spath + "\\baidu手机万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            StringHelp.pathError   = spath + "\\baidu手机万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
            //创建excel文件
            StringHelp.CreateExcel();

            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                MessageBox.Show("城市或号段不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            dt          = DateTime.Now;
            label3.Text = dt + "正在执行……";
            z4Str       = textBox2.Text;

            ThreadPool.SetMaxThreads(4, 4); //设置最大线程数
            StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + "\r\n--------------------------------" + textBox2.Text + "号段开始-------------------------------------" + "\r\n");

            string    strSql   = "select SUBSTRING(Number7,1,3) q3w from TelphoneData where SUBSTRING(Number7,4,4)=" + textBox2.Text.Trim() + " and city='" + textBox1.Text.Trim() + "' AND SUBSTRING(Number7,1,3) NOT IN ('170','171')";
            DataTable returnDt = SqlHelp.bangding(strSql);

            for (int i = 0; i < returnDt.Rows.Count; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(mainWhile), returnDt.Rows[i][0].ToString());
            }

            //是否结束所有线程
            rhw = ThreadPool.RegisterWaitForSingleObject(new System.Threading.AutoResetEvent(false), CheckThreadPool, null, 5000, false);
        }
Beispiel #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            //C:\Users\Administrator\Documents\Visual Studio 2015\Projects\号码采集系统\号码采集系统\bin\x86\Debug\20170914
            string spath = Environment.CurrentDirectory + "\\" + dateStr;

            if (!Directory.Exists(spath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(spath);
                directoryInfo.Create();
            }
            StringHelp.filePathOut = spath + "\\baidu固话万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            StringHelp.pathError   = spath + "\\baidu固话万号采集_" + textBox2.Text.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
            //创建excel文件
            StringHelp.CreateExcel();

            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                MessageBox.Show("号码不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            dt          = DateTime.Now;
            label3.Text = dt + "正在执行……";
            mainWhile(textBox1.Text.Trim(), textBox2.Text.Trim());
        }
Beispiel #14
0
        public static string connStr = "Data Source=47.93.253.194;Initial Catalog=lywenkaiData;User ID=sa;Password=system@123";// pooling=false

        public static int ExecuteSql(string strSql)
        {
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                using (SqlCommand cmd = new SqlCommand(strSql, conn))
                {
                    try
                    {
                        int rows = 0;
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        Object locker = new Object();
                        lock (locker)
                        {
                            rows = cmd.ExecuteNonQuery();
                        }
                        return(rows);
                    }
                    catch (SqlException ex)
                    {
                        int rows = 0;
                        do
                        {
                            StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + strSql + ex.Message + "\r\n");
                            System.Threading.Thread.Sleep(3 * 1000);
                            StringHelp.getState();
                            rows = ExecuteSql(strSql);
                        } while (rows <= 0);
                        StringHelp.Write(StringHelp.pathError, DateTime.Now.ToString() + "重新执行\r\n");
                        return(rows);
                    }
                }
            }
        }
Beispiel #15
0
        //string[] repalys = { "加油奥利给!", "期盼降价", "看好这款车!" };

        private void button6_Click(object sender, EventArgs e)
        {
            //文件路径
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "回复.txt";

            try
            {
                if (File.Exists(filePath))
                {
                    string rps = File.ReadAllText(filePath);
                    string ids = textBox8.Text;
                    if (rps == "")
                    {
                        MessageBox.Show("回复文件不存在!");
                    }


                    string[] urlarr = textBox1.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None); //url
                    string[] rparr  = rps.Split(new string[] { "\r\n" }, StringSplitOptions.None);           //例句
                    string[] idarr  = ids.Split(new string[] { "\r\n" }, StringSplitOptions.None);

                    //生成随机数句子
                    ArrayList myAL = new ArrayList();
                    Random    rd   = new Random();
                    for (int k = 0; k < 10; k++)
                    {
                        while (true)
                        {
                            int temp = rd.Next(1, rparr.Length);
                            if (!myAL.Contains(temp))
                            {
                                myAL.Add(temp);
                                break;
                            }
                        }
                    }

                    for (int u = 0; u < urlarr.Length; u++)
                    {
                        string url     = urlarr[u];
                        string topicid = url.Split('/', '-')[6];//https://club.autohome.com.cn/bbs/thread/d846d5111aef1fdc/90932303-1.html
                        //HtmlAgilityPack 添加Nuget包1.9,兼容2.0fw
                        HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();

                        string htmlStr = StringHelp.GetHtml1(url);
                        htmlDocument.LoadHtml(htmlStr);
                        string daohang = "//*[@id='js-sticky-toolbar']/div/div/div[1]/div[1]/a";//浏览器-检查-复制xpath
                        var    nods    = htmlDocument.DocumentNode.SelectNodes(daohang);
                        string href    = nods[0].Attributes["href"].Value;
                        string bbsid   = href.Split('-')[2];


                        for (int i = 0; i < 10;)
                        {
                            for (int n = 0; n < idarr.Length; n++)
                            {
                                //取数据
                                int d = int.Parse(myAL[i].ToString());

                                string   replyUrl = "https://club.autohome.com.cn/frontapi/reply/add";
                                Encoding encoding = Encoding.GetEncoding("utf-8");
                                IDictionary <string, string> parameters = new Dictionary <string, string>();
                                parameters.Add("bbs", "c");
                                parameters.Add("bbsid", bbsid);
                                parameters.Add("topicid", topicid);
                                parameters.Add("content", rparr[d]);
                                HttpWebResponse response = StringHelp.CreatePostHttpResponse(replyUrl, parameters, encoding, idarr[n]);
                                //打印返回值
                                Stream       stream   = response.GetResponseStream(); //获取响应的字符串流
                                StreamReader sr       = new StreamReader(stream);     //创建一个stream读取流
                                string       jsonText = sr.ReadToEnd();               //从头读到尾,放到字符串html


                                JObject jo         = (JObject)JsonConvert.DeserializeObject(jsonText); //或者JObject jo = JObject.Parse(jsonText);
                                string  returncode = jo["returncode"].ToString();                      //输出 "深圳"
                                if (returncode == "0")
                                {
                                    textBox7.Text += "成功\r\n";
                                }
                                else
                                {
                                    //textBox7.Text += jo["message"].ToString() + "\r\n";
                                    MessageBox.Show(jo["message"].ToString());
                                }

                                Thread.Sleep(3000);//3s
                                i++;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("回复文件不存在");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }



            MessageBox.Show("执行完成!");
        }
Beispiel #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            var filePath = "";

            if (!File.Exists(txtFileName.Text))
            {
                MessageBox.Show("文件不存在。");
                return;
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("城市不能为空。");
                return;
            }
            else
            {
                filePath = openFileDialog1.FileName;//txtFileName.Text;
                //读取excel
                IWorkbook ssfworkbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    var fileExtension = Path.GetExtension(filePath);
                    if (fileExtension == ".xls")
                    {
                        ssfworkbook            = new HSSFWorkbook(file);
                        StringHelp.filePathOut = filePath.Substring(0, filePath.Length - 4) + "_360手机批量检索结果_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                        StringHelp.pathError   = filePath.Substring(0, filePath.Length - 5) + "_360手机批量执行日志_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
                    }
                    else if (fileExtension == ".xlsx")
                    {
                        ssfworkbook            = new XSSFWorkbook(file);
                        StringHelp.filePathOut = filePath.Substring(0, filePath.Length - 5) + "_360手机批量检索结果_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                        StringHelp.pathError   = filePath.Substring(0, filePath.Length - 5) + "_360手机批量执行日志_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
                    }
                    else
                    {
                        MessageBox.Show("文件类型不支持");
                        return;
                    }
                }
                StringHelp.CreateExcel();
                //for (int i = 0; i < ssfworkbook.NumberOfSheets; i++)//遍历薄
                //{
                var sheet = ssfworkbook.GetSheetAt(0);
                dt = DateTime.Now;
                int daoNum = sheet.LastRowNum + 1;
                label3.Text = "导入" + daoNum + "个号码。";
                label4.Text = dt + "正在采集……";
                ThreadPool.SetMaxThreads(4, 4);  //设置最大线程数
                List <Thread> arr = new List <Thread>();
                for (int j = 0; j < daoNum; j++) //LastRowNum 获取的是最后一行的编号(编号从0开始)。getPhysicalNumberOfRows()获取的是物理行数,也就是不包括那些空行(隔行)的情况。
                {
                    var row = sheet.GetRow(j);   //读取当前行数据
                    if (row.GetCell(0).ToString() != "")
                    {
                        if (checkBox1.Checked)
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(mainWhile0), row.GetCell(0).ToString());
                        }
                        else
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(mainWhile), row.GetCell(0).ToString());
                        }
                    }
                }
                //}
            }

            rhw = ThreadPool.RegisterWaitForSingleObject(new System.Threading.AutoResetEvent(false), CheckThreadPool, null, 10000, false);
        }
Beispiel #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            var filePath = "";

            if (!File.Exists(txtFileName.Text))
            {
                MessageBox.Show("文件不存在。");
                return;
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("区号不能为空。");
                return;
            }
            else
            {
                filePath = openFileDialog1.FileName;//txtFileName.Text;
                //读取excel
                IWorkbook ssfworkbook;
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    var fileExtension = Path.GetExtension(filePath);
                    if (fileExtension == ".xls")
                    {
                        ssfworkbook            = new HSSFWorkbook(file);
                        StringHelp.filePathOut = filePath.Substring(0, filePath.Length - 4) + "_360固话批量检索结果_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                        StringHelp.pathError   = filePath.Substring(0, filePath.Length - 5) + "_360固话批量执行日志_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
                    }
                    else if (fileExtension == ".xlsx")
                    {
                        ssfworkbook            = new XSSFWorkbook(file);
                        StringHelp.filePathOut = filePath.Substring(0, filePath.Length - 5) + "_360固话批量检索结果_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
                        StringHelp.pathError   = filePath.Substring(0, filePath.Length - 5) + "_360固话批量执行日志_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
                    }
                    else
                    {
                        MessageBox.Show("文件类型不支持");
                        return;
                    }
                }
                StringHelp.CreateExcel();
                //for (int i = 0; i < ssfworkbook.NumberOfSheets; i++)//遍历薄
                //{
                var sheet = ssfworkbook.GetSheetAt(0);
                dt = DateTime.Now;
                int daoNum = sheet.LastRowNum + 1;
                label3.Text = "导入" + daoNum + "个号码。";
                label4.Text = dt + "正在采集……";
                for (int j = 0; j < daoNum; j++) //LastRowNum 获取的是最后一行的编号(编号从0开始)。getPhysicalNumberOfRows()获取的是物理行数,也就是不包括那些空行(隔行)的情况。
                {
                    var row = sheet.GetRow(j);   //读取当前行数据
                    if (row.GetCell(0).ToString() != "")
                    {
                        mainWhile(textBox2.Text + row.GetCell(0).ToString());
                    }
                }
                //}
            }

            DateTime end = DateTime.Now;

            StringHelp.Write(StringHelp.pathError, end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "获取个数:" + num + "\r\n");
            label4.Text = end.ToString() + "执行完毕,已将检索结果导出到与导入文件所在的相同目录。";
            MessageBox.Show(end.ToString() + "执行结束。" + "用时:" + DateHelp.DateDiff(end, dt) + "。" +
                            "\r\n获取个数:" + num + ", 已将检索结果导出到与导入文件所在的相同目录。\r\n");
        }
Beispiel #18
0
        //public static IFont font = newhssfworkbook.CreateFont();//创建字体样式
        //public static ICellStyle style = newhssfworkbook.CreateCellStyle();//创建单元格样式

        public static void WriteExcel(TelCollection tel)
        {
            #region 设置字体
            font.Color = NPOI.HSSF.Util.HSSFColor.Blue.Index; //设置字体颜色
            style.SetFont(font);                              //设置单元格样式中的字体样式
            #endregion


            //默认数据行
            var newrow = newsheet.CreateRow(newsheet.LastRowNum + 1);//创建新行
            //搜索引擎
            var newcell0 = newrow.CreateCell(0);
            newcell0.SetCellValue(tel.Search);

            #region 号码
            var newcell1 = newrow.CreateCell(1);
            newcell1.SetCellValue(tel.Telphone);                       //手机号
            //设置号码超链接
            HSSFHyperlink link = new HSSFHyperlink(HyperlinkType.Url); //建一个HSSFHyperlink实体,指明链接类型为URL(这里是枚举,可以根据需求自行更改)
            if (tel.Search == "360")
            {
                link.Address = Reg360.url + tel.Telphone;//给HSSFHyperlink的地址赋值
            }
            else
            {
                link.Address = RegBaidu.url + tel.Telphone;
            }
            newcell1.Hyperlink = link;  //将链接方式赋值给单元格的Hyperlink即可将链接附加到单元格上
            //超链接字体
            newcell1.CellStyle = style; //为单元格设置显示样式
            #endregion


            #region 标题
            var newcell2 = newrow.CreateCell(2);
            newcell2.SetCellValue(tel.Title);                               //标题
            //设置标题超链接
            HSSFHyperlink titleLink = new HSSFHyperlink(HyperlinkType.Url); //建一个HSSFHyperlink实体,指明链接类型为URL(这里是枚举,可以根据需求自行更改)
            titleLink.Address  = tel.TitleLink;                             //给HSSFHyperlink的地址赋值
            newcell2.Hyperlink = titleLink;                                 //将链接方式赋值给单元格的Hyperlink即可将链接附加到单元格上
            //设置字体
            newcell2.CellStyle = style;                                     //为单元格设置显示样式
            #endregion

            //简介
            var newcell3 = newrow.CreateCell(3);
            newcell3.SetCellValue(tel.Abstract);

            Object locker = new Object();
            lock (locker)
            {
                try
                {
                    FileStream fs = File.OpenWrite(filePathOut);
                    newhssfworkbook.Write(fs);   //向打开的这个xls文件中写入表并保存。
                    fs.Close();
                }
                catch (Exception ex)
                {
                    StringHelp.Write(StringHelp.pathError, ex.Message + tel.Telphone + "\r\n");
                    System.Threading.Thread.Sleep(1 * 1000);
                    WriteExcel(tel);
                    StringHelp.Write(StringHelp.pathError, tel.Telphone + "重新执行\r\n");
                }
            }
        }