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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Access

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

Access support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data.Entity;
   4:  using System.Linq;
   5:  using System.Text;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Data
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Access support class for Next Generation Network (NGN) data model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  17:      ///
  18:      /// 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
  19:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  20:      ///
  21:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23:      /// 
  24:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  25:      /// 
  26:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  27:      /// </remarks> 
  28:      public partial class Access
  29:      {
  30:          /// <summary/>
  31:          public Access() { }
  32:   
  33:          ////////////////////////////////////////////////////////////////////////////
  34:   
  35:          /// <summary>
  36:          ///
  37:          /// </summary>
  38:          public static void Create(Ia.Ngn.Cl.Model.Access newAccess, out Ia.Cl.Model.Result result)
  39:          {
  40:              Ia.Ngn.Cl.Model.Access access;
  41:   
  42:              result = new Ia.Cl.Model.Result();
  43:   
  44:              try
  45:              {
  46:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  47:                  {
  48:                      // check if it exists already
  49:                      access = (from a in db.Accesses where a.Id == newAccess.Id select a).SingleOrDefault();
  50:   
  51:                      if (access == null)
  52:                      {
  53:                          newAccess.Created = newAccess.Updated = DateTime.UtcNow.AddHours(3);
  54:   
  55:                          db.Accesses.Add(newAccess);
  56:                          db.SaveChanges();
  57:   
  58:                          result.AddSuccess("Access record " + newAccess.Name + " created. ");
  59:                      }
  60:                      else
  61:                      {
  62:                          result.AddError("Access record " + newAccess.Name + " already exists. ");
  63:                      }
  64:                  }
  65:              }
  66:              catch (Exception ex)
  67:              {
  68:                  result.AddError("Exception: Access record was not created: " + ex.Message);
  69:              }
  70:          }
  71:   
  72:          ////////////////////////////////////////////////////////////////////////////
  73:   
  74:          /// <summary>
  75:          ///
  76:          /// </summary>
  77:          public static Ia.Ngn.Cl.Model.Access Read(Ia.Ngn.Cl.Model.Ngn db, string id)
  78:          {
  79:              Ia.Ngn.Cl.Model.Access access;
  80:   
  81:              access = (from a in db.Accesses where a.Id == id select a).SingleOrDefault();
  82:   
  83:              return access;
  84:          }
  85:   
  86:          ////////////////////////////////////////////////////////////////////////////
  87:   
  88:          /// <summary>
  89:          ///
  90:          /// </summary>
  91:          public static Ia.Ngn.Cl.Model.Access Read(string id)
  92:          {
  93:              Ia.Ngn.Cl.Model.Access item;
  94:   
  95:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  96:              {
  97:                  item = (from a in db.Accesses where a.Id == id select a).SingleOrDefault();
  98:              }
  99:   
 100:              return item;
 101:          }
 102:   
 103:          ////////////////////////////////////////////////////////////////////////////
 104:   
 105:          /// <summary>
 106:          ///
 107:          /// </summary>
 108:          public static Ia.Ngn.Cl.Model.Access Read(int oltId, int ponNumber, int ontNumber)
 109:          {
 110:              Ia.Ngn.Cl.Model.Access item;
 111:   
 112:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 113:              {
 114:                  item = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber && a.Ont == ontNumber select a).SingleOrDefault();
 115:              }
 116:   
 117:              return item;
 118:          }
 119:   
 120:          ////////////////////////////////////////////////////////////////////////////
 121:   
 122:          /// <summary>
 123:          ///
 124:          /// </summary>
 125:          public static Ia.Ngn.Cl.Model.Access Read(Ia.Ngn.Cl.Model.Ngn db, int oltId, int ponNumber, int ontNumber)
 126:          {
 127:              return (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber && a.Ont == ontNumber select a).SingleOrDefault();
 128:          }
 129:   
 130:          ////////////////////////////////////////////////////////////////////////////
 131:   
 132:          /// <summary>
 133:          ///
 134:          /// </summary>
 135:          public static Ia.Ngn.Cl.Model.Access ReadBySerialInNote(string serial)
 136:          {
 137:              List<Ia.Ngn.Cl.Model.Access> list;
 138:   
 139:              if (!string.IsNullOrEmpty(serial))
 140:              {
 141:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 142:                  {
 143:                      list = (from a in db.Accesses where a.Note.Contains(serial) select a).ToList();
 144:                  }
 145:              }
 146:              else list = null;
 147:   
 148:              return list.FirstOrDefault();
 149:          }
 150:   
 151:          ////////////////////////////////////////////////////////////////////////////
 152:   
 153:          /// <summary>
 154:          ///
 155:          /// </summary>
 156:          public static List<Ia.Ngn.Cl.Model.Access> ReadListByAreaId(int areaId)
 157:          {
 158:              List<Ia.Ngn.Cl.Model.Access> itemList;
 159:   
 160:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 161:              {
 162:                  itemList = (from a in db.Accesses where a.AreaId == areaId select a).ToList();
 163:              }
 164:   
 165:              return itemList;
 166:          }
 167:   
 168:          ////////////////////////////////////////////////////////////////////////////
 169:   
 170:          /// <summary>
 171:          ///
 172:          /// </summary>
 173:          public static int AreaIdFromOltIdAndPon(int oltId, int ponNumber)
 174:          {
 175:              int areaId;
 176:   
 177:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 178:              {
 179:                  areaId = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber select a.AreaId).FirstOrDefault();
 180:   
 181:                  if (areaId == 0)
 182:                  {
 183:                      areaId = (from a in db.Accesses where a.Olt == oltId select a.AreaId).FirstOrDefault();
 184:                  }
 185:              }
 186:   
 187:              return areaId;
 188:          }
 189:   
 190:          ////////////////////////////////////////////////////////////////////////////
 191:   
 192:          /// <summary>
 193:          ///
 194:          /// </summary>
 195:          public static List<Ia.Ngn.Cl.Model.Access> List()
 196:          {
 197:              List<Ia.Ngn.Cl.Model.Access> list;
 198:   
 199:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 200:              {
 201:                  list = (from a in db.Accesses select a).ToList();
 202:              }
 203:   
 204:              return list;
 205:          }
 206:   
 207:          ////////////////////////////////////////////////////////////////////////////
 208:   
 209:          /// <summary>
 210:          ///
 211:          /// </summary>
 212:          public static List<Ia.Ngn.Cl.Model.Access> List(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 213:          {
 214:              List<Ia.Ngn.Cl.Model.Access> list;
 215:   
 216:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 217:              {
 218:                  list = (from a in db.Accesses where a.Olt == olt.Id select a).ToList();
 219:              }
 220:   
 221:              return list;
 222:          }
 223:   
 224:          ////////////////////////////////////////////////////////////////////////////
 225:   
 226:          /// <summary>
 227:          ///
 228:          /// </summary>
 229:          public static List<Ia.Ngn.Cl.Model.Access> List(int oltId, int ponNumber)
 230:          {
 231:              List<Ia.Ngn.Cl.Model.Access> itemList;
 232:   
 233:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 234:              {
 235:                  itemList = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber select a).ToList();
 236:              }
 237:   
 238:              return itemList;
 239:          }
 240:   
 241:          ////////////////////////////////////////////////////////////////////////////
 242:   
 243:          /// <summary>
 244:          ///
 245:          /// </summary>
 246:          public static bool Update(Ia.Ngn.Cl.Model.Access updatedAccess, out string result)
 247:          {
 248:              bool b;
 249:              Ia.Ngn.Cl.Model.Access access;
 250:   
 251:              b = false;
 252:              result = string.Empty;
 253:   
 254:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 255:              {
 256:                  access = (from a in db.Accesses where a.Id == updatedAccess.Id select a).SingleOrDefault();
 257:   
 258:                  if (access.Update(updatedAccess))
 259:                  {
 260:                      db.Accesses.Attach(access);
 261:                      db.Entry(access).State = System.Data.Entity.EntityState.Modified;
 262:                  }
 263:   
 264:                  db.SaveChanges();
 265:   
 266:                  b = true;
 267:              }
 268:   
 269:              return b;
 270:          }
 271:   
 272:          ////////////////////////////////////////////////////////////////////////////
 273:   
 274:          /// <summary>
 275:          ///
 276:          /// </summary>
 277:          public static void Delete(string id, out Ia.Cl.Model.Result result)
 278:          {
 279:              result = new Ia.Cl.Model.Result();
 280:   
 281:              try
 282:              {
 283:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 284:                  {
 285:                      var v = (from a in db.Accesses where a.Id == id select a).FirstOrDefault();
 286:   
 287:                      if (v != null)
 288:                      {
 289:                          db.Accesses.Remove(v);
 290:                          db.SaveChanges();
 291:   
 292:                          result.AddSuccess("Access record deleted. ");
 293:                      }
 294:                      else
 295:                      {
 296:                          result.AddWarning("Access record does not exist. ");
 297:                      }
 298:   
 299:                  }
 300:              }
 301:              catch (Exception ex)
 302:              {
 303:                  result.AddError("Exception: Access record was not deleted: " + ex.Message);
 304:              }
 305:          }
 306:   
 307:          ////////////////////////////////////////////////////////////////////////////
 308:          ////////////////////////////////////////////////////////////////////////////
 309:   
 310:          /// <summary>
 311:          ///
 312:          /// </summary>
 313:          public static List<int> OntsNotInAccessList(List<Ia.Ngn.Cl.Model.Access> accessList)
 314:          {
 315:              // below: produce a list of ONTs between 1 and 32 that are not in ontList
 316:              List<int> ontNotInListArrayList = new List<int>(32);
 317:   
 318:              for (int i = 1; i <= 32; i++)
 319:              {
 320:                  if (accessList != null)
 321:                  {
 322:                      if ((from a in accessList where a.Ont == i select a).SingleOrDefault() == null)
 323:                      {
 324:                          ontNotInListArrayList.Add(i);
 325:                      }
 326:                      else
 327:                      {
 328:                      }
 329:                  }
 330:                  else
 331:                  {
 332:                      ontNotInListArrayList.Add(i);
 333:                  }
 334:              }
 335:   
 336:              return ontNotInListArrayList;
 337:          }
 338:   
 339:          ////////////////////////////////////////////////////////////////////////////
 340:   
 341:          /// <summary>
 342:          ///
 343:          /// </summary>
 344:          public static List<int> OltIdDistinctList
 345:          {
 346:              get
 347:              {
 348:                  List<int> list;
 349:   
 350:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 351:                  {
 352:                      list = (from o in db.Accesses select o.Olt).Distinct().OrderBy(u => u).ToList();
 353:                  }
 354:   
 355:                  return list;
 356:              }
 357:          }
 358:   
 359:          ////////////////////////////////////////////////////////////////////////////
 360:   
 361:          /// <summary>
 362:          ///
 363:          /// </summary>
 364:          public static Ia.Ngn.Cl.Model.Access ReadByAccessName(string accessName)
 365:          {
 366:              int oltId, pon, ont;
 367:              Ia.Ngn.Cl.Model.Access access;
 368:   
 369:              // below: this expects accessName in exact format like SUR.12.3
 370:   
 371:              Ia.Ngn.Cl.Model.Business.Access.ExtractOltIdAndPonNumberAndOntNumberFromOntName(accessName, out oltId, out pon, out ont);
 372:   
 373:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 374:              {
 375:                  access = (from a in db.Accesses where a.Olt == oltId && a.Pon == pon && a.Ont == ont select a).SingleOrDefault();
 376:              }
 377:   
 378:              return access;
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static List<Ia.Ngn.Cl.Model.Access> ListUsingOntFamilyType(int familyTypeId)
 387:          {
 388:              // below: return access list for family type
 389:              List<Ia.Ngn.Cl.Model.Access> noList, huList, list;
 390:              List<string> equipmentTypeStringList;
 391:   
 392:              list = new List<Ia.Ngn.Cl.Model.Access>();
 393:   
 394:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 395:              {
 396:                  noList = (from a in db.Accesses join o in db.Onts on a equals o.Access where o.FamilyTypeId == familyTypeId select a).ToList();
 397:   
 398:                  equipmentTypeStringList = (from e in Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeList
 399:                                             where e.FamilyType == (Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType)familyTypeId
 400:                                             select e.Name).ToList();
 401:   
 402:                  huList = (from a in db.Accesses join o in db.EmsOnts on a equals o.Access where equipmentTypeStringList.Contains(o.EQUIPMENTID) select a).ToList();
 403:              }
 404:   
 405:              list.AddRange(noList);
 406:              list.AddRange(huList);
 407:   
 408:              return list.ToList();
 409:          }
 410:   
 411:          ////////////////////////////////////////////////////////////////////////////
 412:   
 413:          /// <summary>
 414:          ///
 415:          /// </summary>
 416:          public static List<string> ReadAccessNameListUsingKuwaitNgnAreaIdAndBlock(int kuwaitAreaId, string block)
 417:          {
 418:              Dictionary<string, string> di;
 419:              List<string> accessIdList, accessNameList;
 420:   
 421:              if (kuwaitAreaId > 0 && !string.IsNullOrEmpty(block))
 422:              {
 423:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 424:                  {
 425:                      accessIdList = (from a in db.Accesses where a.AreaId == kuwaitAreaId && a.Block == block select a.Id).ToList();
 426:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 427:   
 428:                      if (accessIdList != null && accessIdList.Count > 0)
 429:                      {
 430:                          accessNameList = new List<string>(accessIdList.Count);
 431:   
 432:                          foreach (string accessId in accessIdList)
 433:                          {
 434:                              if (di.ContainsKey(accessId)) accessNameList.Add(di[accessId]);
 435:                          }
 436:                      }
 437:                      else
 438:                      {
 439:                          accessNameList = null;
 440:                      }
 441:                  }
 442:              }
 443:              else
 444:              {
 445:                  accessNameList = null;
 446:              }
 447:   
 448:              return accessNameList;
 449:          }
 450:   
 451:          ////////////////////////////////////////////////////////////////////////////
 452:   
 453:          /// <summary>
 454:          ///
 455:          /// </summary>
 456:          public static List<Ia.Ngn.Cl.Model.Access> ListByKuwaitNgnAreaId(int kuwaitAreaId)
 457:          {
 458:              List<Ia.Ngn.Cl.Model.Access> list;
 459:   
 460:              if (kuwaitAreaId > 0)
 461:              {
 462:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 463:                  {
 464:                      list = (from a in db.Accesses where a.AreaId == kuwaitAreaId select a).ToList();
 465:                  }
 466:              }
 467:              else
 468:              {
 469:                  list = null;
 470:              }
 471:   
 472:              return list;
 473:          }
 474:   
 475:          ////////////////////////////////////////////////////////////////////////////
 476:   
 477:          /// <summary>
 478:          ///
 479:          /// </summary>
 480:          public static Dictionary<string, string> DistinctAccessKuwaitNgnAreaIdAndBlockDictionary
 481:          {
 482:              get
 483:              {
 484:                  int kuwaitNgnAreaId, block;
 485:                  string kuwaitNgnAreaIdString, blockString, kuwaitNgnAreaBlockValue, kuwaitNgnAreaNameArabicName;
 486:                  Dictionary<string, string> tempDictionary;
 487:                  Dictionary<string, string> dictionary;
 488:   
 489:                  dictionary = new Dictionary<string, string>();
 490:                  tempDictionary = new Dictionary<string, string>();
 491:   
 492:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 493:                  {
 494:                      tempDictionary = (from a in db.Accesses select new { a.AreaId, a.Block }).Distinct().OrderBy(u => u.AreaId).ThenBy(u => u.Block).ToDictionary(m => m.AreaId + "," + m.Block, m => m.AreaId + "," + m.Block);
 495:   
 496:                      if (tempDictionary != null && tempDictionary.Count > 0)
 497:                      {
 498:                          foreach (KeyValuePair<string, string> kvp in tempDictionary)
 499:                          {
 500:                              kuwaitNgnAreaIdString = kvp.Key.Split(',')[0].ToString();
 501:                              blockString = kvp.Key.Split(',')[1].ToString();
 502:   
 503:                              if (int.TryParse(kuwaitNgnAreaIdString, out kuwaitNgnAreaId) && int.TryParse(blockString, out block))
 504:                              {
 505:                                  kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == kuwaitNgnAreaId select kna.NameArabicName).SingleOrDefault();
 506:   
 507:                                  kuwaitNgnAreaBlockValue = kuwaitNgnAreaNameArabicName + ", block " + block;
 508:   
 509:                                  dictionary.Add(kvp.Key, kuwaitNgnAreaBlockValue);
 510:                              }
 511:                              else
 512:                              {
 513:                              }
 514:                          }
 515:                      }
 516:                      else
 517:                      {
 518:                      }
 519:                  }
 520:   
 521:                  return dictionary;
 522:              }
 523:          }
 524:   
 525:          ////////////////////////////////////////////////////////////////////////////
 526:   
 527:          /// <summary>
 528:          ///
 529:          /// </summary>
 530:          public static Dictionary<int, string> DistinctAccessKuwaitNgnAreaIdToNameArabicNameDictionary
 531:          {
 532:              get
 533:              {
 534:                  string kuwaitNgnAreaNameArabicName;
 535:                  List<int> list;
 536:                  Dictionary<int, string> dictionary;
 537:   
 538:                  dictionary = new Dictionary<int, string>();
 539:                  list = new List<int>();
 540:   
 541:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 542:                  {
 543:                      list = (from a in db.Accesses select a.AreaId).Distinct().ToList();
 544:   
 545:                      if (list.Count > 0)
 546:                      {
 547:                          foreach (int i in list)
 548:                          {
 549:                              kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == i select kna.NameArabicName).SingleOrDefault();
 550:   
 551:                              dictionary.Add(i, kuwaitNgnAreaNameArabicName);
 552:                          }
 553:                      }
 554:                      else
 555:                      {
 556:                      }
 557:                  }
 558:   
 559:                  return dictionary;
 560:              }
 561:          }
 562:   
 563:          ////////////////////////////////////////////////////////////////////////////
 564:   
 565:          /// <summary>
 566:          ///
 567:          /// </summary>
 568:          public static Dictionary<string, int> IdToKuwaitNgnAreaIdDictionary
 569:          {
 570:              get
 571:              {
 572:                  Dictionary<string, int> dictionary;
 573:   
 574:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 575:                  {
 576:                      dictionary = (from a in db.Accesses select new { a.Id, a.AreaId }).ToDictionary(u => u.Id, u => u.AreaId);
 577:                  }
 578:   
 579:                  return dictionary;
 580:              }
 581:          }
 582:   
 583:          ////////////////////////////////////////////////////////////////////////////
 584:   
 585:          /// <summary>
 586:          ///
 587:          /// </summary>
 588:          public static Dictionary<string, string> IdToKuwaitNgnAreaSymbolDictionary
 589:          {
 590:              get
 591:              {
 592:                  Dictionary<string, int> accessIdToKuwaitNgnAreaIdDictionary;
 593:                  Dictionary<int, string> areaIdToSymbolDictionary;
 594:                  Dictionary<string, string> dictionary;
 595:   
 596:                  accessIdToKuwaitNgnAreaIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaIdDictionary;
 597:                  areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 598:   
 599:                  dictionary = new Dictionary<string, string>(accessIdToKuwaitNgnAreaIdDictionary.Count);
 600:   
 601:                  foreach (KeyValuePair<string, int> kvp in accessIdToKuwaitNgnAreaIdDictionary)
 602:                  {
 603:                      if (areaIdToSymbolDictionary.ContainsKey(kvp.Value)) dictionary[kvp.Key] = areaIdToSymbolDictionary[kvp.Value];
 604:                  }
 605:   
 606:                  return dictionary;
 607:              }
 608:          }
 609:   
 610:          ////////////////////////////////////////////////////////////////////////////
 611:   
 612:          /// <summary>
 613:          ///
 614:          /// </summary>
 615:          public static Dictionary<string, int> IdToOltIdDictionary
 616:          {
 617:              get
 618:              {
 619:                  Dictionary<string, int> dictionary;
 620:   
 621:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 622:                  {
 623:                      dictionary = (from a in db.Accesses select new { a.Id, a.Olt }).ToDictionary(u => u.Id, u => u.Olt);
 624:                  }
 625:   
 626:                  return dictionary;
 627:              }
 628:          }
 629:   
 630:          ////////////////////////////////////////////////////////////////////////////
 631:   
 632:          /// <summary>
 633:          ///
 634:          /// </summary>
 635:          public static Dictionary<string, Ia.Ngn.Cl.Model.Access> IdToAccessDictionary
 636:          {
 637:              get
 638:              {
 639:                  Dictionary<string, Ia.Ngn.Cl.Model.Access> dictionary;
 640:   
 641:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 642:                  {
 643:                      dictionary = (from a in db.Accesses select new { AccessId = a.Id, Access = a }).ToDictionary(u => u.AccessId, u => u.Access);
 644:                  }
 645:   
 646:                  return dictionary;
 647:              }
 648:          }
 649:   
 650:          ////////////////////////////////////////////////////////////////////////////
 651:   
 652:          /// <summary>
 653:          ///
 654:          /// </summary>
 655:          public static Dictionary<string, Ia.Ngn.Cl.Model.Access> IdToHuaweiAccessDictionary
 656:          {
 657:              get
 658:              {
 659:                  List<int> oltIdList;
 660:                  Dictionary<string, Ia.Ngn.Cl.Model.Access> dictionary;
 661:   
 662:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 663:   
 664:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 665:                  {
 666:                      dictionary = (from a in db.Accesses where oltIdList.Contains(a.Olt) select new { AccessId = a.Id, Access = a }).ToDictionary(u => u.AccessId, u => u.Access);
 667:                  }
 668:   
 669:                  return dictionary;
 670:              }
 671:          }
 672:   
 673:          ////////////////////////////////////////////////////////////////////////////
 674:   
 675:          /// <summary>
 676:          ///
 677:          /// </summary>
 678:          public static List<string> IdList
 679:          {
 680:              get
 681:              {
 682:                  List<string> list;
 683:   
 684:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 685:                  {
 686:                      list = (from a in db.Accesses select a.Id).ToList();
 687:                  }
 688:   
 689:                  return list;
 690:              }
 691:          }
 692:   
 693:          ////////////////////////////////////////////////////////////////////////////
 694:   
 695:          /// <summary>
 696:          ///
 697:          /// </summary>
 698:          public static List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> FamilyStatisticInKuwaitNgnAreaAndBlockTable
 699:          {
 700:              // FamilyType { Undefined = 0, Sfu = 1, Soho = 2, Mdu = 3 };
 701:   
 702:              get
 703:              {
 704:                  Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock item;
 705:                  List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> list, sfu, soho, mdu;
 706:   
 707:                  list = new List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock>();
 708:   
 709:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 710:                  {
 711:                      sfu = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 1 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Sfu = g.Count() }).ToList();
 712:                      soho = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 2 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Soho = g.Count() }).ToList();
 713:                      mdu = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 3 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Mdu = g.Count() }).ToList();
 714:   
 715:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in sfu) list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Sfu = a.Sfu });
 716:   
 717:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in soho)
 718:                      {
 719:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 720:   
 721:                          if (item != null) item.Soho = a.Soho;
 722:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Soho = a.Soho });
 723:                      }
 724:   
 725:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in mdu)
 726:                      {
 727:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 728:   
 729:                          if (item != null) item.Mdu = a.Mdu;
 730:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Mdu = a.Mdu });
 731:                      }
 732:   
 733:                      list = list.OrderBy(u => u.AreaId).ThenBy(u => u.Block).ToList();
 734:   
 735:                      return list;
 736:                  }
 737:              }
 738:          }
 739:   
 740:          ////////////////////////////////////////////////////////////////////////////
 741:   
 742:          /// <summary>
 743:          ///
 744:          /// </summary>
 745:          public static List<Ia.Ngn.Cl.Model.Access> ListOfAccessesWithProvisionedAndReadyOntsAndEmsOntsButDoNotExistInCustomerDepartmentDatabase()
 746:          {
 747:              return ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(0);
 748:          }
 749:   
 750:          ////////////////////////////////////////////////////////////////////////////
 751:   
 752:          /// <summary>
 753:          ///
 754:          /// </summary>
 755:          public static List<Ia.Ngn.Cl.Model.Access> ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(int siteId)
 756:          {
 757:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
 758:              List<int> nokiaOltIdList, huaweiOltIdList;
 759:              List<Ia.Ngn.Cl.Model.Access> list, nokiaList, huaweiOntList;
 760:   
 761:              // this is related to AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 762:   
 763:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 764:              {
 765:                  if (siteId == 0)
 766:                  {
 767:                      // if siteId is 0 we will return results for all sites
 768:   
 769:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 770:   
 771:                      // Nokia
 772:                      nokiaList = (from a in db.Accesses
 773:                                       // join oid in nokiaOltIdList on a.Olt equals oid
 774:                                   join o in db.Onts on a equals o.Access
 775:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 776:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 777:                                   from subsro in gj.DefaultIfEmpty()
 778:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 779:                                   && o.Serial != null
 780:                                   && o.Serial != "ALCL00000000"
 781:                                   && o.FamilyTypeId != 0
 782:                                   && o.ActiveSoftware != null
 783:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 784:                                   && osv.Ip != null
 785:                                   && subsro.Access.Id == null
 786:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 787:   
 788:                      // Huawei
 789:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 790:   
 791:                      huaweiOntList = (from a in db.Accesses
 792:                                       join o in db.EmsOnts on a equals o.Access
 793:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 794:                                       from subsro in gj.DefaultIfEmpty()
 795:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 796:                                       && huaweiOltIdList.Contains(a.Olt)
 797:                                       && subsro.Access.Id == null
 798:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 799:   
 800:                      list = nokiaList.Union(huaweiOntList).ToList();
 801:                  }
 802:                  else
 803:                  {
 804:                      site = (from a in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where a.Id == siteId select a).SingleOrDefault();
 805:   
 806:                      nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList(siteId);
 807:   
 808:                      // Nokia
 809:                      nokiaList = (from a in db.Accesses
 810:                                   join oid in nokiaOltIdList on a.Olt equals oid
 811:                                   join o in db.Onts on a equals o.Access
 812:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 813:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 814:                                   from subsro in gj.DefaultIfEmpty()
 815:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 816:                                   && o.Serial != null
 817:                                   && o.Serial != "ALCL00000000"
 818:                                   && o.FamilyTypeId != 0
 819:                                   && o.ActiveSoftware != null
 820:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 821:                                   && osv.Ip != null
 822:                                   && subsro.Access.Id == null
 823:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 824:   
 825:                      // Huawei
 826:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList(siteId);
 827:   
 828:                      huaweiOntList = (from a in db.Accesses
 829:                                       join o in db.EmsOnts on a equals o.Access
 830:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 831:                                       from subsro in gj.DefaultIfEmpty()
 832:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 833:                                       && huaweiOltIdList.Contains(a.Olt)
 834:                                       && subsro.Access.Id == null
 835:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 836:   
 837:                      list = nokiaList.Union(huaweiOntList).ToList();
 838:                  }
 839:              }
 840:   
 841:              return list.OrderBy(u => u.Id).ToList();
 842:          }
 843:   
 844:          ////////////////////////////////////////////////////////////////////////////
 845:   
 846:          /// <summary>
 847:          ///
 848:          /// </summary>
 849:          public static List<Ia.Ngn.Cl.Model.Access> AccessesWithMismatchedInfomationInServiceRequestOntList()
 850:          {
 851:              List<Ia.Ngn.Cl.Model.Access> list;
 852:              //Dictionary<int, string> areaIdToSymbolDictionary;
 853:   
 854:              //areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 855:   
 856:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 857:              {
 858:                  // I will ignore area because its fixed with access id, which is shared by both Access and ServiceRequestOnt
 859:   
 860:                  list = (from a in db.Accesses
 861:                          join o in db.Onts on a equals o.Access
 862:                          join osv in db.OntServiceVoips on o equals osv.Ont
 863:                          join sro in db.ServiceRequestOnts on a equals sro.Access
 864:                          //join areaSymbol in areaIdToSymbolDictionary on a.AreaId equals areaSymbol.Key
 865:                          //where sro.AreaSymbol != areaSymbol.Value
 866:                          where (sro.Block != a.Block && !string.IsNullOrEmpty(a.Block))
 867:                          || (sro.Street != a.Street && !string.IsNullOrEmpty(a.Street))
 868:                          || (sro.PremisesOld != a.PremisesOld && !string.IsNullOrEmpty(a.PremisesOld))
 869:                          || (sro.PremisesNew != a.PremisesNew && !string.IsNullOrEmpty(a.PremisesNew))
 870:                          || (sro.Paci != a.Paci && !string.IsNullOrEmpty(a.Paci))
 871:                          //|| (sro.PossibleNumberOfTd != a.PossibleNumberOfTd)
 872:                          //|| (sro.PossibleNumberOfEthernet != a.PossibleNumberOfEthernet)
 873:                          select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 874:              }
 875:   
 876:              return list.OrderBy(u => u.Id).ToList();
 877:          }
 878:   
 879:          ////////////////////////////////////////////////////////////////////////////
 880:   
 881:          /// <summary>
 882:          ///
 883:          /// </summary>
 884:          public static Dictionary<string, int> AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 885:          {
 886:              get
 887:              {
 888:                  Dictionary<string, int> dictionary, nokiaDictionary, huaweiDictionary;
 889:                  List<int> huaweiOltIdList;//, nokiaOltIdList;
 890:   
 891:                  // this is related to ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId()
 892:   
 893:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 894:                  {
 895:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 896:   
 897:                      // Nokia
 898:                      nokiaDictionary = (from a in db.Accesses
 899:                                         join o in db.Onts on a equals o.Access
 900:                                         join osv in db.OntServiceVoips on o equals osv.Ont
 901:                                         join sro in db.ServiceRequestOnts on a equals sro.Access
 902:                                         where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr // ?
 903:                                         && o.Serial != null
 904:                                         && o.Serial != "ALCL00000000"
 905:                                         && o.FamilyTypeId != 0 // ?
 906:                                         && o.ActiveSoftware != null
 907:                                         //&& o.ActiveSoftware == o.PlannedSoftware
 908:                                         && osv.Ip != null
 909:                                         select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 910:   
 911:                      // Huawei
 912:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 913:   
 914:                      huaweiDictionary = (from a in db.Accesses
 915:                                          join o in db.EmsOnts on a equals o.Access
 916:                                          join sro in db.ServiceRequestOnts on a equals sro.Access
 917:                                          //where o.FamilyTypeId != 0
 918:                                          where o.EQUIPMENTID != "--"
 919:                                          && huaweiOltIdList.Contains(a.Olt)
 920:                                          select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 921:   
 922:                      dictionary = nokiaDictionary.Union(huaweiDictionary).ToDictionary(k => k.Key, v => v.Value);
 923:                  }
 924:   
 925:                  return dictionary;
 926:              }
 927:          }
 928:   
 929:          ////////////////////////////////////////////////////////////////////////////
 930:   
 931:          /// <summary>
 932:          ///
 933:          /// </summary>
 934:          public static List<Ia.Ngn.Cl.Model.Access> NokiaAccessList
 935:          {
 936:              get
 937:              {
 938:                  List<int> oltIdList;
 939:                  List<Ia.Ngn.Cl.Model.Access> list;
 940:   
 941:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 942:   
 943:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 944:                  {
 945:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 946:                  }
 947:   
 948:                  return list;
 949:              }
 950:          }
 951:   
 952:          ////////////////////////////////////////////////////////////////////////////
 953:   
 954:          /// <summary>
 955:          ///
 956:          /// </summary>
 957:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessList
 958:          {
 959:              get
 960:              {
 961:                  List<int> oltIdList;
 962:                  List<Ia.Ngn.Cl.Model.Access> list;
 963:   
 964:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 965:   
 966:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 967:                  {
 968:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 969:                  }
 970:   
 971:                  return list;
 972:              }
 973:          }
 974:   
 975:          ////////////////////////////////////////////////////////////////////////////
 976:   
 977:          /// <summary>
 978:          ///
 979:          /// </summary>
 980:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessesWithNoEmsOntList
 981:          {
 982:              get
 983:              {
 984:                  List<int> huaweiOltIdList;
 985:                  List<Ia.Ngn.Cl.Model.Access> list;
 986:   
 987:                  huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 988:   
 989:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 990:                  {
 991:                      list = (from a in db.Accesses
 992:                              join o in db.EmsOnts on a equals o.Access into gj
 993:                              from subsro in gj.DefaultIfEmpty()
 994:                              where huaweiOltIdList.Contains(a.Olt) && subsro.Access.Id == null
 995:                              select a).Distinct().ToList();
 996:                  }
 997:   
 998:                  return list;
 999:              }
1000:          }
1001:   
1002:          ////////////////////////////////////////////////////////////////////////////
1003:   
1004:          /// <summary>
1005:          ///
1006:          /// </summary>
1007:          public static Ia.Ngn.Cl.Model.Access ReadByIp(string ip)
1008:          {
1009:              // below: return the Access object of this ip
1010:   
1011:              Ia.Ngn.Cl.Model.Access item;
1012:   
1013:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1014:              {
1015:                  item = (from a in db.Accesses join o in db.Onts on a equals o.Access join ov in db.OntServiceVoips on o equals ov.Ont where ov.Ip == ip select a).SingleOrDefault();
1016:              }
1017:   
1018:              return item;
1019:          }
1020:   
1021:          ////////////////////////////////////////////////////////////////////////////
1022:   
1023:          /// <summary>
1024:          ///
1025:          /// </summary>
1026:          public static Ia.Ngn.Cl.Model.Access ReadByIp(Ia.Ngn.Cl.Model.Ngn db, string ip)
1027:          {
1028:              // below: return the Access object of this ip
1029:   
1030:              return (from a in db.Accesses join o in db.Onts on a equals o.Access join ov in db.OntServiceVoips on o equals ov.Ont where ov.Ip == ip select a).SingleOrDefault();
1031:          }
1032:   
1033:          ////////////////////////////////////////////////////////////////////////////
1034:   
1035:          /// <summary>
1036:          ///
1037:          /// </summary>
1038:          public static Ia.Ngn.Cl.Model.Ui.Access StatisticalAccess(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, ref List<Ia.Ngn.Cl.Model.Ui.Access> accessList, out string note)
1039:          {
1040:              int numberOfTrials;
1041:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1042:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1043:   
1044:              numberOfTrials = 0;
1045:   
1046:              if (serviceAddress.AreaId != 0)
1047:              {
1048:                  numberOfTrials++;
1049:   
1050:                  _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId).ToList();
1051:   
1052:                  if (!string.IsNullOrEmpty(serviceAddress.Block) && _accessList.Any(u => u.Block == serviceAddress.Block))
1053:                  {
1054:                      numberOfTrials++;
1055:   
1056:                      note = string.Empty;
1057:   
1058:                      _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block).ToList();
1059:   
1060:                      if (!string.IsNullOrEmpty(serviceAddress.Street))
1061:                      {
1062:                          numberOfTrials++;
1063:   
1064:                          statisticalAccess = StatisticalAccessBlockAndStreet(serviceAddress, serviceAddress.Street, ref accessList, ref note, ref numberOfTrials);
1065:                      }
1066:                      else
1067:                      {
1068:                          statisticalAccess = StatisticalAccessBlockAndNoStreet(serviceAddress, ref accessList, ref note, ref numberOfTrials);
1069:                      }
1070:                  }
1071:                  else
1072:                  {
1073:                      numberOfTrials++;
1074:   
1075:                      statisticalAccess = null;
1076:   
1077:                      note = "serviceAddress.Block is empty or null";
1078:                  }
1079:              }
1080:              else
1081:              {
1082:                  numberOfTrials++;
1083:   
1084:                  statisticalAccess = null;
1085:   
1086:                  note = "serviceAddress.AreaId is 0";
1087:              }
1088:   
1089:              if (statisticalAccess != null) statisticalAccess.NumberOfTrials = numberOfTrials;
1090:   
1091:              return statisticalAccess;
1092:          }
1093:   
1094:          //
1095:          ////////////////////////////////////////////////////////////////////////////
1096:   
1097:          /// <summary>
1098:          ///
1099:          /// </summary>
1100:          private static Ia.Ngn.Cl.Model.Ui.Access LevenshteinDistance(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, ref List<Ia.Ngn.Cl.Model.Ui.Access> accessList)
1101:          {
1102:              string accessLevenshteinString, serviceAddressLevenshteinString, idOfKeyWithMinValue;
1103:              Dictionary<string, int> dictionary;
1104:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1105:   
1106:              dictionary = new Dictionary<string, int>();
1107:   
1108:              serviceAddressLevenshteinString = serviceAddress.Block + ":" + serviceAddress.Street + ":" + serviceAddress.PremisesOld + ":" + serviceAddress.PremisesNew;
1109:   
1110:              foreach (var a in accessList)
1111:              {
1112:                  accessLevenshteinString = a.Block + ":" + a.Street + ":" + a.PremisesOld + ":" + a.PremisesNew;
1113:   
1114:                  dictionary[a.Id] = Ia.Cl.Model.Default.LevenshteinDistance(serviceAddressLevenshteinString, accessLevenshteinString);
1115:              }
1116:   
1117:              var minValue = dictionary.Values.Min();
1118:   
1119:              idOfKeyWithMinValue = dictionary.FirstOrDefault(u => u.Value == minValue).Key;
1120:   
1121:              statisticalAccess = (from a in accessList where a.Id == idOfKeyWithMinValue select a).SingleOrDefault();
1122:   
1123:              return statisticalAccess;
1124:          }
1125:   
1126:          ////////////////////////////////////////////////////////////////////////////
1127:   
1128:          /// <summary>
1129:          ///
1130:          /// </summary>
1131:          private static Ia.Ngn.Cl.Model.Ui.Access StatisticalAccessBlockAndStreet(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, string street, ref List<Ia.Ngn.Cl.Model.Ui.Access> accessList, ref string note, ref int numberOfTrials)
1132:          {
1133:              string po, pn;
1134:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1135:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1136:   
1137:              numberOfTrials++;
1138:   
1139:              _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block && u.Street == street).ToList();
1140:   
1141:              note = string.Empty;
1142:   
1143:              EvaluateAndCorrectPremisesOldAndPremisesNew(serviceAddress.PremisesOld, serviceAddress.PremisesNew, out po, out pn);
1144:              serviceAddress.PremisesOld = po;
1145:              serviceAddress.PremisesNew = pn;
1146:   
1147:              statisticalAccess = (from a in _accessList
1148:                                   where a.AreaId == serviceAddress.AreaId
1149:                                       && a.Block == serviceAddress.Block
1150:                                       && a.Street == street
1151:                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1152:                                       && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1153:                                   select a).FirstOrDefault();
1154:   
1155:              if (statisticalAccess == null)
1156:              {
1157:                  numberOfTrials++;
1158:   
1159:                  statisticalAccess = (from a in _accessList
1160:                                       where a.AreaId == serviceAddress.AreaId
1161:                                           && a.Block == serviceAddress.Block
1162:                                           && a.Street == street
1163:                                           && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1164:                                       select a).FirstOrDefault();
1165:   
1166:                  if (statisticalAccess == null)
1167:                  {
1168:                      numberOfTrials++;
1169:   
1170:                      statisticalAccess = (from a in _accessList
1171:                                           where a.AreaId == serviceAddress.AreaId
1172:                                               && a.Block == serviceAddress.Block
1173:                                               && a.Street == street
1174:                                               && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1175:                                           select a).FirstOrDefault();
1176:   
1177:                      if (statisticalAccess == null)
1178:                      {
1179:                          numberOfTrials++;
1180:   
1181:                          statisticalAccess = (from a in _accessList
1182:                                               where a.AreaId == serviceAddress.AreaId
1183:                                                   && a.Block == serviceAddress.Block
1184:                                                   && a.Street == street
1185:                                                   && a.PremisesOld == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1186:                                               select a).FirstOrDefault();
1187:   
1188:                          if (statisticalAccess == null)
1189:                          {
1190:                              numberOfTrials++;
1191:   
1192:                              statisticalAccess = (from a in _accessList
1193:                                                   where a.AreaId == serviceAddress.AreaId
1194:                                                       && a.Block == serviceAddress.Block
1195:                                                       && a.Street == street
1196:                                                       && a.PremisesNew == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1197:                                                   select a).FirstOrDefault();
1198:   
1199:                              if (statisticalAccess == null)
1200:                              {
1201:                                  numberOfTrials++;
1202:   
1203:                                  statisticalAccess = (from a in _accessList
1204:                                                       where a.AreaId == serviceAddress.AreaId
1205:                                                           && a.Block == serviceAddress.Block
1206:                                                           && a.Street == street
1207:                                                           && a.PremisesNew == serviceAddress.Boulevard && !string.IsNullOrEmpty(serviceAddress.Boulevard)
1208:                                                       select a).FirstOrDefault();
1209:   
1210:                                  if (statisticalAccess == null)
1211:                                  {
1212:                                      numberOfTrials++;
1213:   
1214:                                      statisticalAccess = (from a in _accessList
1215:                                                           where a.AreaId == serviceAddress.AreaId
1216:                                                               && a.Block == serviceAddress.Block
1217:                                                               && a.Street == street
1218:                                                               && a.PremisesOld == serviceAddress.Boulevard && !string.IsNullOrEmpty(serviceAddress.Boulevard)
1219:                                                           select a).FirstOrDefault();
1220:   
1221:                                      if (statisticalAccess == null)
1222:                                      {
1223:                                          numberOfTrials++;
1224:   
1225:                                          statisticalAccess = (from a in _accessList
1226:                                                               where a.AreaId == serviceAddress.AreaId
1227:                                                                   && a.Block == serviceAddress.Block
1228:                                                                   && a.Street == street
1229:                                                                   && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1230:                                                                   && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1231:                                                               select a).FirstOrDefault();
1232:   
1233:                                          if (statisticalAccess == null)
1234:                                          {
1235:                                              numberOfTrials++;
1236:   
1237:                                              statisticalAccess = (from a in _accessList
1238:                                                                   where a.AreaId == serviceAddress.AreaId
1239:                                                                       && a.Block == serviceAddress.Block
1240:                                                                       && a.Street == street
1241:                                                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1242:                                                                       && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1243:                                                                   select a).FirstOrDefault();
1244:   
1245:                                              if (statisticalAccess == null)
1246:                                              {
1247:                                                  numberOfTrials++;
1248:   
1249:                                                  statisticalAccess = (from a in _accessList
1250:                                                                       where a.AreaId == serviceAddress.AreaId
1251:                                                                           && a.Block == serviceAddress.Block
1252:                                                                           && a.Street == street
1253:                                                                           && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1254:                                                                       select a).FirstOrDefault();
1255:   
1256:                                                  if (statisticalAccess == null)
1257:                                                  {
1258:                                                      numberOfTrials++;
1259:   
1260:                                                      statisticalAccess = (from a in _accessList
1261:                                                                           where a.AreaId == serviceAddress.AreaId
1262:                                                                               && a.Block == serviceAddress.Block
1263:                                                                               && a.Street == street
1264:                                                                               && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1265:                                                                           select a).FirstOrDefault();
1266:   
1267:                                                      if (statisticalAccess == null)
1268:                                                      {
1269:                                                          numberOfTrials++;
1270:   
1271:   
1272:                                                      }
1273:                                                  }
1274:                                              }
1275:                                          }
1276:                                      }
1277:                                  }
1278:                              }
1279:                          }
1280:                      }
1281:                  }
1282:              }
1283:   
1284:              return statisticalAccess;
1285:          }
1286:   
1287:          ////////////////////////////////////////////////////////////////////////////
1288:   
1289:          /// <summary>
1290:          ///
1291:          /// </summary>
1292:          private static Ia.Ngn.Cl.Model.Ui.Access StatisticalAccessBlockAndNoStreet(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, ref List<Ia.Ngn.Cl.Model.Ui.Access> accessList, ref string note, ref int numberOfTrials)
1293:          {
1294:              string po, pn;
1295:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1296:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1297:   
1298:              numberOfTrials++;
1299:   
1300:              _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block).ToList();
1301:   
1302:              note = string.Empty;
1303:   
1304:              EvaluateAndCorrectPremisesOldAndPremisesNew(serviceAddress.PremisesOld, serviceAddress.PremisesNew, out po, out pn);
1305:              serviceAddress.PremisesOld = po;
1306:              serviceAddress.PremisesNew = pn;
1307:   
1308:              statisticalAccess = (from a in _accessList
1309:                                   where a.AreaId == serviceAddress.AreaId
1310:                                       && a.Block == serviceAddress.Block
1311:                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1312:                                       && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1313:                                   select a).FirstOrDefault();
1314:   
1315:              if (statisticalAccess == null)
1316:              {
1317:                  statisticalAccess = (from a in _accessList
1318:                                       where a.AreaId == serviceAddress.AreaId
1319:                                           && a.Block == serviceAddress.Block
1320:                                           && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1321:                                       select a).FirstOrDefault();
1322:   
1323:                  if (statisticalAccess == null)
1324:                  {
1325:                      numberOfTrials++;
1326:   
1327:                      statisticalAccess = (from a in _accessList
1328:                                           where a.AreaId == serviceAddress.AreaId
1329:                                               && a.Block == serviceAddress.Block
1330:                                               && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1331:                                           select a).FirstOrDefault();
1332:   
1333:                      if (statisticalAccess == null)
1334:                      {
1335:                          numberOfTrials++;
1336:   
1337:                          statisticalAccess = (from a in _accessList
1338:                                               where a.AreaId == serviceAddress.AreaId
1339:                                                   && a.Block == serviceAddress.Block
1340:                                                   && a.PremisesOld == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1341:                                               select a).FirstOrDefault();
1342:   
1343:                          if (statisticalAccess == null)
1344:                          {
1345:                              numberOfTrials++;
1346:   
1347:                              statisticalAccess = (from a in _accessList
1348:                                                   where a.AreaId == serviceAddress.AreaId
1349:                                                       && a.Block == serviceAddress.Block
1350:                                                       && a.PremisesNew == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1351:                                                   select a).FirstOrDefault();
1352:   
1353:                              if (statisticalAccess == null)
1354:                              {
1355:                                  numberOfTrials++;
1356:   
1357:                                  statisticalAccess = (from a in _accessList
1358:                                                       where a.AreaId == serviceAddress.AreaId
1359:                                                           && a.Block == serviceAddress.Block
1360:                                                           && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1361:                                                           && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1362:                                                       select a).FirstOrDefault();
1363:   
1364:                                  if (statisticalAccess == null)
1365:                                  {
1366:                                      numberOfTrials++;
1367:   
1368:                                      statisticalAccess = (from a in _accessList
1369:                                                           where a.AreaId == serviceAddress.AreaId
1370:                                                               && a.Block == serviceAddress.Block
1371:                                                               && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1372:                                                               && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1373:                                                           select a).FirstOrDefault();
1374:   
1375:                                      if (statisticalAccess == null)
1376:                                      {
1377:                                          numberOfTrials++;
1378:   
1379:                                          statisticalAccess = (from a in _accessList
1380:                                                               where a.AreaId == serviceAddress.AreaId
1381:                                                                   && a.Block == serviceAddress.Block
1382:                                                                   && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1383:                                                               select a).FirstOrDefault();
1384:   
1385:                                          if (statisticalAccess == null)
1386:                                          {
1387:                                              numberOfTrials++;
1388:   
1389:                                              statisticalAccess = (from a in _accessList
1390:                                                                   where a.AreaId == serviceAddress.AreaId
1391:                                                                       && a.Block == serviceAddress.Block
1392:                                                                       && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1393:                                                                   select a).FirstOrDefault();
1394:   
1395:                                              if (statisticalAccess == null)
1396:                                              {
1397:                                                  numberOfTrials++;
1398:   
1399:                                                  statisticalAccess = null;
1400:   
1401:                                                  note = "serviceAddress.Street is empty or null";
1402:                                              }
1403:                                          }
1404:                                      }
1405:                                  }
1406:                              }
1407:                          }
1408:                      }
1409:                  }
1410:              }
1411:   
1412:              return statisticalAccess;
1413:          }
1414:   
1415:          ////////////////////////////////////////////////////////////////////////////
1416:   
1417:          /// <summary>
1418:          ///
1419:          /// </summary>
1420:          public static void EvaluateAndCorrectPremisesOldAndPremisesNew(string premisesOld, string premisesNew, out string newPremisesOld, out string newPremisesNew)
1421:          {
1422:              int po, pn;
1423:   
1424:              if (!string.IsNullOrEmpty(premisesOld) && !string.IsNullOrEmpty(premisesNew))
1425:              {
1426:                  if (int.TryParse(premisesOld, out po) && int.TryParse(premisesNew, out pn))
1427:                  {
1428:                      // if equal then one is invalid
1429:                      if (po == pn)
1430:                      {
1431:                          if (po > 100)
1432:                          {
1433:                              newPremisesOld = po.ToString();
1434:                              newPremisesNew = string.Empty;
1435:                          }
1436:                          else
1437:                          {
1438:                              newPremisesOld = string.Empty;
1439:                              newPremisesNew = po.ToString();
1440:                          }
1441:                      }
1442:                      else
1443:                      {
1444:                          if (pn > po)
1445:                          {
1446:                              newPremisesOld = pn.ToString();
1447:                              newPremisesNew = po.ToString();
1448:                          }
1449:                          else
1450:                          {
1451:                              newPremisesOld = po.ToString();
1452:                              newPremisesNew = pn.ToString();
1453:                          }
1454:                      }
1455:                  }
1456:                  else if (int.TryParse(premisesOld, out po) && !int.TryParse(premisesNew, out pn))
1457:                  {
1458:                      // if equal then one is invalid
1459:                      if (po.ToString() == premisesNew)
1460:                      {
1461:                          if (po > 100)
1462:                          {
1463:                              newPremisesOld = po.ToString();
1464:                              newPremisesNew = string.Empty;
1465:                          }
1466:                          else
1467:                          {
1468:                              newPremisesOld = string.Empty;
1469:                              newPremisesNew = po.ToString();
1470:                          }
1471:                      }
1472:                      else
1473:                      {
1474:                          if (premisesNew.Length > po.ToString().Length)
1475:                          {
1476:                              newPremisesOld = premisesNew;
1477:                              newPremisesNew = po.ToString();
1478:                          }
1479:                          else
1480:                          {
1481:                              newPremisesOld = po.ToString();
1482:                              newPremisesNew = premisesNew;
1483:                          }
1484:                      }
1485:                  }
1486:                  else if (!int.TryParse(premisesOld, out po) && int.TryParse(premisesNew, out pn))
1487:                  {
1488:                      // if equal then one is invalid
1489:                      if (premisesOld == pn.ToString())
1490:                      {
1491:                          if (premisesOld.Length >= 3)
1492:                          {
1493:                              newPremisesOld = premisesOld.ToString();
1494:                              newPremisesNew = string.Empty;
1495:                          }
1496:                          else
1497:                          {
1498:                              newPremisesOld = string.Empty;
1499:                              newPremisesNew = premisesOld;
1500:                          }
1501:                      }
1502:                      else
1503:                      {
1504:                          if (pn.ToString().Length > premisesOld.Length)
1505:                          {
1506:                              newPremisesOld = pn.ToString();
1507:                              newPremisesNew = premisesOld;
1508:                          }
1509:                          else
1510:                          {
1511:                              newPremisesOld = premisesOld;
1512:                              newPremisesNew = pn.ToString();
1513:                          }
1514:                      }
1515:                  }
1516:                  else //if (!int.TryParse(premisesOld, out po) && !int.TryParse(premisesNew, out pn))
1517:                  {
1518:                      // if equal then one is invalid
1519:                      if (premisesOld == premisesNew)
1520:                      {
1521:                          if (premisesOld.Length >= 3)
1522:                          {
1523:                              newPremisesOld = premisesOld;
1524:                              newPremisesNew = string.Empty;
1525:                          }
1526:                          else
1527:                          {
1528:                              newPremisesOld = string.Empty;
1529:                              newPremisesNew = premisesOld;
1530:                          }
1531:                      }
1532:                      else
1533:                      {
1534:                          if (premisesNew.Length > premisesOld.Length)
1535:                          {
1536:                              newPremisesOld = premisesNew;
1537:                              newPremisesNew = premisesOld;
1538:                          }
1539:                          else
1540:                          {
1541:                              newPremisesOld = premisesOld;
1542:                              newPremisesNew = premisesNew;
1543:                          }
1544:                      }
1545:                  }
1546:              }
1547:              else if (!string.IsNullOrEmpty(premisesOld) && string.IsNullOrEmpty(premisesNew))
1548:              {
1549:                  if (premisesOld.Length >= 3)
1550:                  {
1551:                      newPremisesOld = premisesOld;
1552:                      newPremisesNew = string.Empty;
1553:                  }
1554:                  else
1555:                  {
1556:                      newPremisesOld = string.Empty;
1557:                      newPremisesNew = premisesOld;
1558:                  }
1559:              }
1560:              else if (string.IsNullOrEmpty(premisesOld) && !string.IsNullOrEmpty(premisesNew))
1561:              {
1562:                  if (premisesNew.Length < 3)
1563:                  {
1564:                      newPremisesOld = string.Empty;
1565:                      newPremisesNew = premisesNew;
1566:                  }
1567:                  else
1568:                  {
1569:                      newPremisesOld = premisesNew;
1570:                      newPremisesNew = string.Empty;
1571:                  }
1572:              }
1573:              else //if (string.IsNullOrEmpty(premisesOld) && string.IsNullOrEmpty(premisesNew))
1574:              {
1575:                  newPremisesOld = string.Empty;
1576:                  newPremisesNew = string.Empty;
1577:              }
1578:          }
1579:   
1580:          ////////////////////////////////////////////////////////////////////////////
1581:          ////////////////////////////////////////////////////////////////////////////
1582:   
1583:          /// <summary>
1584:          ///
1585:          /// </summary>
1586:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Access access)
1587:          {
1588:              StringBuilder sb;
1589:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
1590:   
1591:              sb = new StringBuilder();
1592:   
1593:              vendor = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Id == access.Id select o.Pon.PonGroup.Olt.Odf.Vendor).SingleOrDefault();
1594:   
1595:              sb.AppendLine("Vendor: " + vendor.Name);
1596:              sb.AppendLine("Name: " + access.Name);
1597:              sb.AppendLine("Address: " + access.Address);
1598:   
1599:              if (!string.IsNullOrEmpty(access.Paci)) sb.AppendLine("Paci: " + access.Paci);
1600:              if (!string.IsNullOrEmpty(access.Note)) sb.AppendLine("Note: " + access.Note);
1601:   
1602:              return sb.ToString();
1603:          }
1604:   
1605:          ////////////////////////////////////////////////////////////////////////////
1606:          ////////////////////////////////////////////////////////////////////////////
1607:      }
1608:   
1609:      ////////////////////////////////////////////////////////////////////////////
1610:      ////////////////////////////////////////////////////////////////////////////
1611:  }