Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Germany

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

German cities and states.

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