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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequestOnt

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

Service Request Ont support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Linq;
   5:  using System.Data;
   6:  using System.Data.Entity;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Service Request Ont support class for Next Generation Network (NGN) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class ServiceRequestOnt
  30:      {
  31:          private const int LengthOfRequestOntIdRange = 100;
  32:          private static Dictionary<string, string> ontAccessIdToOntAccessNameDictionary = new Dictionary<string, string>();
  33:          private static Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntNotInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt>();
  34:          private static Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt>();
  35:          private static Queue<Tuple<string, string>> serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>();
  36:   
  37:          ////////////////////////////////////////////////////////////////////////////
  38:   
  39:          /// <summary>
  40:          ///
  41:          /// </summary>
  42:          public ServiceRequestOnt() { }
  43:   
  44:          ////////////////////////////////////////////////////////////////////////////    
  45:   
  46:          /// <summary>
  47:          ///
  48:          /// </summary>
  49:          public static bool ServiceRequestOntNotInCustomerDepartmentDatabaseQueueCountIsNotZero
  50:          {
  51:              get
  52:              {
  53:                  return serviceRequestOntNotInCustomerDepartmentDatabaseQueue.Count > 0;
  54:              }
  55:          }
  56:   
  57:          ////////////////////////////////////////////////////////////////////////////
  58:   
  59:          /// <summary>
  60:          ///
  61:          /// </summary>
  62:          public static List<string> IdList
  63:          {
  64:              get
  65:              {
  66:                  List<string> list;
  67:   
  68:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  69:                  {
  70:                      list = (from a in db.ServiceRequestOnts select a.Id).ToList();
  71:                  }
  72:   
  73:                  return list;
  74:              }
  75:          }
  76:   
  77:          ////////////////////////////////////////////////////////////////////////////
  78:   
  79:          /// <summary>
  80:          ///
  81:          /// </summary>
  82:          public static List<Ia.Ngn.Cl.Model.ServiceRequestOnt> List
  83:          {
  84:              get
  85:              {
  86:                  List<Ia.Ngn.Cl.Model.ServiceRequestOnt> list;
  87:   
  88:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  89:                  {
  90:                      list = (from a in db.ServiceRequestOnts select a).ToList();
  91:                  }
  92:   
  93:                  return list;
  94:              }
  95:          }
  96:   
  97:          ////////////////////////////////////////////////////////////////////////////    
  98:   
  99:          /// <summary>
 100:          ///
 101:          /// </summary>
 102:          public static Ia.Ngn.Cl.Model.ServiceRequestOnt ServiceRequestOntNotInCustomerDepartmentDatabase(out Ia.Cl.Model.Result result)
 103:          {
 104:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
 105:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 106:              List<Ia.Ngn.Cl.Model.Access> accessList;
 107:   
 108:              result = new Ia.Cl.Model.Result();
 109:   
 110:              if (serviceRequestOntNotInCustomerDepartmentDatabaseQueue.Count == 0)
 111:              {
 112:                  serviceRequestOntList = new List<Ia.Ngn.Cl.Model.ServiceRequestOnt>();
 113:   
 114:                  accessList = Ia.Ngn.Cl.Model.Data.Access.ListOfAccessesWithProvisionedAndReadyOntsAndEmsOntsButDoNotExistInCustomerDepartmentDatabase();
 115:   
 116:                  serviceRequestOntList = PrepareServiceRequestOntListFromAccessList(accessList);
 117:   
 118:                  serviceRequestOntNotInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt>(serviceRequestOntList);
 119:              }
 120:   
 121:              if (serviceRequestOntNotInCustomerDepartmentDatabaseQueue.Count > 0)
 122:              {
 123:                  serviceRequestOnt = serviceRequestOntNotInCustomerDepartmentDatabaseQueue.Dequeue();
 124:   
 125:                  result.AddSuccess("(" + serviceRequestOnt.Name + "/" + serviceRequestOntNotInCustomerDepartmentDatabaseQueue.Count + ")");
 126:              }
 127:              else
 128:              {
 129:                  serviceRequestOnt = null;
 130:   
 131:                  result.AddSuccess("No mismatch between OFN and billing database. ");
 132:              }
 133:   
 134:              return serviceRequestOnt;
 135:          }
 136:   
 137:          ////////////////////////////////////////////////////////////////////////////    
 138:   
 139:          /// <summary>
 140:          ///
 141:          /// </summary>
 142:          public static Ia.Ngn.Cl.Model.ServiceRequestOnt ServiceRequestOntNotUpdatedInCustomerDepartmentDatabase(out Ia.Cl.Model.Result result)
 143:          {
 144:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
 145:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 146:              List<Ia.Ngn.Cl.Model.Access> accessList;
 147:   
 148:              result = new Ia.Cl.Model.Result();
 149:   
 150:              if (serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue.Count == 0)
 151:              {
 152:                  accessList = Ia.Ngn.Cl.Model.Data.Access.AccessesWithMismatchedInfomationInServiceRequestOntList();
 153:   
 154:                  serviceRequestOntList = PrepareServiceRequestOntListFromAccessList(accessList);
 155:   
 156:                  serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOnt>(serviceRequestOntList);
 157:              }
 158:   
 159:              if (serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue.Count > 0)
 160:              {
 161:                  serviceRequestOnt = serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue.Dequeue();
 162:   
 163:                  result.AddSuccess("(" + serviceRequestOnt.Name + "/" + serviceRequestOntNotUpdatedInCustomerDepartmentDatabaseQueue.Count + ")");
 164:              }
 165:              else
 166:              {
 167:                  serviceRequestOnt = null;
 168:   
 169:                  result.AddSuccess("No mismatch in record values between OFN and billing database. ");
 170:              }
 171:   
 172:              return serviceRequestOnt;
 173:          }
 174:   
 175:          ////////////////////////////////////////////////////////////////////////////    
 176:   
 177:          /// <summary>
 178:          ///
 179:          /// </summary>
 180:          private static List<Ia.Ngn.Cl.Model.ServiceRequestOnt> PrepareServiceRequestOntListFromAccessList(List<Ia.Ngn.Cl.Model.Access> accessList)
 181:          {
 182:              bool familyExists;
 183:              int possibleNumberOfTd, possibleNumberOfEthernet;
 184:              string areaSymbol, accessOntFamilyTypeCapacityString;
 185:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
 186:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
 187:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 188:   
 189:              serviceRequestOntList = new List<Ia.Ngn.Cl.Model.ServiceRequestOnt>();
 190:   
 191:              accessList = accessList.OrderByDescending(a => a.Created).ToList();
 192:   
 193:              foreach (Ia.Ngn.Cl.Model.Access access in accessList)
 194:              {
 195:                  if (access.Onts != null && access.Onts.Count > 0)
 196:                  {
 197:                      accessOntFamilyTypeCapacityString = Ia.Ngn.Cl.Model.Data.Nokia.Ont.FamilyTypeFromId(access.Onts.FirstOrDefault().FamilyTypeId);
 198:   
 199:                      possibleNumberOfTd = Ia.Ngn.Cl.Model.Business.Nokia.Ams.PossibleNumberOfTdForOntFamilyType(access.Onts.FirstOrDefault().FamilyTypeId);
 200:                      possibleNumberOfEthernet = Ia.Ngn.Cl.Model.Business.Nokia.Ams.PossibleNumberOfHsiCardPortServiceConfigurationForOntFamilyType(access.Onts.FirstOrDefault().FamilyTypeId);
 201:   
 202:                      accessOntFamilyTypeCapacityString += " (" + possibleNumberOfTd + ")";
 203:   
 204:                      familyExists = true;
 205:                  }
 206:                  else if (access.EmsOnts != null && access.EmsOnts.Count > 0)
 207:                  {
 208:                      accessOntFamilyTypeCapacityString = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyTypeStringFromEquipmentType(access.EmsOnts.FirstOrDefault().EquipmentType);
 209:   
 210:                      possibleNumberOfTd = Ia.Ngn.Cl.Model.Business.Huawei.Ems.PossibleNumberOfTdForOntEquipmentType(access.EmsOnts.FirstOrDefault().EquipmentType);
 211:                      possibleNumberOfEthernet = Ia.Ngn.Cl.Model.Business.Huawei.Ems.PossibleNumberOfHsiServiceForOntEquipmentType(access.EmsOnts.FirstOrDefault().EquipmentType);
 212:   
 213:                      accessOntFamilyTypeCapacityString += " (" + possibleNumberOfTd + ")";
 214:   
 215:                      familyExists = true;
 216:                  }
 217:                  else
 218:                  {
 219:                      possibleNumberOfTd = possibleNumberOfEthernet = 0;
 220:                      familyExists = false;
 221:                      accessOntFamilyTypeCapacityString = "";
 222:                  }
 223:   
 224:                  if (familyExists)
 225:                  {
 226:                      if (possibleNumberOfTd > 0 && possibleNumberOfEthernet > 0)
 227:                      {
 228:                          ont = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == access.Olt && o.Pon.Number == access.Pon && o.Number == access.Ont select o).SingleOrDefault();
 229:   
 230:                          if (ont != null)
 231:                          {
 232:                              areaSymbol = ont.Pon.PonGroup.Symbol;
 233:   
 234:                              serviceRequestOnt = new Ia.Ngn.Cl.Model.ServiceRequestOnt()
 235:                              {
 236:                                  Id = access.Id,
 237:                                  Pon = access.Pon,
 238:                                  Ont = access.Ont,
 239:                                  Paci = access.Paci,
 240:                                  AreaSymbol = areaSymbol,
 241:                                  Block = access.Block,
 242:                                  Street = access.Street,
 243:                                  PremisesOld = access.PremisesOld,
 244:                                  PremisesNew = access.PremisesNew,
 245:   
 246:                                  PossibleNumberOfTd = possibleNumberOfTd,
 247:                                  PossibleNumberOfEthernet = possibleNumberOfEthernet
 248:                              };
 249:   
 250:                              serviceRequestOntList.Add(serviceRequestOnt);
 251:                          }
 252:                          else
 253:                          {
 254:   
 255:                          }
 256:                      }
 257:                      else
 258:                      {
 259:   
 260:                      }
 261:                  }
 262:                  else
 263:                  {
 264:   
 265:                  }
 266:              }
 267:   
 268:              return serviceRequestOntList;
 269:          }
 270:   
 271:          ////////////////////////////////////////////////////////////////////////////    
 272:   
 273:          /// <summary>
 274:          ///
 275:          /// </summary>
 276:          public static Tuple<string, string> ServiceRequestOntIdStartEndRangeManager(out Ia.Cl.Model.Result result)
 277:          {
 278:              string startAccessName, endAccessName;
 279:              Tuple<string, string> tuple;
 280:              List<string> ontListAccessIdList;
 281:              List<Tuple<string, string>> tupleList;
 282:   
 283:              result = new Ia.Cl.Model.Result();
 284:   
 285:              if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count == 0)
 286:              {
 287:                  ontListAccessIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdList;
 288:                  ontAccessIdToOntAccessNameDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 289:   
 290:                  tupleList = Ia.Cl.Model.Default.OptimizedStartEndRangeTupleList(ontListAccessIdList, LengthOfRequestOntIdRange);
 291:   
 292:                  serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>(tupleList);
 293:              }
 294:   
 295:              if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count > 0)
 296:              {
 297:                  tuple = serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Dequeue();
 298:   
 299:                  // debug
 300:                  //tuple = new Tuple<string, string>("104010301512009", "104010301512019");
 301:   
 302:                  startAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item1];
 303:                  endAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item2];
 304:   
 305:                  result.AddSuccess("(" + startAccessName + " - " + endAccessName + "/" + serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count + ")");
 306:              }
 307:              else
 308:              {
 309:                  tuple = null;
 310:   
 311:                  result.AddWarning("(0-0 0/0)");
 312:              }
 313:   
 314:              return tuple;
 315:          }
 316:   
 317:          ////////////////////////////////////////////////////////////////////////////    
 318:   
 319:          /// <summary>
 320:          ///
 321:          /// </summary>
 322:          public static string OracleSqlCommandSelectProperServiceRequestOntRecordList(Tuple<string, string> startEndRangeTuple)
 323:          {
 324:              return OracleSqlCommandSelectProperServiceRequestOntRecordList(startEndRangeTuple.Item1, startEndRangeTuple.Item2);
 325:          }
 326:   
 327:          ////////////////////////////////////////////////////////////////////////////    
 328:   
 329:          /// <summary>
 330:          ///
 331:          /// </summary>
 332:          public static string OracleSqlCommandSelectProperServiceRequestOntRecordList(string start, string end)
 333:          {
 334:              string sql;
 335:   
 336:              //if (startEndRangeTuple != null) sql = "select distinct DP_ID as Id, DP as Value from (select DP, DP_ID from FM_NET where (DP_ID >= " + startEndRangeTuple.Item1 + " and DP_ID <= " + startEndRangeTuple.Item2 + ") order by DP_ID asc) where (DP like '%/%/%' or DP like '% % %' or DP like '%.%.%')"; // and rownum <= " + Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.LengthOfRequestOntIdRange;
 337:              //if (startEndRangeTuple != null) sql = "select distinct DP_ID as Id, DP_NAME as Value from FM_DP where (DP_ID >= " + startEndRangeTuple.Item1 + " and DP_ID <= " + startEndRangeTuple.Item2 + @") and (DP_NAME like '%/%/%' or DP_NAME like '% % %' or DP_NAME like '%.%.%') order by DP_ID asc";
 338:              //if (startEndRangeTuple != null) sql = "select distinct DP_ID as Id, DP_NAME as Value from FM_DP where (DP_ID >= " + startEndRangeTuple.Item1 + " and DP_ID <= " + startEndRangeTuple.Item2 + @") and (DP_NAME like '%/%/%' or DP_NAME like '% % %' or DP_NAME like '%.%.%' or DP_NAME like '% % %' or DP_NAME like '%.% %') order by DP_ID asc";
 339:              if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end)) sql = @"select id, pon, ont, area_id as AreaSymbol, blook as Block, street, plot as PremisesOld, building as PremisesNew, paci, line_nos as PossibleNumberOfTd, ethernet_nos as PossibleNumberOfEthernet from ont_data where (id >= " + start + " and id <= " + end + @") order by id asc";
 340:              else sql = string.Empty;
 341:   
 342:              return sql;
 343:          }
 344:   
 345:          ////////////////////////////////////////////////////////////////////////////    
 346:   
 347:          /// <summary>
 348:          ///
 349:          /// </summary>
 350:          public static string OracleSqlCommandInsertServiceRequestOntRecord(Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt)
 351:          {
 352:              string sql;
 353:   
 354:              sql = @"insert into ONT_DATA(ID, PON, ONT, AREA_ID, BLOOK, STREET, PLOT, BUILDING, PACI, LINE_NOS, ETHERNET_NOS) values "
 355:                           + @"("
 356:                           + @"N&quote;" + serviceRequestOnt.Id + @"&quote;,"
 357:                           + @"N&quote;" + serviceRequestOnt.Pon + @"&quote;,"
 358:                           + @"N&quote;" + serviceRequestOnt.Ont + @"&quote;,"
 359:                           + @"N&quote;" + serviceRequestOnt.AreaSymbol + @"&quote;,"
 360:                           + @"N&quote;" + serviceRequestOnt.Block + @"&quote;,"
 361:                           + @"N&quote;" + serviceRequestOnt.Street + @"&quote;,"
 362:                           + @"N&quote;" + serviceRequestOnt.PremisesOld + @"&quote;,"
 363:                           + @"N&quote;" + serviceRequestOnt.PremisesNew + @"&quote;,"
 364:                           + @"N&quote;" + serviceRequestOnt.Paci + @"&quote;,"
 365:                           + @"N&quote;" + serviceRequestOnt.PossibleNumberOfTd + @"&quote;,"
 366:                           + @"N&quote;" + serviceRequestOnt.PossibleNumberOfEthernet + @"&quote;"
 367:                                                       + @")";
 368:   
 369:              sql = sql.Replace("'", " ");
 370:              sql = sql.Replace("&quote;", "'");
 371:   
 372:              return sql;
 373:          }
 374:   
 375:          ////////////////////////////////////////////////////////////////////////////    
 376:   
 377:          /// <summary>
 378:          ///
 379:          /// </summary>
 380:          public static string OracleSqlCommandUpdateServiceRequestOntRecord(Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt)
 381:          {
 382:              string sql;
 383:   
 384:              sql = @"update ONT_DATA set PON = N&quote;" + serviceRequestOnt.Pon + @"&quote;, "
 385:  + @"ONT = N&quote;" + serviceRequestOnt.Ont + @"&quote;, "
 386:  + @"AREA_ID = N&quote;" + serviceRequestOnt.AreaSymbol + @"&quote;, "
 387:  + @"BLOOK = N&quote;" + serviceRequestOnt.Block + @"&quote;, "
 388:  + @"STREET = N&quote;" + serviceRequestOnt.Street + @"&quote;, "
 389:  + @"PLOT = N&quote;" + serviceRequestOnt.PremisesOld + @"&quote;, "
 390:  + @"BUILDING = N&quote;" + serviceRequestOnt.PremisesNew + @"&quote;, "
 391:  + @"PACI = N&quote;" + serviceRequestOnt.Paci + @"&quote;, "
 392:  + @"LINE_NOS = N&quote;" + serviceRequestOnt.PossibleNumberOfTd + @"&quote;, "
 393:  + @"ETHERNET_NOS = N&quote;" + serviceRequestOnt.PossibleNumberOfEthernet + @"&quote;"
 394:  + @" where ID = N&quote;" + serviceRequestOnt.Id + @"&quote;";
 395:   
 396:              sql = sql.Replace("'", " ");
 397:              sql = sql.Replace("&quote;", "'");
 398:   
 399:              return sql;
 400:          }
 401:   
 402:          ////////////////////////////////////////////////////////////////////////////    
 403:   
 404:          /// <summary>
 405:          ///
 406:          /// </summary>
 407:          public static string OracleSqlCommandDeleteServiceRequestOntRecord(Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt)
 408:          {
 409:              string sql;
 410:   
 411:              sql = @"delete from ONT_DATA where ID = N&quote;" + serviceRequestOnt.Id + @"&quote;";
 412:   
 413:              sql = sql.Replace("'", " ");
 414:              sql = sql.Replace("&quote;", "'");
 415:   
 416:              return sql;
 417:          }
 418:   
 419:          ////////////////////////////////////////////////////////////////////////////    
 420:   
 421:          /// <summary>
 422:          ///
 423:          /// </summary>
 424:          public static string OracleSqlCommandDeleteServiceRequestOntRecord(string sqlWhereString)
 425:          {
 426:              string sql;
 427:   
 428:              sql = @"delete from ONT_DATA where " + sqlWhereString;
 429:   
 430:              return sql;
 431:          }
 432:   
 433:          ////////////////////////////////////////////////////////////////////////////
 434:   
 435:          /// <summary>
 436:          ///
 437:          /// </summary>
 438:          public static void UpdateForServiceRequestOntIdRangeWithOutputDataTable(DataTable dataTable, Tuple<string, string> startEndRangeTuple, out Ia.Cl.Model.Result result)
 439:          {
 440:              //bool isUpdated;
 441:              int pon, ont, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 442:              string r, start, end, areaSymbol, accessName, serviceRequestOntId;
 443:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt, newServiceRequestOnt;
 444:              List<string> insertedItemIdList, newServiceRequestOntIdList;
 445:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 446:   
 447:              //isUpdated = false;
 448:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 449:              r = string.Empty;
 450:              result = new Ia.Cl.Model.Result();
 451:              insertedItemIdList = new List<string>();
 452:              newServiceRequestOntIdList = new List<string>();
 453:   
 454:              if (dataTable != null)
 455:              {
 456:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 457:                  {
 458:                      readItemCount = dataTable.Rows.Count;
 459:   
 460:                      start = startEndRangeTuple.Item1;
 461:                      end = startEndRangeTuple.Item2;
 462:   
 463:                      serviceRequestOntList = Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.ReadListWithinIdRange(start, end);
 464:                      existingItemCount = serviceRequestOntList.Count;
 465:   
 466:                      insertedItemIdList = new List<string>(dataTable.Rows.Count + 1);
 467:   
 468:                      foreach (DataRow dataRow in dataTable.Rows)
 469:                      {
 470:                          serviceRequestOntId = dataRow["Id"].ToString();
 471:   
 472:                          ont = int.Parse(dataRow["Ont"].ToString());
 473:                          pon = int.Parse(dataRow["Pon"].ToString());
 474:                          areaSymbol = dataRow["AreaSymbol"].ToString();
 475:   
 476:                          accessName = Ia.Ngn.Cl.Model.Business.Access.Name(areaSymbol, pon, ont);
 477:   
 478:                          serviceRequestOnt = (from sro in db.ServiceRequestOnts where sro.Id == serviceRequestOntId select sro).SingleOrDefault();
 479:   
 480:                          newServiceRequestOnt = new Ia.Ngn.Cl.Model.ServiceRequestOnt()
 481:                          {
 482:                              Id = serviceRequestOntId,
 483:   
 484:                              Pon = pon,
 485:                              Ont = ont,
 486:                              AreaSymbol = areaSymbol,
 487:                              Block = dataRow["Block"].ToString(),
 488:                              Street = dataRow["Street"].ToString(),
 489:                              PremisesOld = dataRow["PremisesOld"].ToString(),
 490:                              PremisesNew = dataRow["PremisesNew"].ToString(),
 491:                              Paci = dataRow["Paci"].ToString(),
 492:                              PossibleNumberOfTd = int.Parse(dataRow["PossibleNumberOfTd"].ToString()),
 493:                              PossibleNumberOfEthernet = int.Parse(dataRow["PossibleNumberOfEthernet"].ToString()),
 494:   
 495:                              Created = DateTime.UtcNow.AddHours(3),
 496:                              Updated = DateTime.UtcNow.AddHours(3),
 497:   
 498:                              Access = Ia.Ngn.Cl.Model.Business.ServiceRequestType.ExtractAccess(db, accessName)
 499:                          };
 500:   
 501:                          if (serviceRequestOnt == null)
 502:                          {
 503:                              insertedItemIdList.Add(serviceRequestOntId);
 504:   
 505:                              db.ServiceRequestOnts.Add(newServiceRequestOnt);
 506:   
 507:                              insertedItemCount++;
 508:                          }
 509:                          else
 510:                          {
 511:                              // below: copy values from newServiceRequestOnt to serviceRequestOnt
 512:   
 513:                              if (serviceRequestOnt.Update(newServiceRequestOnt))
 514:                              {
 515:                                  db.ServiceRequestOnts.Attach(serviceRequestOnt);
 516:                                  db.Entry(serviceRequestOnt).State = System.Data.Entity.EntityState.Modified;
 517:   
 518:                                  updatedItemCount++;
 519:                              }
 520:                          }
 521:   
 522:                          // below: this will enable the removal of SRT that don't have a valid SR
 523:                          newServiceRequestOntIdList.Add(serviceRequestOntId);
 524:                      }
 525:   
 526:                      db.SaveChanges();
 527:   
 528:                      // below: this function will remove values that were not present in the reading
 529:                      if (serviceRequestOntList.Count > 0)
 530:                      {
 531:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestOnt sro in serviceRequestOntList)
 532:                          {
 533:                              if (!newServiceRequestOntIdList.Contains(sro.Id))
 534:                              {
 535:                                  serviceRequestOnt = (from sro2 in db.ServiceRequestOnts where sro2.Id == sro.Id select sro2).SingleOrDefault();
 536:   
 537:                                  if (serviceRequestOnt != null)
 538:                                  {
 539:                                      db.ServiceRequestOnts.Remove(serviceRequestOnt);
 540:                                      deletedItemCount++;
 541:                                  }
 542:                              }
 543:                          }
 544:   
 545:                          db.SaveChanges();
 546:                      }
 547:   
 548:                      /*
 549:                      // note that I had to create the object first (above) then assign a foreign key reference to it
 550:                      foreach (int i in insertedItemIdList)
 551:                      {
 552:                          newServiceRequestOnt = new Ia.Ngn.Cl.Model.ServiceRequestOnt();
 553:  
 554:                          serviceRequestOnt = (from sro in db.ServiceRequestOnts where sro.Id == i select sro).SingleOrDefault();
 555:  
 556:                          if (serviceRequestOnt != null)
 557:                          {
 558:                              newServiceRequestOnt.Copy(serviceRequestOnt);
 559:  
 560:                              //newServiceRequestOnt.ServiceRequest = (from q in db.ServiceRequests where q.Id == serviceRequestId select q).SingleOrDefault();
 561:                              newServiceRequestOnt.Access = Ia.Ngn.Cl.Model.Business.ServiceRequestType.ExtractAccess(db, serviceRequestOnt.Value);
 562:  
 563:                              if (serviceRequestOnt.Update(newServiceRequestOnt))
 564:                              {
 565:                                  db.ServiceRequestOnts.Attach(serviceRequestOnt);
 566:                                  db.Entry(serviceRequestOnt).State = System.Data.Entity.EntityState.Modified;
 567:  
 568:                                  updatedItemCount++;
 569:                              }
 570:                          }
 571:                      }
 572:                      */
 573:   
 574:                      db.SaveChanges();
 575:   
 576:                      //if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 577:                      //else isUpdated = false;
 578:   
 579:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ");
 580:                  }
 581:              }
 582:              else
 583:              {
 584:                  result.AddWarning("(dataTable == null/?/?) ");
 585:              }
 586:          }
 587:   
 588:          ////////////////////////////////////////////////////////////////////////////
 589:   
 590:          /// <summary>
 591:          ///
 592:          /// </summary>
 593:          public static List<Ia.Ngn.Cl.Model.ServiceRequestOnt> ReadListWithinIdRange(string start, string end)
 594:          {
 595:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 596:   
 597:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 598:              {
 599:                  serviceRequestOntList = (from sro in db.ServiceRequestOnts where sro.Id.CompareTo(start) >= 0 && sro.Id.CompareTo(end) <= 0 select sro).ToList();
 600:              }
 601:   
 602:              return serviceRequestOntList;
 603:          }
 604:   
 605:          /*
 606:          ////////////////////////////////////////////////////////////////////////////
 607:  
 608:          /// <summary>
 609:          ///
 610:          /// </summary>
 611:          public static void UpdateNullAccess(out Ia.Cl.Model.Result result)
 612:          {
 613:              int updatedItemCount;
 614:              Ia.Ngn.Cl.Model.ServiceRequestOnt updatedServiceRequestOnt;
 615:              List<Ia.Ngn.Cl.Model.ServiceRequestOnt> serviceRequestOntList;
 616:  
 617:              updatedItemCount = 0;
 618:              result = new Ia.Cl.Model.Result();
 619:  
 620:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 621:              {
 622:                  serviceRequestOntList = (from sro in db.ServiceRequestOnts where sro.Access == null select sro).ToList();
 623:  
 624:                  if (serviceRequestOntList != null && serviceRequestOntList.Count > 0)
 625:                  {
 626:                      foreach (Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt in serviceRequestOntList)
 627:                      {
 628:                          updatedServiceRequestOnt = (from q in db.ServiceRequestOnts where q.Id == serviceRequestOnt.Id select q).SingleOrDefault();
 629:  
 630:                          try
 631:                          {
 632:                              updatedServiceRequestOnt.Access = Ia.Ngn.Cl.Model.Business.ServiceRequestType.ExtractAccess(db, serviceRequestOnt.Value);
 633:                          }
 634:                          catch(Exception ex)
 635:                          {
 636:  
 637:                          }
 638:  
 639:                          if (updatedServiceRequestOnt.Access != null)
 640:                          {
 641:                              db.ServiceRequestOnts.Attach(updatedServiceRequestOnt);
 642:                              db.Entry(serviceRequestOnt).State = System.Data.Entity.EntityState.Modified;
 643:  
 644:                              updatedItemCount++;
 645:                          }
 646:                      }
 647:  
 648:                      db.SaveChanges();
 649:  
 650:                      result.AddSuccess("Number of updated records: " + updatedItemCount + ". ");
 651:                  }
 652:                  else
 653:                  {
 654:                      result.AddSuccess("No service request ONTs with Access = null. ");
 655:                  }
 656:              }
 657:          }
 658:          */
 659:   
 660:          ////////////////////////////////////////////////////////////////////////////
 661:   
 662:          /// <summary>
 663:          ///
 664:          /// </summary>
 665:          public static bool Delete(string id, out string result)
 666:          {
 667:              bool b;
 668:   
 669:              b = false;
 670:              result = string.Empty;
 671:   
 672:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 673:              {
 674:                  var v = (from o in db.ServiceRequestOnts where o.Id == id select o).FirstOrDefault();
 675:   
 676:                  if (v != null)
 677:                  {
 678:                      db.ServiceRequestOnts.Remove(v);
 679:                      db.SaveChanges();
 680:   
 681:                      b = true;
 682:                  }
 683:                  else b = false;
 684:              }
 685:   
 686:              return b;
 687:          }
 688:   
 689:          ////////////////////////////////////////////////////////////////////////////
 690:   
 691:          /// <summary>
 692:          ///
 693:          /// </summary>
 694:          public static bool DeleteByAccessId(string accessId, out string result)
 695:          {
 696:              bool recordExisted;
 697:   
 698:              recordExisted = false;
 699:              result = string.Empty;
 700:   
 701:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 702:              {
 703:                  // --delete from ServiceRequestOnts where Access_Id = '1040101010040004'
 704:                  var v = (from sro in db.ServiceRequestOnts where sro.Access.Id == accessId select sro).FirstOrDefault(); //.SingleOrDefault();
 705:   
 706:                  if (v != null)
 707:                  {
 708:                      db.ServiceRequestOnts.Remove(v);
 709:                      db.SaveChanges();
 710:   
 711:                      recordExisted = true;
 712:                  }
 713:                  else recordExisted = false;
 714:              }
 715:   
 716:              return recordExisted;
 717:          }
 718:   
 719:          ////////////////////////////////////////////////////////////////////////////    
 720:          ////////////////////////////////////////////////////////////////////////////    
 721:      }
 722:   
 723:      ////////////////////////////////////////////////////////////////////////////
 724:      ////////////////////////////////////////////////////////////////////////////
 725:  }