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

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

Service Request support class of Next Generation Network'a (NGN's) business model.

   1:  using System.Collections.Generic;
   2:  using System.Linq;
   3:  using System.Text.RegularExpressions;
   4:  using System.Data;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Business
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Service Request support class of Next Generation Network'a (NGN's) business model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class ServiceRequest
  28:      {
  29:          /// <summary/>
  30:          public ServiceRequest() { }
  31:   
  32:          public const string ServiceRequestCustomerIdInputTypeString = "serviceRequestCustomerId";
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////    
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public struct NumberSerial
  40:          {
  41:              public long Id
  42:              {
  43:                  get { return (long)Number * 100 + Serial; }
  44:              }
  45:              public int Number { get; set; }
  46:              public int Serial { get; set; }
  47:          }
  48:   
  49:          ////////////////////////////////////////////////////////////////////////////
  50:   
  51:          /// <summary>
  52:          ///
  53:          /// </summary>
  54:          public static Ia.Ngn.Cl.Model.Business.ServiceAddress StatisticalServiceAddress(string service, string customerAddress, out string level)
  55:          {
  56:              string provinceArea;
  57:              Match match;
  58:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
  59:   
  60:              serviceAddress = new ServiceAddress();
  61:   
  62:              serviceAddress.Service = service;
  63:   
  64:              if (customerAddress != null)
  65:              {
  66:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddress(customerAddress);
  67:   
  68:                  // below: special handeling needed here
  69:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddressMissingProvinceArea(service, customerAddress);
  70:   
  71:                  // ',قطعة 4 قسيمة 538,'
  72:                  // below:
  73:                  // (.+),قطعة
  74:                  // ? entries
  75:                  match = Regex.Match(customerAddress, @"^(.+),قطعة", RegexOptions.Singleline);
  76:   
  77:                  if (match.Success)
  78:                  {
  79:                      level = "1";
  80:   
  81:                      provinceArea = match.Groups[1].Value;
  82:                      serviceAddress.AreaId = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where provinceArea == a.ServiceRequestAddressProvinceAreaName select a.Id).SingleOrDefault();
  83:                  }
  84:                  else
  85:                  {
  86:                      serviceAddress.AreaId = 0;
  87:                  }
  88:   
  89:                  // below:
  90:                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5 قسيمة 17, منزل 17
  91:                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
  92:   
  93:                  if (match.Success)
  94:                  {
  95:                      level = "1-";
  96:   
  97:                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  98:                      serviceAddress.Street = match.Groups[3].Value;
  99:                      serviceAddress.Boulevard = match.Groups[4].Value;
 100:                      serviceAddress.PremisesOld = match.Groups[5].Value;
 101:                      serviceAddress.PremisesNew = match.Groups[6].Value;
 102:                  }
 103:                  else
 104:                  {
 105:                      level = "2";
 106:   
 107:                      // below:
 108:                      // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17, منزل 17
 109:                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 110:   
 111:                      if (match.Success)
 112:                      {
 113:                          level = "2-";
 114:   
 115:                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 116:                          serviceAddress.Street = match.Groups[3].Value;
 117:                          serviceAddress.Boulevard = null;
 118:                          serviceAddress.PremisesOld = match.Groups[4].Value;
 119:                          serviceAddress.PremisesNew = match.Groups[5].Value;
 120:                      }
 121:                      else
 122:                      {
 123:                          level = "3";
 124:   
 125:                          // below:
 126:                          // الجهراء الجهراء المدينة,قطعة 79 شارع 5, منزل 17
 127:                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+), منزل (.+)$", RegexOptions.Singleline);
 128:   
 129:                          if (match.Success)
 130:                          {
 131:                              level = "3-";
 132:   
 133:                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 134:                              serviceAddress.Street = match.Groups[3].Value;
 135:                              serviceAddress.Boulevard = null;
 136:                              serviceAddress.PremisesOld = null;
 137:                              serviceAddress.PremisesNew = match.Groups[4].Value;
 138:                          }
 139:                          else
 140:                          {
 141:                              level = "4";
 142:   
 143:                              // below:
 144:                              // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17
 145:                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+),$", RegexOptions.Singleline);
 146:   
 147:                              if (match.Success)
 148:                              {
 149:                                  level = "4-";
 150:   
 151:                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 152:                                  serviceAddress.Street = match.Groups[3].Value;
 153:                                  serviceAddress.Boulevard = null;
 154:                                  serviceAddress.PremisesOld = match.Groups[4].Value;
 155:                                  serviceAddress.PremisesNew = null;
 156:                              }
 157:                              else
 158:                              {
 159:                                  level = "5";
 160:   
 161:                                  // below:
 162:                                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5
 163:                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+),$", RegexOptions.Singleline);
 164:   
 165:                                  if (match.Success)
 166:                                  {
 167:                                      level = "5-";
 168:   
 169:                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 170:                                      serviceAddress.Street = match.Groups[3].Value;
 171:                                      serviceAddress.Boulevard = match.Groups[4].Value;
 172:                                      serviceAddress.PremisesOld = null;
 173:                                      serviceAddress.PremisesNew = null;
 174:                                  }
 175:                                  else
 176:                                  {
 177:                                      level = "6";
 178:   
 179:                                      // below:
 180:                                      // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17, منزل 17
 181:                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 182:   
 183:                                      if (match.Success)
 184:                                      {
 185:                                          level = "6-";
 186:   
 187:                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 188:                                          serviceAddress.Street = null;
 189:                                          serviceAddress.Boulevard = null;
 190:                                          serviceAddress.PremisesOld = match.Groups[3].Value;
 191:                                          serviceAddress.PremisesNew = match.Groups[4].Value;
 192:                                      }
 193:                                      else
 194:                                      {
 195:                                          level = "7";
 196:   
 197:                                          // below:
 198:                                          // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17
 199:                                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+),$", RegexOptions.Singleline);
 200:   
 201:                                          if (match.Success)
 202:                                          {
 203:                                              level = "7-";
 204:   
 205:                                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 206:                                              serviceAddress.Street = null;
 207:                                              serviceAddress.Boulevard = null;
 208:                                              serviceAddress.PremisesOld = match.Groups[3].Value;
 209:                                              serviceAddress.PremisesNew = null;
 210:                                          }
 211:                                          else
 212:                                          {
 213:                                              level = "8";
 214:   
 215:                                              // below:
 216:                                              // الجهراء الجهراء المدينة,قطعة 79, منزل 17
 217:                                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+), منزل (.+)$", RegexOptions.Singleline);
 218:   
 219:                                              if (match.Success)
 220:                                              {
 221:                                                  level = "8-";
 222:   
 223:                                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 224:                                                  serviceAddress.Street = null;
 225:                                                  serviceAddress.Boulevard = null;
 226:                                                  serviceAddress.PremisesOld = null;
 227:                                                  serviceAddress.PremisesNew = match.Groups[3].Value;
 228:                                              }
 229:                                              else
 230:                                              {
 231:                                                  level = "9";
 232:   
 233:                                                  // below:
 234:                                                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5
 235:                                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+)$", RegexOptions.Singleline);
 236:   
 237:                                                  if (match.Success)
 238:                                                  {
 239:                                                      level = "9-";
 240:   
 241:                                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 242:                                                      serviceAddress.Street = match.Groups[3].Value;
 243:                                                      serviceAddress.Boulevard = null;
 244:                                                      serviceAddress.PremisesOld = null;
 245:                                                      serviceAddress.PremisesNew = null;
 246:                                                  }
 247:                                                  else
 248:                                                  {
 249:                                                      level = "10";
 250:   
 251:                                                      // below:
 252:                                                      // الجهراء الجهراء المدينة,قطعة 79
 253:                                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+),$", RegexOptions.Singleline);
 254:   
 255:                                                      if (match.Success)
 256:                                                      {
 257:                                                          level = "10-";
 258:   
 259:                                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 260:                                                          serviceAddress.Street = null;
 261:                                                          serviceAddress.Boulevard = null;
 262:                                                          serviceAddress.PremisesOld = null;
 263:                                                          serviceAddress.PremisesNew = null;
 264:                                                      }
 265:                                                      else
 266:                                                      {
 267:                                                          level = "11";
 268:                                                      }
 269:                                                  }
 270:                                              }
 271:                                          }
 272:                                      }
 273:                                  }
 274:                              }
 275:                          }
 276:                      }
 277:                  }
 278:   
 279:                  // below: we will try to store integers in integer format
 280:   
 281:                  //serviceAddress.Block this is already in int format
 282:                  serviceAddress.Street = int.TryParse(serviceAddress.Street, out int i) ? i.ToString() : serviceAddress.Street;
 283:                  serviceAddress.Boulevard = int.TryParse(serviceAddress.Boulevard, out i) ? i.ToString() : serviceAddress.Boulevard;
 284:                  serviceAddress.PremisesOld = int.TryParse(serviceAddress.PremisesOld, out i) ? i.ToString() : serviceAddress.PremisesOld;
 285:                  serviceAddress.PremisesNew = int.TryParse(serviceAddress.PremisesNew, out i) ? i.ToString() : serviceAddress.PremisesNew;
 286:              }
 287:              else
 288:              {
 289:                  level = "0";
 290:   
 291:                  serviceAddress.AreaId = 0;
 292:              }
 293:   
 294:              return serviceAddress;
 295:          }
 296:   
 297:          ////////////////////////////////////////////////////////////////////////////    
 298:      }
 299:   
 300:      ////////////////////////////////////////////////////////////////////////////    
 301:      ////////////////////////////////////////////////////////////////////////////
 302:   
 303:      /// <summary>
 304:      ///
 305:      /// </summary>
 306:      public static class ServiceRequestExtension
 307:      {
 308:          ////////////////////////////////////////////////////////////////////////////
 309:   
 310:          /// <summary>
 311:          /// Extension method: Collect distinct numbers Number list
 312:          /// </summary>
 313:          public static List<int> DistinctNumberList(this List<Ia.Ngn.Cl.Model.ServiceRequest> sourceList)
 314:          {
 315:              List<int> numberList;
 316:   
 317:              numberList = (from n in sourceList select n.Number).Distinct().ToList<int>();
 318:   
 319:              return numberList;
 320:          }
 321:   
 322:          ////////////////////////////////////////////////////////////////////////////
 323:   
 324:          /// <summary>
 325:          /// Extension method: Collect distinct number-serials into NumberSerial list
 326:          /// </summary>
 327:          public static List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> DistinctNumberSerialList(this List<Ia.Ngn.Cl.Model.ServiceRequest> sourceList)
 328:          {
 329:              List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList;
 330:   
 331:              numberSerialList = (from n in sourceList select new Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial { Number = n.Number, Serial = n.Serial }).Distinct().ToList();
 332:   
 333:              return numberSerialList;
 334:          }
 335:   
 336:          ////////////////////////////////////////////////////////////////////////////
 337:          ////////////////////////////////////////////////////////////////////////////
 338:      }
 339:   
 340:      ////////////////////////////////////////////////////////////////////////////
 341:      ////////////////////////////////////////////////////////////////////////////
 342:  }