)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Kuwait (Ia.Cl.Model)

Public general use code classes and xml files that we've compiled and used over the years:

Kuwait provinces, cities, and areas.

    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:     /// Kuwait provinces, cities, and areas.
   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 Kuwait
   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 Kuwait() { }
   59:  
   60:         ////////////////////////////////////////////////////////////////////////////
   61:  
   62:         /// <summary>
   63:         /// 
   64:         /// </summary>
   65:         public Kuwait(int itu)
   66:         {
   67:             Kuwait country;
   68:  
   69:             country = KuwaitAreaById(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 Kuwait KuwaitAreaById(int id)
   85:         {
   86:             Kuwait kuwaitArea;
   87:  
   88:             kuwaitArea = (from q in XDocument.Elements("countryList").Elements("country")
   89:                           where q.Attribute("itu").Value == id.ToString()
   90:                           select new Kuwait
   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<Kuwait>();
  100:  
  101:             return kuwaitArea;
  102:         }
  103:  
  104:         ////////////////////////////////////////////////////////////////////////////
  105:  
  106:         /// <summary>
  107:         ///
  108:         /// </summary>
  109:         public static SortedList KuwaitAreaSortedList
  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("kuwait").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<Kuwait> KuwaitAreaList
  145:         {
  146:             get
  147:             {
  148:                 List<Kuwait> kuwaitAreaList;
  149:  
  150:                 kuwaitAreaList = (from q in XDocument.Elements("kuwait").Elements("province").Elements("city").Elements("area")
  151:                                   select new Kuwait
  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<Kuwait>();
  161:  
  162:                 return kuwaitAreaList;
  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.kuwait.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: }