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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequestHistory

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

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

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Data;
   5:  using System.Linq;
   6:  using System.Text;
   7:  using System.Text.RegularExpressions;
   8:   
   9:  namespace Ia.Ngn.Cl.Model.Data
  10:  {
  11:      ////////////////////////////////////////////////////////////////////////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Service Request History support class for Next Generation Network (NGN) data model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2019-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  19:      ///
  20:      /// 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
  21:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  22:      ///
  23:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  24:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  25:      /// 
  26:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  27:      /// 
  28:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  29:      /// </remarks> 
  30:      public partial class ServiceRequestHistory
  31:      {
  32:          private static int sequentialQueueOriginalCount;
  33:          private static Queue<string> sequentialQueue = new Queue<string>();
  34:   
  35:          ////////////////////////////////////////////////////////////////////////////    
  36:   
  37:          /// <summary>
  38:          ///
  39:          /// </summary>
  40:          public static List<string> TempSrhVsSrMismatchListListToReadFromServiceRequestHistory
  41:          {
  42:              get
  43:              {
  44:                  List<int> list = new List<int>() { 23717782, 24847117, 25520223, 25523999, 25520233, 25523888, 24804523, 24800864, 23729385, 24805109, 23725407, 23728745, 23728538, 23723543, 23718191, 23903186, 24805972, 25439836, 25518527, 25427218, 25429311, 25429392, 25528248, 23726016, 25525848, 25442010, 23721872, 24802689, 24805120, 24805146, 24802734, 25433471, 25527876, 24805890, 23724904, 23731932, 24801227, 24801350, 24808571, 23732827, 25442456, 25379991, 25431970, 23730359, 24581799, 24804216, 25210350, 25210609, 25210470, 25210890, 25210878, 25211800, 24557210, 24833975, 23731832, 23731851, 25220605, 25220606, 25221765, 25231447, 25231448, 25231449, 25221541, 25430397, 24585905, 25242441, 25242402, 24840330, 24844309, 25231210, 24813257, 23733627, 24848908, 25417033, 25421721, 25434741, 25417031, 25437090, 25417025, 25437690, 25432551, 25437947, 25447778, 23631338, 25416073, 25437906, 24814942, 25234585, 23730804, 24530939, 25226022, 25525880, 25226083, 23726616, 24661065, 25214717, 24669292, 24669640, 25413710, 23740551, 24350067, 24350179, 24831316, 24811740, 24818447, 24383011, 25515625, 25516704, 25515268, 25514216, 25519762, 25520592, 25517903, 24555100, 25389421, 25382915, 24901250, 24976363, 23633405, 25436222, 25436444, 24973474, 25426212, 25432222, 23635363, 24588107, 25428179, 25244003, 25244004, 25244005, 25241667, 23635654, 23902123, 25426861, 25217505, 24900162, 24357672, 25216686, 24569578, 25395356, 25425685, 25380624, 25390301, 24816325, 25249690, 25515380, 23636788, 24544124, 24842115, 25215760, 24667470, 24543083, 25399953, 25416868, 23740607, 25414919, 24601006, 25239229 };
  45:                  return list.ConvertAll<string>(delegate (int i) { return i.ToString(); });
  46:              }
  47:          }
  48:   
  49:          ////////////////////////////////////////////////////////////////////////////
  50:   
  51:          /// <summary>
  52:          ///
  53:          /// </summary>
  54:          public ServiceRequestHistory() { }
  55:   
  56:          ////////////////////////////////////////////////////////////////////////////    
  57:   
  58:          /// <summary>
  59:          ///
  60:          /// </summary>
  61:          public static string OracleSqlSelectBeforeJuly21st2004CommandByService(string service)
  62:          {
  63:              return OracleSqlSelectCommandByService(service, true);
  64:          }
  65:   
  66:          ////////////////////////////////////////////////////////////////////////////    
  67:   
  68:          /// <summary>
  69:          ///
  70:          /// </summary>
  71:          public static string OracleSqlCommandSelectByService(string service)
  72:          {
  73:              return OracleSqlSelectCommandByService(service, false);
  74:          }
  75:   
  76:          ////////////////////////////////////////////////////////////////////////////    
  77:   
  78:          /// <summary>
  79:          ///
  80:          /// </summary>
  81:          private static string OracleSqlSelectCommandByService(string service, bool selectBeforeJuly21st2004)
  82:          {
  83:              string sql, sqlBeforeJuly21st2004;
  84:   
  85:              if (selectBeforeJuly21st2004) sqlBeforeJuly21st2004 = @"and start_date <= to_date(''21/7/2004'', ''dd/mm/yyyy'')";
  86:              else sqlBeforeJuly21st2004 = string.Empty;
  87:   
  88:              if (!string.IsNullOrEmpty(service))
  89:              {
  90:                  // format [select ...  csn.srv_no = 25233434 ...] is important for proper parsing and reading of number in UpdateWithServiceAndOutputDataTable()
  91:                  sql = @"select csn.srv_cat_id,csn.srv_no,csn.srv_ser_no,csn.status,c.code_name status_name,csn.start_date,csn.end_date,cs.srv_id,s.srv_name,srv_date
  92:  from cust_srv_nos csn,cust_services cs,services s,system_codes c
  93:  where csn.srv_cat_id in (3,38)
  94:  and csn.srv_no = " + service + @" " + @"
  95:  " + sqlBeforeJuly21st2004 + @"
  96:  and cs.srv_date >= csn.start_date
  97:  and csn.srv_cat_id = cs.srv_cat_id 
  98:  and csn.srv_no = cs.srv_no
  99:  and csn.srv_ser_no = cs.srv_ser_no
 100:  and s.srv_cat_id = cs.srv_cat_id
 101:  and s.srv_id = cs.srv_id 
 102:  and c.code_id = csn.status
 103:  order by csn.start_date,srv_id
 104:  ";
 105:              }
 106:              else sql = string.Empty;
 107:   
 108:              return sql;
 109:          }
 110:   
 111:          ////////////////////////////////////////////////////////////////////////////
 112:   
 113:          /// <summary>
 114:          /// Return a list of service request histories
 115:          /// </summary>
 116:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List()
 117:          {
 118:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 119:   
 120:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 121:              {
 122:                  list = (from srh in db.ServiceRequestHistories select srh).ToList();
 123:              }
 124:   
 125:              return list;
 126:          }
 127:   
 128:          ////////////////////////////////////////////////////////////////////////////
 129:   
 130:          /// <summary>
 131:          /// Return a list of service request histories for a number
 132:          /// </summary>
 133:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(int number)
 134:          {
 135:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 136:   
 137:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 138:              {
 139:                  list = (from srh in db.ServiceRequestHistories where srh.Number == number select srh).ToList();
 140:              }
 141:   
 142:              return list;
 143:          }
 144:   
 145:          ////////////////////////////////////////////////////////////////////////////
 146:   
 147:          /// <summary>
 148:          /// Return a list of un-ended service request histories
 149:          /// </summary>
 150:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> UnEndedDateTimeList()
 151:          {
 152:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 153:   
 154:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 155:              {
 156:                  list = (from srh in db.ServiceRequestHistories where srh.EndDateTime == Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime select srh).ToList();
 157:              }
 158:   
 159:              return list;
 160:          }
 161:   
 162:          ////////////////////////////////////////////////////////////////////////////
 163:   
 164:          /// <summary>
 165:          /// Return a list of un-ended service request histories for a number
 166:          /// </summary>
 167:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> UnEndedDateTimeList(int number)
 168:          {
 169:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 170:   
 171:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 172:              {
 173:                  list = (from srh in db.ServiceRequestHistories where srh.Number == number && srh.EndDateTime == Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime select srh).ToList();
 174:              }
 175:   
 176:              return list;
 177:          }
 178:   
 179:          ////////////////////////////////////////////////////////////////////////////
 180:   
 181:          /// <summary>
 182:          /// Return a list of service request histories that have numbers within the passed list
 183:          /// </summary>
 184:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(List<int> numberList)
 185:          {
 186:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 187:   
 188:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 189:              {
 190:                  list = (from srh in db.ServiceRequestHistories where numberList.Contains(srh.Number) select srh).ToList();
 191:              }
 192:   
 193:              return list;
 194:          }
 195:   
 196:          ////////////////////////////////////////////////////////////////////////////
 197:   
 198:          /// <summary>
 199:          /// Return list of service requests histories with number
 200:          /// </summary>
 201:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(string service)
 202:          {
 203:              int number;
 204:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 205:   
 206:              if (!string.IsNullOrEmpty(service))
 207:              {
 208:                  if (int.TryParse(service, out number))
 209:                  {
 210:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 211:                      {
 212:                          list = (from srh in db.ServiceRequestHistories where srh.Number == number select srh).ToList();
 213:                      }
 214:                  }
 215:                  else list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 216:              }
 217:              else list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 218:   
 219:              return list;
 220:          }
 221:   
 222:          ////////////////////////////////////////////////////////////////////////////
 223:   
 224:          /// <summary>
 225:          /// Return a list of service requests histories that have numbers within the passed domain list
 226:          /// </summary>
 227:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> ListByDomain(List<int> domainList)
 228:          {
 229:              List<string> stringDomainList;
 230:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 231:   
 232:              stringDomainList = new List<string>();
 233:   
 234:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 235:              {
 236:                  if (domainList != null)
 237:                  {
 238:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 239:   
 240:                      list = (from srh in db.ServiceRequestHistories where domainList.Any(u => srh.Number.ToString().StartsWith(u.ToString())) select srh).ToList();
 241:                  }
 242:                  else
 243:                  {
 244:                      list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 245:                  }
 246:              }
 247:   
 248:              return list;
 249:          }
 250:   
 251:          ////////////////////////////////////////////////////////////////////////////
 252:   
 253:          /// <summary>
 254:          ///
 255:          /// </summary>
 256:          public static List<string> ServiceInServiceOrInServiceRequestServiceButNotInServiceRequestHistoryList
 257:          {
 258:              get
 259:              {
 260:                  List<string> l1, l2, list;
 261:   
 262:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 263:                  {
 264:                      l1 = (from s in db.Service2s
 265:                            join srh in db.ServiceRequestHistories on s.Service equals srh.Number.ToString() into gj
 266:                            from subsrh in gj.DefaultIfEmpty()
 267:                            where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && subsrh.Id == null
 268:                            orderby s.Service ascending
 269:                            select s.Service).Distinct().ToList();
 270:   
 271:                      l2 = (from srs in db.ServiceRequestServices // note there is a srh.ServiceRequestService
 272:                            join srh in db.ServiceRequestHistories on srs.Service equals srh.Number.ToString() into gj
 273:                            from subsrh in gj.DefaultIfEmpty()
 274:                            where subsrh.Id == null
 275:                            orderby srs.Service ascending
 276:                            select srs.Service).Distinct().ToList();
 277:                  }
 278:   
 279:                  list = l1.Union(l2).Distinct().ToList();
 280:   
 281:                  return list;
 282:              }
 283:          }
 284:   
 285:          ////////////////////////////////////////////////////////////////////////////
 286:   
 287:          /// <summary>
 288:          ///
 289:          /// </summary>
 290:          public static List<string> ServiceInServiceRequestHistoryButNotInServiceRequestServiceList
 291:          {
 292:              get
 293:              {
 294:                  List<string> list;
 295:   
 296:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 297:                  {
 298:                      /*
 299:                       select distinct srh.Number from ServiceRequestHistories srh
 300:                       left outer join ServiceRequestServices srs on srs.Service = srh.Number
 301:                       where srs.Id is null
 302:                       */
 303:   
 304:                      list = (from srh in db.ServiceRequestHistories
 305:                              join srs in db.ServiceRequestServices on srh.Number.ToString() equals srs.Service into gj
 306:                              from subsrs in gj.DefaultIfEmpty()
 307:                              where subsrs.Id == null
 308:                              orderby srh.Number ascending
 309:                              select srh.Number.ToString()).Distinct().ToList();
 310:                  }
 311:   
 312:                  return list;
 313:              }
 314:          }
 315:   
 316:          ////////////////////////////////////////////////////////////////////////////
 317:   
 318:          /// <summary>
 319:          /// 
 320:          /// </summary>
 321:          public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory> ServiceToServiceRequestHistoryDictionary(List<int> domainList)
 322:          {
 323:              string key;
 324:              List<string> stringDomainList;
 325:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 326:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory> dictionary;
 327:   
 328:              stringDomainList = new List<string>();
 329:   
 330:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 331:              {
 332:                  if (domainList != null)
 333:                  {
 334:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 335:   
 336:                      list = (from srh in db.ServiceRequestHistories where domainList.Any(u => srh.Number.ToString().StartsWith(u.ToString())) orderby srh.ServiceDateTime ascending select srh).ToList();
 337:   
 338:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory>(list.Count);
 339:   
 340:                      foreach (var srh in list)
 341:                      {
 342:                          key = srh.Number.ToString();
 343:   
 344:                          if (dictionary.ContainsKey(key))
 345:                          {
 346:                              dictionary[key] = srh;
 347:                          }
 348:                          else dictionary[key] = srh;
 349:                      }
 350:                  }
 351:                  else
 352:                  {
 353:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 354:                  }
 355:              }
 356:   
 357:              return dictionary;
 358:          }
 359:   
 360:          ////////////////////////////////////////////////////////////////////////////
 361:   
 362:          /// <summary>
 363:          ///
 364:          /// </summary>
 365:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> ListWithinRequestDateTimeRange(DateTime startRequestDateTime, DateTime endRequestDateTime)
 366:          {
 367:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 368:   
 369:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 370:              {
 371:                  list = (from srh in db.ServiceRequestHistories where srh.ServiceDateTime >= startRequestDateTime && srh.ServiceDateTime < endRequestDateTime select srh).ToList();
 372:              }
 373:   
 374:              return list;
 375:          }
 376:   
 377:          ////////////////////////////////////////////////////////////////////////////
 378:   
 379:          /// <summary>
 380:          /// Return the latest RequestDateTime for number
 381:          /// </summary>
 382:          public static DateTime LatestRequestDateTime(int number)
 383:          {
 384:              DateTime dateTime;
 385:              Ia.Ngn.Cl.Model.ServiceRequestHistory item;
 386:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 387:   
 388:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 389:              {
 390:                  list = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List(number.ToString());
 391:   
 392:                  if (list.Count > 0)
 393:                  {
 394:                      item = list.OrderByDescending(u => u.Id).FirstOrDefault();
 395:   
 396:                      dateTime = item.ServiceDateTime;
 397:                  }
 398:                  else
 399:                  {
 400:                      dateTime = DateTime.MinValue;
 401:                  }
 402:              }
 403:   
 404:              return dateTime;
 405:          }
 406:   
 407:          ////////////////////////////////////////////////////////////////////////////    
 408:   
 409:          /// <summary>
 410:          ///
 411:          /// </summary>
 412:          public static string SequentialServiceManager(out int sequentialQueueCount, out string progressCounterString)
 413:          {
 414:              string service;
 415:              List<string> list;
 416:   
 417:              if (sequentialQueue.Count == 0)
 418:              {
 419:                  // temp
 420:                  //list = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.TempSrhVsSrMismatchListListToReadFromServiceRequestHistory;
 421:                  list = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.ServiceInServiceOrInServiceRequestServiceButNotInServiceRequestHistoryList;
 422:   
 423:                  sequentialQueue = new Queue<string>(list);
 424:   
 425:                  sequentialQueueOriginalCount = sequentialQueue.Count;
 426:              }
 427:   
 428:              if (sequentialQueue.Count > 0) service = sequentialQueue.Dequeue();
 429:              else service = string.Empty;
 430:   
 431:              progressCounterString = "(" + sequentialQueue.Count + "/" + sequentialQueueOriginalCount + ")";
 432:   
 433:              sequentialQueueCount = sequentialQueue.Count;
 434:   
 435:              return service;
 436:          }
 437:   
 438:          ////////////////////////////////////////////////////////////////////////////
 439:   
 440:          /// <summary>
 441:          ///
 442:          /// </summary>
 443:          public static void UpdateWithServiceAndOutputDataTable(string service, DataTable dataTable, out bool isUpdated, out string result)
 444:          {
 445:              // below: the SQL statement should be within the dataTable.TableName variable
 446:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 447:              int number, serial, serviceId;
 448:              string sql, sqlService, r, serviceRequestHistoryId;
 449:              DateTime serviceDateTime, startDateTime, endDateTime;
 450:              ArrayList newServiceRequestHistoryIdArrayList;
 451:              Match match;
 452:              Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory, newServiceRequestHistory;
 453:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> serviceRequestHistoryList;
 454:   
 455:              isUpdated = false;
 456:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 457:              result = r = "";
 458:   
 459:              if (dataTable != null)
 460:              {
 461:                  sql = dataTable.TableName;
 462:   
 463:                  // [select ...  csn.srv_no = 25233434 ...] 
 464:                  match = Regex.Match(sql, @"csn.srv_no = (\d+) ", RegexOptions.Singleline);
 465:   
 466:                  if (match.Success)
 467:                  {
 468:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 469:                      {
 470:                          readItemCount = dataTable.Rows.Count;
 471:   
 472:                          sqlService = match.Groups[1].Value;
 473:   
 474:                          if (service == sqlService)
 475:                          {
 476:                              serviceRequestHistoryList = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List(service);
 477:                              existingItemCount = serviceRequestHistoryList.Count;
 478:   
 479:                              newServiceRequestHistoryIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
 480:   
 481:                              foreach (DataRow dataRow in dataTable.Rows)
 482:                              {
 483:                                  // select csn.srv_cat_id,csn.srv_no,csn.srv_ser_no,csn.status,c.code_name status_name,csn.start_date,csn.end_date,cs.srv_id,s.srv_name,srv_date
 484:   
 485:                                  if (int.TryParse(dataRow["srv_no"].ToString(), out number))
 486:                                  {
 487:                                      if (int.TryParse(dataRow["srv_ser_no"].ToString(), out serial))
 488:                                      {
 489:                                          if (int.TryParse(dataRow["srv_id"].ToString(), out serviceId))
 490:                                          {
 491:                                              if (DateTime.TryParse(dataRow["srv_date"].ToString(), out serviceDateTime))
 492:                                              {
 493:                                                  serviceRequestHistoryId = Ia.Ngn.Cl.Model.Business.ServiceRequestHistory.ServiceRequestHistoryId(number, serial, serviceId, serviceDateTime);
 494:   
 495:                                                  if (DateTime.TryParse(dataRow["start_date"].ToString(), out startDateTime)) { }
 496:                                                  else startDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 497:   
 498:                                                  if (DateTime.TryParse(dataRow["end_date"].ToString(), out endDateTime)) { }
 499:                                                  else endDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 500:   
 501:                                                  // important: if datetime is older than Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime we will change it to it
 502:                                                  if (serviceDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) serviceDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 503:                                                  if (startDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) startDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 504:                                                  if (endDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) endDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 505:   
 506:                                                  newServiceRequestHistory = new Ia.Ngn.Cl.Model.ServiceRequestHistory()
 507:                                                  {
 508:                                                      Id = serviceRequestHistoryId,
 509:                                                      Number = number,
 510:                                                      Serial = serial,
 511:                                                      Status = int.Parse(dataRow["status"].ToString()),
 512:                                                      StartDateTime = startDateTime,
 513:                                                      EndDateTime = endDateTime,
 514:   
 515:                                                      ServiceDateTime = serviceDateTime,
 516:                                                      ServiceId = serviceId,
 517:                                                      ServiceCategoryId = int.Parse(dataRow["srv_cat_id"].ToString())
 518:                                                  };
 519:   
 520:                                                  serviceRequestHistory = (from srh in serviceRequestHistoryList where srh.Id == newServiceRequestHistory.Id select srh).SingleOrDefault();
 521:   
 522:                                                  if (serviceRequestHistory == null)
 523:                                                  {
 524:                                                      newServiceRequestHistory.Created = newServiceRequestHistory.Updated = DateTime.UtcNow.AddHours(3);
 525:   
 526:                                                      db.ServiceRequestHistories.Add(newServiceRequestHistory);
 527:   
 528:                                                      insertedItemCount++;
 529:                                                  }
 530:                                                  else
 531:                                                  {
 532:                                                      // below: copy values from newServiceRequestHistory to serviceRequestHistory
 533:   
 534:                                                      if (serviceRequestHistory.Update(newServiceRequestHistory))
 535:                                                      {
 536:                                                          db.ServiceRequestHistories.Attach(serviceRequestHistory);
 537:                                                          db.Entry(serviceRequestHistory).State = System.Data.Entity.EntityState.Modified;
 538:   
 539:                                                          updatedItemCount++;
 540:                                                      }
 541:                                                  }
 542:   
 543:                                                  newServiceRequestHistoryIdArrayList.Add(serviceRequestHistoryId); // keep at the end
 544:                                              }
 545:                                              else
 546:                                              {
 547:                                                  throw new ArgumentOutOfRangeException(@"srv_date out of range. ");
 548:                                              }
 549:                                          }
 550:                                          else
 551:                                          {
 552:                                              throw new ArgumentOutOfRangeException(@"srv_id out of range. ");
 553:                                          }
 554:                                      }
 555:                                      else
 556:                                      {
 557:                                          throw new ArgumentOutOfRangeException(@"srv_ser_no out of range. ");
 558:                                      }
 559:                                  }
 560:                                  else
 561:                                  {
 562:                                      throw new ArgumentOutOfRangeException(@"srv_no out of range. ");
 563:                                  }
 564:                              }
 565:   
 566:                              // below: this function will remove values that were not present in the reading
 567:                              if (serviceRequestHistoryList.Count > 0)
 568:                              {
 569:                                  foreach (Ia.Ngn.Cl.Model.ServiceRequestHistory srh in serviceRequestHistoryList)
 570:                                  {
 571:                                      if (!newServiceRequestHistoryIdArrayList.Contains(srh.Id))
 572:                                      {
 573:                                          serviceRequestHistory = (from srh2 in db.ServiceRequestHistories where srh2.Id == srh.Id select srh2).SingleOrDefault();
 574:   
 575:                                          db.ServiceRequestHistories.Remove(serviceRequestHistory);
 576:   
 577:                                          deletedItemCount++;
 578:                                      }
 579:                                  }
 580:                              }
 581:   
 582:                              db.SaveChanges();
 583:   
 584:                              if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 585:                              else isUpdated = false;
 586:   
 587:                              result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") " + r;
 588:                          }
 589:                          else
 590:                          {
 591:                              result = "(service != sqlService) ";
 592:                          }
 593:                      }
 594:                  }
 595:                  else
 596:                  {
 597:                      result = "(?/?/?: SQL in TableName is unmatched) ";
 598:                  }
 599:              }
 600:              else
 601:              {
 602:                  result = "(dataTable == null/?/?) ";
 603:              }
 604:          }
 605:   
 606:          ////////////////////////////////////////////////////////////////////////////
 607:   
 608:          /// <summary>
 609:          ///
 610:          /// </summary>
 611:          public static bool UpdateServiceRequestService(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, out string result)
 612:          {
 613:              bool b;
 614:   
 615:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 616:              {
 617:                  serviceRequest = (from sr in db.ServiceRequests where sr.Id == serviceRequest.Id select sr).SingleOrDefault();
 618:   
 619:                  if (serviceRequest.ServiceRequestService != serviceRequestService)
 620:                  {
 621:                      serviceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestService.Id select srs).SingleOrDefault();
 622:   
 623:                      db.ServiceRequests.Attach(serviceRequest);
 624:                      db.Entry(serviceRequest).Property(x => x.ServiceRequestService).IsModified = true;
 625:   
 626:                      db.SaveChanges();
 627:   
 628:                      result = "Success: ServiceRequests ServiceRequestService updated. ";
 629:                      b = true;
 630:                  }
 631:                  else
 632:                  {
 633:                      result = "Warning: ServiceRequests ServiceRequestService value was not updated because its the same. ";
 634:   
 635:                      b = false;
 636:                  }
 637:              }
 638:   
 639:              return b;
 640:          }
 641:   
 642:          ////////////////////////////////////////////////////////////////////////////
 643:   
 644:          /// <summary>
 645:          ///
 646:          /// </summary>
 647:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory)
 648:          {
 649:              StringBuilder sb;
 650:   
 651:              sb = new StringBuilder();
 652:   
 653:              //sb.AppendLine("Id: " + serviceRequestHistoriesHistory.Id);
 654:              sb.AppendLine("Number: " + serviceRequestHistory.Number + "/" + serviceRequestHistory.Serial);
 655:              //sb.AppendLine("Serial: " + serviceRequestHistories.Serial);
 656:              sb.AppendLine("Status: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.SystemCode[serviceRequestHistory.Status].ToString());
 657:              sb.AppendLine("StartDateTime: " + serviceRequestHistory.StartDateTime.ToString("yyyy-MM-dd HH:mm"));
 658:              sb.AppendLine("EndDateTime: " + serviceRequestHistory.EndDateTime.ToString("yyyy-MM-dd HH:mm"));
 659:              sb.AppendLine("RequestDateTime: " + serviceRequestHistory.ServiceDateTime.ToString("yyyy-MM-dd HH:mm"));
 660:              sb.AppendLine("Service: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceSortedList[serviceRequestHistory.ServiceId].ToString());
 661:              sb.AppendLine("ServiceCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceCategorySortedList[serviceRequestHistory.ServiceCategoryId].ToString());
 662:   
 663:              return sb.ToString();
 664:          }
 665:   
 666:          ////////////////////////////////////////////////////////////////////////////    
 667:          ////////////////////////////////////////////////////////////////////////////    
 668:      }
 669:   
 670:      ////////////////////////////////////////////////////////////////////////////
 671:      ////////////////////////////////////////////////////////////////////////////
 672:  }