/// <summary>
 /// 开始更新城市数据
 /// </summary>
 public void LoadCityXML()
 {
     try
     {
         string path = Application.StartupPath + @"\XML\CityList.xml";
         if (!File.Exists(path)) return;
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(path);
         XmlNodeList cityNodes = xmlDoc.SelectNodes("CityList/Sheng");
         if (cityNodes != null && cityNodes.Count > 0)
         {
             //清空网址表
             dmData.ClearCityData();
             string shengName = string.Empty;
             string shiName = string.Empty;
             City city = null;
             foreach (XmlNode shengNode in cityNodes)
             {
                 //省级
                 city = new City();
                 shengName = shengNode.Attributes[0].Value;
                 city.Name = shengName;
                 dmData.InsertCityData(city);
                 foreach (XmlNode shiNode in shengNode.ChildNodes)
                 {
                     //市级
                     city = new City();
                     shiName = shiNode.Attributes[0].Value;
                     city.Name = shiName;
                     city.ShengParent = shengName;
                     dmData.InsertCityData(city);
                     foreach (XmlNode xianNode in shiNode.ChildNodes)
                     {
                         //县级
                         city = new City();
                         city.Name = xianNode.Attributes[0].Value;
                         city.ShengParent = shengName;
                         city.ShiParent = shiName;
                         city.Code = xianNode.InnerText;
                         dmData.InsertCityData(city);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.WriteLog(ex.ToString());
     }
 }
        public int InsertCityData(City city)
        {
            int result = 0;
            try
            {
                string sql = "INSERT INTO t_city(Name,ShengParent,ShiParent,Code)values(@Name,@ShengParent,@ShiParent,@Code)";

                SQLiteParameter[] parameters = new SQLiteParameter[]{
                                         new SQLiteParameter("@Name",city.Name),
                                         new SQLiteParameter("@ShengParent",city.ShengParent),
                                         new SQLiteParameter("@ShiParent",city.ShiParent),
                                         new SQLiteParameter("@Code",city.Code)
                                         };
                SqlAction action = new SqlAction();
                result = action.IntQuery(sql, parameters);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.ToString());
            }
            return result;
        }
Beispiel #3
0
 public DataTable GetCityData(CityType type, string parent)
 {
     DataTable data = new DataTable();
     try
     {
         string sqlString = string.Empty;
         SQLiteParameter[] parameters = null;
         City city = new City();
         switch (type)
         {
             case CityType.Sheng:
                 sqlString = "select Name  from t_city where ShengParent IS NULL and ShiParent IS NULL and Code IS NULL";
                 break;
             case CityType.Shi:
                 sqlString = "select Name  from t_city where ShengParent=@ShengParent and ShiParent IS NULL and Code IS NULL";
                 parameters = new SQLiteParameter[]{
                                  new SQLiteParameter("@ShengParent",parent)
                                  };
                 break;
             case CityType.Xian:
                 sqlString = "select Name,Code  from t_city where ShiParent=@ShiParent";
                 parameters = new SQLiteParameter[]{
                                  new SQLiteParameter("@ShiParent",parent)
                                  };
                 break;
         }
         SqlAction action = new SqlAction();
         data = action.DataTableQuery(sqlString, parameters);
     }
     catch (Exception ex)
     {
         log.WriteLog(ex.ToString());
     }
     return data;
 }