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

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