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

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