1: using System;
2: using System.Collections;
3: using System.Collections.Generic;
4: using System.IO;
5: using System.Linq;
6: using System.Reflection;
7: using System.Xml.Linq;
8:
9: namespace Ia.Cl.Model
10: {
11: ////////////////////////////////////////////////////////////////////////////
12:
13: /// <summary publish="true">
14: /// German cities and states.
15: /// </summary>
16: /// <remarks>
17: /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
18: ///
19: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
20: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
21: ///
22: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24: ///
25: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
26: ///
27: /// Copyright notice: This notice may not be removed or altered from any source distribution.
28: /// </remarks>
29: public class Germany
30: {
31: private static XDocument xd;
32:
33: // <area id="5" name="Bneid Al Gar" arabicName="بنيد القار" latitude="29.3730" longitude="48.0047" zoom="14"/>
34:
35: /// <summary/>
36: public int Id { get; set; }
37: /// <summary/>
38: public string Name { get; set; }
39: /// <summary/>
40: public string ArabicName { get; set; }
41: /// <summary/>
42: public string Latitude { get; set; }
43: /// <summary/>
44: public string Longitude { get; set; }
45: /// <summary/>
46: public int Zoom { get; set; }
47:
48: ////////////////////////////////////////////////////////////////////////////
49:
50: /// <summary>
51: ///
52: /// </summary>
53: public Germany() { }
54:
55: ////////////////////////////////////////////////////////////////////////////
56:
57: /// <summary>
58: ///
59: /// </summary>
60: public Germany(int itu)
61: {
62: Germany country;
63:
64: country = GermanyById(itu);
65:
66: this.Id = country.Id;
67: this.Name = country.Name;
68: this.ArabicName = country.ArabicName;
69: this.Latitude = country.Latitude;
70: this.Longitude = country.Longitude;
71: this.Zoom = country.Zoom;
72: }
73:
74: ////////////////////////////////////////////////////////////////////////////
75:
76: /// <summary>
77: ///
78: /// </summary>
79: public static Germany GermanyById(int id)
80: {
81: Germany kuwaitArea;
82:
83: kuwaitArea = (from q in XDocument.Elements("countryList").Elements("country")
84: where q.Attribute("itu").Value == id.ToString()
85: select new Germany
86: {
87: Id = id,
88: Name = q.Attribute("name").Value,
89: ArabicName = q.Attribute("arabicName").Value,
90: Latitude = q.Attribute("latitude").Value,
91: Longitude = q.Attribute("longitude").Value,
92: Zoom = int.Parse(q.Attribute("zoom").Value)
93: }
94: ).First<Germany>();
95:
96: return kuwaitArea;
97: }
98:
99: ////////////////////////////////////////////////////////////////////////////
100:
101: /// <summary>
102: ///
103: /// </summary>
104: public static SortedList GermanySortedList
105: {
106: get
107: {
108: int id;
109: string name;
110: SortedList sl;
111:
112: sl = new SortedList(300);
113:
114: foreach (XElement xe in XDocument.Elements("kuwait").Elements("province").Elements("city").Elements("area"))
115: {
116: try
117: {
118: id = int.Parse(xe.Parent.Parent.Attribute("id").Value.PadLeft(2, '0') + xe.Parent.Attribute("id").Value.PadLeft(2, '0') + xe.Attribute("id").Value.PadLeft(2, '0'));
119: name = xe.Attribute("name").Value;
120: }
121: catch (Exception)
122: {
123: id = 0;
124: name = null;
125: }
126:
127: sl[id] = name;
128: }
129:
130: return sl;
131: }
132: }
133:
134: ////////////////////////////////////////////////////////////////////////////
135:
136: /// <summary>
137: ///
138: /// </summary>
139: public static List<Germany> GermanyList
140: {
141: get
142: {
143: List<Germany> kuwaitAreaList;
144:
145: kuwaitAreaList = (from q in XDocument.Elements("kuwait").Elements("province").Elements("city").Elements("area")
146: select new Germany
147: {
148: Id = int.Parse(q.Parent.Parent.Attribute("id").Value.PadLeft(2, '0') + q.Parent.Attribute("id").Value.PadLeft(2, '0') + q.Attribute("id").Value.PadLeft(2, '0')),
149: Name = q.Attribute("name").Value,
150: ArabicName = q.Attribute("arabicName").Value,
151: Latitude = (q.Attribute("latitude") != null) ? q.Attribute("latitude").Value : "",
152: Longitude = (q.Attribute("longitude") != null) ? q.Attribute("longitude").Value : "",
153: Zoom = (q.Attribute("zoom") != null) ? int.Parse(q.Attribute("zoom").Value) : 0
154: }
155: ).ToList<Germany>();
156:
157: return kuwaitAreaList;
158: }
159: }
160:
161: ////////////////////////////////////////////////////////////////////////////
162:
163: /// <summary>
164: ///
165: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
166: ///
167: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
168: /// 2. Add "using System.Reflection".
169: /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
170: ///
171: /// </summary>
172:
173: public static XDocument XDocument
174: {
175: get
176: {
177: Assembly _assembly;
178: StreamReader streamReader;
179:
180: xd = null;
181: _assembly = Assembly.GetExecutingAssembly();
182: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Cl.model.country.germany.xml"));
183:
184: try
185: {
186: if (streamReader.Peek() != -1)
187: {
188: xd = System.Xml.Linq.XDocument.Load(streamReader);
189: }
190: }
191: catch (Exception)
192: {
193: }
194: finally
195: {
196: }
197:
198: return xd;
199: }
200: }
201:
202: ////////////////////////////////////////////////////////////////////////////
203: ////////////////////////////////////////////////////////////////////////////
204: }
205: }