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

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