public List <OrgType> GetOrgTypes() { String command = "SELECT * FROM org_type;"; cmd.CommandText = command; rdr = cmd.ExecuteReader(); List <OrgType> res = new List <OrgType>(0); while (rdr.Read()) { OrgType tmp = new OrgType(); tmp.id = rdr.GetInt16(1); tmp.title = rdr.GetString(2); res.Add(tmp); } rdr.Close(); return(res); }
public TotalInfo ParseFile() { XmlDocument xDoc = new XmlDocument(); xDoc.Load(filePath); TotalInfo totalInfo = new TotalInfo(); // получим корневой элемент XmlElement xRoot = xDoc.DocumentElement; totalInfo.Date = xRoot.GetAttribute("date"); // обход всех узлов в корневом элементе foreach (XmlNode xnode in xRoot) { // go through organosations if (xnode.Name == "organizations") { List <Organisation> orgList = new List <Organisation>(0); foreach (XmlNode organisation in xnode) { Organisation org = new Organisation(); XmlNode org_id = organisation.Attributes.GetNamedItem("id"); XmlNode org_type = organisation.Attributes.GetNamedItem("org_type"); XmlNode title = organisation["title"].Attributes.GetNamedItem("value"); XmlNode region_id = organisation["region"].Attributes.GetNamedItem("id"); XmlNode city_id = organisation["city"].Attributes.GetNamedItem("id"); XmlNode phone = organisation["phone"].Attributes.GetNamedItem("value"); XmlNode address = organisation["address"].Attributes.GetNamedItem("value"); if (org_id != null && org_type != null && title != null && region_id != null && city_id != null && phone != null && address != null) { org.org_id = org_id.Value; org.org_type = int.Parse(org_type.Value); org.title = title.Value; org.region_id = region_id.Value; org.city_id = city_id.Value; org.phone = phone.Value; org.address = address.Value; } List <Currency> currList = new List <Currency>(0); foreach (XmlNode currencies in organisation) { if (currencies.Name == "currencies") { Currency curr = new Currency(); foreach (XmlNode c in currencies) { XmlNode eng_id = c.Attributes.GetNamedItem("id"); XmlNode purchase = c.Attributes.GetNamedItem("br"); XmlNode sale = c.Attributes.GetNamedItem("ar"); if (eng_id != null && purchase != null && sale != null) { curr.eng_id = eng_id.Value; curr.purchase = purchase.Value; curr.sale = sale.Value; } currList.Add(curr); } } } org.currencies = currList; orgList.Add(org); } totalInfo.organisations = orgList; } if (xnode.Name == "org_types") { List <OrgType> orgTypeList = new List <OrgType>(0); foreach (XmlNode orgType in xnode) { OrgType orgTypeStruct = new OrgType(); XmlNode id = orgType.Attributes.GetNamedItem("id"); XmlNode title = orgType.Attributes.GetNamedItem("title"); if (id != null && title != null) { orgTypeStruct.id = int.Parse(id.Value); orgTypeStruct.title = title.Value; } orgTypeList.Add(orgTypeStruct); } totalInfo.orgTypes = orgTypeList; } if (xnode.Name == "currencies") { List <CurrInfo> currInfoList = new List <CurrInfo>(0); foreach (XmlNode curr in xnode) { CurrInfo currInfo = new CurrInfo(); XmlNode eng_id = curr.Attributes.GetNamedItem("id"); XmlNode title = curr.Attributes.GetNamedItem("title"); if (eng_id != null && title != null) { currInfo.eng_id = eng_id.Value; currInfo.title = title.Value; //db.InsertIntoWithValues("curr_info", new List<String> { "eng_title", "rus_title" }, // new List<String> { eng_id.Value, title.Value }); } currInfoList.Add(currInfo); } totalInfo.currenciesInfo = currInfoList; } if (xnode.Name == "regions") { List <Region> regList = new List <Region>(0); foreach (XmlNode reg in xnode) { Region regStruct = new Region(); XmlNode region_id = reg.Attributes.GetNamedItem("id"); XmlNode title = reg.Attributes.GetNamedItem("title"); if (region_id != null && title != null) { regStruct.region_id = region_id.Value; regStruct.title = title.Value; //db.InsertIntoWithValues("region", // new List<String> { "region_id" , "title" }, // new List<String> { region_id.Value, title.Value }); } regList.Add(regStruct); } totalInfo.regions = regList; } if (xnode.Name == "cities") { List <City> cityList = new List <City>(0); foreach (XmlNode city in xnode) { City cityStruct = new City(); XmlNode city_id = city.Attributes.GetNamedItem("id"); XmlNode title = city.Attributes.GetNamedItem("title"); if (city_id != null && title != null) { cityStruct.city_id = city_id.Value; cityStruct.title = title.Value; //db.InsertIntoWithValues("city", // new List<String> { "city_id", "title" }, // new List<String> { city_id.Value, title.Value }); } cityList.Add(cityStruct); } totalInfo.cities = cityList; } } return(totalInfo); }