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: /// Saudi Arabia provinces, cities, and areas.
15: /// </summary>
16: /// <remarks>
17: /// Copyright © 2023-2024 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 SaudiArabia
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:
38: /// <summary/>
39: public string Name { get; set; }
40:
41: /// <summary/>
42: public string ArabicName { get; set; }
43:
44: /// <summary/>
45: public string Latitude { get; set; }
46:
47: /// <summary/>
48: public string Longitude { get; set; }
49:
50: /// <summary/>
51: public int Zoom { get; set; }
52:
53: ////////////////////////////////////////////////////////////////////////////
54:
55: /// <summary>
56: ///
57: /// </summary>
58: public SaudiArabia() { }
59:
60: ////////////////////////////////////////////////////////////////////////////
61:
62: /// <summary>
63: ///
64: /// </summary>
65: public SaudiArabia(int itu)
66: {
67: SaudiArabia country;
68:
69: country = SaudiArabiaAreaById(itu);
70:
71: this.Id = country.Id;
72: this.Name = country.Name;
73: this.ArabicName = country.ArabicName;
74: this.Latitude = country.Latitude;
75: this.Longitude = country.Longitude;
76: this.Zoom = country.Zoom;
77: }
78:
79: ////////////////////////////////////////////////////////////////////////////
80:
81: /// <summary>
82: ///
83: /// </summary>
84: public static SaudiArabia SaudiArabiaAreaById(int id)
85: {
86: SaudiArabia saudiArabiaArea;
87:
88: saudiArabiaArea = (from q in XDocument.Elements("countryList").Elements("country")
89: where q.Attribute("itu").Value == id.ToString()
90: select new SaudiArabia
91: {
92: Id = id,
93: Name = q.Attribute("name").Value,
94: ArabicName = q.Attribute("arabicName").Value,
95: Latitude = q.Attribute("latitude").Value,
96: Longitude = q.Attribute("longitude").Value,
97: Zoom = int.Parse(q.Attribute("zoom").Value)
98: }
99: ).First<SaudiArabia>();
100:
101: return saudiArabiaArea;
102: }
103:
104: ////////////////////////////////////////////////////////////////////////////
105:
106: /// <summary>
107: ///
108: /// </summary>
109: public static SortedList SaudiArabiaAreaSortedList
110: {
111: get
112: {
113: int id;
114: string name;
115: SortedList sl;
116:
117: sl = new SortedList(300);
118:
119: foreach (XElement xe in XDocument.Elements("saudiArabia").Elements("province").Elements("city").Elements("area"))
120: {
121: try
122: {
123: 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'));
124: name = xe.Attribute("name").Value;
125: }
126: catch (Exception)
127: {
128: id = 0;
129: name = null;
130: }
131:
132: sl[id] = name;
133: }
134:
135: return sl;
136: }
137: }
138:
139: ////////////////////////////////////////////////////////////////////////////
140:
141: /// <summary>
142: ///
143: /// </summary>
144: public static List<SaudiArabia> SaudiArabiaAreaList
145: {
146: get
147: {
148: List<SaudiArabia> saudiArabiaAreaList;
149:
150: saudiArabiaAreaList = (from q in XDocument.Elements("saudiArabia").Elements("province").Elements("city").Elements("area")
151: select new SaudiArabia
152: {
153: 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')),
154: Name = q.Attribute("name").Value,
155: ArabicName = q.Attribute("arabicName").Value,
156: Latitude = (q.Attribute("latitude") != null) ? q.Attribute("latitude").Value : "",
157: Longitude = (q.Attribute("longitude") != null) ? q.Attribute("longitude").Value : "",
158: Zoom = (q.Attribute("zoom") != null) ? int.Parse(q.Attribute("zoom").Value) : 0
159: }
160: ).ToList<SaudiArabia>();
161:
162: return saudiArabiaAreaList;
163: }
164: }
165:
166: ////////////////////////////////////////////////////////////////////////////
167:
168: /// <summary>
169: ///
170: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
171: ///
172: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
173: /// 2. Add "using System.Reflection".
174: /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
175: ///
176: /// </summary>
177:
178: public static XDocument XDocument
179: {
180: get
181: {
182: Assembly _assembly;
183: StreamReader streamReader;
184:
185: xd = null;
186: _assembly = Assembly.GetExecutingAssembly();
187: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Cl.model.country.saudi-arabia.xml"));
188:
189: try
190: {
191: if (streamReader.Peek() != -1)
192: {
193: xd = System.Xml.Linq.XDocument.Load(streamReader);
194: }
195: }
196: catch (Exception)
197: {
198: }
199: finally
200: {
201: }
202:
203: return xd;
204: }
205: }
206:
207: ////////////////////////////////////////////////////////////////////////////
208: ////////////////////////////////////////////////////////////////////////////
209: }
210: }