public List<BaseInfo> CityNextItem(string citycode) { List<CityTestData> list = new List<CityTestData>(); List<BaseInfo> info = new List<BaseInfo>(); XMLManger xml = new XMLManger(); System.Windows.Resources.StreamResourceInfo input = Application.GetResourceStream(new Uri("/citylist;component/SampleData/city_next.xml", UriKind.Relative)); list = xml.ParseCity(input.Stream).ToList(); if (citycode != "") { var data1 = from x in list where x.CityId == citycode select x.data; List<BaseInfo[]> data2 = data1.ToList(); foreach (BaseInfo[] data in data2) { for (int i = 0; i < data.Length; i++) { info.Add(data[i]); } } } return info; }
void makeStrsql(string filename) { string path = string.Format(@"{0}xml\{1}", AppDomain.CurrentDomain.BaseDirectory, filename); XMLManger xml = new XMLManger(); List<CityTestData> list = xml.ParseCity(path).ToList(); var queryID = from x in list select x.CityId; FileStream file = new FileStream(@"c:\" + filename.Replace("xml", "txt"), FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter wr = new StreamWriter(file); foreach (var id in queryID) { var query = from x in list where x.CityId == id select x.data; foreach (var q in query) { foreach (BaseInfo b in q as BaseInfo[]) { string strsql = string.Empty; switch (filename) { case "province.xml": strsql = string.Format(@"INSERT INTO [province] ([provincename],[provincecode],[provincepy]) VALUES ('{0}','{1}','{2}');", b.Id, b.Name, id); break; case "city.xml": strsql = string.Format(@"INSERT INTO [city] ([cityname],[citycode],[cityparentcode]) VALUES ('{0}','{1}','{2}');", b.Name, b.Id, id); break; ; case "city_next.xml": strsql = string.Format(@"INSERT INTO [citynext] ([cityname],[citycode],[cityparentcode]) VALUES ('{0}','{1}','{2}');", b.Name, b.Id, id); break; } wr.WriteLine(strsql); wr.WriteLine("go"); } } } wr.Close();//关闭流 file.Close(); }