شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

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 Optical Fiber Network (OFN) business model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Globalization;
   5:  using System.Linq;
   6:  using System.Text.RegularExpressions;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Business
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Service Request support class of Optical Fiber Network (OFN) business model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2020 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 ServiceRequest
  30:      {
  31:          /// <summary/>
  32:          public ServiceRequest() { }
  33:   
  34:          private static int sequentialProvisioningWorkflowQueueOriginalCount;
  35:          private static Dictionary<string, DateTime> provisioningWorkflowServiceIdDateTimeDictionary = new Dictionary<string, DateTime>();
  36:          private static Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>();
  37:   
  38:          /// <summary/>
  39:          public enum Procedure { Create, Read, Update, Delete, None };
  40:   
  41:          /// <summary/>
  42:          public struct ProvisioningWorkflow<T>
  43:          {
  44:              /// <summary/>
  45:              public T Item { get; set; }
  46:   
  47:              /// <summary/>
  48:              public Procedure Procedure { get; set; }
  49:   
  50:              /// <summary/>
  51:              public DateTime DateTime { get; set; }
  52:          }
  53:   
  54:          ////////////////////////////////////////////////////////////////////////////    
  55:   
  56:          /// <summary>
  57:          ///
  58:          /// </summary>
  59:          public struct NumberSerial
  60:          {
  61:              public long Id
  62:              {
  63:                  get { return (long)Number * 100 + Serial; }
  64:              }
  65:              public int Number { get; set; }
  66:              public int Serial { get; set; }
  67:          }
  68:   
  69:          ////////////////////////////////////////////////////////////////////////////    
  70:          ////////////////////////////////////////////////////////////////////////////    
  71:   
  72:          /// <summary>
  73:          ///
  74:          /// </summary>
  75:          public static string OracleSqlCommandForServiceRequestIdRange(Tuple<int, int> startEndRange)
  76:          {
  77:              return OracleSqlCommandForServiceRequestIdRange(startEndRange.Item1, startEndRange.Item2);
  78:          }
  79:   
  80:          ////////////////////////////////////////////////////////////////////////////    
  81:   
  82:          /// <summary>
  83:          ///
  84:          /// </summary>
  85:          public static string OracleSqlCommandForServiceRequestIdRange(int start, int end)
  86:          {
  87:              string sql;
  88:   
  89:              // select * from SRV_REQ_FIPER where SRV_REQ_ID >= 110000 and SRV_REQ_ID <= 110200 order by SRV_REQ_ID asc
  90:              sql = @"select * from SRV_REQ_FIPER where SRV_REQ_ID >= " + start + " and SRV_REQ_ID <= " + end + " order by SRV_REQ_ID asc";
  91:   
  92:              return sql;
  93:          }
  94:   
  95:          ////////////////////////////////////////////////////////////////////////////    
  96:   
  97:          /// <summary>
  98:          ///
  99:          /// </summary>
 100:          public static string OracleSqlCommandForServiceRequest(string service)
 101:          {
 102:              string sql;
 103:   
 104:              if (!string.IsNullOrEmpty(service))
 105:              {
 106:                  // select * from SRV_REQ_FIPER where SRV_NO = 23632222 order by SRV_REQ_ID asc
 107:                  sql = @"select * from SRV_REQ_FIPER where SRV_NO = " + service + " order by SRV_REQ_ID asc";
 108:              }
 109:              else sql = string.Empty;
 110:   
 111:              return sql;
 112:          }
 113:   
 114:          ////////////////////////////////////////////////////////////////////////////    
 115:   
 116:          /// <summary>
 117:          ///
 118:          /// </summary>
 119:          private static string OracleSqlCommandForGivenDateTime(DateTime dateTime)
 120:          {
 121:              string sql;
 122:   
 123:              //sql = @"select * from SRV_REQ_FIPER LEFT OUTER JOIN SRV_REQ_FIPER_TECH ON SRV_REQ_FIPER_TECH.SRV_REQ_ID = SRV_REQ_FIPER.SRV_REQ_ID where REQ_DATE >= '" + dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' and REQ_DATE < '" + dateTime.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' order by REQ_DATE asc, SRV_REQ_ID asc";
 124:              sql = @"select * from SRV_REQ_FIPER where REQ_DATE >= '" + dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' and REQ_DATE < '" + dateTime.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' order by SRV_REQ_ID asc";
 125:   
 126:              return sql;
 127:          }
 128:   
 129:          ////////////////////////////////////////////////////////////////////////////    
 130:   
 131:          /// <summary>
 132:          ///
 133:          /// </summary>
 134:          private static string OracleSqlCommandForSingleRandomDateTimeWithinTheLastNDays(int rangeOfPastDays, out DateTime selectedDate)
 135:          {
 136:              // below:
 137:              int i;
 138:              string sql;
 139:   
 140:              i = Ia.Cl.Model.Default.Random(rangeOfPastDays);
 141:   
 142:              selectedDate = DateTime.UtcNow.AddDays(-i);
 143:   
 144:              sql = OracleSqlCommandForGivenDateTime(selectedDate);
 145:   
 146:              return sql;
 147:          }
 148:   
 149:          ////////////////////////////////////////////////////////////////////////////    
 150:   
 151:          /// <summary>
 152:          ///
 153:          /// </summary>
 154:          private static string OracleSqlCommandForSingleDateTimeUsingDayIndexBetweenNowAndEarliestDate(ref int index, out DateTime selectedDate)
 155:          {
 156:              // below: select a date between now and the earliest date using an variable index value
 157:              string sql;
 158:              DateTime now;
 159:   
 160:              now = DateTime.UtcNow.AddHours(3);
 161:   
 162:              // below: check that inIndex is an index of a day between earliest day and now, and reset it to 0 if it is bigger than now
 163:              if (DateTime.Compare(Ia.Ngn.Cl.Model.Business.Administration.EarliestServiceRequestDate.AddDays(index), now) < 0)
 164:              {
 165:                  // below: within range
 166:              }
 167:              else index = 0;
 168:   
 169:              selectedDate = Ia.Ngn.Cl.Model.Business.Administration.EarliestServiceRequestDate.AddDays(index++);
 170:   
 171:              sql = OracleSqlCommandForGivenDateTime(selectedDate);
 172:   
 173:              return sql;
 174:          }
 175:   
 176:          ////////////////////////////////////////////////////////////////////////////
 177:          ////////////////////////////////////////////////////////////////////////////
 178:   
 179:          /// <summary>
 180:          ///
 181:          /// </summary>
 182:          public static ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> SequentialProvisioningWorkflowOfOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseListItem(out int sequentialProvisioningWorkflowQueueCount, out string progressCounterString)
 183:          {
 184:              ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> pw;
 185:              List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> list;
 186:   
 187:              if (sequentialProvisioningWorkflowQueue.Count == 0)
 188:              {
 189:                  list = Ia.Ngn.Cl.Model.Business.ServiceRequest.ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList;
 190:   
 191:                  sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>(list);
 192:   
 193:                  sequentialProvisioningWorkflowQueueOriginalCount = sequentialProvisioningWorkflowQueue.Count;
 194:              }
 195:   
 196:              if (sequentialProvisioningWorkflowQueue.Count > 0) pw = sequentialProvisioningWorkflowQueue.Dequeue();
 197:              else pw = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = null, Procedure = Procedure.None };
 198:   
 199:              progressCounterString = "(" + sequentialProvisioningWorkflowQueue.Count + "/" + sequentialProvisioningWorkflowQueueOriginalCount + ")";
 200:   
 201:              sequentialProvisioningWorkflowQueueCount = sequentialProvisioningWorkflowQueue.Count;
 202:   
 203:              return pw;
 204:          }
 205:   
 206:          ////////////////////////////////////////////////////////////////////////////
 207:   
 208:          /// <summary>
 209:          ///
 210:          /// </summary>
 211:          public static List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList
 212:          {
 213:              get
 214:              {
 215:                  DateTime dateTime;
 216:                  ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> provisioningWorkflow;
 217:                  List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> provisioningWorkflowList;
 218:   
 219:                  dateTime = DateTime.UtcNow.AddHours(3);
 220:   
 221:                  provisioningWorkflowList = new List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>();
 222:   
 223:                  Ia.Ngn.Cl.Model.Data.ServiceRequestOntDetail.ServiceRequestOntDetailCreateAndDeleteList(out List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, out List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailDeleteList);
 224:   
 225:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailCreateList)
 226:                  {
 227:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Create, DateTime = dateTime };
 228:                      provisioningWorkflowList.Add(provisioningWorkflow);
 229:   
 230:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
 231:                      provisioningWorkflowList.Add(provisioningWorkflow);
 232:                  }
 233:   
 234:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailDeleteList)
 235:                  {
 236:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Delete, DateTime = dateTime };
 237:                      provisioningWorkflowList.Add(provisioningWorkflow);
 238:   
 239:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
 240:                      provisioningWorkflowList.Add(provisioningWorkflow);
 241:                  }
 242:   
 243:                  return provisioningWorkflowList;
 244:              }
 245:          }
 246:   
 247:          ////////////////////////////////////////////////////////////////////////////
 248:          ////////////////////////////////////////////////////////////////////////////
 249:   
 250:          /// <summary>
 251:          ///
 252:          /// </summary>
 253:          public static Ia.Ngn.Cl.Model.Business.ServiceAddress ServiceAddress(string service, string customerAddress, out string level)
 254:          {
 255:              int areaId;
 256:              string provinceArea;
 257:              Match match;
 258:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
 259:   
 260:              serviceAddress = new ServiceAddress { Service = service };
 261:   
 262:              if (!string.IsNullOrEmpty(customerAddress))
 263:              {
 264:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddress(customerAddress);
 265:   
 266:                  // below: special handeling needed here
 267:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddressMissingProvinceArea(service, customerAddress);
 268:   
 269:                  // ',قطعة 4 قسيمة 538,'
 270:                  // get areaId only
 271:                  match = Regex.Match(customerAddress, @"^(.+?),", RegexOptions.Singleline);
 272:   
 273:                  if (match.Success)
 274:                  {
 275:                      level = "1";
 276:   
 277:                      provinceArea = match.Groups[1].Value;
 278:                      areaId = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitOfnAreaList 
 279:                                where provinceArea == a.ServiceRequestAddressProvinceAreaName 
 280:                                select a.Id).SingleOrDefault();
 281:   
 282:                      if (areaId != 0)
 283:                      {
 284:                          serviceAddress.AreaId = areaId;
 285:   
 286:                          // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5 قسيمة 17, منزل 17
 287:                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 288:   
 289:                          if (match.Success)
 290:                          {
 291:                              level = "1-";
 292:   
 293:                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 294:                              serviceAddress.Street = match.Groups[3].Value;
 295:                              serviceAddress.Boulevard = match.Groups[4].Value;
 296:                              serviceAddress.PremisesOld = match.Groups[5].Value;
 297:                              serviceAddress.PremisesNew = match.Groups[6].Value;
 298:                          }
 299:                          else
 300:                          {
 301:                              // حولى بيان,قطعة 12 شارع 1 جادة 9, منزل 38
 302:                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+), منزل (.+)$", RegexOptions.Singleline);
 303:   
 304:                              if (match.Success)
 305:                              {
 306:                                  level = "2-";
 307:   
 308:                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 309:                                  serviceAddress.Street = match.Groups[3].Value;
 310:                                  serviceAddress.Boulevard = match.Groups[4].Value;
 311:                                  serviceAddress.PremisesOld = match.Groups[5].Value;
 312:                                  serviceAddress.PremisesNew = match.Groups[6].Value;
 313:                              }
 314:                              else
 315:                              {
 316:                                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17, منزل 17
 317:                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 318:   
 319:                                  if (match.Success)
 320:                                  {
 321:                                      level = "3-";
 322:   
 323:                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 324:                                      serviceAddress.Street = match.Groups[3].Value;
 325:                                      serviceAddress.Boulevard = string.Empty;
 326:                                      serviceAddress.PremisesOld = match.Groups[4].Value;
 327:                                      serviceAddress.PremisesNew = match.Groups[5].Value;
 328:                                  }
 329:                                  else
 330:                                  {
 331:                                      // الجهراء الجهراء المدينة,قطعة 79 شارع 5, منزل 17
 332:                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+), منزل (.+)$", RegexOptions.Singleline);
 333:   
 334:                                      if (match.Success)
 335:                                      {
 336:                                          level = "4-";
 337:   
 338:                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 339:                                          serviceAddress.Street = match.Groups[3].Value;
 340:                                          serviceAddress.Boulevard = string.Empty;
 341:                                          serviceAddress.PremisesOld = string.Empty;
 342:                                          serviceAddress.PremisesNew = match.Groups[4].Value;
 343:                                      }
 344:                                      else
 345:                                      {
 346:                                          // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17
 347:                                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+),$", RegexOptions.Singleline);
 348:   
 349:                                          if (match.Success)
 350:                                          {
 351:                                              level = "5-";
 352:   
 353:                                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 354:                                              serviceAddress.Street = match.Groups[3].Value;
 355:                                              serviceAddress.Boulevard = string.Empty;
 356:                                              serviceAddress.PremisesOld = match.Groups[4].Value;
 357:                                              serviceAddress.PremisesNew = string.Empty;
 358:                                          }
 359:                                          else
 360:                                          {
 361:                                              // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5
 362:                                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+),$", RegexOptions.Singleline);
 363:   
 364:                                              if (match.Success)
 365:                                              {
 366:                                                  level = "6-";
 367:   
 368:                                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 369:                                                  serviceAddress.Street = match.Groups[3].Value;
 370:                                                  serviceAddress.Boulevard = match.Groups[4].Value;
 371:                                                  serviceAddress.PremisesOld = string.Empty;
 372:                                                  serviceAddress.PremisesNew = string.Empty;
 373:                                              }
 374:                                              else
 375:                                              {
 376:                                                  // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17, منزل 17
 377:                                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 378:   
 379:                                                  if (match.Success)
 380:                                                  {
 381:                                                      level = "7-";
 382:   
 383:                                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 384:                                                      serviceAddress.Street = string.Empty;
 385:                                                      serviceAddress.Boulevard = string.Empty;
 386:                                                      serviceAddress.PremisesOld = match.Groups[3].Value;
 387:                                                      serviceAddress.PremisesNew = match.Groups[4].Value;
 388:                                                  }
 389:                                                  else
 390:                                                  {
 391:                                                      // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17
 392:                                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+),$", RegexOptions.Singleline);
 393:   
 394:                                                      if (match.Success)
 395:                                                      {
 396:                                                          level = "8-";
 397:   
 398:                                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 399:                                                          serviceAddress.Street = string.Empty;
 400:                                                          serviceAddress.Boulevard = string.Empty;
 401:                                                          serviceAddress.PremisesOld = match.Groups[3].Value;
 402:                                                          serviceAddress.PremisesNew = string.Empty;
 403:                                                      }
 404:                                                      else
 405:                                                      {
 406:                                                          // الجهراء الجهراء المدينة,قطعة 79, منزل 17
 407:                                                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+), منزل (.+)$", RegexOptions.Singleline);
 408:   
 409:                                                          if (match.Success)
 410:                                                          {
 411:                                                              level = "9-";
 412:   
 413:                                                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 414:                                                              serviceAddress.Street = string.Empty;
 415:                                                              serviceAddress.Boulevard = string.Empty;
 416:                                                              serviceAddress.PremisesOld = string.Empty;
 417:                                                              serviceAddress.PremisesNew = match.Groups[3].Value;
 418:                                                          }
 419:                                                          else
 420:                                                          {
 421:                                                              // الجهراء الجهراء المدينة,قطعة 79 شارع 5
 422:                                                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+)$", RegexOptions.Singleline);
 423:   
 424:                                                              if (match.Success)
 425:                                                              {
 426:                                                                  level = "10-";
 427:   
 428:                                                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 429:                                                                  serviceAddress.Street = match.Groups[3].Value;
 430:                                                                  serviceAddress.Boulevard = string.Empty;
 431:                                                                  serviceAddress.PremisesOld = string.Empty;
 432:                                                                  serviceAddress.PremisesNew = string.Empty;
 433:                                                              }
 434:                                                              else
 435:                                                              {
 436:                                                                  // الجهراء الجهراء المدينة,قطعة 79
 437:                                                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+),$", RegexOptions.Singleline);
 438:   
 439:                                                                  if (match.Success)
 440:                                                                  {
 441:                                                                      level = "11-";
 442:   
 443:                                                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 444:                                                                      serviceAddress.Street = string.Empty;
 445:                                                                      serviceAddress.Boulevard = string.Empty;
 446:                                                                      serviceAddress.PremisesOld = string.Empty;
 447:                                                                      serviceAddress.PremisesNew = string.Empty;
 448:                                                                  }
 449:                                                                  else
 450:                                                                  {
 451:                                                                      // حولي السلام,,
 452:                                                                      match = Regex.Match(customerAddress, @"^(.+),,$", RegexOptions.Singleline);
 453:   
 454:                                                                      if (match.Success)
 455:                                                                      {
 456:                                                                          level = "12-";
 457:   
 458:                                                                          serviceAddress.Block = string.Empty;
 459:                                                                          serviceAddress.Street = string.Empty;
 460:                                                                          serviceAddress.Boulevard = string.Empty;
 461:                                                                          serviceAddress.PremisesOld = string.Empty;
 462:                                                                          serviceAddress.PremisesNew = string.Empty;
 463:                                                                      }
 464:                                                                      else
 465:                                                                      {
 466:                                                                          level = "13";
 467:                                                                      }
 468:                                                                  }
 469:                                                              }
 470:                                                          }
 471:                                                      }
 472:                                                  }
 473:                                              }
 474:                                          }
 475:                                      }
 476:                                  }
 477:                              }
 478:                          }
 479:   
 480:                          // below: we will try to store integers in integer format
 481:   
 482:                          //serviceAddress.Block this is already in int format
 483:                          serviceAddress.Street = int.TryParse(serviceAddress.Street, out int i) ? i.ToString() : serviceAddress.Street;
 484:                          serviceAddress.Boulevard = int.TryParse(serviceAddress.Boulevard, out i) ? i.ToString() : serviceAddress.Boulevard;
 485:                          serviceAddress.PremisesOld = int.TryParse(serviceAddress.PremisesOld, out i) ? i.ToString() : serviceAddress.PremisesOld;
 486:                          serviceAddress.PremisesNew = int.TryParse(serviceAddress.PremisesNew, out i) ? i.ToString() : serviceAddress.PremisesNew;
 487:   
 488:                          // I will change all 0 entries to string.Empty
 489:   
 490:                          if (serviceAddress.Block == "0") serviceAddress.Block = string.Empty;
 491:                          if (serviceAddress.Street == "0") serviceAddress.Street = string.Empty;
 492:                          if (serviceAddress.Boulevard == "0") serviceAddress.Boulevard = string.Empty;
 493:                          if (serviceAddress.PremisesOld == "0") serviceAddress.PremisesOld = string.Empty;
 494:                          if (serviceAddress.PremisesNew == "0") serviceAddress.PremisesNew = string.Empty;
 495:                      }
 496:                      else
 497:                      {
 498:                          level = "0";
 499:   
 500:                          serviceAddress.AreaId = 0;
 501:                          serviceAddress.Block = string.Empty;
 502:                          serviceAddress.Street = string.Empty;
 503:                          serviceAddress.Boulevard = string.Empty;
 504:                          serviceAddress.PremisesOld = string.Empty;
 505:                          serviceAddress.PremisesNew = string.Empty;
 506:                      }
 507:                  }
 508:                  else
 509:                  {
 510:                      level = "0";
 511:   
 512:                      serviceAddress.AreaId = 0;
 513:                      serviceAddress.Block = string.Empty;
 514:                      serviceAddress.Street = string.Empty;
 515:                      serviceAddress.Boulevard = string.Empty;
 516:                      serviceAddress.PremisesOld = string.Empty;
 517:                      serviceAddress.PremisesNew = string.Empty;
 518:                  }
 519:              }
 520:              else
 521:              {
 522:                  level = "0";
 523:   
 524:                  serviceAddress.AreaId = 0;
 525:                  serviceAddress.Block = string.Empty;
 526:                  serviceAddress.Street = string.Empty;
 527:                  serviceAddress.Boulevard = string.Empty;
 528:                  serviceAddress.PremisesOld = string.Empty;
 529:                  serviceAddress.PremisesNew = string.Empty;
 530:              }
 531:   
 532:              return serviceAddress;
 533:          }
 534:   
 535:          ////////////////////////////////////////////////////////////////////////////    
 536:   
 537:          /// <summary>
 538:          ///
 539:          /// </summary>
 540:          public static bool ServiceRequestIdIsAllowedForProcessing(int serviceRequestId)
 541:          {
 542:              bool b;
 543:   
 544:              // see ServiceRequestIsAllowedProcessing in authority.cs
 545:   
 546:              if (serviceRequestId == 2390979) b = false; // Violation of PRIMARY KEY constraint 'PK_dbo.ServiceRequests'. Cannot insert duplicate key in object 'dbo.ServiceRequests'. The duplicate key value is (2390979).
 547:              else if (serviceRequestId == 2391097) b = false; // Violation of PRIMARY KEY constraint 'PK_dbo.ServiceRequests'. Cannot insert duplicate key in object 'dbo.ServiceRequests'. The duplicate key value is (2391097).
 548:              //else if (serviceRequestId == 2316113) b = false; // 2316113 problamatic causes duplicate primary key error
 549:              else b = true;
 550:   
 551:              return b;
 552:          }
 553:   
 554:          ////////////////////////////////////////////////////////////////////////////
 555:   
 556:          /// <summary>
 557:          /// Generate a OptimizedStartEndRangeList() but with a range buffer before start and after end.
 558:          /// </summary>
 559:          public static List<Tuple<int, int>> OptimizedStartEndRangeBufferedList(List<int> list, int count, int bufferRange)
 560:          {
 561:              int start, end;
 562:              List<Tuple<int, int>> tupleList;
 563:   
 564:              tupleList = OptimizedStartEndRangeTupleList(list, count);
 565:   
 566:              if (tupleList != null && tupleList.Count > 0)
 567:              {
 568:                  start = tupleList[0].Item1;
 569:                  end = tupleList[tupleList.Count - 1].Item2;
 570:   
 571:                  tupleList.Insert(tupleList.Count, new Tuple<int, int>(end + 1, end + bufferRange + 1));
 572:                  tupleList.Insert(0, new Tuple<int, int>((start - bufferRange) > 0 ? (start - bufferRange) : 0, start - 1)); // keep order
 573:              }
 574:   
 575:              tupleList.Sort();
 576:   
 577:              return tupleList;
 578:          }
 579:   
 580:          ////////////////////////////////////////////////////////////////////////////
 581:   
 582:          /// <summary>
 583:          /// Generate a list of start-end count optimized to read around count number of values from passed list. 
 584:          /// </summary>
 585:          public static List<Tuple<int, int>> OptimizedStartEndRangeTupleList(List<int> list, int count)
 586:          {
 587:              bool started, done;
 588:              int c, start, end;
 589:              Tuple<int, int> tuple;
 590:              List<Tuple<int, int>> tupleList;
 591:   
 592:              tupleList = new List<Tuple<int, int>>();
 593:   
 594:              started = true;
 595:              done = false;
 596:              c = start = 0;
 597:   
 598:              if (list.Count > 0 && count > 0)
 599:              {
 600:                  foreach (int item in list)
 601:                  {
 602:                      if (started)
 603:                      {
 604:                          start = item;
 605:                          started = false;
 606:                      }
 607:   
 608:                      if (c == 0)
 609:                      {
 610:                          done = false;
 611:                      }
 612:   
 613:                      if (c == count - 1)
 614:                      {
 615:                          end = item;
 616:   
 617:                          tuple = new Tuple<int, int>(start, end);
 618:   
 619:                          tupleList.Add(tuple);
 620:   
 621:                          start = item + 1;
 622:                          done = true;
 623:                          c = 0;
 624:                      }
 625:                      else c++;
 626:                  }
 627:   
 628:                  if (!done)
 629:                  {
 630:                      end = list[list.Count - 1];
 631:   
 632:                      tuple = new Tuple<int, int>(start, end);
 633:   
 634:                      tupleList.Add(tuple);
 635:                  }
 636:              }
 637:              else throw new System.ArgumentException("List empty or range too short. ");
 638:   
 639:              tupleList.Sort();
 640:   
 641:              return tupleList;
 642:          }
 643:   
 644:          ////////////////////////////////////////////////////////////////////////////    
 645:          ////////////////////////////////////////////////////////////////////////////    
 646:      }
 647:   
 648:      ////////////////////////////////////////////////////////////////////////////    
 649:      ////////////////////////////////////////////////////////////////////////////
 650:   
 651:      /// <summary>
 652:      ///
 653:      /// </summary>
 654:      public static class ServiceRequestExtension
 655:      {
 656:          ////////////////////////////////////////////////////////////////////////////
 657:   
 658:          /// <summary>
 659:          /// Extension method: Collect number list
 660:          /// </summary>
 661:          public static List<int> NumberList(this List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList)
 662:          {
 663:              List<int> numberList;
 664:   
 665:              if (serviceRequestList.Count > 0)
 666:              {
 667:                  numberList = (from n in serviceRequestList select n.Number).Distinct().ToList<int>();
 668:              }
 669:              else numberList = new List<int>();
 670:   
 671:              return numberList;
 672:          }
 673:   
 674:          ////////////////////////////////////////////////////////////////////////////
 675:   
 676:          /// <summary>
 677:          /// Extension method: Collect distinct number-serials into NumberSerial list
 678:          /// </summary>
 679:          public static List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> DistinctNumberSerialList(this List<Ia.Ngn.Cl.Model.ServiceRequest> sourceList)
 680:          {
 681:              List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList;
 682:   
 683:              if (sourceList.Count > 0)
 684:              {
 685:                  numberSerialList = (from n in sourceList
 686:                                      select new Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial { Number = n.Number, Serial = n.Serial }).Distinct().ToList();
 687:              }
 688:              else numberSerialList = new List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial>();
 689:   
 690:              return numberSerialList;
 691:          }
 692:   
 693:          ////////////////////////////////////////////////////////////////////////////
 694:          ////////////////////////////////////////////////////////////////////////////
 695:      }
 696:   
 697:      ////////////////////////////////////////////////////////////////////////////
 698:      ////////////////////////////////////////////////////////////////////////////
 699:  }