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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Access

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

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

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data.Entity;
   4:  using System.Linq;
   5:  using System.Text;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Data
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Access support class for Next Generation Network (NGN) data model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-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 = System.Data.Entity.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:              int oltId, pon, ont;
 430:              Ia.Ngn.Cl.Model.Access access;
 431:   
 432:              // below: this expects accessName in exact format like SUR.12.3
 433:   
 434:              Ia.Ngn.Cl.Model.Business.Access.ExtractOltIdAndPonNumberAndOntNumberFromOntName(accessName, out oltId, out pon, out ont);
 435:   
 436:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 437:              {
 438:                  access = (from a in db.Accesses where a.Olt == oltId && a.Pon == pon && a.Ont == ont select a).SingleOrDefault();
 439:              }
 440:   
 441:              return access;
 442:          }
 443:   
 444:          ////////////////////////////////////////////////////////////////////////////
 445:   
 446:          /// <summary>
 447:          ///
 448:          /// </summary>
 449:          public static List<Ia.Ngn.Cl.Model.Access> ListUsingOntFamilyType(int familyTypeId)
 450:          {
 451:              // below: return access list for family type
 452:              List<Ia.Ngn.Cl.Model.Access> nokiaList, huaweiList, list;
 453:   
 454:              list = new List<Ia.Ngn.Cl.Model.Access>();
 455:   
 456:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 457:              {
 458:                  nokiaList = (from a in db.Accesses join o in db.Onts on a equals o.Access where o.FamilyTypeId == familyTypeId select a).ToList();
 459:   
 460:                  var systemNameListList = (from e in Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeList
 461:                                            where e.FamilyType == (Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType)familyTypeId
 462:                                            select e.SystemNameList).ToList();
 463:   
 464:                  var equipmentTypeStringList = new List<string>();
 465:   
 466:                  foreach (var systemNameList in systemNameListList)
 467:                  {
 468:                      foreach (string systemName in systemNameList)
 469:                      {
 470:                          equipmentTypeStringList.Add(systemName);
 471:                      }
 472:                  }
 473:   
 474:                  equipmentTypeStringList = equipmentTypeStringList.Distinct().ToList();
 475:   
 476:                  huaweiList = (from a in db.Accesses join eo in db.EmsOnts on a equals eo.Access where equipmentTypeStringList.Contains(eo.EQUIPMENTID) select a).ToList();
 477:              }
 478:   
 479:              list.AddRange(nokiaList);
 480:              list.AddRange(huaweiList);
 481:   
 482:              return list.ToList();
 483:          }
 484:   
 485:          ////////////////////////////////////////////////////////////////////////////
 486:   
 487:          /// <summary>
 488:          ///
 489:          /// </summary>
 490:          public static List<string> ReadAccessNameListUsingKuwaitNgnAreaIdAndBlock(int kuwaitAreaId, string block)
 491:          {
 492:              Dictionary<string, string> di;
 493:              List<string> accessIdList, accessNameList;
 494:   
 495:              if (kuwaitAreaId > 0 && !string.IsNullOrEmpty(block))
 496:              {
 497:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 498:                  {
 499:                      accessIdList = (from a in db.Accesses where a.AreaId == kuwaitAreaId && a.Block == block select a.Id).ToList();
 500:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 501:   
 502:                      if (accessIdList != null && accessIdList.Count > 0)
 503:                      {
 504:                          accessNameList = new List<string>(accessIdList.Count);
 505:   
 506:                          foreach (string accessId in accessIdList)
 507:                          {
 508:                              if (di.ContainsKey(accessId)) accessNameList.Add(di[accessId]);
 509:                          }
 510:                      }
 511:                      else
 512:                      {
 513:                          accessNameList = null;
 514:                      }
 515:                  }
 516:              }
 517:              else
 518:              {
 519:                  accessNameList = null;
 520:              }
 521:   
 522:              return accessNameList;
 523:          }
 524:   
 525:          ////////////////////////////////////////////////////////////////////////////
 526:   
 527:          /// <summary>
 528:          ///
 529:          /// </summary>
 530:          public static List<Ia.Ngn.Cl.Model.Access> ListByKuwaitNgnAreaId(int kuwaitAreaId)
 531:          {
 532:              List<Ia.Ngn.Cl.Model.Access> list;
 533:   
 534:              if (kuwaitAreaId > 0)
 535:              {
 536:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 537:                  {
 538:                      list = (from a in db.Accesses where a.AreaId == kuwaitAreaId select a).ToList();
 539:                  }
 540:              }
 541:              else
 542:              {
 543:                  list = null;
 544:              }
 545:   
 546:              return list;
 547:          }
 548:   
 549:          ////////////////////////////////////////////////////////////////////////////
 550:   
 551:          /// <summary>
 552:          ///
 553:          /// </summary>
 554:          public static Dictionary<string, string> DistinctAccessKuwaitNgnAreaIdAndBlockDictionary
 555:          {
 556:              get
 557:              {
 558:                  int kuwaitNgnAreaId, block;
 559:                  string kuwaitNgnAreaIdString, blockString, kuwaitNgnAreaBlockValue, kuwaitNgnAreaNameArabicName;
 560:                  Dictionary<string, string> tempDictionary;
 561:                  Dictionary<string, string> dictionary;
 562:   
 563:                  dictionary = new Dictionary<string, string>();
 564:                  tempDictionary = new Dictionary<string, string>();
 565:   
 566:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 567:                  {
 568:                      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);
 569:   
 570:                      if (tempDictionary != null && tempDictionary.Count > 0)
 571:                      {
 572:                          foreach (KeyValuePair<string, string> kvp in tempDictionary)
 573:                          {
 574:                              kuwaitNgnAreaIdString = kvp.Key.Split(',')[0].ToString();
 575:                              blockString = kvp.Key.Split(',')[1].ToString();
 576:   
 577:                              if (int.TryParse(kuwaitNgnAreaIdString, out kuwaitNgnAreaId) && int.TryParse(blockString, out block))
 578:                              {
 579:                                  kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == kuwaitNgnAreaId select kna.NameArabicName).SingleOrDefault();
 580:   
 581:                                  kuwaitNgnAreaBlockValue = kuwaitNgnAreaNameArabicName + ", block " + block;
 582:   
 583:                                  dictionary.Add(kvp.Key, kuwaitNgnAreaBlockValue);
 584:                              }
 585:                              else
 586:                              {
 587:                              }
 588:                          }
 589:                      }
 590:                      else
 591:                      {
 592:                      }
 593:                  }
 594:   
 595:                  return dictionary;
 596:              }
 597:          }
 598:   
 599:          ////////////////////////////////////////////////////////////////////////////
 600:   
 601:          /// <summary>
 602:          ///
 603:          /// </summary>
 604:          public static Dictionary<int, string> DistinctAccessKuwaitNgnAreaIdToNameArabicNameDictionary
 605:          {
 606:              get
 607:              {
 608:                  string kuwaitNgnAreaNameArabicName;
 609:                  List<int> list;
 610:                  Dictionary<int, string> dictionary;
 611:   
 612:                  dictionary = new Dictionary<int, string>();
 613:                  list = new List<int>();
 614:   
 615:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 616:                  {
 617:                      list = (from a in db.Accesses select a.AreaId).Distinct().ToList();
 618:   
 619:                      if (list.Count > 0)
 620:                      {
 621:                          foreach (int i in list)
 622:                          {
 623:                              kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == i select kna.NameArabicName).SingleOrDefault();
 624:   
 625:                              dictionary.Add(i, kuwaitNgnAreaNameArabicName);
 626:                          }
 627:                      }
 628:                      else
 629:                      {
 630:                      }
 631:                  }
 632:   
 633:                  return dictionary;
 634:              }
 635:          }
 636:   
 637:          ////////////////////////////////////////////////////////////////////////////
 638:   
 639:          /// <summary>
 640:          ///
 641:          /// </summary>
 642:          public static Dictionary<string, int> IdToKuwaitNgnAreaIdDictionary
 643:          {
 644:              get
 645:              {
 646:                  Dictionary<string, int> dictionary;
 647:   
 648:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 649:                  {
 650:                      dictionary = (from a in db.Accesses select new { a.Id, a.AreaId }).ToDictionary(u => u.Id, u => u.AreaId);
 651:                  }
 652:   
 653:                  return dictionary;
 654:              }
 655:          }
 656:   
 657:          ////////////////////////////////////////////////////////////////////////////
 658:   
 659:          /// <summary>
 660:          ///
 661:          /// </summary>
 662:          public static Dictionary<string, string> IdToKuwaitNgnAreaSymbolDictionary
 663:          {
 664:              get
 665:              {
 666:                  Dictionary<string, int> accessIdToKuwaitNgnAreaIdDictionary;
 667:                  Dictionary<int, string> areaIdToSymbolDictionary;
 668:                  Dictionary<string, string> dictionary;
 669:   
 670:                  accessIdToKuwaitNgnAreaIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaIdDictionary;
 671:                  areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 672:   
 673:                  dictionary = new Dictionary<string, string>(accessIdToKuwaitNgnAreaIdDictionary.Count);
 674:   
 675:                  foreach (KeyValuePair<string, int> kvp in accessIdToKuwaitNgnAreaIdDictionary)
 676:                  {
 677:                      if (areaIdToSymbolDictionary.ContainsKey(kvp.Value)) dictionary[kvp.Key] = areaIdToSymbolDictionary[kvp.Value];
 678:                  }
 679:   
 680:                  return dictionary;
 681:              }
 682:          }
 683:   
 684:          ////////////////////////////////////////////////////////////////////////////
 685:   
 686:          /// <summary>
 687:          ///
 688:          /// </summary>
 689:          public static Dictionary<string, int> IdToOltIdDictionary
 690:          {
 691:              get
 692:              {
 693:                  Dictionary<string, int> dictionary;
 694:   
 695:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 696:                  {
 697:                      dictionary = (from a in db.Accesses select new { a.Id, a.Olt }).ToDictionary(u => u.Id, u => u.Olt);
 698:                  }
 699:   
 700:                  return dictionary;
 701:              }
 702:          }
 703:   
 704:          ////////////////////////////////////////////////////////////////////////////
 705:   
 706:          /// <summary>
 707:          ///
 708:          /// </summary>
 709:          public static Dictionary<string, Ia.Ngn.Cl.Model.Access> IdToAccessDictionary
 710:          {
 711:              get
 712:              {
 713:                  Dictionary<string, Ia.Ngn.Cl.Model.Access> dictionary;
 714:   
 715:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 716:                  {
 717:                      dictionary = (from a in db.Accesses select new { AccessId = a.Id, Access = a }).ToDictionary(u => u.AccessId, u => u.Access);
 718:                  }
 719:   
 720:                  return dictionary;
 721:              }
 722:          }
 723:   
 724:          ////////////////////////////////////////////////////////////////////////////
 725:   
 726:          /// <summary>
 727:          ///
 728:          /// </summary>
 729:          public static Dictionary<string, Ia.Ngn.Cl.Model.Access> IdToHuaweiAccessDictionary
 730:          {
 731:              get
 732:              {
 733:                  List<int> oltIdList;
 734:                  Dictionary<string, Ia.Ngn.Cl.Model.Access> dictionary;
 735:   
 736:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 737:   
 738:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 739:                  {
 740:                      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);
 741:                  }
 742:   
 743:                  return dictionary;
 744:              }
 745:          }
 746:   
 747:          ////////////////////////////////////////////////////////////////////////////
 748:   
 749:          /// <summary>
 750:          ///
 751:          /// </summary>
 752:          public static List<string> IdList
 753:          {
 754:              get
 755:              {
 756:                  List<string> list;
 757:   
 758:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 759:                  {
 760:                      list = (from a in db.Accesses select a.Id).ToList();
 761:                  }
 762:   
 763:                  return list;
 764:              }
 765:          }
 766:   
 767:          ////////////////////////////////////////////////////////////////////////////
 768:   
 769:          /// <summary>
 770:          ///
 771:          /// </summary>
 772:          public static List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> FamilyStatisticInKuwaitNgnAreaAndBlockTable
 773:          {
 774:              // FamilyType { Undefined = 0, Sfu = 1, Soho = 2, Mdu = 3 };
 775:   
 776:              get
 777:              {
 778:                  Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock item;
 779:                  List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> list, sfu, soho, mdu;
 780:   
 781:                  list = new List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock>();
 782:   
 783:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 784:                  {
 785:                      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();
 786:                      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();
 787:                      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();
 788:   
 789:                      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 });
 790:   
 791:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in soho)
 792:                      {
 793:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 794:   
 795:                          if (item != null) item.Soho = a.Soho;
 796:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Soho = a.Soho });
 797:                      }
 798:   
 799:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in mdu)
 800:                      {
 801:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 802:   
 803:                          if (item != null) item.Mdu = a.Mdu;
 804:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Mdu = a.Mdu });
 805:                      }
 806:   
 807:                      list = list.OrderBy(u => u.AreaId).ThenBy(u => u.Block).ToList();
 808:   
 809:                      return list;
 810:                  }
 811:              }
 812:          }
 813:   
 814:          ////////////////////////////////////////////////////////////////////////////
 815:   
 816:          /// <summary>
 817:          ///
 818:          /// </summary>
 819:          public static List<Ia.Ngn.Cl.Model.Access> AccessesWithProvisionedAndReadyOntsAndEmsOntsButDoNotExistInCustomerDepartmentDatabaseList()
 820:          {
 821:              return ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(0);
 822:          }
 823:   
 824:          ////////////////////////////////////////////////////////////////////////////
 825:   
 826:          /// <summary>
 827:          ///
 828:          /// </summary>
 829:          public static List<Ia.Ngn.Cl.Model.Access> ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(int siteId)
 830:          {
 831:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
 832:              List<int> nokiaOltIdList, huaweiOltIdList;
 833:              List<Ia.Ngn.Cl.Model.Access> list, nokiaList, huaweiOntList;
 834:   
 835:              // this is related to AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 836:   
 837:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 838:              {
 839:                  if (siteId == 0)
 840:                  {
 841:                      // if siteId is 0 we will return results for all sites
 842:   
 843:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 844:   
 845:                      // Nokia
 846:                      nokiaList = (from a in db.Accesses
 847:                                       // join oid in nokiaOltIdList on a.Olt equals oid
 848:                                   join o in db.Onts on a equals o.Access
 849:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 850:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 851:                                   from subsro in gj.DefaultIfEmpty()
 852:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 853:                                   && o.Serial != null
 854:                                   && o.Serial != "ALCL00000000"
 855:                                   && o.FamilyTypeId != 0
 856:                                   && o.ActiveSoftware != null
 857:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 858:                                   && osv.Ip != null
 859:                                   && subsro.Access.Id == null
 860:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 861:   
 862:                      // Huawei
 863:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 864:   
 865:                      huaweiOntList = (from a in db.Accesses
 866:                                       join o in db.EmsOnts on a equals o.Access
 867:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 868:                                       from subsro in gj.DefaultIfEmpty()
 869:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 870:                                       && huaweiOltIdList.Contains(a.Olt)
 871:                                       && subsro.Access.Id == null
 872:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 873:   
 874:                      list = nokiaList.Union(huaweiOntList).ToList();
 875:                  }
 876:                  else
 877:                  {
 878:                      site = (from a in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where a.Id == siteId select a).SingleOrDefault();
 879:   
 880:                      nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList(siteId);
 881:   
 882:                      // Nokia
 883:                      nokiaList = (from a in db.Accesses
 884:                                   join oid in nokiaOltIdList on a.Olt equals oid
 885:                                   join o in db.Onts on a equals o.Access
 886:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 887:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 888:                                   from subsro in gj.DefaultIfEmpty()
 889:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 890:                                   && o.Serial != null
 891:                                   && o.Serial != "ALCL00000000"
 892:                                   && o.FamilyTypeId != 0
 893:                                   && o.ActiveSoftware != null
 894:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 895:                                   && osv.Ip != null
 896:                                   && subsro.Access.Id == null
 897:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 898:   
 899:                      // Huawei
 900:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList(siteId);
 901:   
 902:                      huaweiOntList = (from a in db.Accesses
 903:                                       join o in db.EmsOnts on a equals o.Access
 904:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 905:                                       from subsro in gj.DefaultIfEmpty()
 906:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 907:                                       && huaweiOltIdList.Contains(a.Olt)
 908:                                       && subsro.Access.Id == null
 909:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 910:   
 911:                      list = nokiaList.Union(huaweiOntList).ToList();
 912:                  }
 913:              }
 914:   
 915:              return list.OrderBy(u => u.Id).ToList();
 916:          }
 917:   
 918:          ////////////////////////////////////////////////////////////////////////////
 919:   
 920:          /// <summary>
 921:          ///
 922:          /// </summary>
 923:          public static List<Ia.Ngn.Cl.Model.Access> AccessesWithMismatchedInfomationInServiceRequestOntList()
 924:          {
 925:              List<Ia.Ngn.Cl.Model.Access> list;
 926:              //Dictionary<int, string> areaIdToSymbolDictionary;
 927:   
 928:              //areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 929:   
 930:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 931:              {
 932:                  // I will ignore area because its fixed with access id, which is shared by both Access and ServiceRequestOnt
 933:   
 934:                  list = (from a in db.Accesses
 935:                          join o in db.Onts on a equals o.Access
 936:                          join osv in db.OntServiceVoips on o equals osv.Ont
 937:                          join sro in db.ServiceRequestOnts on a equals sro.Access
 938:                          //join areaSymbol in areaIdToSymbolDictionary on a.AreaId equals areaSymbol.Key
 939:                          //where sro.AreaSymbol != areaSymbol.Value
 940:                          where (sro.Block != a.Block && !string.IsNullOrEmpty(a.Block))
 941:                          || (sro.Street != a.Street && !string.IsNullOrEmpty(a.Street))
 942:                          || (sro.PremisesOld != a.PremisesOld && !string.IsNullOrEmpty(a.PremisesOld))
 943:                          || (sro.PremisesNew != a.PremisesNew && !string.IsNullOrEmpty(a.PremisesNew))
 944:                          || (sro.Paci != a.Paci && !string.IsNullOrEmpty(a.Paci))
 945:                          //|| (sro.PossibleNumberOfTd != a.PossibleNumberOfTd)
 946:                          //|| (sro.PossibleNumberOfEthernet != a.PossibleNumberOfEthernet)
 947:                          select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 948:              }
 949:   
 950:              return list.OrderBy(u => u.Id).ToList();
 951:          }
 952:   
 953:          ////////////////////////////////////////////////////////////////////////////    
 954:   
 955:          /// <summary>
 956:          ///
 957:          /// </summary>
 958:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.AccessCapacity> AccessCapacityDictionary()
 959:          {
 960:              // Similar to Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.PrepareServiceRequestOntListFromAccessList()
 961:   
 962:              bool familyExists;
 963:              int possibleNumberOfTd, possibleNumberOfEthernet;
 964:              string accessOntFamilyTypeCapacityString;
 965:   
 966:              var list = Ia.Ngn.Cl.Model.Data.Access.ListWithOntsAndEmsOnts();
 967:   
 968:              var dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.AccessCapacity>(list.Count);
 969:   
 970:              foreach (var access in list)
 971:              {
 972:                  if (access.Onts != null && access.Onts.Count > 0)
 973:                  {
 974:                      if (access.Onts.First().FamilyType != Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType.Undefined)
 975:                      {
 976:                          accessOntFamilyTypeCapacityString = Ia.Ngn.Cl.Model.Data.Nokia.Ont.FamilyTypeFromId(access.Onts.FirstOrDefault().FamilyTypeId);
 977:   
 978:                          possibleNumberOfTd = Ia.Ngn.Cl.Model.Business.Nokia.Ams.PossibleNumberOfTdForOntFamilyType(access.Onts.FirstOrDefault().FamilyTypeId);
 979:                          possibleNumberOfEthernet = Ia.Ngn.Cl.Model.Business.Nokia.Ams.PossibleNumberOfHsiCardPortServiceConfigurationForOntFamilyType(access.Onts.FirstOrDefault().FamilyTypeId);
 980:   
 981:                          accessOntFamilyTypeCapacityString += " (" + possibleNumberOfTd + ")";
 982:   
 983:                          familyExists = true;
 984:                      }
 985:                      else
 986:                      {
 987:                          possibleNumberOfTd = 0;
 988:                          possibleNumberOfEthernet = 0;
 989:   
 990:                          accessOntFamilyTypeCapacityString = string.Empty;
 991:   
 992:                          familyExists = false;
 993:                      }
 994:                  }
 995:                  else if (access.EmsOnts != null && access.EmsOnts.Count > 0)
 996:                  {
 997:                      var familyType = access.EmsOnts.First().FamilyType;
 998:                      var equipmentType = access.EmsOnts.First().EquipmentType;
 999:   
1000:                      if (familyType != Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined && equipmentType != null)
1001:                      {
1002:                          accessOntFamilyTypeCapacityString = familyType.ToString().ToUpper();
1003:   
1004:                          possibleNumberOfTd = equipmentType.TelPorts;
1005:                          possibleNumberOfEthernet = equipmentType.EthernetPorts;
1006:   
1007:                          accessOntFamilyTypeCapacityString += " (" + possibleNumberOfTd + ")";
1008:   
1009:                          familyExists = true;
1010:                      }
1011:                      else
1012:                      {
1013:                          possibleNumberOfTd = 0;
1014:                          possibleNumberOfEthernet = 0;
1015:   
1016:                          accessOntFamilyTypeCapacityString = string.Empty;
1017:   
1018:                          familyExists = false;
1019:                      }
1020:                  }
1021:                  else
1022:                  {
1023:                      possibleNumberOfTd = 0;
1024:                      possibleNumberOfEthernet = 0;
1025:   
1026:                      accessOntFamilyTypeCapacityString = string.Empty;
1027:   
1028:                      familyExists = false;
1029:                  }
1030:   
1031:                  if (familyExists)
1032:                  {
1033:                      dictionary[access.Id] = new Business.AccessCapacity
1034:                      {
1035:                          AccessId = access.Id,
1036:                          PossibleNumberOfTd = possibleNumberOfTd,
1037:                          PossibleNumberOfEthernet = possibleNumberOfEthernet,
1038:                          FamilyTypeCapacityString = accessOntFamilyTypeCapacityString
1039:                      };
1040:                  }
1041:                  else
1042:                  {
1043:   
1044:                  }
1045:              }
1046:   
1047:              return dictionary;
1048:          }
1049:   
1050:          ////////////////////////////////////////////////////////////////////////////
1051:   
1052:          /// <summary>
1053:          ///
1054:          /// </summary>
1055:          public static Dictionary<string, int> AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
1056:          {
1057:              get
1058:              {
1059:                  Dictionary<string, int> dictionary, nokiaDictionary, huaweiDictionary;
1060:                  List<int> huaweiOltIdList;//, nokiaOltIdList;
1061:   
1062:                  // this is related to ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId()
1063:   
1064:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1065:                  {
1066:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
1067:   
1068:                      // Nokia
1069:                      nokiaDictionary = (from a in db.Accesses
1070:                                         join o in db.Onts on a equals o.Access
1071:                                         join osv in db.OntServiceVoips on o equals osv.Ont
1072:                                         join sro in db.ServiceRequestOnts on a equals sro.Access
1073:                                         where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr // ?
1074:                                         && o.Serial != null
1075:                                         && o.Serial != "ALCL00000000"
1076:                                         && o.FamilyTypeId != 0 // ?
1077:                                         && o.ActiveSoftware != null
1078:                                         //&& o.ActiveSoftware == o.PlannedSoftware
1079:                                         && osv.Ip != null
1080:                                         select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
1081:   
1082:                      // Huawei
1083:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
1084:   
1085:                      huaweiDictionary = (from a in db.Accesses
1086:                                          join o in db.EmsOnts on a equals o.Access
1087:                                          join sro in db.ServiceRequestOnts on a equals sro.Access
1088:                                          //where o.FamilyTypeId != 0
1089:                                          where o.EQUIPMENTID != "--"
1090:                                          && huaweiOltIdList.Contains(a.Olt)
1091:                                          select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
1092:   
1093:                      dictionary = nokiaDictionary.Union(huaweiDictionary).ToDictionary(k => k.Key, v => v.Value);
1094:                  }
1095:   
1096:                  return dictionary;
1097:              }
1098:          }
1099:   
1100:          ////////////////////////////////////////////////////////////////////////////
1101:   
1102:          /// <summary>
1103:          ///
1104:          /// </summary>
1105:          public static List<Ia.Ngn.Cl.Model.Access> NokiaAccessList
1106:          {
1107:              get
1108:              {
1109:                  List<int> oltIdList;
1110:                  List<Ia.Ngn.Cl.Model.Access> list;
1111:   
1112:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
1113:   
1114:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1115:                  {
1116:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
1117:                  }
1118:   
1119:                  return list;
1120:              }
1121:          }
1122:   
1123:          ////////////////////////////////////////////////////////////////////////////
1124:   
1125:          /// <summary>
1126:          ///
1127:          /// </summary>
1128:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessList
1129:          {
1130:              get
1131:              {
1132:                  List<int> oltIdList;
1133:                  List<Ia.Ngn.Cl.Model.Access> list;
1134:   
1135:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
1136:   
1137:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1138:                  {
1139:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
1140:                  }
1141:   
1142:                  return list;
1143:              }
1144:          }
1145:   
1146:          ////////////////////////////////////////////////////////////////////////////
1147:   
1148:          /// <summary>
1149:          ///
1150:          /// </summary>
1151:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessesWithNoEmsOntList
1152:          {
1153:              get
1154:              {
1155:                  List<int> huaweiOltIdList;
1156:                  List<Ia.Ngn.Cl.Model.Access> list;
1157:   
1158:                  huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
1159:   
1160:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
1161:                  {
1162:                      list = (from a in db.Accesses
1163:                              join o in db.EmsOnts on a equals o.Access into gj
1164:                              from subsro in gj.DefaultIfEmpty()
1165:                              where huaweiOltIdList.Contains(a.Olt) && subsro.Access.Id == null
1166:                              select a).Distinct().ToList();
1167:                  }
1168:   
1169:                  return list;
1170:              }
1171:          }
1172:   
1173:          ////////////////////////////////////////////////////////////////////////////
1174:   
1175:          /// <summary>
1176:          ///
1177:          /// </summary>
1178:          public static Ia.Ngn.Cl.Model.Access ReadByIp(string ip)
1179:          {
1180:              // below: return the Access object of this ip
1181:   
1182:              Ia.Ngn.Cl.Model.Access item;
1183:   
1184:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1185:              {
1186:                  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();
1187:              }
1188:   
1189:              return item;
1190:          }
1191:   
1192:          ////////////////////////////////////////////////////////////////////////////
1193:   
1194:          /// <summary>
1195:          ///
1196:          /// </summary>
1197:          public static Ia.Ngn.Cl.Model.Access ReadByIp(Ia.Ngn.Cl.Model.Ngn db, string ip)
1198:          {
1199:              // below: return the Access object of this ip
1200:   
1201:              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();
1202:          }
1203:   
1204:          ////////////////////////////////////////////////////////////////////////////
1205:   
1206:          /// <summary>
1207:          ///
1208:          /// </summary>
1209:          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)
1210:          {
1211:              int numberOfTrials;
1212:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1213:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1214:   
1215:              numberOfTrials = 0;
1216:   
1217:              if (serviceAddress.AreaId != 0)
1218:              {
1219:                  numberOfTrials++;
1220:   
1221:                  _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId).ToList();
1222:   
1223:                  if (!string.IsNullOrEmpty(serviceAddress.Block) && _accessList.Any(u => u.Block == serviceAddress.Block))
1224:                  {
1225:                      numberOfTrials++;
1226:   
1227:                      note = string.Empty;
1228:   
1229:                      _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block).ToList();
1230:   
1231:                      if (!string.IsNullOrEmpty(serviceAddress.Street))
1232:                      {
1233:                          numberOfTrials++;
1234:   
1235:                          statisticalAccess = StatisticalAccessBlockAndStreet(serviceAddress, serviceAddress.Street, ref accessList, ref note, ref numberOfTrials);
1236:                      }
1237:                      else
1238:                      {
1239:                          statisticalAccess = StatisticalAccessBlockAndNoStreet(serviceAddress, ref accessList, ref note, ref numberOfTrials);
1240:                      }
1241:                  }
1242:                  else
1243:                  {
1244:                      numberOfTrials++;
1245:   
1246:                      statisticalAccess = null;
1247:   
1248:                      note = "serviceAddress.Block is empty or null";
1249:                  }
1250:              }
1251:              else
1252:              {
1253:                  numberOfTrials++;
1254:   
1255:                  statisticalAccess = null;
1256:   
1257:                  note = "serviceAddress.AreaId is 0";
1258:              }
1259:   
1260:              if (statisticalAccess != null) statisticalAccess.NumberOfTrials = numberOfTrials;
1261:   
1262:              return statisticalAccess;
1263:          }
1264:   
1265:          //
1266:          ////////////////////////////////////////////////////////////////////////////
1267:   
1268:          /// <summary>
1269:          ///
1270:          /// </summary>
1271:          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)
1272:          {
1273:              string accessLevenshteinString, serviceAddressLevenshteinString, idOfKeyWithMinValue;
1274:              Dictionary<string, int> dictionary;
1275:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1276:   
1277:              dictionary = new Dictionary<string, int>();
1278:   
1279:              serviceAddressLevenshteinString = serviceAddress.Block + ":" + serviceAddress.Street + ":" + serviceAddress.PremisesOld + ":" + serviceAddress.PremisesNew;
1280:   
1281:              foreach (var a in accessList)
1282:              {
1283:                  accessLevenshteinString = a.Block + ":" + a.Street + ":" + a.PremisesOld + ":" + a.PremisesNew;
1284:   
1285:                  dictionary[a.Id] = Ia.Cl.Model.Default.LevenshteinDistance(serviceAddressLevenshteinString, accessLevenshteinString);
1286:              }
1287:   
1288:              var minValue = dictionary.Values.Min();
1289:   
1290:              idOfKeyWithMinValue = dictionary.FirstOrDefault(u => u.Value == minValue).Key;
1291:   
1292:              statisticalAccess = (from a in accessList where a.Id == idOfKeyWithMinValue select a).SingleOrDefault();
1293:   
1294:              return statisticalAccess;
1295:          }
1296:   
1297:          ////////////////////////////////////////////////////////////////////////////
1298:   
1299:          /// <summary>
1300:          ///
1301:          /// </summary>
1302:          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)
1303:          {
1304:              string po, pn;
1305:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1306:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1307:   
1308:              numberOfTrials++;
1309:   
1310:              _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block && u.Street == street).ToList();
1311:   
1312:              note = string.Empty;
1313:   
1314:              EvaluateAndCorrectPremisesOldAndPremisesNew(serviceAddress.PremisesOld, serviceAddress.PremisesNew, out po, out pn);
1315:              serviceAddress.PremisesOld = po;
1316:              serviceAddress.PremisesNew = pn;
1317:   
1318:              statisticalAccess = (from a in _accessList
1319:                                   where a.AreaId == serviceAddress.AreaId
1320:                                       && a.Block == serviceAddress.Block
1321:                                       && a.Street == street
1322:                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1323:                                       && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1324:                                   select a).FirstOrDefault();
1325:   
1326:              if (statisticalAccess == null)
1327:              {
1328:                  numberOfTrials++;
1329:   
1330:                  statisticalAccess = (from a in _accessList
1331:                                       where a.AreaId == serviceAddress.AreaId
1332:                                           && a.Block == serviceAddress.Block
1333:                                           && a.Street == street
1334:                                           && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1335:                                       select a).FirstOrDefault();
1336:   
1337:                  if (statisticalAccess == null)
1338:                  {
1339:                      numberOfTrials++;
1340:   
1341:                      statisticalAccess = (from a in _accessList
1342:                                           where a.AreaId == serviceAddress.AreaId
1343:                                               && a.Block == serviceAddress.Block
1344:                                               && a.Street == street
1345:                                               && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1346:                                           select a).FirstOrDefault();
1347:   
1348:                      if (statisticalAccess == null)
1349:                      {
1350:                          numberOfTrials++;
1351:   
1352:                          statisticalAccess = (from a in _accessList
1353:                                               where a.AreaId == serviceAddress.AreaId
1354:                                                   && a.Block == serviceAddress.Block
1355:                                                   && a.Street == street
1356:                                                   && a.PremisesOld == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1357:                                               select a).FirstOrDefault();
1358:   
1359:                          if (statisticalAccess == null)
1360:                          {
1361:                              numberOfTrials++;
1362:   
1363:                              statisticalAccess = (from a in _accessList
1364:                                                   where a.AreaId == serviceAddress.AreaId
1365:                                                       && a.Block == serviceAddress.Block
1366:                                                       && a.Street == street
1367:                                                       && a.PremisesNew == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1368:                                                   select a).FirstOrDefault();
1369:   
1370:                              if (statisticalAccess == null)
1371:                              {
1372:                                  numberOfTrials++;
1373:   
1374:                                  statisticalAccess = (from a in _accessList
1375:                                                       where a.AreaId == serviceAddress.AreaId
1376:                                                           && a.Block == serviceAddress.Block
1377:                                                           && a.Street == street
1378:                                                           && a.PremisesNew == serviceAddress.Boulevard && !string.IsNullOrEmpty(serviceAddress.Boulevard)
1379:                                                       select a).FirstOrDefault();
1380:   
1381:                                  if (statisticalAccess == null)
1382:                                  {
1383:                                      numberOfTrials++;
1384:   
1385:                                      statisticalAccess = (from a in _accessList
1386:                                                           where a.AreaId == serviceAddress.AreaId
1387:                                                               && a.Block == serviceAddress.Block
1388:                                                               && a.Street == street
1389:                                                               && a.PremisesOld == serviceAddress.Boulevard && !string.IsNullOrEmpty(serviceAddress.Boulevard)
1390:                                                           select a).FirstOrDefault();
1391:   
1392:                                      if (statisticalAccess == null)
1393:                                      {
1394:                                          numberOfTrials++;
1395:   
1396:                                          statisticalAccess = (from a in _accessList
1397:                                                               where a.AreaId == serviceAddress.AreaId
1398:                                                                   && a.Block == serviceAddress.Block
1399:                                                                   && a.Street == street
1400:                                                                   && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1401:                                                                   && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1402:                                                               select a).FirstOrDefault();
1403:   
1404:                                          if (statisticalAccess == null)
1405:                                          {
1406:                                              numberOfTrials++;
1407:   
1408:                                              statisticalAccess = (from a in _accessList
1409:                                                                   where a.AreaId == serviceAddress.AreaId
1410:                                                                       && a.Block == serviceAddress.Block
1411:                                                                       && a.Street == street
1412:                                                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1413:                                                                       && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1414:                                                                   select a).FirstOrDefault();
1415:   
1416:                                              if (statisticalAccess == null)
1417:                                              {
1418:                                                  numberOfTrials++;
1419:   
1420:                                                  statisticalAccess = (from a in _accessList
1421:                                                                       where a.AreaId == serviceAddress.AreaId
1422:                                                                           && a.Block == serviceAddress.Block
1423:                                                                           && a.Street == street
1424:                                                                           && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1425:                                                                       select a).FirstOrDefault();
1426:   
1427:                                                  if (statisticalAccess == null)
1428:                                                  {
1429:                                                      numberOfTrials++;
1430:   
1431:                                                      statisticalAccess = (from a in _accessList
1432:                                                                           where a.AreaId == serviceAddress.AreaId
1433:                                                                               && a.Block == serviceAddress.Block
1434:                                                                               && a.Street == street
1435:                                                                               && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1436:                                                                           select a).FirstOrDefault();
1437:   
1438:                                                      if (statisticalAccess == null)
1439:                                                      {
1440:                                                          numberOfTrials++;
1441:   
1442:   
1443:                                                      }
1444:                                                  }
1445:                                              }
1446:                                          }
1447:                                      }
1448:                                  }
1449:                              }
1450:                          }
1451:                      }
1452:                  }
1453:              }
1454:   
1455:              return statisticalAccess;
1456:          }
1457:   
1458:          ////////////////////////////////////////////////////////////////////////////
1459:   
1460:          /// <summary>
1461:          ///
1462:          /// </summary>
1463:          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)
1464:          {
1465:              string po, pn;
1466:              Ia.Ngn.Cl.Model.Ui.Access statisticalAccess;
1467:              List<Ia.Ngn.Cl.Model.Ui.Access> _accessList;
1468:   
1469:              numberOfTrials++;
1470:   
1471:              _accessList = accessList.Where(u => u.AreaId == serviceAddress.AreaId && u.Block == serviceAddress.Block).ToList();
1472:   
1473:              note = string.Empty;
1474:   
1475:              EvaluateAndCorrectPremisesOldAndPremisesNew(serviceAddress.PremisesOld, serviceAddress.PremisesNew, out po, out pn);
1476:              serviceAddress.PremisesOld = po;
1477:              serviceAddress.PremisesNew = pn;
1478:   
1479:              statisticalAccess = (from a in _accessList
1480:                                   where a.AreaId == serviceAddress.AreaId
1481:                                       && a.Block == serviceAddress.Block
1482:                                       && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1483:                                       && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1484:                                   select a).FirstOrDefault();
1485:   
1486:              if (statisticalAccess == null)
1487:              {
1488:                  statisticalAccess = (from a in _accessList
1489:                                       where a.AreaId == serviceAddress.AreaId
1490:                                           && a.Block == serviceAddress.Block
1491:                                           && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1492:                                       select a).FirstOrDefault();
1493:   
1494:                  if (statisticalAccess == null)
1495:                  {
1496:                      numberOfTrials++;
1497:   
1498:                      statisticalAccess = (from a in _accessList
1499:                                           where a.AreaId == serviceAddress.AreaId
1500:                                               && a.Block == serviceAddress.Block
1501:                                               && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1502:                                           select a).FirstOrDefault();
1503:   
1504:                      if (statisticalAccess == null)
1505:                      {
1506:                          numberOfTrials++;
1507:   
1508:                          statisticalAccess = (from a in _accessList
1509:                                               where a.AreaId == serviceAddress.AreaId
1510:                                                   && a.Block == serviceAddress.Block
1511:                                                   && a.PremisesOld == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1512:                                               select a).FirstOrDefault();
1513:   
1514:                          if (statisticalAccess == null)
1515:                          {
1516:                              numberOfTrials++;
1517:   
1518:                              statisticalAccess = (from a in _accessList
1519:                                                   where a.AreaId == serviceAddress.AreaId
1520:                                                       && a.Block == serviceAddress.Block
1521:                                                       && a.PremisesNew == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1522:                                                   select a).FirstOrDefault();
1523:   
1524:                              if (statisticalAccess == null)
1525:                              {
1526:                                  numberOfTrials++;
1527:   
1528:                                  statisticalAccess = (from a in _accessList
1529:                                                       where a.AreaId == serviceAddress.AreaId
1530:                                                           && a.Block == serviceAddress.Block
1531:                                                           && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1532:                                                           && a.PremisesNew == serviceAddress.PremisesNew && !string.IsNullOrEmpty(serviceAddress.PremisesNew)
1533:                                                       select a).FirstOrDefault();
1534:   
1535:                                  if (statisticalAccess == null)
1536:                                  {
1537:                                      numberOfTrials++;
1538:   
1539:                                      statisticalAccess = (from a in _accessList
1540:                                                           where a.AreaId == serviceAddress.AreaId
1541:                                                               && a.Block == serviceAddress.Block
1542:                                                               && a.PremisesOld == serviceAddress.PremisesOld && !string.IsNullOrEmpty(serviceAddress.PremisesOld)
1543:                                                               && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1544:                                                           select a).FirstOrDefault();
1545:   
1546:                                      if (statisticalAccess == null)
1547:                                      {
1548:                                          numberOfTrials++;
1549:   
1550:                                          statisticalAccess = (from a in _accessList
1551:                                                               where a.AreaId == serviceAddress.AreaId
1552:                                                                   && a.Block == serviceAddress.Block
1553:                                                                   && !string.IsNullOrEmpty(serviceAddress.PremisesOld) && !string.IsNullOrEmpty(a.PremisesOld) && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1554:                                                               select a).FirstOrDefault();
1555:   
1556:                                          if (statisticalAccess == null)
1557:                                          {
1558:                                              numberOfTrials++;
1559:   
1560:                                              statisticalAccess = (from a in _accessList
1561:                                                                   where a.AreaId == serviceAddress.AreaId
1562:                                                                       && a.Block == serviceAddress.Block
1563:                                                                       && !string.IsNullOrEmpty(serviceAddress.PremisesNew) && !string.IsNullOrEmpty(a.PremisesNew) && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1564:                                                                   select a).FirstOrDefault();
1565:   
1566:                                              if (statisticalAccess == null)
1567:                                              {
1568:                                                  numberOfTrials++;
1569:   
1570:                                                  statisticalAccess = null;
1571:   
1572:                                                  note = "serviceAddress.Street is empty or null";
1573:                                              }
1574:                                          }
1575:                                      }
1576:                                  }
1577:                              }
1578:                          }
1579:                      }
1580:                  }
1581:              }
1582:   
1583:              return statisticalAccess;
1584:          }
1585:   
1586:          ////////////////////////////////////////////////////////////////////////////
1587:   
1588:          /// <summary>
1589:          ///
1590:          /// </summary>
1591:          public static void EvaluateAndCorrectPremisesOldAndPremisesNew(string premisesOld, string premisesNew, out string newPremisesOld, out string newPremisesNew)
1592:          {
1593:              int po, pn;
1594:   
1595:              if (!string.IsNullOrEmpty(premisesOld) && !string.IsNullOrEmpty(premisesNew))
1596:              {
1597:                  if (int.TryParse(premisesOld, out po) && int.TryParse(premisesNew, out pn))
1598:                  {
1599:                      // if equal then one is invalid
1600:                      if (po == pn)
1601:                      {
1602:                          if (po > 100)
1603:                          {
1604:                              newPremisesOld = po.ToString();
1605:                              newPremisesNew = string.Empty;
1606:                          }
1607:                          else
1608:                          {
1609:                              newPremisesOld = string.Empty;
1610:                              newPremisesNew = po.ToString();
1611:                          }
1612:                      }
1613:                      else
1614:                      {
1615:                          if (pn > po)
1616:                          {
1617:                              newPremisesOld = pn.ToString();
1618:                              newPremisesNew = po.ToString();
1619:                          }
1620:                          else
1621:                          {
1622:                              newPremisesOld = po.ToString();
1623:                              newPremisesNew = pn.ToString();
1624:                          }
1625:                      }
1626:                  }
1627:                  else if (int.TryParse(premisesOld, out po) && !int.TryParse(premisesNew, out pn))
1628:                  {
1629:                      // if equal then one is invalid
1630:                      if (po.ToString() == premisesNew)
1631:                      {
1632:                          if (po > 100)
1633:                          {
1634:                              newPremisesOld = po.ToString();
1635:                              newPremisesNew = string.Empty;
1636:                          }
1637:                          else
1638:                          {
1639:                              newPremisesOld = string.Empty;
1640:                              newPremisesNew = po.ToString();
1641:                          }
1642:                      }
1643:                      else
1644:                      {
1645:                          if (premisesNew.Length > po.ToString().Length)
1646:                          {
1647:                              newPremisesOld = premisesNew;
1648:                              newPremisesNew = po.ToString();
1649:                          }
1650:                          else
1651:                          {
1652:                              newPremisesOld = po.ToString();
1653:                              newPremisesNew = premisesNew;
1654:                          }
1655:                      }
1656:                  }
1657:                  else if (!int.TryParse(premisesOld, out po) && int.TryParse(premisesNew, out pn))
1658:                  {
1659:                      // if equal then one is invalid
1660:                      if (premisesOld == pn.ToString())
1661:                      {
1662:                          if (premisesOld.Length >= 3)
1663:                          {
1664:                              newPremisesOld = premisesOld.ToString();
1665:                              newPremisesNew = string.Empty;
1666:                          }
1667:                          else
1668:                          {
1669:                              newPremisesOld = string.Empty;
1670:                              newPremisesNew = premisesOld;
1671:                          }
1672:                      }
1673:                      else
1674:                      {
1675:                          if (pn.ToString().Length > premisesOld.Length)
1676:                          {
1677:                              newPremisesOld = pn.ToString();
1678:                              newPremisesNew = premisesOld;
1679:                          }
1680:                          else
1681:                          {
1682:                              newPremisesOld = premisesOld;
1683:                              newPremisesNew = pn.ToString();
1684:                          }
1685:                      }
1686:                  }
1687:                  else //if (!int.TryParse(premisesOld, out po) && !int.TryParse(premisesNew, out pn))
1688:                  {
1689:                      // if equal then one is invalid
1690:                      if (premisesOld == premisesNew)
1691:                      {
1692:                          if (premisesOld.Length >= 3)
1693:                          {
1694:                              newPremisesOld = premisesOld;
1695:                              newPremisesNew = string.Empty;
1696:                          }
1697:                          else
1698:                          {
1699:                              newPremisesOld = string.Empty;
1700:                              newPremisesNew = premisesOld;
1701:                          }
1702:                      }
1703:                      else
1704:                      {
1705:                          if (premisesNew.Length > premisesOld.Length)
1706:                          {
1707:                              newPremisesOld = premisesNew;
1708:                              newPremisesNew = premisesOld;
1709:                          }
1710:                          else
1711:                          {
1712:                              newPremisesOld = premisesOld;
1713:                              newPremisesNew = premisesNew;
1714:                          }
1715:                      }
1716:                  }
1717:              }
1718:              else if (!string.IsNullOrEmpty(premisesOld) && string.IsNullOrEmpty(premisesNew))
1719:              {
1720:                  if (premisesOld.Length >= 3)
1721:                  {
1722:                      newPremisesOld = premisesOld;
1723:                      newPremisesNew = string.Empty;
1724:                  }
1725:                  else
1726:                  {
1727:                      newPremisesOld = string.Empty;
1728:                      newPremisesNew = premisesOld;
1729:                  }
1730:              }
1731:              else if (string.IsNullOrEmpty(premisesOld) && !string.IsNullOrEmpty(premisesNew))
1732:              {
1733:                  if (premisesNew.Length < 3)
1734:                  {
1735:                      newPremisesOld = string.Empty;
1736:                      newPremisesNew = premisesNew;
1737:                  }
1738:                  else
1739:                  {
1740:                      newPremisesOld = premisesNew;
1741:                      newPremisesNew = string.Empty;
1742:                  }
1743:              }
1744:              else //if (string.IsNullOrEmpty(premisesOld) && string.IsNullOrEmpty(premisesNew))
1745:              {
1746:                  newPremisesOld = string.Empty;
1747:                  newPremisesNew = string.Empty;
1748:              }
1749:          }
1750:   
1751:          ////////////////////////////////////////////////////////////////////////////
1752:          ////////////////////////////////////////////////////////////////////////////
1753:   
1754:          /// <summary>
1755:          ///
1756:          /// </summary>
1757:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Access access)
1758:          {
1759:              StringBuilder sb;
1760:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
1761:   
1762:              sb = new StringBuilder();
1763:   
1764:              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();
1765:   
1766:              sb.AppendLine("Vendor: " + vendor.Name);
1767:              sb.AppendLine("Name: " + access.Name);
1768:              sb.AppendLine("Address: " + access.Address);
1769:   
1770:              if (!string.IsNullOrEmpty(access.Paci)) sb.AppendLine("Paci: " + access.Paci);
1771:              if (!string.IsNullOrEmpty(access.Note)) sb.AppendLine("Note: " + access.Note);
1772:   
1773:              return sb.ToString();
1774:          }
1775:   
1776:          ////////////////////////////////////////////////////////////////////////////
1777:          ////////////////////////////////////////////////////////////////////////////
1778:      }
1779:   
1780:      ////////////////////////////////////////////////////////////////////////////
1781:      ////////////////////////////////////////////////////////////////////////////
1782:  }