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

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