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

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 for Next Generation Network (NGN) data model.

   1:  using Ia.Ngn.Cl.Model.Business; // Needed for ServerExtension
   2:  using Newtonsoft.Json;
   3:  using System;
   4:  using System.Collections;
   5:  using System.Collections.Generic;
   6:  using System.Data;
   7:  using System.Data.Entity;
   8:  using System.IO;
   9:  using System.Linq;
  10:  using System.Reflection;
  11:  using System.Text;
  12:  using System.Text.RegularExpressions;
  13:  using System.Xml.Linq;
  14:   
  15:  namespace Ia.Ngn.Cl.Model.Data
  16:  {
  17:      ////////////////////////////////////////////////////////////////////////////
  18:   
  19:      /// <summary publish="true">
  20:      /// Service Request support class for Next Generation Network (NGN) data model.
  21:      /// </summary>
  22:      /// 
  23:      /// <remarks> 
  24:      /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  25:      ///
  26:      /// 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
  27:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  28:      ///
  29:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  30:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  31:      /// 
  32:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  33:      /// 
  34:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  35:      /// </remarks> 
  36:      public partial class ServiceRequest
  37:      {
  38:          private static int serviceRequestIdStartEndRangeBufferedListIndex, serviceRequestIdLatestStartEndRangeBufferedListIndex;
  39:          private static SortedList serviceCategorySortedList, serviceSortedList, customerCategorySortedList, statusSortedList;
  40:          private static XDocument xDocument;
  41:          private static List<int> serviceIdAllowedForProcessingList;
  42:          private static Dictionary<int, string> systemCode;
  43:          private static List<Tuple<int, int>> serviceRequestIdStartEndRangeBufferedTupleList;
  44:          private static Dictionary<string, string> serviceToDbNameDictionary, serviceToCustomerAddressDictionary;
  45:          private static DateTime serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp;
  46:          private static Dictionary<string, List<string>> dbNameToServiceListDictionary, accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
  47:          private static DateTime dbNameToServiceListDictionaryTimestamp, accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp;
  48:          private static Dictionary<string, string> serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
  49:   
  50:          private static readonly object objectLock = new object();
  51:   
  52:          ////////////////////////////////////////////////////////////////////////////
  53:   
  54:          /// <summary>
  55:          ///
  56:          /// </summary>
  57:          public ServiceRequest() { }
  58:   
  59:          ////////////////////////////////////////////////////////////////////////////
  60:   
  61:          /// <summary>
  62:          ///
  63:          /// </summary>
  64:          public static Dictionary<int, string> SystemCode
  65:          {
  66:              get
  67:              {
  68:                  lock (objectLock)
  69:                  {
  70:                      if (systemCode == null || systemCode.Count == 0) systemCode = Ia.Ngn.Cl.Model.Data.ServiceRequest._SystemCode;
  71:   
  72:                      return systemCode;
  73:                  }
  74:              }
  75:          }
  76:   
  77:          ////////////////////////////////////////////////////////////////////////////
  78:   
  79:          /// <summary>
  80:          ///
  81:          /// </summary>
  82:          private static Dictionary<int, string> _SystemCode
  83:          {
  84:              get
  85:              {
  86:                  // select code_id, code_name from system_codes
  87:   
  88:                  systemCode = new Dictionary<int, string>(100)
  89:                  {
  90:                      [6008] = "قطع مطالبات",
  91:                      [6009] = "قطع إدارى",
  92:                      [4007] = "إفراج",
  93:                      [4008] = "قيد التجديد",
  94:                      [4009] = "قيد إخطار الجهة",
  95:                      [4010] = "تسيل جزئي",
  96:                      [1001] = "جديد",
  97:                      [1002] = "مطلوب",
  98:                      [1003] = "متاح",
  99:                      [2001] = "قيد الموافقة الفنية",
 100:                      [2002] = "قيد الدفع",
 101:                      [2003] = "قيد التنفيذ",
 102:                      [2004] = "تعذر التنفيذ",
 103:                      [2005] = "تم التنفيذ",
 104:                      [3001] = "نقل من رصيد خدمة - دائن",
 105:                      [3002] = "نقل من رصيد خدمة - مدين",
 106:                      [4001] = "سارية",
 107:                      [4002] = "منتهية",
 108:                      [4003] = "مستردة",
 109:                      [4004] = "تسييل",
 110:                      [5001] = "سارية",
 111:                      [5002] = "منتهية",
 112:                      [5003] = "ملغاة",
 113:                      [4005] = "ملغاة",
 114:                      [5004] = "مبدئية",
 115:                      [6001] = "قيد التنفيذ",
 116:                      [6002] = "تم التنفيذ",
 117:                      [6003] = "تعذر التنفيذ",
 118:                      [4006] = "جديدة",
 119:                      [7001] = "يعمل",
 120:                      [7002] = "قطع مؤقت",
 121:                      [7003] = "قطع مبرمج",
 122:                      [1004] = "مقطوع",
 123:                      [5005] = "متأخرة السداد",
 124:                      [7004] = "قيد التنفيذ",
 125:                      [8001] = "قيد التنفيذ",
 126:                      [8002] = "تم التنفيذ",
 127:                      [8003] = "تعذر التنفيذ",
 128:                      [1005] = "يعمل",
 129:                      [7005] = "تعذر التنفيذ",
 130:                      [9001] = "دائن",
 131:                      [9002] = "مدين",
 132:                      [7006] = "رفع نهائي",
 133:                      [1203] = "مبدئية",
 134:                      [1201] = "سارية",
 135:                      [1202] = "ملغاة",
 136:                      [1101] = "انهاء",
 137:                      [1102] = "قطع مؤقت",
 138:                      [1301] = "قطع مبرمج",
 139:                      [1302] = "أمر عمل",
 140:                      [7007] = "رفع محاسبة",
 141:                      [1401] = "نص",
 142:                      [1402] = "رقم",
 143:                      [1403] = "تاريخ",
 144:                      [1404] = "تاريخ/وقت",
 145:                      [7008] = "قطع معاكسة",
 146:                      [1501] = "خدمة أساسية",
 147:                      [1502] = "تشغيل خدمة فرعية",
 148:                      [1503] = "إيقاف خدمة فرعية",
 149:                      [1504] = "عملية",
 150:                      [1505] = "منتج",
 151:                      [1510] = "خدمات متنوعة",
 152:                      [1103] = "إعادة",
 153:                      [1506] = "خدمة اساسية - مجموعة",
 154:                      [1507] = "خدمة تابعة",
 155:                      [1508] = "خدمة مدمجة",
 156:                      [2101] = "جديد",
 157:                      [2102] = "تم الحساب",
 158:                      [2103] = "نسخة جديدة",
 159:                      [2201] = "ملف المكالمات الدولية",
 160:                      [6004] = "إعادة الحالة",
 161:                      [1601] = "مبدئية",
 162:                      [1602] = "نهائية",
 163:                      [1603] = "ملغاة",
 164:                      [2006] = "ملغاة",
 165:                      [7009] = "ملغى",
 166:                      [7010] = "لا يعمل",
 167:                      [2104] = "مفقود",
 168:                      [5006] = "سارية - مؤقتة",
 169:                      [5007] = "مرحلة",
 170:                      [1701] = "عادي",
 171:                      [1702] = "نطاق",
 172:                      [1509] = "إيقاف خدمة أساسية"
 173:                  };
 174:   
 175:                  return systemCode;
 176:              }
 177:          }
 178:   
 179:          ////////////////////////////////////////////////////////////////////////////
 180:   
 181:          /// <summary>
 182:          ///
 183:          /// </summary>
 184:          public static SortedList ServiceCategorySortedList
 185:          {
 186:              get
 187:              {
 188:                  lock (objectLock)
 189:                  {
 190:                      if (serviceCategorySortedList == null || serviceCategorySortedList.Count == 0) serviceCategorySortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceCategorySortedList;
 191:   
 192:                      return serviceCategorySortedList;
 193:                  }
 194:              }
 195:          }
 196:   
 197:          ////////////////////////////////////////////////////////////////////////////
 198:   
 199:          /// <summary>
 200:          ///
 201:          /// </summary>
 202:          private static SortedList _ServiceCategorySortedList
 203:          {
 204:              get
 205:              {
 206:                  int id;
 207:   
 208:                  serviceCategorySortedList = new SortedList(10);
 209:   
 210:                  foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("categoryList").Elements("category"))
 211:                  {
 212:                      id = int.Parse(x.Attribute("id").Value);
 213:   
 214:                      serviceCategorySortedList[id] = x.Attribute("arabicName").Value;
 215:                  }
 216:   
 217:                  return serviceCategorySortedList;
 218:              }
 219:          }
 220:   
 221:          ////////////////////////////////////////////////////////////////////////////
 222:   
 223:          /// <summary>
 224:          ///
 225:          /// </summary>
 226:          public static SortedList ServiceSortedList
 227:          {
 228:              get
 229:              {
 230:                  lock (objectLock)
 231:                  {
 232:                      if (serviceSortedList == null || serviceSortedList.Count == 0) serviceSortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceSortedList;
 233:   
 234:                      return serviceSortedList;
 235:                  }
 236:              }
 237:          }
 238:   
 239:          ////////////////////////////////////////////////////////////////////////////
 240:   
 241:          /// <summary>
 242:          ///
 243:          /// </summary>
 244:          private static SortedList _ServiceSortedList
 245:          {
 246:              get
 247:              {
 248:                  int id;
 249:   
 250:                  serviceSortedList = new SortedList(10);
 251:   
 252:                  foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("serviceList").Elements("service"))
 253:                  {
 254:                      id = int.Parse(x.Attribute("id").Value);
 255:   
 256:                      serviceSortedList[id] = x.Attribute("arabicName").Value;
 257:                  }
 258:   
 259:                  return serviceSortedList;
 260:              }
 261:          }
 262:   
 263:          ////////////////////////////////////////////////////////////////////////////
 264:   
 265:          /// <summary>
 266:          ///
 267:          /// </summary>
 268:          public static SortedList CustomerCategorySortedList
 269:          {
 270:              get
 271:              {
 272:                  lock (objectLock)
 273:                  {
 274:                      if (customerCategorySortedList == null || customerCategorySortedList.Count == 0) customerCategorySortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._CustomerCategorySortedList;
 275:   
 276:                      return customerCategorySortedList;
 277:                  }
 278:              }
 279:          }
 280:   
 281:          ////////////////////////////////////////////////////////////////////////////
 282:   
 283:          /// <summary>
 284:          ///
 285:          /// </summary>
 286:          private static SortedList _CustomerCategorySortedList
 287:          {
 288:              get
 289:              {
 290:                  int id;
 291:   
 292:                  customerCategorySortedList = new SortedList(10);
 293:   
 294:                  foreach (XElement x in XDocument.Element("serviceRequest").Elements("customer").Elements("categoryList").Elements("category"))
 295:                  {
 296:                      id = int.Parse(x.Attribute("id").Value);
 297:   
 298:                      customerCategorySortedList[id] = x.Attribute("arabicName").Value;
 299:                  }
 300:   
 301:                  return customerCategorySortedList;
 302:              }
 303:          }
 304:   
 305:          ////////////////////////////////////////////////////////////////////////////
 306:   
 307:          /// <summary>
 308:          ///
 309:          /// </summary>
 310:          public static SortedList StatusSortedList
 311:          {
 312:              get
 313:              {
 314:                  lock (objectLock)
 315:                  {
 316:                      if (statusSortedList == null || statusSortedList.Count == 0) statusSortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._StatusSortedList;
 317:   
 318:                      return statusSortedList;
 319:                  }
 320:              }
 321:          }
 322:   
 323:          ////////////////////////////////////////////////////////////////////////////
 324:   
 325:          /// <summary>
 326:          ///
 327:          /// </summary>
 328:          private static SortedList _StatusSortedList
 329:          {
 330:              get
 331:              {
 332:                  int id;
 333:   
 334:                  statusSortedList = new SortedList(10);
 335:   
 336:                  foreach (XElement x in XDocument.Element("serviceRequest").Elements("statusList").Elements("status"))
 337:                  {
 338:                      id = int.Parse(x.Attribute("id").Value);
 339:   
 340:                      statusSortedList[id] = x.Attribute("arabicName").Value;
 341:                  }
 342:   
 343:                  return statusSortedList;
 344:              }
 345:          }
 346:   
 347:          ////////////////////////////////////////////////////////////////////////////
 348:   
 349:          /// <summary>
 350:          ///
 351:          /// </summary>
 352:          public static List<int> ServiceIdAllowedForProcessingList
 353:          {
 354:              get
 355:              {
 356:                  lock (objectLock)
 357:                  {
 358:                      if (serviceIdAllowedForProcessingList == null || serviceIdAllowedForProcessingList.Count == 0) serviceIdAllowedForProcessingList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceIdAllowedForProcessingList;
 359:   
 360:                      return serviceIdAllowedForProcessingList;
 361:                  }
 362:              }
 363:          }
 364:   
 365:          ////////////////////////////////////////////////////////////////////////////
 366:   
 367:          /// <summary>
 368:          ///
 369:          /// </summary>
 370:          private static List<int> _ServiceIdAllowedForProcessingList
 371:          {
 372:              get
 373:              {
 374:                  int id;
 375:   
 376:                  serviceIdAllowedForProcessingList = new List<int>(100);
 377:   
 378:                  foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("serviceList").Elements("service"))
 379:                  {
 380:                      if (x.HasAttributes && x.Attribute("allowProcessing") != null)
 381:                      {
 382:                          if (x.Attribute("allowProcessing").Value == "true")
 383:                          {
 384:                              id = int.Parse(x.Attribute("id").Value);
 385:                              serviceIdAllowedForProcessingList.Add(id);
 386:                          }
 387:                      }
 388:                  }
 389:   
 390:                  return serviceIdAllowedForProcessingList;
 391:              }
 392:          }
 393:   
 394:          ////////////////////////////////////////////////////////////////////////////    
 395:          ////////////////////////////////////////////////////////////////////////////    
 396:   
 397:          /// <summary>
 398:          ///
 399:          /// </summary>
 400:          public static Tuple<int, int> ServiceRequestIdStartEndRangeManager(ref int index, out string result)
 401:          {
 402:              int count, edgeBufferRange, lastestRangeList;
 403:              Tuple<int, int> tuple;
 404:              List<int> serviceRequestIdList;
 405:   
 406:              count = 10;
 407:              edgeBufferRange = 5000;
 408:              lastestRangeList = 21;
 409:   
 410:              if (serviceRequestIdStartEndRangeBufferedTupleList == null || serviceRequestIdStartEndRangeBufferedListIndex == 0)
 411:              {
 412:                  serviceRequestIdStartEndRangeBufferedListIndex = index;
 413:   
 414:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 415:                  {
 416:                      serviceRequestIdList = (from sr in db.ServiceRequests orderby sr.Id ascending select sr.Id).ToList();
 417:                  }
 418:   
 419:                  serviceRequestIdStartEndRangeBufferedTupleList = Ia.Ngn.Cl.Model.Business.ServiceRequest.OptimizedStartEndRangeBufferedList(serviceRequestIdList, count, edgeBufferRange);
 420:              }
 421:   
 422:              if (serviceRequestIdStartEndRangeBufferedTupleList.Count > 0)
 423:              {
 424:                  if (Ia.Ngn.Cl.Model.Business.Administration.NowIsOfficialWorkingTime)
 425:                  {
 426:                      // flip between last and latest range to favor reading fresh work orders quickly
 427:                      if (Ia.Cl.Model.Default.RandomBool)
 428:                      {
 429:                          serviceRequestIdLatestStartEndRangeBufferedListIndex = serviceRequestIdStartEndRangeBufferedTupleList.Count - Ia.Cl.Model.Default.Random(lastestRangeList) - 1;
 430:                          serviceRequestIdLatestStartEndRangeBufferedListIndex = (serviceRequestIdLatestStartEndRangeBufferedListIndex >= 0) ? serviceRequestIdLatestStartEndRangeBufferedListIndex : 0;
 431:                      }
 432:                      else serviceRequestIdLatestStartEndRangeBufferedListIndex = serviceRequestIdStartEndRangeBufferedTupleList.Count - 1;
 433:   
 434:                      tuple = serviceRequestIdStartEndRangeBufferedTupleList[serviceRequestIdLatestStartEndRangeBufferedListIndex];
 435:   
 436:                      if (serviceRequestIdLatestStartEndRangeBufferedListIndex == serviceRequestIdStartEndRangeBufferedTupleList.Count - 1)
 437:                      {
 438:                          tuple = new Tuple<int, int>(tuple.Item1, tuple.Item2 + edgeBufferRange);
 439:                      }
 440:   
 441:                      result = "(latest: " + tuple.Item1 + "-" + tuple.Item2 + " " + serviceRequestIdLatestStartEndRangeBufferedListIndex + "/" + serviceRequestIdStartEndRangeBufferedTupleList.Count + ")";
 442:                  }
 443:                  else
 444:                  {
 445:                      tuple = serviceRequestIdStartEndRangeBufferedTupleList[serviceRequestIdStartEndRangeBufferedListIndex];
 446:   
 447:                      result = "(historic: " + tuple.Item1 + "-" + tuple.Item2 + " " + serviceRequestIdStartEndRangeBufferedListIndex + "/" + serviceRequestIdStartEndRangeBufferedTupleList.Count + ")";
 448:   
 449:                      serviceRequestIdStartEndRangeBufferedListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(serviceRequestIdStartEndRangeBufferedTupleList, serviceRequestIdStartEndRangeBufferedListIndex);
 450:                  }
 451:              }
 452:              else
 453:              {
 454:                  result = "(0-0 0/0)";
 455:   
 456:                  tuple = null;
 457:              }
 458:   
 459:              index = serviceRequestIdStartEndRangeBufferedListIndex;
 460:   
 461:              return tuple;
 462:          }
 463:   
 464:          ////////////////////////////////////////////////////////////////////////////    
 465:   
 466:          /// <summary>
 467:          ///
 468:          /// </summary>
 469:          public static string AlterSessionOfCustomerDepartmentOracleDatabase
 470:          {
 471:              get
 472:              {
 473:                  return @"alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS'";
 474:              }
 475:          }
 476:   
 477:          ////////////////////////////////////////////////////////////////////////////
 478:   
 479:          /// <summary>
 480:          /// Return list of service requests
 481:          /// </summary>
 482:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List()
 483:          {
 484:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 485:   
 486:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 487:              {
 488:                  serviceRequestList = (from sr in db.ServiceRequests select sr).ToList();
 489:              }
 490:   
 491:              return serviceRequestList;
 492:          }
 493:   
 494:          ////////////////////////////////////////////////////////////////////////////
 495:   
 496:          /// <summary>
 497:          /// Return list of service requests with number
 498:          /// </summary>
 499:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(int number)
 500:          {
 501:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 502:   
 503:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 504:              {
 505:                  serviceRequestList = (from sr in db.ServiceRequests where sr.Number == number select sr).ToList();
 506:              }
 507:   
 508:              return serviceRequestList;
 509:          }
 510:   
 511:          ////////////////////////////////////////////////////////////////////////////
 512:   
 513:          /// <summary>
 514:          /// Return list of service requests with service
 515:          /// </summary>
 516:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(string service)
 517:          {
 518:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 519:   
 520:              if (!string.IsNullOrEmpty(service))
 521:              {
 522:                  if (int.TryParse(service, out int number))
 523:                  {
 524:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 525:                      {
 526:                          serviceRequestList = (from sr in db.ServiceRequests where sr.Number == number select sr).ToList();
 527:                      }
 528:                  }
 529:                  else
 530:                  {
 531:                      throw new ArgumentException(@"List(): service is not a number, service: " + service);
 532:                  }
 533:              }
 534:              else serviceRequestList = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 535:   
 536:              return serviceRequestList;
 537:          }
 538:   
 539:          ////////////////////////////////////////////////////////////////////////////
 540:   
 541:          /// <summary>
 542:          /// Return a list of service requests that have numbers (including changed-to numbers) within the passed list
 543:          /// </summary>
 544:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<int> numberList)
 545:          {
 546:              List<string> serviceList;
 547:   
 548:              serviceList = (from n in numberList select n.ToString()).ToList();
 549:   
 550:              return List(serviceList);
 551:          }
 552:   
 553:          ////////////////////////////////////////////////////////////////////////////
 554:   
 555:          /// <summary>
 556:          /// Return a list of service requests that have numbers (including changed-to numbers) within the passed list
 557:          /// </summary>
 558:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<string> serviceList)
 559:          {
 560:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList, viaServiceRequestTypeList;
 561:   
 562:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 563:              {
 564:                  serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService).Include(a => a.ServiceRequestTypes)
 565:                                        where serviceList.Contains(sr.Number.ToString())
 566:                                        select sr).ToList();
 567:   
 568:                  viaServiceRequestTypeList = (from srt in db.ServiceRequestTypes.Include(a => a.ServiceRequest).Include(a => a.ServiceRequest.ServiceRequestService)
 569:                                               where srt.TypeId == 11 && serviceList.Contains(srt.Value)
 570:                                               select srt.ServiceRequest).Include(a => a.ServiceRequestTypes).ToList();
 571:   
 572:                  serviceRequestList = serviceRequestList.Union(viaServiceRequestTypeList).Distinct().ToList();
 573:              }
 574:   
 575:              return serviceRequestList.ToList();
 576:          }
 577:   
 578:          ////////////////////////////////////////////////////////////////////////////
 579:   
 580:          /// <summary>
 581:          /// Return a list of service requests that have numbers-serials within the passed list
 582:          /// </summary>
 583:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList)
 584:          {
 585:              List<long> idList;
 586:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 587:   
 588:              idList = numberSerialList.IdList();
 589:   
 590:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 591:              {
 592:                  serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
 593:                                        where
 594:                                        //numberSerialList.Contains(q.Number, q.Serial) does not work
 595:                                        //((from r in numberSerialList where r.Number == q.Number && r.Serial == q.Serial select r) != null) does not work
 596:                                        //numberList.Any<int>(i=> i == q.Number)  does not work
 597:                                        idList.Contains((long)sr.Number * 100 + sr.Serial)
 598:                                        select sr).ToList();
 599:              }
 600:   
 601:              return serviceRequestList;
 602:          }
 603:   
 604:          ////////////////////////////////////////////////////////////////////////////
 605:   
 606:          /// <summary>
 607:          /// Return a list of numbers, including changed-to numbers, that are related to the passed number list
 608:          /// </summary>
 609:          public static List<int> OldNumberAndChangedAndChangedToList(List<int> numberList)
 610:          {
 611:              List<int> number1List, number2List, number3List, number4List, number5List;
 612:              List<string> serviceList, service1List, service2List, service3List, service4List, service5List; ;
 613:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList, serviceRequest1List, serviceRequest2List, serviceRequest3List, serviceRequest4List, serviceRequest5List;
 614:   
 615:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 616:              {
 617:                  serviceList = (from n in numberList select n.ToString()).ToList();
 618:   
 619:                  serviceRequest1List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
 620:                                         where numberList.Contains(sr.Number)
 621:                                         select sr).ToList();
 622:   
 623:                  if (serviceRequest1List.Count > 0)
 624:                  {
 625:                      number1List = (from sr in serviceRequest1List select sr.Number).Distinct().ToList();
 626:   
 627:                      number2List = new List<int>();
 628:   
 629:                      foreach (var srt in serviceRequest1List.SelectMany(u => u.ServiceRequestTypes))
 630:                      {
 631:                          if (srt.TypeId == 11 && int.TryParse(srt.Value, out int i)) number2List.Add(i);
 632:                      }
 633:   
 634:                      // below: this is the collect first changed-to number information
 635:                      if (number2List.Count > 0)
 636:                      {
 637:                          serviceRequest2List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
 638:                                                 where number2List.Contains(sr.Number)
 639:                                                 select sr).ToList();
 640:   
 641:                          if (serviceRequest2List.Count > 0)
 642:                          {
 643:                              number1List = (from sr in serviceRequest2List select sr.Number).Distinct().ToList();
 644:   
 645:                              number3List = new List<int>();
 646:   
 647:                              foreach (var srt in serviceRequest2List.SelectMany(u => u.ServiceRequestTypes))
 648:                              {
 649:                                  if (srt.TypeId == 11 && int.TryParse(srt.Value, out int i)) number3List.Add(i);
 650:                              }
 651:   
 652:                              // below: this is the collect second changed-to number information
 653:                              if (number3List.Count > 0)
 654:                              {
 655:                                  serviceRequest3List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
 656:                                                         where number3List.Contains(sr.Number)
 657:                                                         select sr).ToList();
 658:                              }
 659:                              else serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 660:                          }
 661:                          else
 662:                          {
 663:                              serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 664:                              serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 665:                          }
 666:                      }
 667:                      else
 668:                      {
 669:                          serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 670:                          serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 671:                      }
 672:                  }
 673:                  else
 674:                  {
 675:                      serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 676:                      serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 677:                  }
 678:   
 679:   
 680:                  //
 681:                  serviceRequest4List = (from srt in db.ServiceRequestTypes.Include(a => a.ServiceRequest)
 682:                                         where srt.TypeId == 11 && serviceList.Contains(srt.Value)
 683:                                         select srt.ServiceRequest).ToList();
 684:   
 685:                  if (serviceRequest4List.Count > 0)
 686:                  {
 687:                      number1List = (from sr in serviceRequest4List select sr.Number).Distinct().ToList();
 688:   
 689:                      serviceRequest5List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
 690:                                             where number1List.Contains(sr.Number)
 691:                                             select sr).ToList();
 692:                  }
 693:                  else serviceRequest5List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 694:   
 695:                  //
 696:                  serviceRequestList = serviceRequest1List.Union(serviceRequest2List).Union(serviceRequest3List).Union(serviceRequest4List).Union(serviceRequest5List).Distinct().ToList();
 697:   
 698:                  if (serviceRequestList.Count > 0)
 699:                  {
 700:                      numberList = (from n in serviceRequestList select n.Number).Distinct().ToList();
 701:                  }
 702:                  else numberList = new List<int>();
 703:              }
 704:   
 705:              return numberList.ToList();
 706:          }
 707:   
 708:          ////////////////////////////////////////////////////////////////////////////
 709:   
 710:          /// <summary>
 711:          /// Return a list of numbers, including changed-to numbers, that are related to the passed number list
 712:          /// </summary>
 713:          public static List<int> NumberAndChangedAndChangedToList(List<int> numberList)
 714:          {
 715:              List<int> list;
 716:   
 717:              list = new List<int>();
 718:   
 719:              _NumberAndChangedAndChangedToList(numberList, ref list);
 720:   
 721:              return list;
 722:          }
 723:   
 724:          ////////////////////////////////////////////////////////////////////////////
 725:   
 726:          /// <summary>
 727:          /// Return a list of numbers, including changed-to numbers, that are related to the passed number list
 728:          /// </summary>
 729:          private static void _NumberAndChangedAndChangedToList(List<int> numberList, ref List<int> list)
 730:          {
 731:              List<int> _list, changedList, changedToList, changedExceptList, changedToExceptList;
 732:              List<string> serviceList;
 733:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequests;
 734:   
 735:              changedList = new List<int>();
 736:              changedToList = new List<int>();
 737:   
 738:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 739:              {
 740:                  serviceList = (from n in numberList select n.ToString()).ToList();
 741:   
 742:                  // list
 743:                  serviceRequests = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes) where numberList.Contains(sr.Number) select sr).ToList();
 744:   
 745:                  _list = (from sr in serviceRequests select sr.Number).Distinct().ToList();
 746:   
 747:                  list = list.Union(_list).Distinct().ToList();
 748:   
 749:                  // changedToList
 750:                  foreach (var srt in serviceRequests.SelectMany(u => u.ServiceRequestTypes))
 751:                  {
 752:                      if (srt.TypeId == 11 && int.TryParse(srt.Value, out int i)) changedToList.Add(i);
 753:                  }
 754:   
 755:                  // changedList
 756:                  serviceRequests = (from srt in db.ServiceRequestTypes.Include(a => a.ServiceRequest) where srt.TypeId == 11 && serviceList.Contains(srt.Value) select srt.ServiceRequest).ToList();
 757:                  changedList = (from sr in serviceRequests select sr.Number).Distinct().ToList();
 758:   
 759:                  changedToExceptList = changedToList.Except(list).ToList();
 760:                  if (changedToExceptList.Count > 0) _NumberAndChangedAndChangedToList(changedToExceptList, ref list);
 761:   
 762:                  list = list.Union(changedToExceptList).Distinct().ToList();
 763:   
 764:                  changedExceptList = changedList.Except(list).ToList();
 765:                  if (changedExceptList.Count > 0) _NumberAndChangedAndChangedToList(changedExceptList, ref list);
 766:   
 767:                  list = list.Union(changedExceptList).Distinct().ToList();
 768:              }
 769:          }
 770:   
 771:          ////////////////////////////////////////////////////////////////////////////
 772:          ////////////////////////////////////////////////////////////////////////////
 773:   
 774:          /// <summary>
 775:          /// Return a list of service requests that have numbers within the passed domain list
 776:          /// </summary>
 777:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListByDomain(List<int> domainList)
 778:          {
 779:              List<string> stringDomainList;
 780:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 781:   
 782:              stringDomainList = new List<string>();
 783:   
 784:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 785:              {
 786:                  if (domainList != null)
 787:                  {
 788:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 789:   
 790:                      serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
 791:                                            where domainList.Any(u => sr.Number.ToString().StartsWith(u.ToString()))
 792:                                            select sr).ToList();
 793:                  }
 794:                  else
 795:                  {
 796:                      serviceRequestList = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
 797:                  }
 798:              }
 799:   
 800:              return serviceRequestList;
 801:          }
 802:   
 803:          ////////////////////////////////////////////////////////////////////////////
 804:   
 805:          /// <summary>
 806:          ///
 807:          /// </summary>
 808:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListWithinDateTimeRange(DateTime startDateTime, DateTime endDateTime)
 809:          {
 810:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 811:   
 812:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 813:              {
 814:                  serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService) where sr.RequestDateTime >= startDateTime && sr.RequestDateTime < endDateTime select sr).ToList();
 815:              }
 816:   
 817:              return serviceRequestList;
 818:          }
 819:   
 820:          ////////////////////////////////////////////////////////////////////////////
 821:   
 822:          /// <summary>
 823:          ///
 824:          /// </summary>
 825:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListWithinIdRange(int start, int end)
 826:          {
 827:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 828:   
 829:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 830:              {
 831:                  serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService) where sr.Id >= start && sr.Id <= end select sr).ToList();
 832:              }
 833:   
 834:              return serviceRequestList;
 835:          }
 836:   
 837:          ////////////////////////////////////////////////////////////////////////////
 838:          ////////////////////////////////////////////////////////////////////////////
 839:   
 840:          /// <summary>
 841:          ///
 842:          /// </summary>
 843:          public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ngn.Cl.Model.ServiceRequest> newServiceRequestList, out string result)
 844:          {
 845:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, serviceRequestId;
 846:              string serviceRequestServiceId;
 847:              Ia.Ngn.Cl.Model.ServiceRequest serviceRequest;
 848:   
 849:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 850:              result = string.Empty;
 851:   
 852:              readItemCount = newServiceRequestList.Count;
 853:   
 854:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 855:              {
 856:                  foreach (Ia.Ngn.Cl.Model.ServiceRequest newServiceRequest in newServiceRequestList)
 857:                  {
 858:                      serviceRequestId = newServiceRequest.Id;
 859:   
 860:                      serviceRequest = (from sr in db.ServiceRequests where sr.Id == serviceRequestId select sr).SingleOrDefault();
 861:   
 862:                      existingItemCount = (serviceRequest != null) ? 1 : 0;
 863:   
 864:                      try
 865:                      {
 866:                          if (newServiceRequest.ServiceRequestService != null)
 867:                          {
 868:                              serviceRequestServiceId = newServiceRequest.ServiceRequestService.Id;
 869:   
 870:                              newServiceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestServiceId select srs).SingleOrDefault();
 871:                          }
 872:   
 873:                          if (serviceRequest.Update(newServiceRequest))
 874:                          {
 875:                              db.ServiceRequests.Attach(serviceRequest);
 876:                              db.Entry(serviceRequest).State = System.Data.Entity.EntityState.Modified;
 877:   
 878:                              updatedItemCount++;
 879:                          }
 880:                      }
 881:                      catch (Exception e)
 882:                      {
 883:   
 884:                      }
 885:                  }
 886:   
 887:                  db.SaveChanges();
 888:   
 889:                  result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ";
 890:              }
 891:          }
 892:   
 893:          ////////////////////////////////////////////////////////////////////////////
 894:   
 895:          /// <summary>
 896:          ///
 897:          /// </summary>
 898:          public static bool UpdateServiceRequestService(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, out string result)
 899:          {
 900:              bool b;
 901:   
 902:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 903:              {
 904:                  serviceRequest = (from sr in db.ServiceRequests where sr.Id == serviceRequest.Id select sr).SingleOrDefault();
 905:   
 906:                  if (serviceRequest.ServiceRequestService != serviceRequestService)
 907:                  {
 908:                      serviceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestService.Id select srs).SingleOrDefault();
 909:   
 910:                      db.ServiceRequests.Attach(serviceRequest);
 911:                      db.Entry(serviceRequest).Property(x => x.ServiceRequestService).IsModified = true;
 912:   
 913:                      db.SaveChanges();
 914:   
 915:                      result = "Success: ServiceRequests ServiceRequestService updated. ";
 916:                      b = true;
 917:                  }
 918:                  else
 919:                  {
 920:                      result = "Warning: ServiceRequests ServiceRequestService value was not updated because its the same. ";
 921:   
 922:                      b = false;
 923:                  }
 924:              }
 925:   
 926:              return b;
 927:          }
 928:   
 929:          ////////////////////////////////////////////////////////////////////////////
 930:   
 931:          /// <summary>
 932:          ///
 933:          /// </summary>
 934:          public static void UpdateForADateTimeRangeWithOutputDataTable(DataTable dataTable, DateTime dateTime, out string result)
 935:          {
 936:              // below: the SQL statement should be within the dataTable.TableName variable
 937:              int number, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 938:              int serviceRequestId;
 939:              string sql, r, customerAddress;
 940:              ArrayList newServiceRequestIdArryList;
 941:              DateTime startDateTime, endDateTime;
 942:              Match match;
 943:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
 944:              Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
 945:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 946:              List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
 947:   
 948:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 949:              result = r = string.Empty;
 950:   
 951:              startDateTime = DateTime.MinValue;
 952:   
 953:              if (dataTable != null)
 954:              {
 955:                  sql = dataTable.TableName;
 956:   
 957:                  // select * from SRV_REQ_FIPER where REQ_DATE >= 'dd/MM/yyyy' and REQ_DATE < 'dd/MM/yyyy' order by REQ_DATE ASC, SRV_REQ_ID ASC;
 958:                  // select * from SRV_REQ_FIPER where REQ_DATE >= '01-10-2006' and REQ_DATE < '02-10-2006' order by REQ_DATE asc, SRV_REQ_ID asc;
 959:   
 960:                  match = Regex.Match(sql, @".+'(\d{2})\/(\d{2})\/(\d{4})'.+'(\d{2})\/(\d{2})\/(\d{4})'.+", RegexOptions.Singleline);
 961:                  //                             1        2        3        4          5        6
 962:   
 963:                  if (match.Success)
 964:                  {
 965:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 966:                      {
 967:                          readItemCount = dataTable.Rows.Count;
 968:   
 969:                          //if (dataTable.Rows.Count > 0)
 970:                          //{
 971:                          startDateTime = DateTime.Parse(match.Groups[3].Value + "-" + match.Groups[2].Value + "-" + match.Groups[1].Value);
 972:                          endDateTime = DateTime.Parse(match.Groups[6].Value + "-" + match.Groups[5].Value + "-" + match.Groups[4].Value);
 973:   
 974:                          serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ListWithinDateTimeRange(startDateTime, endDateTime);
 975:                          existingItemCount = serviceRequestList.Count;
 976:   
 977:                          newServiceRequestIdArryList = new ArrayList(dataTable.Rows.Count + 1);
 978:   
 979:                          foreach (DataRow dataRow in dataTable.Rows)
 980:                          {
 981:                              number = int.Parse(dataRow["SRV_NO"].ToString());
 982:   
 983:                              if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(number))
 984:                              {
 985:                                  serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
 986:   
 987:                                  customerAddress = dataRow["ADDRESS"].ToString();
 988:                                  serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
 989:   
 990:                                  newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
 991:                                  {
 992:                                      Id = serviceRequestId,
 993:                                      Number = number,
 994:   
 995:                                      CustomerAddress = customerAddress,
 996:                                      AreaId = serviceAddress.AreaId,
 997:   
 998:                                      CustomerCategoryId = int.Parse(dataRow["CUST_CAT_ID"].ToString()),
 999:                                      CustomerId = int.Parse(dataRow["ACCOUNT_NO"].ToString()),
1000:                                      CustomerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString()),
1001:                                      RequestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString()),
1002:                                      Serial = int.Parse(dataRow["SRV_SER_NO"].ToString()),
1003:                                      ServiceCategoryId = int.Parse(dataRow["SRV_CAT_ID"].ToString()),
1004:                                      ServiceId = int.Parse(dataRow["SRV_ID"].ToString()),
1005:                                      Balance = double.Parse(dataRow["BALANCE"].ToString()),
1006:                                      Status = int.Parse(dataRow["STATUS"].ToString())
1007:                                  };
1008:   
1009:                                  serviceRequest = (from sr in serviceRequestList where sr.Id == newServiceRequest.Id select sr).SingleOrDefault();
1010:   
1011:                                  if (serviceRequest == null)
1012:                                  {
1013:                                      newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1014:   
1015:                                      db.ServiceRequests.Add(newServiceRequest);
1016:   
1017:                                      insertedItemCount++;
1018:                                  }
1019:                                  else
1020:                                  {
1021:                                      // below: copy values from newServiceRequest to serviceRequest
1022:   
1023:                                      if (serviceRequest.Update(newServiceRequest))
1024:                                      {
1025:                                          db.ServiceRequests.Attach(serviceRequest);
1026:                                          db.Entry(serviceRequest).State = System.Data.Entity.EntityState.Modified;
1027:   
1028:                                          updatedItemCount++;
1029:                                      }
1030:                                  }
1031:   
1032:                                  newServiceRequestIdArryList.Add(serviceRequestId);
1033:                              }
1034:                              else
1035:                              {
1036:                                  r += "Number: " + number + " is not within allowed domain list, ";
1037:                              }
1038:                          }
1039:   
1040:                          // below: this function will remove values that were not present in the reading
1041:                          if (serviceRequestList.Count > 0)
1042:                          {
1043:                              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
1044:                              {
1045:                                  if (!newServiceRequestIdArryList.Contains(sr.Id))
1046:                                  {
1047:                                      serviceRequest = (from sr2 in db.ServiceRequests where sr2.Id == sr.Id select sr2).SingleOrDefault();
1048:   
1049:                                      db.ServiceRequests.Remove(serviceRequest);
1050:   
1051:                                      // below: we will also remove SRT records referensing this SR
1052:                                      serviceRequestTypeList = (from srt in db.ServiceRequestTypes where srt.ServiceRequest.Id == sr.Id select srt).ToList();
1053:   
1054:                                      foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
1055:   
1056:                                      deletedItemCount++;
1057:                                  }
1058:                              }
1059:                          }
1060:   
1061:                          db.SaveChanges();
1062:   
1063:                          result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") " + r;
1064:                          //}
1065:                          //else
1066:                          //{
1067:                          //    result = "(" + readItemCount + "/?/?) ";
1068:                          //}
1069:                      }
1070:                  }
1071:                  else
1072:                  {
1073:                      result = "(?/?/?: SQL in TableName is unmatched) ";
1074:                  }
1075:              }
1076:              else
1077:              {
1078:                  result = "(dataTable == null/?/?) ";
1079:              }
1080:          }
1081:   
1082:          ////////////////////////////////////////////////////////////////////////////
1083:   
1084:          /// <summary>
1085:          ///
1086:          /// </summary>
1087:          public static string UpdateForServiceRequestWithOutputDataTableAndIdRange(DataTable dataTable, out List<string> insertedOrUpdatedOrDeletedServiceList)
1088:          {
1089:              // below: the SQL statement should be within the dataTable.TableName variable
1090:              int serviceRequestId, start, end, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
1091:              string sql, r, customerAddress, result;
1092:              ArrayList newServiceRequestIdArrayList;
1093:              Match match;
1094:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1095:              Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
1096:              List<int> numbersNotWithinAllowedDomainList;
1097:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1098:              List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
1099:   
1100:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1101:              result = r = string.Empty;
1102:              numbersNotWithinAllowedDomainList = new List<int>();
1103:   
1104:              insertedOrUpdatedOrDeletedServiceList = new List<string>();
1105:   
1106:              if (dataTable != null)
1107:              {
1108:                  sql = dataTable.TableName;
1109:   
1110:                  // select * from SRV_REQ_FIPER where SRV_REQ_ID >= 110000 and SRV_REQ_ID <= 321203 order by REQ_DATE asc, SRV_REQ_ID asc
1111:                  match = Regex.Match(sql, @"SRV_REQ_ID >= (\d+) and SRV_REQ_ID <= (\d+) ", RegexOptions.Singleline);
1112:                  //                                       1                       2
1113:   
1114:                  if (match.Success)
1115:                  {
1116:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
1117:                      {
1118:                          readItemCount = dataTable.Rows.Count;
1119:   
1120:                          start = int.Parse(match.Groups[1].Value);
1121:                          end = int.Parse(match.Groups[2].Value);
1122:   
1123:                          serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ListWithinIdRange(start, end);
1124:                          existingItemCount = serviceRequestList.Count;
1125:   
1126:                          newServiceRequestIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
1127:   
1128:                          foreach (DataRow dataRow in dataTable.Rows)
1129:                          {
1130:                              if (int.TryParse(dataRow["SRV_NO"].ToString(), out int number))
1131:                              {
1132:                                  if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(number))
1133:                                  {
1134:                                      serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
1135:   
1136:                                      if (Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceRequestIdIsAllowedForProcessing(serviceRequestId))
1137:                                      {
1138:                                          customerAddress = dataRow["ADDRESS"].ToString();
1139:   
1140:                                          serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
1141:   
1142:                                          newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
1143:                                          {
1144:                                              Id = serviceRequestId,
1145:                                              Number = number,
1146:   
1147:                                              CustomerAddress = customerAddress,
1148:                                              AreaId = serviceAddress.AreaId,
1149:   
1150:                                              CustomerCategoryId = int.TryParse(dataRow["CUST_CAT_ID"].ToString(), out int i) ? i : 0,
1151:                                              CustomerId = int.TryParse(dataRow["ACCOUNT_NO"].ToString(), out i) ? i : 0,
1152:                                              CustomerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString()),
1153:                                              RequestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString()),
1154:                                              Serial = int.TryParse(dataRow["SRV_SER_NO"].ToString(), out i) ? i : 0,
1155:                                              ServiceCategoryId = int.TryParse(dataRow["SRV_CAT_ID"].ToString(), out i) ? i : 0,
1156:                                              ServiceId = int.TryParse(dataRow["SRV_ID"].ToString(), out i) ? i : 0,
1157:                                              Balance = double.Parse(dataRow["BALANCE"].ToString()),
1158:   
1159:                                              Status = int.TryParse(dataRow["STATUS"].ToString(), out i) ? i : 0
1160:                                          };
1161:   
1162:                                          serviceRequest = (from sr in serviceRequestList where sr.Id == newServiceRequest.Id select sr).SingleOrDefault();
1163:   
1164:                                          if (serviceRequest == null)
1165:                                          {
1166:                                              newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1167:   
1168:                                              db.ServiceRequests.Add(newServiceRequest);
1169:   
1170:                                              insertedOrUpdatedOrDeletedServiceList.Add(newServiceRequest.Number.ToString());
1171:                                              insertedItemCount++;
1172:                                          }
1173:                                          else
1174:                                          {
1175:                                              // below: copy values from newServiceRequest to serviceRequest
1176:   
1177:                                              if (serviceRequest.UpdateSkipServiceRequestService(newServiceRequest))
1178:                                              {
1179:                                                  db.ServiceRequests.Attach(serviceRequest);
1180:                                                  db.Entry(serviceRequest).State = System.Data.Entity.EntityState.Modified;
1181:   
1182:                                                  insertedOrUpdatedOrDeletedServiceList.Add(serviceRequest.Number.ToString());
1183:                                                  updatedItemCount++;
1184:                                              }
1185:                                          }
1186:   
1187:                                          newServiceRequestIdArrayList.Add(serviceRequestId); // keep at the end
1188:                                      }
1189:                                      else
1190:                                      {
1191:   
1192:                                      }
1193:                                  }
1194:                                  else
1195:                                  {
1196:                                      numbersNotWithinAllowedDomainList.Add(number);
1197:                                  }
1198:                              }
1199:                              else
1200:                              {
1201:                                  //
1202:                              }
1203:                          }
1204:   
1205:                          /*
1206:                          if (numbersNotWithinAllowedDomainList.Count > 0)
1207:                          {
1208:                              r = "Numbers not within allowed domain list: ";
1209:  
1210:                              foreach (int n in numbersNotWithinAllowedDomainList) r += n + ",";
1211:  
1212:                              r = r.Trim(',');
1213:                          }
1214:                          */
1215:   
1216:                          // below: this function will remove values that were not present in the reading
1217:                          if (serviceRequestList.Count > 0)
1218:                          {
1219:                              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
1220:                              {
1221:                                  if (!newServiceRequestIdArrayList.Contains(sr.Id))
1222:                                  {
1223:                                      serviceRequest = (from sr2 in db.ServiceRequests where sr2.Id == sr.Id select sr2).SingleOrDefault();
1224:   
1225:                                      db.ServiceRequests.Remove(serviceRequest);
1226:   
1227:                                      // below: we will also remove SRT records referensing this SR
1228:                                      serviceRequestTypeList = (from srt in db.ServiceRequestTypes where srt.ServiceRequest.Id == sr.Id select srt).ToList();
1229:   
1230:                                      foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
1231:   
1232:                                      insertedOrUpdatedOrDeletedServiceList.Add(serviceRequest.Number.ToString());
1233:                                      deletedItemCount++;
1234:                                  }
1235:                              }
1236:                          }
1237:   
1238:                          db.SaveChanges();
1239:   
1240:                          //if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
1241:                          //else isUpdated = false;
1242:   
1243:                          result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") " + r;
1244:                      }
1245:                  }
1246:                  else
1247:                  {
1248:                      result = "(?/?/?: SQL in TableName is unmatched) ";
1249:                  }
1250:              }
1251:              else
1252:              {
1253:                  result = "(dataTable == null/?/?) ";
1254:              }
1255:   
1256:              return result;
1257:          }
1258:   
1259:          ////////////////////////////////////////////////////////////////////////////
1260:   
1261:          /// <summary>
1262:          ///
1263:          /// </summary>
1264:          public static void UpdateForServiceRequestWithOutputDataTableAndService(DataTable dataTable, string service, out bool isUpdated, out string result)
1265:          {
1266:              int serviceRequestId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
1267:              string sql, sqlService, r, customerAddress;
1268:              ArrayList newServiceRequestIdArrayList;
1269:              Match match;
1270:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1271:              Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
1272:              List<int> numbersNotWithinAllowedDomainList;
1273:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1274:              List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
1275:   
1276:              isUpdated = false;
1277:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1278:              result = r = string.Empty;
1279:              numbersNotWithinAllowedDomainList = new List<int>();
1280:   
1281:              if (dataTable != null)
1282:              {
1283:                  // below: the SQL statement should be within the dataTable.TableName variable
1284:                  sql = dataTable.TableName;
1285:   
1286:                  // select * from SRV_REQ_FIPER where SRV_NO = 23632222 order by SRV_REQ_ID asc
1287:                  match = Regex.Match(sql, @"SRV_NO = (\d+) order by SRV_REQ_ID asc", RegexOptions.Singleline);
1288:   
1289:                  if (match.Success)
1290:                  {
1291:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
1292:                      {
1293:                          readItemCount = dataTable.Rows.Count;
1294:   
1295:                          sqlService = match.Groups[1].Value;
1296:   
1297:                          if (service == sqlService)
1298:                          {
1299:                              serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(service);
1300:                              existingItemCount = serviceRequestList.Count;
1301:   
1302:                              newServiceRequestIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
1303:   
1304:                              foreach (DataRow dataRow in dataTable.Rows)
1305:                              {
1306:                                  if (int.TryParse(dataRow["SRV_NO"].ToString(), out int number))
1307:                                  {
1308:                                      if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(number))
1309:                                      {
1310:                                          serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
1311:                                          customerAddress = dataRow["ADDRESS"].ToString();
1312:   
1313:                                          serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
1314:   
1315:                                          newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
1316:                                          {
1317:                                              Id = serviceRequestId,
1318:                                              Number = number,
1319:                                              CustomerAddress = customerAddress,
1320:                                              AreaId = serviceAddress.AreaId,
1321:                                              CustomerCategoryId = int.TryParse(dataRow["CUST_CAT_ID"].ToString(), out int i) ? i : 0,
1322:                                              CustomerId = int.TryParse(dataRow["ACCOUNT_NO"].ToString(), out i) ? i : 0,
1323:                                              CustomerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString()),
1324:                                              RequestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString()),
1325:                                              Serial = int.TryParse(dataRow["SRV_SER_NO"].ToString(), out i) ? i : 0,
1326:                                              ServiceCategoryId = int.TryParse(dataRow["SRV_CAT_ID"].ToString(), out i) ? i : 0,
1327:                                              ServiceId = int.TryParse(dataRow["SRV_ID"].ToString(), out i) ? i : 0,
1328:                                              Balance = double.Parse(dataRow["BALANCE"].ToString()),
1329:                                              Status = int.TryParse(dataRow["STATUS"].ToString(), out i) ? i : 0
1330:                                          };
1331:   
1332:                                          serviceRequest = (from sr in serviceRequestList where sr.Id == newServiceRequest.Id select sr).SingleOrDefault();
1333:   
1334:                                          if (serviceRequest == null)
1335:                                          {
1336:                                              newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1337:   
1338:                                              db.ServiceRequests.Add(newServiceRequest);
1339:   
1340:                                              insertedItemCount++;
1341:                                          }
1342:                                          else
1343:                                          {
1344:                                              // below: copy values from newServiceRequest to serviceRequest
1345:   
1346:                                              if (serviceRequest.UpdateSkipServiceRequestService(newServiceRequest))
1347:                                              {
1348:                                                  db.ServiceRequests.Attach(serviceRequest);
1349:                                                  db.Entry(serviceRequest).State = System.Data.Entity.EntityState.Modified;
1350:   
1351:                                                  updatedItemCount++;
1352:                                              }
1353:                                          }
1354:   
1355:                                          newServiceRequestIdArrayList.Add(serviceRequestId); // keep at the end
1356:                                      }
1357:                                      else
1358:                                      {
1359:                                          numbersNotWithinAllowedDomainList.Add(number);
1360:                                      }
1361:                                  }
1362:                                  else
1363:                                  {
1364:                                      //
1365:                                  }
1366:                              }
1367:   
1368:                              /*
1369:                              if (numbersNotWithinAllowedDomainList.Count > 0)
1370:                              {
1371:                                  r = "Numbers not within allowed domain list: ";
1372:  
1373:                                  foreach (int n in numbersNotWithinAllowedDomainList) r += n + ",";
1374:  
1375:                                  r = r.Trim(',');
1376:                              }
1377:                              */
1378:   
1379:                              // below: this function will remove values that were not present in the reading
1380:                              if (serviceRequestList.Count > 0)
1381:                              {
1382:                                  foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
1383:                                  {
1384:                                      if (!newServiceRequestIdArrayList.Contains(sr.Id))
1385:                                      {
1386:                                          serviceRequest = (from sr2 in db.ServiceRequests where sr2.Id == sr.Id select sr2).SingleOrDefault();
1387:   
1388:                                          db.ServiceRequests.Remove(serviceRequest);
1389:   
1390:                                          // below: we will also remove SRT records referencing this SR
1391:                                          serviceRequestTypeList = (from srt in db.ServiceRequestTypes where srt.ServiceRequest.Id == sr.Id select srt).ToList();
1392:   
1393:                                          foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
1394:   
1395:                                          deletedItemCount++;
1396:                                      }
1397:                                  }
1398:                              }
1399:   
1400:                              db.SaveChanges();
1401:   
1402:                              if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
1403:                              else isUpdated = false;
1404:   
1405:                              result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") " + r;
1406:                          }
1407:                          else
1408:                          {
1409:                              throw new ArgumentException(@"UpdateForServiceRequestWithOutputDataTableAndService(): service != sqlService, service: " + service + ", sqlService: " + sqlService);
1410:                          }
1411:                      }
1412:                  }
1413:                  else
1414:                  {
1415:                      result = "(?/?/?: SQL in TableName is unmatched) ";
1416:                  }
1417:              }
1418:              else
1419:              {
1420:                  result = "(dataTable == null/?/?) ";
1421:              }
1422:          }
1423:   
1424:          ////////////////////////////////////////////////////////////////////////////
1425:   
1426:          /// <summary>
1427:          /// 
1428:          /// </summary>
1429:          public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest> ServiceToServiceRequestDictionary(List<int> domainList)
1430:          {
1431:              string key;
1432:              List<string> stringDomainList;
1433:              List<Ia.Ngn.Cl.Model.ServiceRequest> list;
1434:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest> dictionary;
1435:   
1436:              stringDomainList = new List<string>();
1437:   
1438:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1439:              {
1440:                  if (domainList != null)
1441:                  {
1442:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
1443:   
1444:                      list = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService).Include(a => a.ServiceRequestTypes) where domainList.Any(u => sr.Number.ToString().StartsWith(u.ToString())) orderby sr.RequestDateTime ascending select sr).ToList();
1445:   
1446:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest>(list.Count);
1447:   
1448:                      foreach (var sr in list)
1449:                      {
1450:                          key = sr.Number.ToString();
1451:   
1452:                          if (dictionary.ContainsKey(key))
1453:                          {
1454:                              dictionary[key] = sr;
1455:                          }
1456:                          else dictionary[key] = sr;
1457:                      }
1458:                  }
1459:                  else
1460:                  {
1461:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest>();
1462:                  }
1463:              }
1464:   
1465:              return dictionary;
1466:          }
1467:   
1468:          ////////////////////////////////////////////////////////////////////////////
1469:   
1470:          /// <summary>
1471:          ///
1472:          /// </summary>
1473:          public static Hashtable NumberToCustomerAddressHashtable(List<int> domainList)
1474:          {
1475:              Hashtable ht;
1476:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1477:   
1478:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1479:              {
1480:                  if (domainList != null)
1481:                  {
1482:                      serviceRequestList = (from sr in db.ServiceRequests where domainList.Contains(sr.Number / 10000) || domainList.Contains(sr.Number / 1000) select sr).ToList();
1483:   
1484:                      ht = new Hashtable(serviceRequestList.Count);
1485:   
1486:                      foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList.OrderBy(u => u.Id)) ht[sr.Number.ToString()] = sr.CustomerAddress;
1487:                  }
1488:                  else
1489:                  {
1490:                      ht = new Hashtable();
1491:                  }
1492:              }
1493:   
1494:              return ht;
1495:          }
1496:   
1497:          ////////////////////////////////////////////////////////////////////////////
1498:   
1499:          /// <summary>
1500:          /// Return the latest RequestDateTime for number
1501:          /// </summary>
1502:          public static DateTime LatestRequestDateTime(int number)
1503:          {
1504:              DateTime dateTime;
1505:              Ia.Ngn.Cl.Model.ServiceRequest serviceRequest;
1506:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1507:   
1508:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1509:              {
1510:                  serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(number);
1511:   
1512:                  if (serviceRequestList.Count > 0)
1513:                  {
1514:                      serviceRequest = serviceRequestList.OrderByDescending(u => u.Id).FirstOrDefault();
1515:   
1516:                      dateTime = serviceRequest.RequestDateTime;
1517:                  }
1518:                  else
1519:                  {
1520:                      dateTime = DateTime.MinValue;
1521:                  }
1522:              }
1523:   
1524:              return dateTime;
1525:          }
1526:   
1527:          ////////////////////////////////////////////////////////////////////////////
1528:   
1529:          /// <summary>
1530:          ///
1531:          /// </summary>
1532:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> LastN(int numberOfServiceRequests)
1533:          {
1534:              // below:
1535:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1536:   
1537:              serviceRequestList = null;
1538:   
1539:              try
1540:              {
1541:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1542:                  {
1543:                      serviceRequestList = (from sr in db.ServiceRequests orderby sr.RequestDateTime descending select sr).Take(numberOfServiceRequests).ToList();
1544:                  }
1545:              }
1546:              catch (Exception)
1547:              {
1548:                  //resultLabel.Text = "Error during retrieval of data for \"" + ip + "\": " + ex.Message + ". ";
1549:                  //resultLabel.CssClass = "error";
1550:              }
1551:   
1552:              return serviceRequestList;
1553:          }
1554:   
1555:          ////////////////////////////////////////////////////////////////////////////
1556:   
1557:          /// <summary>
1558:          ///
1559:          /// </summary>
1560:          public static List<Ia.Ngn.Cl.Model.ServiceRequest> ForRequestDate(DateTime requestDate)
1561:          {
1562:              // below:
1563:              DateTime nextDate;
1564:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1565:   
1566:              serviceRequestList = null;
1567:   
1568:              // below: 00:00 time values
1569:              requestDate = requestDate.Date;
1570:   
1571:              nextDate = requestDate.AddDays(1);
1572:   
1573:              try
1574:              {
1575:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1576:                  {
1577:                      serviceRequestList = (from sr in db.ServiceRequests where sr.RequestDateTime >= requestDate && sr.RequestDateTime < nextDate orderby sr.RequestDateTime descending select sr).ToList();
1578:                  }
1579:              }
1580:              catch (Exception)
1581:              {
1582:                  //resultLabel.Text = "Error during retrieval of data for \"" + ip + "\": " + ex.Message + ". ";
1583:                  //resultLabel.CssClass = "error";
1584:              }
1585:   
1586:              return serviceRequestList;
1587:          }
1588:   
1589:          ////////////////////////////////////////////////////////////////////////////
1590:          ////////////////////////////////////////////////////////////////////////////
1591:   
1592:          /// <summary>
1593:          ///
1594:          /// </summary>
1595:          public static Dictionary<string, string> ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary
1596:          {
1597:              get
1598:              {
1599:                  lock (objectLock)
1600:                  {
1601:                      if (serviceToAccessNameWithinAllowedToBeMigratedOltDictionary == null || serviceToAccessNameWithinAllowedToBeMigratedOltDictionary.Count == 0) serviceToAccessNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary;
1602:   
1603:                      return serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
1604:                  }
1605:              }
1606:          }
1607:   
1608:          ////////////////////////////////////////////////////////////////////////////
1609:   
1610:          /// <summary>
1611:          ///
1612:          /// </summary>
1613:          private static Dictionary<string, string> _ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary
1614:          {
1615:              get
1616:              {
1617:                  Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1618:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceAddress> serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary;
1619:   
1620:                  var areaSymbolList = Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList;
1621:   
1622:                  var kuwaitNgnAreaList = (from k in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where areaSymbolList.Contains(k.Symbol) select k.Id).ToList();
1623:   
1624:                  var serviceToDbNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceToDbNameWithinAllowedToBeMigratedOltDictionary;
1625:                  var serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceToCustomerAddressWithinAllowedToBeMigratedOltDictionary;
1626:   
1627:                  serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceAddress>(serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary.Count);
1628:   
1629:                  foreach (KeyValuePair<string, string> kvp in serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary)
1630:                  {
1631:                      var service = kvp.Key;
1632:                      var address = kvp.Value;
1633:                      serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(service, address, out string level);
1634:   
1635:                      serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary[service] = serviceAddress;
1636:                  }
1637:   
1638:                  serviceToAccessNameWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, string>(serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary.Count);
1639:                  var ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary;
1640:   
1641:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1642:                  {
1643:                      var accessList = (from a in db.Accesses
1644:                                        where kuwaitNgnAreaList.Contains(a.AreaId)
1645:                                        select new Ia.Ngn.Cl.Model.Ui.Access { Id = a.Id, AreaId = a.AreaId, Block = a.Block, Street = a.Street, PremisesOld = a.PremisesOld, PremisesNew = a.PremisesNew }).ToList();
1646:   
1647:                      foreach (var access in accessList)
1648:                      {
1649:                          if (ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary.ContainsKey(access.Id))
1650:                          {
1651:                              access.Name = ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary[access.Id];
1652:                          }
1653:                          else access.Name = string.Empty;
1654:                      }
1655:   
1656:                      foreach (var kvp in serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary)
1657:                      {
1658:                          serviceAddress = new Ia.Ngn.Cl.Model.Business.ServiceAddress();
1659:   
1660:                          serviceAddress.AreaId = kvp.Value.AreaId;
1661:                          serviceAddress.Block = kvp.Value.Block;
1662:                          serviceAddress.Street = kvp.Value.Street;
1663:                          serviceAddress.Boulevard = kvp.Value.Boulevard;
1664:                          serviceAddress.PremisesOld = kvp.Value.PremisesOld;
1665:                          serviceAddress.PremisesNew = kvp.Value.PremisesNew;
1666:                          serviceAddress.Paci = kvp.Value.Paci;
1667:   
1668:                          var statisticalAccess = Ia.Ngn.Cl.Model.Data.Access.StatisticalAccess(serviceAddress, ref accessList, out string note2);
1669:                          if (statisticalAccess != null) statisticalAccess.Note = note2;
1670:   
1671:                          serviceToAccessNameWithinAllowedToBeMigratedOltDictionary[kvp.Key] = statisticalAccess != null ? statisticalAccess.Name : string.Empty;
1672:                      }
1673:                  }
1674:   
1675:                  return serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
1676:              }
1677:          }
1678:   
1679:          ////////////////////////////////////////////////////////////////////////////
1680:   
1681:          /// <summary>
1682:          ///
1683:          /// </summary>
1684:          public static Dictionary<string, List<string>> AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary
1685:          {
1686:              get
1687:              {
1688:                  DateTime now;
1689:                  Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
1690:   
1691:                  now = DateTime.UtcNow.AddHours(3);
1692:                  validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
1693:   
1694:                  lock (objectLock)
1695:                  {
1696:                      if (accessNameToServiceListWithinAllowedToBeMigratedOltDictionary == null || accessNameToServiceListWithinAllowedToBeMigratedOltDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp))
1697:                      {
1698:                          accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary(validityOfData);
1699:                      }
1700:   
1701:                      return accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
1702:                  }
1703:              }
1704:          }
1705:   
1706:          ////////////////////////////////////////////////////////////////////////////
1707:   
1708:          /// <summary>
1709:          ///
1710:          /// </summary>
1711:          private static Dictionary<string, List<string>> _AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary(Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData)
1712:          {
1713:              string title;
1714:              DateTime now, timestamp;
1715:   
1716:              now = DateTime.UtcNow.AddHours(3);
1717:   
1718:              title = "AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary";
1719:   
1720:              timestamp = Ia.Ngn.Cl.Model.Data.Miscellaneous.ReadUpdatedDateTime(title);// + "Timestamp");
1721:   
1722:              if (!Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, timestamp))
1723:              {
1724:                  accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = _AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary();
1725:                  Ia.Ngn.Cl.Model.Data.Miscellaneous.CreateOrUpdate(title, accessNameToServiceListWithinAllowedToBeMigratedOltDictionary);
1726:   
1727:                  timestamp = now;
1728:                  //Ia.Ngn.Cl.Model.Data.Miscellaneous.CreateOrUpdate(title + "Timestamp", timestamp);
1729:              }
1730:              else
1731:              {
1732:                  accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.Miscellaneous.Read<Dictionary<string, List<string>>>(title);
1733:              }
1734:   
1735:              accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp = timestamp;
1736:   
1737:              return accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
1738:          }
1739:   
1740:          ////////////////////////////////////////////////////////////////////////////
1741:   
1742:          /// <summary>
1743:          ///
1744:          /// </summary>
1745:          private static Dictionary<string, List<string>> _AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary()
1746:          {
1747:              string key, value;
1748:              List<string> valueList;
1749:   
1750:              var serviceToAccessNameDictionary = ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary;
1751:   
1752:              accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, List<string>>(serviceToAccessNameDictionary.Count);
1753:   
1754:              foreach (var kvp in serviceToAccessNameDictionary)
1755:              {
1756:                  key = kvp.Value;
1757:   
1758:                  if (!string.IsNullOrEmpty(key))
1759:                  {
1760:                      value = kvp.Key;
1761:   
1762:                      valueList = new List<string>();
1763:   
1764:                      if (!accessNameToServiceListWithinAllowedToBeMigratedOltDictionary.ContainsKey(key))
1765:                      {
1766:                          valueList.Add(value);
1767:   
1768:                          accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key] = valueList;
1769:                      }
1770:                      else
1771:                      {
1772:                          valueList = accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key];
1773:                          valueList.Add(value);
1774:   
1775:                          accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key] = valueList;
1776:                      }
1777:                  }
1778:              }
1779:   
1780:              return accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
1781:          }
1782:   
1783:          ////////////////////////////////////////////////////////////////////////////
1784:   
1785:          /// <summary>
1786:          ///
1787:          /// </summary>
1788:          public static List<string> DbPeerServiceList(List<string> serviceList)
1789:          {
1790:              var dbNameToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.DbNameToServiceListDictionary;
1791:   
1792:              var listList = (from d in dbNameToServiceListDictionary where serviceList.Any(u => d.Value.Contains(u)) select d.Value).ToList();
1793:   
1794:              var list = listList.SelectMany(x => x).ToList();
1795:   
1796:              var peerServiceList = list.Distinct().ToList();
1797:   
1798:              return peerServiceList;
1799:          }
1800:   
1801:          ////////////////////////////////////////////////////////////////////////////
1802:   
1803:          /// <summary>
1804:          ///
1805:          /// </summary>
1806:          public static Dictionary<string, List<string>> DbNameToServiceListDictionary
1807:          {
1808:              get
1809:              {
1810:                  DateTime now;
1811:                  Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
1812:   
1813:                  now = DateTime.UtcNow.AddHours(3);
1814:                  validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
1815:   
1816:                  lock (objectLock)
1817:                  {
1818:                      if (dbNameToServiceListDictionary == null || dbNameToServiceListDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, dbNameToServiceListDictionaryTimestamp))
1819:                      {
1820:                          dbNameToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._DbNameToServiceListDictionary;
1821:                      }
1822:   
1823:                      return dbNameToServiceListDictionary;
1824:                  }
1825:              }
1826:          }
1827:   
1828:          ////////////////////////////////////////////////////////////////////////////
1829:   
1830:          /// <summary>
1831:          ///
1832:          /// </summary>
1833:          private static Dictionary<string, List<string>> _DbNameToServiceListDictionary
1834:          {
1835:              get
1836:              {
1837:                  string key, value;
1838:                  DateTime now;
1839:   
1840:                  List<string> valueList;
1841:   
1842:                  now = DateTime.UtcNow.AddHours(3);
1843:   
1844:                  var serviceToDbNameDictionary = ServiceToDbNameWithinAllowedToBeMigratedOltDictionary;
1845:   
1846:                  dbNameToServiceListDictionary = new Dictionary<string, List<string>>(serviceToDbNameDictionary.Count);
1847:   
1848:                  foreach (KeyValuePair<string, string> kvp in serviceToDbNameDictionary)
1849:                  {
1850:                      key = kvp.Value;
1851:   
1852:                      if (!string.IsNullOrEmpty(key) && key != ":")
1853:                      {
1854:                          value = kvp.Key;
1855:   
1856:                          valueList = new List<string>();
1857:   
1858:                          if (!dbNameToServiceListDictionary.ContainsKey(key))
1859:                          {
1860:                              valueList.Add(value);
1861:   
1862:                              dbNameToServiceListDictionary[key] = valueList;
1863:                          }
1864:                          else
1865:                          {
1866:                              valueList = dbNameToServiceListDictionary[key];
1867:                              valueList.Add(value);
1868:   
1869:                              dbNameToServiceListDictionary[key] = valueList;
1870:                          }
1871:                      }
1872:                  }
1873:   
1874:                  dbNameToServiceListDictionaryTimestamp = now;
1875:   
1876:                  return dbNameToServiceListDictionary;
1877:              }
1878:          }
1879:   
1880:          ////////////////////////////////////////////////////////////////////////////
1881:   
1882:          /// <summary>
1883:          ///
1884:          /// </summary>
1885:          public static Dictionary<string, string> ServiceToDbNameWithinAllowedToBeMigratedOltDictionary
1886:          {
1887:              get
1888:              {
1889:                  DateTime now;
1890:                  Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
1891:   
1892:                  now = DateTime.UtcNow.AddHours(3);
1893:                  validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
1894:   
1895:                  lock (objectLock)
1896:                  {
1897:                      if (serviceToDbNameDictionary == null || serviceToDbNameDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp))
1898:                      {
1899:                          Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(validityOfData, out serviceToDbNameDictionary, out serviceToCustomerAddressDictionary);
1900:                      }
1901:   
1902:                      return serviceToDbNameDictionary;
1903:                  }
1904:              }
1905:          }
1906:   
1907:          ////////////////////////////////////////////////////////////////////////////
1908:   
1909:          /// <summary>
1910:          ///
1911:          /// </summary>
1912:          public static Dictionary<string, string> ServiceToCustomerAddressWithinAllowedToBeMigratedOltDictionary
1913:          {
1914:              get
1915:              {
1916:                  DateTime now;
1917:                  Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
1918:   
1919:                  now = DateTime.UtcNow.AddHours(3);
1920:                  validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.Day;
1921:   
1922:                  lock (objectLock)
1923:                  {
1924:                      if (serviceToCustomerAddressDictionary == null || serviceToCustomerAddressDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp))
1925:                      {
1926:                          Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(validityOfData, out serviceToDbNameDictionary, out serviceToCustomerAddressDictionary);
1927:                      }
1928:   
1929:                      return serviceToCustomerAddressDictionary;
1930:                  }
1931:              }
1932:          }
1933:   
1934:          ////////////////////////////////////////////////////////////////////////////
1935:   
1936:          /// <summary>
1937:          ///
1938:          /// </summary>
1939:          private static void _ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData, out Dictionary<string, string> serviceToDbNameDictionary, out Dictionary<string, string> serviceToCustomerAddressDictionary)
1940:          {
1941:              string title1, title2;
1942:              DateTime now, timestamp, timestamp1, timestamp2;
1943:   
1944:              now = DateTime.UtcNow.AddHours(3);
1945:   
1946:              title1 = "ServiceToDbNameDictionary";
1947:              title2 = "ServiceToCustomerAddressDictionary";
1948:   
1949:              timestamp1 = Ia.Ngn.Cl.Model.Data.Miscellaneous.ReadUpdatedDateTime(title1);// + "Timestamp");
1950:              timestamp2 = Ia.Ngn.Cl.Model.Data.Miscellaneous.ReadUpdatedDateTime(title2);// + "Timestamp");
1951:   
1952:              timestamp = (timestamp1 < timestamp2) ? timestamp1 : timestamp2;
1953:   
1954:              if (!Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, timestamp))
1955:              {
1956:                  _ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(out serviceToDbNameDictionary, out serviceToCustomerAddressDictionary);
1957:   
1958:                  Ia.Ngn.Cl.Model.Data.Miscellaneous.CreateOrUpdate(title1, serviceToDbNameDictionary);
1959:   
1960:                  Ia.Ngn.Cl.Model.Data.Miscellaneous.CreateOrUpdate(title2, serviceToCustomerAddressDictionary);
1961:   
1962:                  timestamp = now;
1963:                  //Ia.Ngn.Cl.Model.Data.Miscellaneous.CreateOrUpdate(title + "Timestamp", timestamp);
1964:              }
1965:              else
1966:              {
1967:                  serviceToDbNameDictionary = Ia.Ngn.Cl.Model.Data.Miscellaneous.Read<Dictionary<string, string>>(title1);
1968:   
1969:                  serviceToCustomerAddressDictionary = Ia.Ngn.Cl.Model.Data.Miscellaneous.Read<Dictionary<string, string>>(title2);
1970:              }
1971:   
1972:              serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp = timestamp;
1973:          }
1974:   
1975:          ////////////////////////////////////////////////////////////////////////////
1976:   
1977:          /// <summary>
1978:          ///
1979:          /// </summary>
1980:          private static void _ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(out Dictionary<string, string> serviceToDbNameDictionary, out Dictionary<string, string> serviceToCustomerAddressDictionary)
1981:          {
1982:              Dictionary<string, int> serviceToLastSerialDictionary;
1983:   
1984:              var areaSymbolList = Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList;
1985:   
1986:              var areaIdList = (from k in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where areaSymbolList.Contains(k.Symbol) select k.Id).ToList();
1987:   
1988:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1989:              {
1990:                  var statisticalVariableList = (from sr in db.ServiceRequests
1991:                                                     //join srs in db.ServiceRequestServices on sr.Number.ToString() equals srs.Service // on sr.ServiceRequestService.Id equals srs.Id
1992:                                                 join srt in db.ServiceRequestTypes on sr.Id equals srt.ServiceRequest.Id into srts
1993:                                                 from srt in srts.DefaultIfEmpty()
1994:                                                 where areaIdList.Contains(sr.AreaId) && (srt == null || srt.TypeId == 1 || srt.TypeId == 2)
1995:                                                 select new Ia.Ngn.Cl.Model.Business.ServiceRequestStatisticalVariable
1996:                                                 {
1997:                                                     //Provisioned = srs.Provisioned,
1998:                                                     ServiceRequestId = sr.Id,
1999:                                                     Service = sr.Number.ToString(),
2000:                                                     Serial = sr.Serial,
2001:                                                     AreaId = sr.AreaId,
2002:                                                     CustomerAddress = sr.CustomerAddress,
2003:                                                     /* CustomerName = sr.CustomerName, */
2004:                                                     ServiceRequestTypeValue = srt == null ? string.Empty : srt.Value,
2005:                                                 }).ToList();
2006:   
2007:                  serviceToLastSerialDictionary = new Dictionary<string, int>(statisticalVariableList.Count);
2008:                  serviceToDbNameDictionary = new Dictionary<string, string>(statisticalVariableList.Count);
2009:                  serviceToCustomerAddressDictionary = new Dictionary<string, string>(statisticalVariableList.Count);
2010:   
2011:                  foreach (var sv in statisticalVariableList/*.Where(u => u.Provisioned)*/.OrderBy(u => u.ServiceRequestId))
2012:                  {
2013:                      serviceToLastSerialDictionary[sv.Service] = sv.Serial;
2014:                  }
2015:   
2016:                  foreach (var sv in statisticalVariableList/*.Where(u => u.Provisioned)*/.OrderBy(u => u.ServiceRequestId))
2017:                  {
2018:                      if (serviceToLastSerialDictionary[sv.Service] == sv.Serial)
2019:                      {
2020:                          if (serviceToDbNameDictionary.ContainsKey(sv.Service))
2021:                          {
2022:                              // ServiceRequestTypes values do not contain ":"
2023:                              if (!serviceToDbNameDictionary[sv.Service].Contains(":")) serviceToDbNameDictionary[sv.Service] += ":" + sv.ServiceRequestTypeValue;
2024:                          }
2025:                          else serviceToDbNameDictionary[sv.Service] = sv.ServiceRequestTypeValue;
2026:   
2027:                          if (!serviceToCustomerAddressDictionary.ContainsKey(sv.Service)) serviceToCustomerAddressDictionary[sv.Service] = sv.CustomerAddress;
2028:                      }
2029:                  }
2030:              }
2031:          }
2032:   
2033:          ////////////////////////////////////////////////////////////////////////////
2034:          ////////////////////////////////////////////////////////////////////////////
2035:   
2036:          /// <summary>
2037:          ///
2038:          /// </summary>
2039:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
2040:          {
2041:              StringBuilder sb;
2042:   
2043:              sb = new StringBuilder();
2044:   
2045:              // Id    Number    Serial    Status    RequestDateTime    Service    ServiceCategory    CustomerId    CustomerName    CustomerCategory    CustomerAddress    Balance
2046:              sb.AppendLine("Id: " + serviceRequest.Id);
2047:              sb.AppendLine("Number: " + serviceRequest.Number + "/" + serviceRequest.Serial);
2048:              //sb.AppendLine("Serial: " + serviceRequest.Serial);
2049:              sb.AppendLine("Status: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.StatusSortedList[serviceRequest.Status].ToString());
2050:              sb.AppendLine("RequestDateTime: " + serviceRequest.RequestDateTime.ToString("yyyy-MM-dd HH:mm"));
2051:              sb.AppendLine("Service: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceSortedList[serviceRequest.ServiceId].ToString());
2052:              //sb.AppendLine("ServiceCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceCategorySortedList[serviceRequest.ServiceCategoryId].ToString());
2053:              //sb.AppendLine("CustomerId: " + serviceRequest.CustomerId);
2054:              sb.AppendLine("CustomerName: " + serviceRequest.CustomerName);
2055:              //sb.AppendLine("CustomerCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.CustomerCategorySortedList[serviceRequest.CustomerCategoryId].ToString());
2056:   
2057:              sb.AppendLine("CustomerAddress: " + serviceRequest.CustomerAddress);
2058:              //sb.AppendLine("Balance: " + serviceRequest.Balance);
2059:   
2060:              return sb.ToString();
2061:          }
2062:   
2063:          ////////////////////////////////////////////////////////////////////////////
2064:   
2065:          /// <summary>
2066:          /// 
2067:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
2068:          /// 
2069:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
2070:          /// 2. Add "using System.Reflection".
2071:          /// 3. See sample below.
2072:          /// 
2073:          /// </summary>
2074:   
2075:          private static XDocument XDocument
2076:          {
2077:              get
2078:              {
2079:                  if (xDocument == null)
2080:                  {
2081:                      Assembly _assembly;
2082:                      StreamReader streamReader;
2083:   
2084:                      _assembly = Assembly.GetExecutingAssembly();
2085:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.service-request.xml"));
2086:   
2087:                      try
2088:                      {
2089:                          if (streamReader.Peek() != -1)
2090:                          {
2091:                              xDocument = System.Xml.Linq.XDocument.Load(streamReader);
2092:                          }
2093:                      }
2094:                      catch (Exception)
2095:                      {
2096:                      }
2097:                      finally
2098:                      {
2099:                      }
2100:                  }
2101:   
2102:                  return xDocument;
2103:              }
2104:          }
2105:   
2106:          ////////////////////////////////////////////////////////////////////////////    
2107:          ////////////////////////////////////////////////////////////////////////////    
2108:      }
2109:   
2110:      ////////////////////////////////////////////////////////////////////////////
2111:      ////////////////////////////////////////////////////////////////////////////
2112:  }