예제 #1
0
        private void btn_Start_Click(object sender, EventArgs e)
        {
            DataTable dt       = GetTable();
            string    CityName = "成都"; //
            int       LineID   = 0;    //
            string    LineName = "";   //

            for (int i = 1; i < 9; i++)
            {
                try
                {
                    LineID   = i;
                    LineName = string.Format("{0}地铁{1}号线", CityName, LineID);
                    string tempLineName   = System.Web.HttpUtility.UrlEncode(LineName, Encoding.UTF8);
                    string pageHtml       = HttpRequestUtil.GetPageHtml("http://ditu.amap.com/service/poiInfo?query_type=TQUERY&pagesize=20&pagenum=1&qii=true&cluster_state=5&need_utd=true&utd_sceneid=1000&div=PC1000&addr_poi_merge=true&is_classify=true&city=510100&geoobj=104.05071%7C30.584681%7C104.06101%7C30.591479&keywords=" + tempLineName);
                    Regex  regTypeVehicle = new Regex("{\"type\"[\\s\\S]*?(?=,{\"type\":\"polyline\")");

                    MatchCollection    mc         = regTypeVehicle.Matches(pageHtml);
                    Match              match      = mc[0];
                    string             vChildren  = match.Value.ToString();
                    SubWayReturnEntity listSubWay = JsonHelper.JSON.parse <SubWayReturnEntity>(vChildren);

                    foreach (var item in listSubWay.busData)
                    {
                        dt.Rows.Add(0, CityName, LineID, LineName, item.sequence, item.name, item.location.lng, item.location.lat);
                    }

                    //写库
                    //ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings;
                    //string conStr = connections["constrLocal"].ToString();

                    string conStr = "Data Source=127.0.0.1;Initial Catalog=EFDemo;User ID=sa;Password=123456";
                    SqlBuckCopyHelper.SqlBulkCopyByDatatable(conStr, "SubWayLocationT", dt);
                    dt.Clear();
                    //进度
                    this.rbox_info.Text += string.Format("{0} 数据获取成功\r\n", LineName);

                    //
                    Thread.Sleep(20000);
                }
                catch (Exception ex)
                {
                    this.rbox_errInfo.Text += ex.ToString();
                    this.rbox_info.Text    += string.Format("{0} 数据获取失败\r\n", LineName);
                }
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string      outMsg       = string.Empty;
            string      filePath_XML = @"C:\Users\Administrator\Desktop\工具Html\Tools\Tools\App_Data\latitude.xml";
            ChinaEntity temp         = SerializableXml.DeserializeByStream(typeof(ChinaEntity), filePath_XML, out outMsg) as ChinaEntity;

            #region 读取数据
            DataTable dt     = GetTableSchema();
            var       tempID = temp.Latitude.Count + 1;
            for (int i = 1; i <= temp.Latitude.Count; i++)
            {
                DataRow dataRow = dt.NewRow();
                dataRow["ID"]         = i;
                dataRow["TopAreaID"]  = 0;
                dataRow["Name"]       = temp.Latitude[i - 1].Name;
                dataRow["Level"]      = 1;
                dataRow["CreateTime"] = DateTime.Now;
                dataRow["Lat1"]       = string.Empty;
                dataRow["Lng1"]       = string.Empty;
                dataRow["Lat2"]       = string.Empty;
                dataRow["Lng2"]       = string.Empty;
                dataRow["Lat3"]       = string.Empty;
                dataRow["Lng3"]       = string.Empty;
                dt.Rows.Add(dataRow);
                foreach (var item in temp.Latitude[i - 1].City)
                {
                    DataRow dataRow2 = dt.NewRow();
                    dataRow2["ID"]         = tempID; tempID++;
                    dataRow2["TopAreaID"]  = i;
                    dataRow2["Name"]       = item.Name;
                    dataRow2["Level"]      = 2;
                    dataRow2["CreateTime"] = DateTime.Now;
                    if (item.CityChildren.Count >= 3)
                    {
                        dataRow2["Lat1"] = item.CityChildren[0].Lat;
                        dataRow2["Lng1"] = item.CityChildren[0].Lng;
                        dataRow2["Lat2"] = item.CityChildren[1].Lat;
                        dataRow2["Lng2"] = item.CityChildren[1].Lng;
                        dataRow2["Lat3"] = item.CityChildren[2].Lat;
                        dataRow2["Lng3"] = item.CityChildren[2].Lng;
                    }
                    if (item.CityChildren.Count == 2)
                    {
                        dataRow2["Lat1"] = item.CityChildren[0].Lat;
                        dataRow2["Lng1"] = item.CityChildren[0].Lng;
                        dataRow2["Lat2"] = item.CityChildren[1].Lat;
                        dataRow2["Lng2"] = item.CityChildren[1].Lng;
                    }
                    if (item.CityChildren.Count == 1)
                    {
                        dataRow2["Lat1"] = item.CityChildren[0].Lat;
                        dataRow2["Lng1"] = item.CityChildren[0].Lng;
                    }
                    dt.Rows.Add(dataRow2);
                }
            }
            #endregion
            #region name纠正
            StringBuilder sb = new StringBuilder();
            for (int i = 33; i < dt.Rows.Count; i++)
            {
                try
                {
                    DataRow tempRow = dt.Rows[i];
                    string  name1   = GetBaiduAddress(tempRow["Lat1"].ToString(), tempRow["Lng1"].ToString()).result.addressComponent.city;
                    string  name2   = GetBaiduAddress(tempRow["Lat2"].ToString(), tempRow["Lng2"].ToString()).result.addressComponent.city;
                    string  name3   = GetBaiduAddress(tempRow["Lat3"].ToString(), tempRow["Lng3"].ToString()).result.addressComponent.city;
                    if (name1 == name2 || name2 == name3)
                    {
                        dt.Rows[i]["Name"] = name1;
                        sb.AppendFormat("【正常修改】原始为{0},百度分别为{1},{2},{3}", dt.Rows[i]["Name"].ToString(), name1, name1, name1);
                        sb.AppendLine();
                    }
                    else
                    {
                        sb.AppendFormat("【正常修改失败】原始为{0},百度分别为{1},{2},{3", dt.Rows[i]["Name"].ToString(), name1, name1, name1);
                        sb.AppendLine();
                    }
                }
                catch (Exception ex)
                {
                    sb.AppendFormat("【修改异常】{0},百度分别为{1},{2},{3},{4},{5},{6}",
                                    dt.Rows[i]["Name"].ToString()
                                    , dt.Rows[i]["Lat1"].ToString()
                                    , dt.Rows[i]["Lng1"].ToString()
                                    , dt.Rows[i]["Lat2"].ToString()
                                    , dt.Rows[i]["Lng2"].ToString()
                                    , dt.Rows[i]["Lat3"].ToString()
                                    , dt.Rows[i]["Lng3"].ToString()
                                    );
                    sb.AppendLine();
                }
            }
            richTextBox1.Text = sb.ToString();
            #endregion
            string conStr2 = "data source=gps200.coneton.com,4567;initial catalog=zyt_basegps_test;persist security info=true;user id=rdc_dev;password=rdc_dev6983";
            SqlBuckCopyHelper.SqlBulkCopyByDatatable(conStr2, "AreaInfo", dt);
            //进度
            MessageBox.Show("省市经纬度入库完成");
        }
예제 #3
0
        private void btn_vehicleType_Click(object sender, EventArgs e)
        {
            string VLetter;        //首字母
            string AType = "";     //
            string BType = "";     //
            string CType = "";     //
            string Price = "暂无价格"; //价格

            for (int i = 0; i < 26; i++)
            {
                DataTable dt = GetTable();
                VLetter = Encoding.ASCII.GetString(new byte[] { (byte)(i + 65) });
                //VLetter = GetUpperLetter()[i];
                string pageHtml = HttpRequestUtil.GetPageHtmlGB2312("http://www.autohome.com.cn/grade/carhtml/" + VLetter + ".html");
                //string pageHtml = HttpRequestUtil.GetPageHtmlGB2312("http://price.pcauto.com.cn/cars/");
                //Regex regTypeVehicle = new Regex("<div class=\"h3-tit\">[\\s\\S]*?</dd>"); 主型号有误
                Regex regTypeVehicle = new Regex("<div><a href=\"http://car.autohome.com.cn/pic[\\s\\S]*?</dd>");

                MatchCollection mc = regTypeVehicle.Matches(pageHtml);
                foreach (Match match in mc)
                {
                    string vChildren = match.Value.ToString();
                    //==
                    //Regex regA = new Regex("(?<=(<div class=\"h3-tit\">)).*?(?=<)");主型号有误
                    Regex regA   = new Regex("(?<=<div><a href=\"http://car.autohome.com.cn/pic/.*?>).*?(?=<)");
                    Match matchA = regA.Match(vChildren);
                    AType = matchA.Value;
                    //==
                    Regex           regTypeVChildren = new Regex("<div class=\"h3-tit\">[\\s\\S]*?</ul>");
                    MatchCollection mcChildren       = regTypeVChildren.Matches(vChildren);
                    foreach (Match citem in mcChildren)
                    {
                        string Type = citem.Value.ToString();

                        //==
                        Regex regB   = new Regex("(?<=(<div class=\"h3-tit\">)).*?(?=<)");
                        Match matchB = regB.Match(Type);
                        BType = matchB.Value;
                        //==

                        Regex regType = new Regex("(<h4 class=\"toolong\"[\\s\\S]*?</li>)|(<h4><a href=[\\s\\S]*?</li>)");
                        // Regex regType = new Regex("<h4><a href=[\\s\\S]*?</li>");
                        MatchCollection mcType = regType.Matches(Type);
                        foreach (Match tItem in mcType)
                        {
                            string          vData    = tItem.Value.ToString();
                            Regex           regVData = new Regex("<a[\\s\\S]*?</a>");
                            MatchCollection mcVData  = regVData.Matches(vData);
                            //foreach (var item in mcVData)
                            //{
                            string          vValue   = tItem.Value.ToString();
                            Regex           regValue = new Regex("\">[\\s\\S]*?</a>");
                            MatchCollection mcValue  = regVData.Matches(vData);
                            if (mcValue.Count == 4 || mcValue.Count == 3 || mcValue.Count == 5)
                            {
                                Regex regC   = new Regex("(?<=>).*?(?=<)");
                                Match matchC = regC.Match(mcValue[0].ToString());
                                CType = matchC.Value;
                                dt.Rows.Add(0, VLetter, AType, BType, CType, "暂无价格");
                            }
                            else if (mcValue.Count == 6)
                            {
                                Regex regC   = new Regex("(?<=>).*?(?=<)");
                                Match matchC = regC.Match(mcValue[0].ToString());
                                CType = matchC.Value;

                                Match matchP = regC.Match(mcValue[1].ToString());
                                Price = matchP.Value;
                                dt.Rows.Add(0, VLetter, AType, BType, CType ?? "类型错误", Price ?? "价格错误");
                            }
                            //}
                        }
                    }
                }

                try
                {
                    //写库
                    //ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings;
                    //string conStr = connections["constrLocal"].ToString();
                    string conStr = "Data Source=127.0.0.1;Initial Catalog=EFDemo;User ID=sa;Password=123456";
                    SqlBuckCopyHelper.SqlBulkCopyByDatatable(conStr, "VehicleType", dt);
                    //进度
                    MessageBox.Show("车型入库完成");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }