)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ServiceRequestOntDetail (Ia.Ftn.Cl.Model.Data)

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

Service Request Ont Detail support class for Fixed Telecommunications Network (FTN) data model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Linq;
    5:  
    6: namespace Ia.Ftn.Cl.Model.Data
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     /// Service Request Ont Detail support class for Fixed Telecommunications Network (FTN) data model.
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2017-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated 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 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.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ftn.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.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, out List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailDeleteList)
   47:         {
   48:             int serviceType, servicePosition;
   49:             string id;
   50:             DateTime now;
   51:             Ia.Ftn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail;
   52:             Ia.Ftn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
   53:             List<Ia.Ftn.Cl.Model.Business.ServiceServiceRequestOnt> insertList, deleteList;
   54:  
   55:             now = DateTime.UtcNow.AddHours(3);
   56:  
   57:             Ia.Ftn.Cl.Model.Data.Service.DifferenceBetweenServiceAndServiceRequestOntDetailsOfTheCustomerDepartmentDatabase(out insertList, out deleteList);
   58:  
   59:             serviceRequestOntDetailCreateList = new List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>(insertList.Count);
   60:  
   61:             foreach (Ia.Ftn.Cl.Model.Business.ServiceServiceRequestOnt ssro in insertList)
   62:             {
   63:                 serviceType = ssro.ServiceType;
   64:                 servicePosition = ssro.ServicePosition;
   65:                 serviceRequestOnt = ssro.ServiceRequestOnt;
   66:  
   67:                 id = Ia.Ftn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
   68:  
   69:                 serviceRequestOntDetail = new Ia.Ftn.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.Ftn.Cl.Model.ServiceRequestOntDetail>(deleteList.Count);
   85:  
   86:             foreach (Ia.Ftn.Cl.Model.Business.ServiceServiceRequestOnt ssro in deleteList)
   87:             {
   88:                 serviceType = ssro.ServiceType;
   89:                 servicePosition = ssro.ServicePosition;
   90:                 serviceRequestOnt = ssro.ServiceRequestOnt;
   91:  
   92:                 id = Ia.Ftn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, 0, 0);
   93:  
   94:                 // this is a dummy non-existant ServiceRequestOntDetail
   95:                 serviceRequestOntDetail = new Ia.Ftn.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.Ftn.Cl.Model.ServiceRequestOntDetail ServiceRequestOntDetailNotUpdatedInCustomerDepartmentDatabase(out Ia.Cl.Models.Result result)
  116:         {
  117:             int serviceType, servicePosition;
  118:             string id;
  119:             DateTime now;
  120:             Ia.Ftn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail;
  121:             Ia.Ftn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
  122:             List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
  123:             List<Ia.Ftn.Cl.Model.Business.ServiceServiceRequestOnt> list;
  124:  
  125:             result = new Ia.Cl.Models.Result();
  126:             now = DateTime.UtcNow.AddHours(3);
  127:  
  128:             if (serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count == 0)
  129:             {
  130:                 serviceRequestOntDetailList = new List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>();
  131:  
  132:                 list = Ia.Ftn.Cl.Model.Data.Service.ServiceServiceRequestOntDetailWithMismatchedInformationInServiceRequestOntDetailList();
  133:  
  134:                 foreach (Ia.Ftn.Cl.Model.Business.ServiceServiceRequestOnt ssro in list)
  135:                 {
  136:                     serviceType = ssro.ServiceType;
  137:                     servicePosition = ssro.ServicePosition;
  138:                     serviceRequestOnt = ssro.ServiceRequestOnt;
  139:  
  140:                     id = Ia.Ftn.Cl.Model.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
  141:  
  142:                     serviceRequestOntDetail = new Ia.Ftn.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.Ftn.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 FTN 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.Models.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.Models.Result();
  188:  
  189:             if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count == 0)
  190:             {
  191:                 ontListAccessIdList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdList;
  192:                 ontAccessIdToOntAccessNameDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
  193:  
  194:                 tupleList = Ia.Cl.Models.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.Ftn.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.Ftn.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.Ftn.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 Ia.Cl.Models.Result UpdateForServiceRequestOntIdRangeWithOutputDataTable(DataTable dataTable, Tuple<string, string> startEndRangeTuple)
  391:         {
  392:             bool validRecord; // isUpdated;
  393:             int serviceType, servicePosition, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
  394:             string service, r, start, end, serviceRequestOntId, serviceRequestOntDetailId;
  395:             Ia.Cl.Models.Result result;
  396:             Ia.Ftn.Cl.Model.ServiceRequestOntDetail serviceRequestOntDetail, newServiceRequestOntDetail;
  397:             Ia.Ftn.Cl.Model.ServiceRequestOnt serviceRequestOnt;
  398:             List<string> insertedItemIdList, newServiceRequestOntDetailIdList;
  399:             List<Ia.Ftn.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.Models.Result();
  407:             insertedItemIdList = new List<string>();
  408:             newServiceRequestOntDetailIdList = new List<string>();
  409:  
  410:             if (dataTable != null)
  411:             {
  412:                 using (var db = new Ia.Ftn.Cl.Model.Db())
  413:                 {
  414:                     readItemCount = dataTable.Rows.Count;
  415:  
  416:                     start = startEndRangeTuple.Item1;
  417:                     end = startEndRangeTuple.Item2;
  418:  
  419:                     serviceRequestOntDetailList = Ia.Ftn.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.Ftn.Cl.Model.Business.Service.ServiceType.ImsService;
  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.Ftn.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.Ftn.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 = Microsoft.EntityFrameworkCore.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.Ftn.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:             return result;
  548:         }
  549:  
  550:         ////////////////////////////////////////////////////////////////////////////
  551:  
  552:         /// <summary>
  553:         ///
  554:         /// </summary>
  555:         public static bool DeleteByAccessId(string accessId, out string result)
  556:         {
  557:             bool recordExisted;
  558:  
  559:             recordExisted = false;
  560:             result = string.Empty;
  561:  
  562:             using (var db = new Ia.Ftn.Cl.Model.Db())
  563:             {
  564:                 //--delete from ServiceRequestOntDetails where ServiceRequestOnts _Id = (select id from ServiceRequestOnts where Access_Id = '1040101010040004')
  565:  
  566:                 var v = (from srod in db.ServiceRequestOntDetails
  567:                          join sro in db.ServiceRequestOnts on srod.ServiceRequestOnt.Id equals sro.Id
  568:                          where sro.Access.Id == accessId
  569:                          select srod).FirstOrDefault();
  570:  
  571:                 if (v != null)
  572:                 {
  573:                     db.ServiceRequestOntDetails.Remove(v);
  574:                     db.SaveChanges();
  575:  
  576:                     recordExisted = true;
  577:                 }
  578:                 else recordExisted = false;
  579:             }
  580:  
  581:             return recordExisted;
  582:         }
  583:  
  584:         ////////////////////////////////////////////////////////////////////////////
  585:  
  586:         /// <summary>
  587:         ///
  588:         /// </summary>
  589:         public static List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> ReadListWithinIdRange(string start, string end)
  590:         {
  591:             List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
  592:  
  593:             using (var db = new Ia.Ftn.Cl.Model.Db())
  594:             {
  595:                 serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails where srod.Id.CompareTo(start) >= 0 && srod.Id.CompareTo(end) <= 0 select srod).ToList();
  596:             }
  597:  
  598:             return serviceRequestOntDetailList;
  599:         }
  600:  
  601:         ////////////////////////////////////////////////////////////////////////////
  602:  
  603:         /// <summary>
  604:         ///
  605:         /// </summary>
  606:         public static List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> ReadListWithinServiceRequestOntIdRange(string start, string end)
  607:         {
  608:             List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailList;
  609:  
  610:             using (var db = new Ia.Ftn.Cl.Model.Db())
  611:             {
  612:                 serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails
  613:                                                where srod.ServiceRequestOnt.Id.CompareTo(start) >= 0 && srod.ServiceRequestOnt.Id.CompareTo(end) <= 0
  614:                                                select srod).ToList();
  615:             }
  616:  
  617:             return serviceRequestOntDetailList;
  618:         }
  619:  
  620:         ////////////////////////////////////////////////////////////////////////////    
  621:         ////////////////////////////////////////////////////////////////////////////    
  622:     }
  623:  
  624:     ////////////////////////////////////////////////////////////////////////////
  625:     ////////////////////////////////////////////////////////////////////////////
  626: }