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

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 © 2018-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated 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 List<string> serviceList = new List<string>();
  34:   
  35:          ////////////////////////////////////////////////////////////////////////////
  36:   
  37:          /// <summary>
  38:          ///
  39:          /// </summary>
  40:          public ServiceRequestHistory() { }
  41:   
  42:          ////////////////////////////////////////////////////////////////////////////    
  43:   
  44:          /// <summary>
  45:          ///
  46:          /// </summary>
  47:          public static string OracleSqlSelectBeforeJuly21st2004CommandByService(string service)
  48:          {
  49:              return OracleSqlSelectCommandByService(service, true);
  50:          }
  51:   
  52:          ////////////////////////////////////////////////////////////////////////////    
  53:   
  54:          /// <summary>
  55:          ///
  56:          /// </summary>
  57:          public static string OracleSqlCommandSelectByService(string service)
  58:          {
  59:              return OracleSqlSelectCommandByService(service, false);
  60:          }
  61:   
  62:          ////////////////////////////////////////////////////////////////////////////    
  63:   
  64:          /// <summary>
  65:          ///
  66:          /// </summary>
  67:          private static string OracleSqlSelectCommandByService(string service, bool selectBeforeJuly21st2004)
  68:          {
  69:              string sql, sqlBeforeJuly21st2004;
  70:   
  71:              if (selectBeforeJuly21st2004) sqlBeforeJuly21st2004 = @"and start_date <= to_date(''21/7/2004'', ''dd/mm/yyyy'')";
  72:              else sqlBeforeJuly21st2004 = string.Empty;
  73:   
  74:              if (!string.IsNullOrEmpty(service))
  75:              {
  76:                  // format [select ...  csn.srv_no = 25233434 ...] is important for proper parsing and reading of number in UpdateWithServiceAndOutputDataTable()
  77:                  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
  78:  from cust_srv_nos csn,cust_services cs,services s,system_codes c
  79:  where csn.srv_cat_id in (3,38)
  80:  and csn.srv_no = " + service + @" " + @"
  81:  " + sqlBeforeJuly21st2004 + @"
  82:  and cs.srv_date >= csn.start_date
  83:  and csn.srv_cat_id = cs.srv_cat_id 
  84:  and csn.srv_no = cs.srv_no
  85:  and csn.srv_ser_no = cs.srv_ser_no
  86:  and s.srv_cat_id = cs.srv_cat_id
  87:  and s.srv_id = cs.srv_id 
  88:  and c.code_id = csn.status
  89:  order by csn.start_date,srv_id
  90:  ";
  91:              }
  92:              else sql = string.Empty;
  93:   
  94:              return sql;
  95:          }
  96:   
  97:          ////////////////////////////////////////////////////////////////////////////
  98:   
  99:          /// <summary>
 100:          /// Return a list of service request histories
 101:          /// </summary>
 102:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List()
 103:          {
 104:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 105:   
 106:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 107:              {
 108:                  list = (from srh in db.ServiceRequestHistories select srh).ToList();
 109:              }
 110:   
 111:              return list;
 112:          }
 113:   
 114:          ////////////////////////////////////////////////////////////////////////////
 115:   
 116:          /// <summary>
 117:          /// Return a list of service request histories for a number
 118:          /// </summary>
 119:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(int number)
 120:          {
 121:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 122:   
 123:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 124:              {
 125:                  list = (from srh in db.ServiceRequestHistories where srh.Number == number select srh).ToList();
 126:              }
 127:   
 128:              return list;
 129:          }
 130:   
 131:          ////////////////////////////////////////////////////////////////////////////
 132:   
 133:          /// <summary>
 134:          /// Return a list of un-ended service request histories
 135:          /// </summary>
 136:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> UnEndedDateTimeList()
 137:          {
 138:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 139:   
 140:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 141:              {
 142:                  list = (from srh in db.ServiceRequestHistories where srh.EndDateTime == Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime select srh).ToList();
 143:              }
 144:   
 145:              return list;
 146:          }
 147:   
 148:          ////////////////////////////////////////////////////////////////////////////
 149:   
 150:          /// <summary>
 151:          /// Return a list of un-ended service request histories for a number
 152:          /// </summary>
 153:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> UnEndedDateTimeList(int number)
 154:          {
 155:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 156:   
 157:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 158:              {
 159:                  list = (from srh in db.ServiceRequestHistories where srh.Number == number && srh.EndDateTime == Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime select srh).ToList();
 160:              }
 161:   
 162:              return list;
 163:          }
 164:   
 165:          ////////////////////////////////////////////////////////////////////////////
 166:   
 167:          /// <summary>
 168:          /// Return a list of service request histories that have numbers within the passed list
 169:          /// </summary>
 170:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(List<int> numberList)
 171:          {
 172:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 173:   
 174:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 175:              {
 176:                  list = (from srh in db.ServiceRequestHistories where numberList.Contains(srh.Number) select srh).ToList();
 177:              }
 178:   
 179:              return list;
 180:          }
 181:   
 182:          ////////////////////////////////////////////////////////////////////////////
 183:   
 184:          /// <summary>
 185:          /// Return list of service requests histories with number
 186:          /// </summary>
 187:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> List(string service)
 188:          {
 189:              int number;
 190:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 191:   
 192:              if (!string.IsNullOrEmpty(service))
 193:              {
 194:                  if (int.TryParse(service, out number))
 195:                  {
 196:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 197:                      {
 198:                          list = (from srh in db.ServiceRequestHistories where srh.Number == number select srh).ToList();
 199:                      }
 200:                  }
 201:                  else list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 202:              }
 203:              else list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 204:   
 205:              return list;
 206:          }
 207:   
 208:          ////////////////////////////////////////////////////////////////////////////
 209:   
 210:          /// <summary>
 211:          /// Return a list of service requests histories that have numbers within the passed domain list
 212:          /// </summary>
 213:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> ListByDomain(List<int> domainList)
 214:          {
 215:              List<string> stringDomainList;
 216:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 217:   
 218:              stringDomainList = new List<string>();
 219:   
 220:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 221:              {
 222:                  if (domainList != null)
 223:                  {
 224:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 225:   
 226:                      list = (from srh in db.ServiceRequestHistories where domainList.Any(u => srh.Number.ToString().StartsWith(u.ToString())) select srh).ToList();
 227:                  }
 228:                  else
 229:                  {
 230:                      list = new List<Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 231:                  }
 232:              }
 233:   
 234:              return list;
 235:          }
 236:   
 237:          ////////////////////////////////////////////////////////////////////////////
 238:   
 239:          /// <summary>
 240:          ///
 241:          /// </summary>
 242:          public static List<string> ServiceInServiceOrInServiceRequestServiceButNotInServiceRequestHistoryList()
 243:          {
 244:              List<string> l1, l2, l3, list;
 245:   
 246:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 247:              {
 248:                  l1 = (from s in db.Service2
 249:                        join srh in db.ServiceRequestHistories on s.Service equals srh.Number.ToString() into gj
 250:                        from subsrh in gj.DefaultIfEmpty()
 251:                        where /*s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService &&*/ subsrh.Id == null
 252:                        orderby s.Service ascending
 253:                        select s.Service).Distinct().ToList();
 254:   
 255:                  l2 = (from srs in db.ServiceRequestServices // note there is a srh.ServiceRequestService
 256:                        join srh in db.ServiceRequestHistories on srs.Service equals srh.Number.ToString() into gj
 257:                        from subsrh in gj.DefaultIfEmpty()
 258:                        where subsrh.Id == null
 259:                        orderby srs.Service ascending
 260:                        select srs.Service).Distinct().ToList();
 261:   
 262:                  l3 = (from sr in db.ServiceRequests
 263:                        join srh in db.ServiceRequestHistories on sr.Number equals srh.Number into gj
 264:                        from subsrh in gj.DefaultIfEmpty()
 265:                        where subsrh.Id == null
 266:                        orderby sr.Number ascending
 267:                        select sr.Number.ToString()).Distinct().ToList();
 268:              }
 269:   
 270:              list = l1.Union(l2).Union(l3).Distinct().ToList();
 271:   
 272:              return list;
 273:          }
 274:   
 275:          ////////////////////////////////////////////////////////////////////////////
 276:   
 277:          /// <summary>
 278:          ///
 279:          /// </summary>
 280:          public static List<string> ServiceInServiceRequestHistoryButNotInServiceRequestServiceList
 281:          {
 282:              get
 283:              {
 284:                  List<string> list;
 285:   
 286:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 287:                  {
 288:                      /*
 289:                       select distinct srh.Number from ServiceRequestHistories srh
 290:                       left outer join ServiceRequestServices srs on srs.Service = srh.Number
 291:                       where srs.Id is null
 292:                       */
 293:   
 294:                      list = (from srh in db.ServiceRequestHistories
 295:                              join srs in db.ServiceRequestServices on srh.Number.ToString() equals srs.Service into gj
 296:                              from subsrs in gj.DefaultIfEmpty()
 297:                              where subsrs.Id == null
 298:                              orderby srh.Number ascending
 299:                              select srh.Number.ToString()).Distinct().ToList();
 300:                  }
 301:   
 302:                  return list;
 303:              }
 304:          }
 305:   
 306:          ////////////////////////////////////////////////////////////////////////////
 307:   
 308:          /// <summary>
 309:          /// 
 310:          /// </summary>
 311:          public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory> ServiceToServiceRequestHistoryDictionary(List<int> domainList)
 312:          {
 313:              string key;
 314:              List<string> stringDomainList;
 315:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 316:              Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory> dictionary;
 317:   
 318:              stringDomainList = new List<string>();
 319:   
 320:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 321:              {
 322:                  if (domainList != null)
 323:                  {
 324:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 325:   
 326:                      list = (from srh in db.ServiceRequestHistories where domainList.Any(u => srh.Number.ToString().StartsWith(u.ToString())) orderby srh.ServiceDateTime ascending select srh).ToList();
 327:   
 328:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory>(list.Count);
 329:   
 330:                      foreach (var srh in list)
 331:                      {
 332:                          key = srh.Number.ToString();
 333:   
 334:                          if (dictionary.ContainsKey(key))
 335:                          {
 336:                              dictionary[key] = srh;
 337:                          }
 338:                          else dictionary[key] = srh;
 339:                      }
 340:                  }
 341:                  else
 342:                  {
 343:                      dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequestHistory>();
 344:                  }
 345:              }
 346:   
 347:              return dictionary;
 348:          }
 349:   
 350:          ////////////////////////////////////////////////////////////////////////////
 351:   
 352:          /// <summary>
 353:          ///
 354:          /// </summary>
 355:          public static List<Ia.Ngn.Cl.Model.ServiceRequestHistory> ListWithinRequestDateTimeRange(DateTime startRequestDateTime, DateTime endRequestDateTime)
 356:          {
 357:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 358:   
 359:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 360:              {
 361:                  list = (from srh in db.ServiceRequestHistories where srh.ServiceDateTime >= startRequestDateTime && srh.ServiceDateTime < endRequestDateTime select srh).ToList();
 362:              }
 363:   
 364:              return list;
 365:          }
 366:   
 367:          ////////////////////////////////////////////////////////////////////////////
 368:   
 369:          /// <summary>
 370:          /// Return the latest RequestDateTime for number
 371:          /// </summary>
 372:          public static DateTime LatestRequestDateTime(int number)
 373:          {
 374:              DateTime dateTime;
 375:              Ia.Ngn.Cl.Model.ServiceRequestHistory item;
 376:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> list;
 377:   
 378:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 379:              {
 380:                  list = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List(number.ToString());
 381:   
 382:                  if (list.Count > 0)
 383:                  {
 384:                      item = list.OrderByDescending(u => u.Id).FirstOrDefault();
 385:   
 386:                      dateTime = item.ServiceDateTime;
 387:                  }
 388:                  else
 389:                  {
 390:                      dateTime = DateTime.MinValue;
 391:                  }
 392:              }
 393:   
 394:              return dateTime;
 395:          }
 396:   
 397:          ////////////////////////////////////////////////////////////////////////////    
 398:   
 399:          /// <summary>
 400:          ///
 401:          /// </summary>
 402:          public static string SequentialServiceManager(ref int referenceIndex, out int itemIndex, out int listCount)
 403:          {
 404:              string service;
 405:   
 406:              if (serviceList.JustStartedOrRolledOver())
 407:              {
 408:                  serviceList = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.ServiceInServiceOrInServiceRequestServiceButNotInServiceRequestHistoryList();
 409:              }
 410:   
 411:              service = serviceList.Next(ref referenceIndex, out itemIndex, out listCount);
 412:   
 413:              return service;
 414:          }
 415:   
 416:          ////////////////////////////////////////////////////////////////////////////
 417:   
 418:          /// <summary>
 419:          ///
 420:          /// </summary>
 421:          public static void UpdateWithServiceAndOutputDataTable(string service, DataTable dataTable, out bool isUpdated, out string result)
 422:          {
 423:              // below: the SQL statement should be within the dataTable.TableName variable
 424:              int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 425:              int number, serial, serviceId;
 426:              string sql, sqlService, r, serviceRequestHistoryId;
 427:              DateTime serviceDateTime, startDateTime, endDateTime;
 428:              ArrayList newServiceRequestHistoryIdArrayList;
 429:              Match match;
 430:              Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory, newServiceRequestHistory;
 431:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> serviceRequestHistoryList;
 432:   
 433:              isUpdated = false;
 434:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 435:              result = r = string.Empty;
 436:   
 437:              if (dataTable != null)
 438:              {
 439:                  sql = dataTable.TableName;
 440:   
 441:                  // [select ...  csn.srv_no = 25233434 ...] 
 442:                  match = Regex.Match(sql, @"csn.srv_no = (\d+) ", RegexOptions.Singleline);
 443:   
 444:                  if (match.Success)
 445:                  {
 446:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 447:                      {
 448:                          readItemCount = dataTable.Rows.Count;
 449:   
 450:                          sqlService = match.Groups[1].Value;
 451:   
 452:                          if (service == sqlService)
 453:                          {
 454:                              serviceRequestHistoryList = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List(service);
 455:                              existingItemCount = serviceRequestHistoryList.Count;
 456:   
 457:                              newServiceRequestHistoryIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
 458:   
 459:                              foreach (DataRow dataRow in dataTable.Rows)
 460:                              {
 461:                                  // 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
 462:   
 463:                                  if (int.TryParse(dataRow["srv_no"].ToString(), out number))
 464:                                  {
 465:                                      if (int.TryParse(dataRow["srv_ser_no"].ToString(), out serial))
 466:                                      {
 467:                                          if (int.TryParse(dataRow["srv_id"].ToString(), out serviceId))
 468:                                          {
 469:                                              if (DateTime.TryParse(dataRow["srv_date"].ToString(), out serviceDateTime))
 470:                                              {
 471:                                                  serviceRequestHistoryId = Ia.Ngn.Cl.Model.Business.ServiceRequestHistory.ServiceRequestHistoryId(number, serial, serviceId, serviceDateTime);
 472:   
 473:                                                  if (DateTime.TryParse(dataRow["start_date"].ToString(), out startDateTime)) { }
 474:                                                  else startDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 475:   
 476:                                                  if (DateTime.TryParse(dataRow["end_date"].ToString(), out endDateTime)) { }
 477:                                                  else endDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 478:   
 479:                                                  // important: if datetime is older than Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime we will change it to it
 480:                                                  if (serviceDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) serviceDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 481:                                                  if (startDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) startDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 482:                                                  if (endDateTime < Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime) endDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 483:   
 484:                                                  newServiceRequestHistory = new Ia.Ngn.Cl.Model.ServiceRequestHistory()
 485:                                                  {
 486:                                                      Id = serviceRequestHistoryId,
 487:                                                      Number = number,
 488:                                                      Serial = serial,
 489:                                                      Status = int.Parse(dataRow["status"].ToString()),
 490:                                                      StartDateTime = startDateTime,
 491:                                                      EndDateTime = endDateTime,
 492:   
 493:                                                      ServiceDateTime = serviceDateTime,
 494:                                                      ServiceId = serviceId,
 495:                                                      ServiceCategoryId = int.Parse(dataRow["srv_cat_id"].ToString())
 496:                                                  };
 497:   
 498:                                                  serviceRequestHistory = (from srh in serviceRequestHistoryList where srh.Id == newServiceRequestHistory.Id select srh).SingleOrDefault();
 499:   
 500:                                                  if (serviceRequestHistory == null)
 501:                                                  {
 502:                                                      newServiceRequestHistory.Created = newServiceRequestHistory.Updated = DateTime.UtcNow.AddHours(3);
 503:   
 504:                                                      db.ServiceRequestHistories.Add(newServiceRequestHistory);
 505:   
 506:                                                      insertedItemCount++;
 507:                                                  }
 508:                                                  else
 509:                                                  {
 510:                                                      // below: copy values from newServiceRequestHistory to serviceRequestHistory
 511:   
 512:                                                      if (serviceRequestHistory.Update(newServiceRequestHistory))
 513:                                                      {
 514:                                                          db.ServiceRequestHistories.Attach(serviceRequestHistory);
 515:                                                          db.Entry(serviceRequestHistory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 516:   
 517:                                                          updatedItemCount++;
 518:                                                      }
 519:                                                  }
 520:   
 521:                                                  newServiceRequestHistoryIdArrayList.Add(serviceRequestHistoryId); // keep at the end
 522:                                              }
 523:                                              else
 524:                                              {
 525:                                                  throw new ArgumentOutOfRangeException(@"srv_date out of range. ");
 526:                                              }
 527:                                          }
 528:                                          else
 529:                                          {
 530:                                              throw new ArgumentOutOfRangeException(@"srv_id out of range. ");
 531:                                          }
 532:                                      }
 533:                                      else
 534:                                      {
 535:                                          throw new ArgumentOutOfRangeException(@"srv_ser_no out of range. ");
 536:                                      }
 537:                                  }
 538:                                  else
 539:                                  {
 540:                                      throw new ArgumentOutOfRangeException(@"srv_no out of range. ");
 541:                                  }
 542:                              }
 543:   
 544:                              // below: this function will remove values that were not present in the reading
 545:                              if (serviceRequestHistoryList.Count > 0)
 546:                              {
 547:                                  foreach (Ia.Ngn.Cl.Model.ServiceRequestHistory srh in serviceRequestHistoryList)
 548:                                  {
 549:                                      if (!newServiceRequestHistoryIdArrayList.Contains(srh.Id))
 550:                                      {
 551:                                          serviceRequestHistory = (from srh2 in db.ServiceRequestHistories where srh2.Id == srh.Id select srh2).SingleOrDefault();
 552:   
 553:                                          db.ServiceRequestHistories.Remove(serviceRequestHistory);
 554:   
 555:                                          deletedItemCount++;
 556:                                      }
 557:                                  }
 558:                              }
 559:   
 560:                              db.SaveChanges();
 561:   
 562:                              if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 563:                              else isUpdated = false;
 564:   
 565:                              result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") " + r;
 566:                          }
 567:                          else
 568:                          {
 569:                              result = "(service != sqlService) ";
 570:                          }
 571:                      }
 572:                  }
 573:                  else
 574:                  {
 575:                      result = "(?/?/?: SQL in TableName is unmatched) ";
 576:                  }
 577:              }
 578:              else
 579:              {
 580:                  result = "(dataTable == null/?/?) ";
 581:              }
 582:          }
 583:   
 584:          ////////////////////////////////////////////////////////////////////////////
 585:   
 586:          /// <summary>
 587:          ///
 588:          /// </summary>
 589:          public static bool UpdateServiceRequestService(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, out string result)
 590:          {
 591:              bool b;
 592:   
 593:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 594:              {
 595:                  serviceRequest = (from sr in db.ServiceRequests where sr.Id == serviceRequest.Id select sr).SingleOrDefault();
 596:   
 597:                  if (serviceRequest.ServiceRequestService != serviceRequestService)
 598:                  {
 599:                      serviceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestService.Id select srs).SingleOrDefault();
 600:   
 601:                      db.ServiceRequests.Attach(serviceRequest);
 602:                      db.Entry(serviceRequest).Property(u => u.ServiceRequestService).IsModified = true;
 603:   
 604:                      db.SaveChanges();
 605:   
 606:                      result = "Success: ServiceRequests ServiceRequestService updated. ";
 607:                      b = true;
 608:                  }
 609:                  else
 610:                  {
 611:                      result = "Warning: ServiceRequests ServiceRequestService value was not updated because its the same. ";
 612:   
 613:                      b = false;
 614:                  }
 615:              }
 616:   
 617:              return b;
 618:          }
 619:   
 620:          ////////////////////////////////////////////////////////////////////////////
 621:   
 622:          /// <summary>
 623:          ///
 624:          /// </summary>
 625:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory)
 626:          {
 627:              StringBuilder sb;
 628:   
 629:              sb = new StringBuilder();
 630:   
 631:              //sb.AppendLine("Id: " + serviceRequestHistoriesHistory.Id);
 632:              sb.AppendLine("Number: " + serviceRequestHistory.Number + "/" + serviceRequestHistory.Serial);
 633:              //sb.AppendLine("Serial: " + serviceRequestHistories.Serial);
 634:              sb.AppendLine("Status: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.SystemCode[serviceRequestHistory.Status].ToString());
 635:              sb.AppendLine("StartDateTime: " + serviceRequestHistory.StartDateTime.ToString("yyyy-MM-dd HH:mm"));
 636:              sb.AppendLine("EndDateTime: " + serviceRequestHistory.EndDateTime.ToString("yyyy-MM-dd HH:mm"));
 637:              sb.AppendLine("RequestDateTime: " + serviceRequestHistory.ServiceDateTime.ToString("yyyy-MM-dd HH:mm"));
 638:              sb.AppendLine("Service: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceSortedList[serviceRequestHistory.ServiceId].ToString());
 639:              sb.AppendLine("ServiceCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceCategorySortedList[serviceRequestHistory.ServiceCategoryId].ToString());
 640:   
 641:              return sb.ToString();
 642:          }
 643:   
 644:          ////////////////////////////////////////////////////////////////////////////    
 645:          ////////////////////////////////////////////////////////////////////////////    
 646:      }
 647:   
 648:      ////////////////////////////////////////////////////////////////////////////
 649:      ////////////////////////////////////////////////////////////////////////////
 650:  }