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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequestOntDetail

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

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

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Linq;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Data
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Service Request Ont Detail support class for Next Generation Network (NGN) data model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2017-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class ServiceRequestOntDetail
  28:      {
  29:          private const int LengthOfRequestOntIdRange = 100;
  30:          private static Dictionary<string, string> ontAccessIdToOntAccessNameDictionary = new Dictionary<string, string>();
  31:          private static Queue<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>();
  32:          private static Queue<Tuple<string, string>> serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>();
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public ServiceRequestOntDetail() { }
  40:   
  41:          ////////////////////////////////////////////////////////////////////////////    
  42:   
  43:          /// <summary>
  44:          ///
  45:          /// </summary>
  46:          public static void ServiceRequestOntDetailCreateAndDeleteList(out List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, out List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailDeleteList)
  47:          {
  48:              int serviceType, servicePosition;
  49:              string id;
  50:              DateTime now;
  51:              Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail;
  52:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
  53:              List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> insertList, deleteList;
  54:   
  55:              now = DateTime.UtcNow.AddHours(3);
  56:   
  57:              Ia.Ngn.Cl.Model.Data.Service.DifferenceBetweenServiceAndServiceRequestOntDetailsOfTheCustomerDepartmentDatabase(out insertList, out deleteList);
  58:   
  59:              serviceRequestOntDetailCreateList = new List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>(insertList.Count);
  60:   
  61:              foreach (Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt ssro in insertList)
  62:              {
  63:                  serviceType = ssro.ServiceType;
  64:                  servicePosition = ssro.ServicePosition;
  65:                  serviceRequestOnt = ssro.ServiceRequestOnt;
  66:   
  67:                  id = Ia.Ngn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
  68:   
  69:                  serviceRequestOntDetail = new Ia.Ngn.Cl.Model.ServiceRequestOntDetail()
  70:                  {
  71:                      Id = id,
  72:                      Service = ssro.Service,
  73:                      ServiceType = serviceType,
  74:                      ServicePosition = servicePosition,
  75:                      ServiceRequestOnt = serviceRequestOnt,
  76:                      Created = now,
  77:                      Updated = now
  78:                  };
  79:   
  80:                  serviceRequestOntDetailCreateList.Add(serviceRequestOntDetail);
  81:              }
  82:   
  83:   
  84:              serviceRequestOntDetailDeleteList = new List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>(deleteList.Count);
  85:   
  86:              foreach (Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt ssro in deleteList)
  87:              {
  88:                  serviceType = ssro.ServiceType;
  89:                  servicePosition = ssro.ServicePosition;
  90:                  serviceRequestOnt = ssro.ServiceRequestOnt;
  91:   
  92:                  id = Ia.Ngn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, 0, 0);
  93:   
  94:                  // this is a dummy non-existant ServiceRequestOntDetail
  95:                  serviceRequestOntDetail = new Ia.Ngn.Cl.Model.ServiceRequestOntDetail()
  96:                  {
  97:                      Id = id,
  98:                      Service = ssro.Service,
  99:                      ServiceType = serviceType,
 100:                      ServicePosition = servicePosition,
 101:                      ServiceRequestOnt = serviceRequestOnt,
 102:                      Created = now,
 103:                      Updated = now
 104:                  };
 105:   
 106:                  serviceRequestOntDetailDeleteList.Add(serviceRequestOntDetail);
 107:              }
 108:          }
 109:   
 110:          ////////////////////////////////////////////////////////////////////////////    
 111:   
 112:          /// <summary>
 113:          ///
 114:          /// </summary>
 115:          public static Ia.Ngn.Cl.Model.ServiceRequestOntDetail ServiceRequestOntDetailNotUpdatedInCustomerDepartmentDatabase(out Ia.Cl.Model.Result result)
 116:          {
 117:              int serviceType, servicePosition;
 118:              string id;
 119:              DateTime now;
 120:              Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail;
 121:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
 122:              List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
 123:              List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> list;
 124:   
 125:              result = new Ia.Cl.Model.Result();
 126:              now = DateTime.UtcNow.AddHours(3);
 127:   
 128:              if (serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count == 0)
 129:              {
 130:                  serviceRequestOntDetailList = new List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>();
 131:   
 132:                  list = Ia.Ngn.Cl.Model.Data.Service.ServiceServiceRequestOntDetailWithMismatchedInformationInServiceRequestOntDetailList();
 133:   
 134:                  foreach (Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt ssro in list)
 135:                  {
 136:                      serviceType = ssro.ServiceType;
 137:                      servicePosition = ssro.ServicePosition;
 138:                      serviceRequestOnt = ssro.ServiceRequestOnt;
 139:   
 140:                      id = Ia.Ngn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
 141:   
 142:                      serviceRequestOntDetail = new Ia.Ngn.Cl.Model.ServiceRequestOntDetail()
 143:                      {
 144:                          Id = id,
 145:                          Service = ssro.Service,
 146:                          ServiceType = serviceType,
 147:                          ServicePosition = servicePosition,
 148:                          ServiceRequestOnt = serviceRequestOnt,
 149:                          Created = now,
 150:                          Updated = now
 151:                      };
 152:   
 153:                      serviceRequestOntDetailList.Add(serviceRequestOntDetail);
 154:                  }
 155:   
 156:                  serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>(serviceRequestOntDetailList);
 157:              }
 158:   
 159:              if (serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count > 0)
 160:              {
 161:                  serviceRequestOntDetail = serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Dequeue();
 162:   
 163:                  result.AddSuccess("(" + serviceRequestOntDetail.ServiceRequestOnt.Name + "/" + serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count + ")");
 164:              }
 165:              else
 166:              {
 167:                  serviceRequestOntDetail = null;
 168:   
 169:                  result.AddSuccess("No mismatch in properties between OFN and billing database. ");
 170:              }
 171:   
 172:              return serviceRequestOntDetail;
 173:          }
 174:   
 175:          ////////////////////////////////////////////////////////////////////////////    
 176:   
 177:          /// <summary>
 178:          ///
 179:          /// </summary>
 180:          public static Tuple<string, string> ServiceRequestOntDetailIdStartEndRangeManager(out Ia.Cl.Model.Result result)
 181:          {
 182:              string startAccessName, endAccessName;
 183:              Tuple<string, string> tuple;
 184:              List<string> ontListAccessIdList;
 185:              List<Tuple<string, string>> tupleList;
 186:   
 187:              result = new Ia.Cl.Model.Result();
 188:   
 189:              if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count == 0)
 190:              {
 191:                  ontListAccessIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdList;
 192:                  ontAccessIdToOntAccessNameDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 193:   
 194:                  tupleList = Ia.Cl.Model.Default.OptimizedStartEndRangeTupleList(ontListAccessIdList, LengthOfRequestOntIdRange);
 195:   
 196:                  serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>(tupleList);
 197:              }
 198:   
 199:              if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count > 0)
 200:              {
 201:                  tuple = serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Dequeue();
 202:   
 203:                  // debug
 204:                  //tuple = new Tuple<string, string>("104010301512009", "104010301512019");
 205:   
 206:                  startAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item1];
 207:                  endAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item2];
 208:   
 209:                  result.AddSuccess("(" + startAccessName + " - " + endAccessName + "/" + serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count + ")");
 210:              }
 211:              else
 212:              {
 213:                  tuple = null;
 214:   
 215:                  result.AddWarning("(0-0 0/0)");
 216:              }
 217:   
 218:              return tuple;
 219:          }
 220:   
 221:          ////////////////////////////////////////////////////////////////////////////    
 222:   
 223:          /// <summary>
 224:          ///
 225:          /// </summary>
 226:          public static string OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(Tuple<string, string> startEndRangeTuple)
 227:          {
 228:              return OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(startEndRangeTuple.Item1, startEndRangeTuple.Item2);
 229:          }
 230:   
 231:          ////////////////////////////////////////////////////////////////////////////    
 232:   
 233:          /// <summary>
 234:          ///
 235:          /// </summary>
 236:          public static string OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(string start, string end)
 237:          {
 238:              string sql;
 239:   
 240:              // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
 241:   
 242:              if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end)) sql = @"select id, line_ser, ethernet_ser, phone_no, internet_srv_no from ont_details where (id >= " + start + " and id <= " + end + @") order by id asc";
 243:              else sql = string.Empty;
 244:   
 245:              return sql;
 246:          }
 247:   
 248:          ////////////////////////////////////////////////////////////////////////////    
 249:   
 250:          /// <summary>
 251:          ///
 252:          /// </summary>
 253:          public static string OracleSqlCommandInsertServiceRequestOntDetailRecord(Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail)
 254:          {
 255:              int line_ser, ethernet_ser, phone_no;
 256:              string sql, internet_srv_no;
 257:   
 258:              // convert ServiceRequestOntDetail to the format needed in ONT_DETAILS
 259:   
 260:              if (serviceRequestOntDetail.ServiceType == 1)
 261:              {
 262:                  line_ser = serviceRequestOntDetail.ServicePosition;
 263:                  ethernet_ser = 0;
 264:                  phone_no = int.Parse(serviceRequestOntDetail.Service);
 265:                  internet_srv_no = string.Empty;
 266:              }
 267:              else //if (serviceRequestOntDetail.ServiceType == 2)
 268:              {
 269:                  line_ser = 0;
 270:                  ethernet_ser = serviceRequestOntDetail.ServicePosition;
 271:                  phone_no = 0;
 272:                  internet_srv_no = serviceRequestOntDetail.Service;
 273:              }
 274:   
 275:              sql = @"insert into ONT_DETAILS(ID, LINE_SER, ETHERNET_SER, PHONE_NO, INTERNET_SRV_NO) values "
 276:                           + @"("
 277:                           + @"N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote;,"
 278:                           + @"N&quote;" + line_ser + @"&quote;,"
 279:                           + @"N&quote;" + ethernet_ser + @"&quote;,"
 280:                           + @"N&quote;" + phone_no + @"&quote;,"
 281:                           + @"N&quote;" + internet_srv_no + @"&quote;"
 282:                                                       + @")";
 283:   
 284:              sql = sql.Replace("'", " ");
 285:              sql = sql.Replace("&quote;", "'");
 286:   
 287:              return sql;
 288:          }
 289:   
 290:          ////////////////////////////////////////////////////////////////////////////    
 291:   
 292:          /// <summary>
 293:          ///
 294:          /// </summary>
 295:          public static string OracleSqlCommandUpdateServiceRequestOntDetailRecord(Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail)
 296:          {
 297:              int line_ser, ethernet_ser, phone_no;
 298:              string sql, internet_srv_no;
 299:   
 300:              // convert ServiceRequestOntDetail to the format needed in ONT_DETAILS
 301:   
 302:              if (serviceRequestOntDetail.ServiceType == 1)
 303:              {
 304:                  line_ser = serviceRequestOntDetail.ServicePosition;
 305:                  ethernet_ser = 0;
 306:                  phone_no = int.Parse(serviceRequestOntDetail.Service);
 307:                  internet_srv_no = string.Empty;
 308:              }
 309:              else //if (serviceRequestOntDetail.ServiceType == 2)
 310:              {
 311:                  line_ser = 0;
 312:                  ethernet_ser = serviceRequestOntDetail.ServicePosition;
 313:                  phone_no = 0;
 314:                  internet_srv_no = serviceRequestOntDetail.Service;
 315:              }
 316:   
 317:              sql = @"update ONT_DETAILS set LINE_SER = " + line_ser + @", "
 318:  + @"ETHERNET_SER = " + ethernet_ser + @", "
 319:  + @"PHONE_NO = " + phone_no + @", "
 320:  + @"INTERNET_SRV_NO = N&quote;" + internet_srv_no + @"&quote; "
 321:  + @" where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote;";
 322:   
 323:              sql = sql.Replace("'", " ");
 324:              sql = sql.Replace("&quote;", "'");
 325:   
 326:              return sql;
 327:          }
 328:   
 329:          ////////////////////////////////////////////////////////////////////////////    
 330:   
 331:          /// <summary>
 332:          ///
 333:          /// </summary>
 334:          public static string OracleSqlCommandDeleteServiceRequestOntDetailRecord(Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail)
 335:          {
 336:              string sql;
 337:   
 338:              // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
 339:   
 340:              // sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and LINE_SER = N&quote;" + serviceRequestOntDetail.ServicePosition + @"&quote;";
 341:              // sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and PHONE_NO = " + serviceRequestOntDetail.Service + @"";
 342:              sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and (PHONE_NO = " + serviceRequestOntDetail.Service + @" or LINE_SER = " + serviceRequestOntDetail.ServicePosition + @")";
 343:   
 344:              // delete from ONT_DETAILS where ID = N'1060210011518004' and (PHONE_NO = 23751510 or LINE_SER = 1)
 345:   
 346:              sql = sql.Replace("'", " ");
 347:              sql = sql.Replace("&quote;", "'");
 348:   
 349:              return sql;
 350:          }
 351:   
 352:          ////////////////////////////////////////////////////////////////////////////    
 353:   
 354:          /// <summary>
 355:          ///
 356:          /// </summary>
 357:          public static string OracleSqlCommandDeleteServiceRequestOntDetailRecordByService(string service)
 358:          {
 359:              string sql;
 360:   
 361:              sql = @"delete from ONT_DETAILS where PHONE_NO = " + service + @"";
 362:   
 363:              sql = sql.Replace("'", " ");
 364:              sql = sql.Replace("&quote;", "'");
 365:   
 366:              return sql;
 367:          }
 368:   
 369:          ////////////////////////////////////////////////////////////////////////////    
 370:   
 371:          /// <summary>
 372:          ///
 373:          /// </summary>
 374:          public static string OracleSqlCommandDeleteServiceRequestOntDetailRecord(string sqlWhereString)
 375:          {
 376:              string sql;
 377:   
 378:              // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
 379:   
 380:              sql = @"delete from ONT_DETAILS where " + sqlWhereString;
 381:   
 382:              return sql;
 383:          }
 384:   
 385:          ////////////////////////////////////////////////////////////////////////////
 386:   
 387:          /// <summary>
 388:          ///
 389:          /// </summary>
 390:          public static void UpdateForServiceRequestOntIdRangeWithOutputDataTable(DataTable dataTable, Tuple<string, string> startEndRangeTuple, out Ia.Cl.Model.Result result)
 391:          {
 392:              bool validRecord; // isUpdated;
 393:              int serviceType, servicePosition, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 394:              string service, r, start, end, serviceRequestOntId, serviceRequestOntDetailId;
 395:              Ia.Ngn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail, newServiceRequestOntDetail;
 396:              Ia.Ngn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
 397:              List<string> insertedItemIdList, newServiceRequestOntDetailIdList;
 398:              List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
 399:   
 400:              validRecord = false; // isUpdated = false;
 401:              serviceType = servicePosition = 0;
 402:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 403:              service = r = string.Empty;
 404:   
 405:              result = new Ia.Cl.Model.Result();
 406:              insertedItemIdList = new List<string>();
 407:              newServiceRequestOntDetailIdList = new List<string>();
 408:   
 409:              if (dataTable != null)
 410:              {
 411:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 412:                  {
 413:                      readItemCount = dataTable.Rows.Count;
 414:   
 415:                      start = startEndRangeTuple.Item1;
 416:                      end = startEndRangeTuple.Item2;
 417:   
 418:                      serviceRequestOntDetailList = Ia.Ngn.Cl.Model.Data.ServiceRequestOntDetail.ReadListWithinServiceRequestOntIdRange(start, end);
 419:                      existingItemCount = serviceRequestOntDetailList.Count;
 420:   
 421:                      insertedItemIdList = new List<string>(dataTable.Rows.Count + 1);
 422:   
 423:                      int line_ser, ethernet_ser, phone_no;
 424:                      string internet_srv_no;
 425:   
 426:                      foreach (DataRow dataRow in dataTable.Rows)
 427:                      {
 428:                          serviceRequestOntId = dataRow["Id"].ToString();
 429:   
 430:                          if (int.TryParse(dataRow["line_ser"].ToString(), out line_ser) && int.TryParse(dataRow["ethernet_ser"].ToString(), out ethernet_ser) && int.TryParse(dataRow["phone_no"].ToString(), out phone_no))
 431:                          {
 432:                              internet_srv_no = dataRow["internet_srv_no"].ToString();
 433:   
 434:                              // I will convert from the Customer department database convention to my own
 435:   
 436:                              if (line_ser != 0)
 437:                              {
 438:                                  serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService;
 439:                                  service = phone_no.ToString();
 440:                                  servicePosition = line_ser;
 441:   
 442:                                  validRecord = true;
 443:                              }
 444:                              else if (ethernet_ser != 0)
 445:                              {
 446:                                  serviceType = 2; //?? maybe remove ethernet data completely
 447:                                  service = internet_srv_no;
 448:                                  servicePosition = ethernet_ser;
 449:   
 450:                                  validRecord = true;
 451:                              }
 452:                              else
 453:                              {
 454:                                  validRecord = false;
 455:                              }
 456:                          }
 457:                          else
 458:                          {
 459:                              validRecord = false;
 460:                          }
 461:   
 462:                          if (validRecord)
 463:                          {
 464:                              serviceRequestOntDetailId = Ia.Ngn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOntId, serviceType, servicePosition);
 465:   
 466:                              serviceRequestOnt = (from sro in db.ServiceRequestOnts where sro.Id == serviceRequestOntId select sro).SingleOrDefault();
 467:   
 468:                              serviceRequestOntDetail = (from srod in db.ServiceRequestOntDetails where srod.Id == serviceRequestOntDetailId select srod).SingleOrDefault();
 469:   
 470:                              newServiceRequestOntDetail = new Ia.Ngn.Cl.Model.ServiceRequestOntDetail()
 471:                              {
 472:                                  Id = serviceRequestOntDetailId,
 473:                                  ServiceType = serviceType,
 474:                                  Service = service,
 475:                                  ServicePosition = servicePosition,
 476:                                  Created = DateTime.UtcNow.AddHours(3),
 477:                                  Updated = DateTime.UtcNow.AddHours(3),
 478:                                  ServiceRequestOnt = serviceRequestOnt,
 479:                              };
 480:   
 481:                              if (serviceRequestOntDetail == null)
 482:                              {
 483:                                  insertedItemIdList.Add(serviceRequestOntDetailId);
 484:   
 485:                                  db.ServiceRequestOntDetails.Add(newServiceRequestOntDetail);
 486:   
 487:                                  insertedItemCount++;
 488:                              }
 489:                              else
 490:                              {
 491:                                  // below: copy values from newServiceRequestOntDetail to serviceRequestOntDetail
 492:   
 493:                                  if (serviceRequestOntDetail.Update(newServiceRequestOntDetail))
 494:                                  {
 495:                                      db.ServiceRequestOntDetails.Attach(serviceRequestOntDetail);
 496:                                      db.Entry(serviceRequestOntDetail).State = System.Data.Entity.EntityState.Modified;
 497:   
 498:                                      updatedItemCount++;
 499:                                  }
 500:                              }
 501:   
 502:                              // below: this will enable the removal of records that don't have a valid record
 503:                              newServiceRequestOntDetailIdList.Add(serviceRequestOntDetailId);
 504:                          }
 505:                          else
 506:                          {
 507:   
 508:                          }
 509:                      }
 510:   
 511:                      //db.SaveChanges(); // I don't know the problem here keep this due to some strange errors
 512:   
 513:                      // below: this function will remove values that were not present in the reading
 514:                      if (serviceRequestOntDetailList.Count > 0)
 515:                      {
 516:                          foreach (Ia.Ngn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailList)
 517:                          {
 518:                              if (!newServiceRequestOntDetailIdList.Contains(srod.Id))
 519:                              {
 520:                                  serviceRequestOntDetail = (from srod2 in db.ServiceRequestOntDetails where srod2.Id == srod.Id select srod2).SingleOrDefault();
 521:   
 522:                                  if (serviceRequestOntDetail != null)
 523:                                  {
 524:                                      db.ServiceRequestOntDetails.Remove(serviceRequestOntDetail);
 525:                                      deletedItemCount++;
 526:                                  }
 527:                              }
 528:                          }
 529:   
 530:                          //db.SaveChanges(); // keep this due to some strange errors
 531:                      }
 532:   
 533:                      db.SaveChanges(); // keep this due to some strange errors
 534:   
 535:                      //if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 536:                      //else isUpdated = false;
 537:   
 538:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ");
 539:                  }
 540:              }
 541:              else
 542:              {
 543:                  result.AddWarning("(dataTable == null/?/?) ");
 544:              }
 545:          }
 546:   
 547:          ////////////////////////////////////////////////////////////////////////////
 548:   
 549:          /// <summary>
 550:          ///
 551:          /// </summary>
 552:          public static bool DeleteByAccessId(string accessId, out string result)
 553:          {
 554:              bool recordExisted;
 555:   
 556:              recordExisted = false;
 557:              result = string.Empty;
 558:   
 559:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 560:              {
 561:                  //--delete from ServiceRequestOntDetails where ServiceRequestOnts _Id = (select id from ServiceRequestOnts where Access_Id = '1040101010040004')
 562:   
 563:                  var v = (from srod in db.ServiceRequestOntDetails
 564:                           join sro in db.ServiceRequestOnts on srod.ServiceRequestOnt.Id equals sro.Id
 565:                           where sro.Access.Id == accessId
 566:                           select srod).FirstOrDefault();
 567:   
 568:                  if (v != null)
 569:                  {
 570:                      db.ServiceRequestOntDetails.Remove(v);
 571:                      db.SaveChanges();
 572:   
 573:                      recordExisted = true;
 574:                  }
 575:                  else recordExisted = false;
 576:              }
 577:   
 578:              return recordExisted;
 579:          }
 580:   
 581:          ////////////////////////////////////////////////////////////////////////////
 582:   
 583:          /// <summary>
 584:          ///
 585:          /// </summary>
 586:          public static List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> ReadListWithinIdRange(string start, string end)
 587:          {
 588:              List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
 589:   
 590:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 591:              {
 592:                  serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails where srod.Id.CompareTo(start) >= 0 && srod.Id.CompareTo(end) <= 0 select srod).ToList();
 593:              }
 594:   
 595:              return serviceRequestOntDetailList;
 596:          }
 597:   
 598:          ////////////////////////////////////////////////////////////////////////////
 599:   
 600:          /// <summary>
 601:          ///
 602:          /// </summary>
 603:          public static List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> ReadListWithinServiceRequestOntIdRange(string start, string end)
 604:          {
 605:              List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
 606:   
 607:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 608:              {
 609:                  serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails where srod.ServiceRequestOnt.Id.CompareTo(start) >= 0 && srod.ServiceRequestOnt.Id.CompareTo(end) <= 0 select srod).ToList();
 610:              }
 611:   
 612:              return serviceRequestOntDetailList;
 613:          }
 614:   
 615:          ////////////////////////////////////////////////////////////////////////////    
 616:          ////////////////////////////////////////////////////////////////////////////    
 617:      }
 618:   
 619:      ////////////////////////////////////////////////////////////////////////////
 620:      ////////////////////////////////////////////////////////////////////////////
 621:  }