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

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

Service Request support class of Fixed Telecommunications Network (FTN) business model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Globalization;
    5: using System.Linq;
    6: using System.Text.RegularExpressions;
    7:  
    8: namespace Ia.Ftn.Cl.Model.Business
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Service Request support class of Fixed Telecommunications Network (FTN) business model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// 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
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class ServiceRequest
   30:     {
   31:         /// <summary/>
   32:         public ServiceRequest() { }
   33:  
   34:         private static int sequentialProvisioningWorkflowQueueOriginalCount;
   35:         private static Dictionary<string, DateTime> provisioningWorkflowServiceIdDateTimeDictionary = new Dictionary<string, DateTime>();
   36:         private static Queue<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>> sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>>();
   37:  
   38:         /// <summary/>
   39:         public enum Procedure { Create, Read, Update, Delete, None };
   40:  
   41:         /// <summary/>
   42:         public struct ProvisioningWorkflow<T>
   43:         {
   44:             /// <summary/>
   45:             public T Item { get; set; }
   46:  
   47:             /// <summary/>
   48:             public Procedure Procedure { get; set; }
   49:  
   50:             /// <summary/>
   51:             public DateTime DateTime { get; set; }
   52:         }
   53:  
   54:         ////////////////////////////////////////////////////////////////////////////    
   55:  
   56:         /// <summary>
   57:         ///
   58:         /// </summary>
   59:         public struct NumberSerial
   60:         {
   61:             public long Id
   62:             {
   63:                 get { return (long)Number * 100 + Serial; }
   64:             }
   65:             public int Number { get; set; }
   66:             public int Serial { get; set; }
   67:         }
   68:  
   69:         ////////////////////////////////////////////////////////////////////////////    
   70:         ////////////////////////////////////////////////////////////////////////////    
   71:  
   72:         /// <summary>
   73:         ///
   74:         /// </summary>
   75:         public static string OracleSqlCommandForServiceRequestIdRange(Tuple<int, int> startEndRange)
   76:         {
   77:             return OracleSqlCommandForServiceRequestIdRange(startEndRange.Item1, startEndRange.Item2);
   78:         }
   79:  
   80:         ////////////////////////////////////////////////////////////////////////////    
   81:  
   82:         /// <summary>
   83:         ///
   84:         /// </summary>
   85:         public static string OracleSqlCommandForServiceRequestIdRange(int start, int end)
   86:         {
   87:             string sql;
   88:  
   89:             // select * from SRV_REQ_FIPER where SRV_REQ_ID >= 110000 and SRV_REQ_ID <= 110200 order by SRV_REQ_ID asc
   90:             sql = @"select * from SRV_REQ_FIPER where SRV_REQ_ID >= " + start + " and SRV_REQ_ID <= " + end + " order by SRV_REQ_ID asc";
   91:  
   92:             return sql;
   93:         }
   94:  
   95:         ////////////////////////////////////////////////////////////////////////////    
   96:  
   97:         /// <summary>
   98:         ///
   99:         /// </summary>
  100:         public static string OracleSqlCommandForServiceRequest(string service)
  101:         {
  102:             string sql;
  103:  
  104:             if (!string.IsNullOrEmpty(service))
  105:             {
  106:                 // select * from SRV_REQ_FIPER where SRV_NO = 23632222 order by SRV_REQ_ID asc
  107:                 sql = @"select * from SRV_REQ_FIPER where SRV_NO = " + service + " order by SRV_REQ_ID asc";
  108:             }
  109:             else sql = string.Empty;
  110:  
  111:             return sql;
  112:         }
  113:  
  114:         ////////////////////////////////////////////////////////////////////////////    
  115:  
  116:         /// <summary>
  117:         ///
  118:         /// </summary>
  119:         private static string OracleSqlCommandForGivenDateTime(DateTime dateTime)
  120:         {
  121:             string sql;
  122:  
  123:             //sql = @"select * from SRV_REQ_FIPER LEFT OUTER JOIN SRV_REQ_FIPER_TECH ON SRV_REQ_FIPER_TECH.SRV_REQ_ID = SRV_REQ_FIPER.SRV_REQ_ID where REQ_DATE >= '" + dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' and REQ_DATE < '" + dateTime.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' order by REQ_DATE asc, SRV_REQ_ID asc";
  124:             sql = @"select * from SRV_REQ_FIPER where REQ_DATE >= '" + dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' and REQ_DATE < '" + dateTime.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "' order by SRV_REQ_ID asc";
  125:  
  126:             return sql;
  127:         }
  128:  
  129:         ////////////////////////////////////////////////////////////////////////////    
  130:  
  131:         /// <summary>
  132:         ///
  133:         /// </summary>
  134:         private static string OracleSqlCommandForSingleRandomDateTimeWithinTheLastNDays(int rangeOfPastDays, out DateTime selectedDate)
  135:         {
  136:             // below:
  137:             int i;
  138:             string sql;
  139:  
  140:             i = Ia.Cl.Models.Default.Random(rangeOfPastDays);
  141:  
  142:             selectedDate = DateTime.UtcNow.AddDays(-i);
  143:  
  144:             sql = OracleSqlCommandForGivenDateTime(selectedDate);
  145:  
  146:             return sql;
  147:         }
  148:  
  149:         ////////////////////////////////////////////////////////////////////////////    
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         private static string OracleSqlCommandForSingleDateTimeUsingDayIndexBetweenNowAndEarliestDate(ref int index, out DateTime selectedDate)
  155:         {
  156:             // below: select a date between now and the earliest date using an variable index value
  157:             string sql;
  158:             DateTime now;
  159:  
  160:             now = DateTime.UtcNow.AddHours(3);
  161:  
  162:             // below: check that inIndex is an index of a day between earliest day and now, and reset it to 0 if it is bigger than now
  163:             if (DateTime.Compare(Ia.Ftn.Cl.Model.Business.Administration.EarliestServiceRequestDate.AddDays(index), now) < 0)
  164:             {
  165:                 // below: within range
  166:             }
  167:             else index = 0;
  168:  
  169:             selectedDate = Ia.Ftn.Cl.Model.Business.Administration.EarliestServiceRequestDate.AddDays(index++);
  170:  
  171:             sql = OracleSqlCommandForGivenDateTime(selectedDate);
  172:  
  173:             return sql;
  174:         }
  175:  
  176:         ////////////////////////////////////////////////////////////////////////////
  177:  
  178:         /// <summary>
  179:         ///
  180:         /// </summary>
  181:         public static bool TemporaryProcedureToDetectADisconnectWithOracleDatabase(string result)
  182:         {
  183:             bool b;
  184:  
  185:             b = result.Contains("dataTable == null/?/?");
  186:  
  187:             return b;
  188:         }
  189:  
  190:         ////////////////////////////////////////////////////////////////////////////
  191:         ////////////////////////////////////////////////////////////////////////////
  192:  
  193:         /// <summary>
  194:         ///
  195:         /// </summary>
  196:         public static ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> SequentialProvisioningWorkflowOfOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseListItem(out int sequentialProvisioningWorkflowQueueCount, out string progressCounterString)
  197:         {
  198:             ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> pw;
  199:             List<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>> list;
  200:  
  201:             if (sequentialProvisioningWorkflowQueue.Count == 0)
  202:             {
  203:                 list = Ia.Ftn.Cl.Model.Business.ServiceRequest.ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList;
  204:  
  205:                 sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>>(list);
  206:  
  207:                 sequentialProvisioningWorkflowQueueOriginalCount = sequentialProvisioningWorkflowQueue.Count;
  208:             }
  209:  
  210:             if (sequentialProvisioningWorkflowQueue.Count > 0) pw = sequentialProvisioningWorkflowQueue.Dequeue();
  211:             else pw = new ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> { Item = null, Procedure = Procedure.None };
  212:  
  213:             progressCounterString = "(" + sequentialProvisioningWorkflowQueue.Count + "/" + sequentialProvisioningWorkflowQueueOriginalCount + ")";
  214:  
  215:             sequentialProvisioningWorkflowQueueCount = sequentialProvisioningWorkflowQueue.Count;
  216:  
  217:             return pw;
  218:         }
  219:  
  220:         ////////////////////////////////////////////////////////////////////////////
  221:  
  222:         /// <summary>
  223:         ///
  224:         /// </summary>
  225:         public static List<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>> ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList
  226:         {
  227:             get
  228:             {
  229:                 DateTime dateTime;
  230:                 ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> provisioningWorkflow;
  231:                 List<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>> provisioningWorkflowList;
  232:  
  233:                 dateTime = DateTime.UtcNow.AddHours(3);
  234:  
  235:                 provisioningWorkflowList = new List<ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail>>();
  236:  
  237:                 Ia.Ftn.Cl.Model.Data.ServiceRequestOntDetail.ServiceRequestOntDetailCreateAndDeleteList(out List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, out List<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailDeleteList);
  238:  
  239:                 foreach (Ia.Ftn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailCreateList)
  240:                 {
  241:                     provisioningWorkflow = new ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Create, DateTime = dateTime };
  242:                     provisioningWorkflowList.Add(provisioningWorkflow);
  243:  
  244:                     provisioningWorkflow = new ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
  245:                     provisioningWorkflowList.Add(provisioningWorkflow);
  246:                 }
  247:  
  248:                 foreach (Ia.Ftn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailDeleteList)
  249:                 {
  250:                     provisioningWorkflow = new ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Delete, DateTime = dateTime };
  251:                     provisioningWorkflowList.Add(provisioningWorkflow);
  252:  
  253:                     provisioningWorkflow = new ProvisioningWorkflow<Ia.Ftn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
  254:                     provisioningWorkflowList.Add(provisioningWorkflow);
  255:                 }
  256:  
  257:                 return provisioningWorkflowList;
  258:             }
  259:         }
  260:  
  261:         ////////////////////////////////////////////////////////////////////////////
  262:         ////////////////////////////////////////////////////////////////////////////
  263:  
  264:         /// <summary>
  265:         ///
  266:         /// </summary>
  267:         public static Ia.Ftn.Cl.Model.Business.ServiceAddress ServiceAddress(string service, string customerAddress, out string level)
  268:         {
  269:             int areaId;
  270:             string provinceArea;
  271:             Match match;
  272:             Ia.Ftn.Cl.Model.Business.ServiceAddress serviceAddress;
  273:  
  274:             serviceAddress = new ServiceAddress { Service = service };
  275:  
  276:             if (!string.IsNullOrEmpty(customerAddress))
  277:             {
  278:                 customerAddress = Ia.Ftn.Cl.Model.Business.Default.CorrectCustomerAddress(customerAddress);
  279:  
  280:                 // below: special handeling needed here
  281:                 customerAddress = Ia.Ftn.Cl.Model.Business.Default.CorrectCustomerAddressMissingProvinceArea(service, customerAddress);
  282:  
  283:                 // ',قطعة 4 قسيمة 538,'
  284:                 // get areaId only
  285:                 match = Regex.Match(customerAddress, @"^(.+?),", RegexOptions.Singleline);
  286:  
  287:                 if (match.Success)
  288:                 {
  289:                     level = "1";
  290:  
  291:                     provinceArea = match.Groups[1].Value;
  292:                     areaId = (from a in Ia.Ftn.Cl.Model.Data.Service.KuwaitFtnAreaList
  293:                               where provinceArea == a.ServiceRequestAddressProvinceAreaName
  294:                               select a.Id).SingleOrDefault();
  295:  
  296:                     if (areaId != 0)
  297:                     {
  298:                         serviceAddress.AreaId = areaId;
  299:  
  300:                         // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5 قسيمة 17, منزل 17
  301:                         match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
  302:  
  303:                         if (match.Success)
  304:                         {
  305:                             level = "1-";
  306:  
  307:                             serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  308:                             serviceAddress.Street = match.Groups[3].Value;
  309:                             serviceAddress.Boulevard = match.Groups[4].Value;
  310:                             serviceAddress.PremisesOld = match.Groups[5].Value;
  311:                             serviceAddress.PremisesNew = match.Groups[6].Value;
  312:                         }
  313:                         else
  314:                         {
  315:                             // حولى بيان,قطعة 12 شارع 1 جادة 9, منزل 38
  316:                             match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+), منزل (.+)$", RegexOptions.Singleline);
  317:  
  318:                             if (match.Success)
  319:                             {
  320:                                 level = "2-";
  321:  
  322:                                 serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  323:                                 serviceAddress.Street = match.Groups[3].Value;
  324:                                 serviceAddress.Boulevard = match.Groups[4].Value;
  325:                                 serviceAddress.PremisesOld = match.Groups[5].Value;
  326:                                 serviceAddress.PremisesNew = match.Groups[6].Value;
  327:                             }
  328:                             else
  329:                             {
  330:                                 // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17, منزل 17
  331:                                 match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
  332:  
  333:                                 if (match.Success)
  334:                                 {
  335:                                     level = "3-";
  336:  
  337:                                     serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  338:                                     serviceAddress.Street = match.Groups[3].Value;
  339:                                     serviceAddress.Boulevard = string.Empty;
  340:                                     serviceAddress.PremisesOld = match.Groups[4].Value;
  341:                                     serviceAddress.PremisesNew = match.Groups[5].Value;
  342:                                 }
  343:                                 else
  344:                                 {
  345:                                     // الجهراء الجهراء المدينة,قطعة 79 شارع 5, منزل 17
  346:                                     match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+), منزل (.+)$", RegexOptions.Singleline);
  347:  
  348:                                     if (match.Success)
  349:                                     {
  350:                                         level = "4-";
  351:  
  352:                                         serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  353:                                         serviceAddress.Street = match.Groups[3].Value;
  354:                                         serviceAddress.Boulevard = string.Empty;
  355:                                         serviceAddress.PremisesOld = string.Empty;
  356:                                         serviceAddress.PremisesNew = match.Groups[4].Value;
  357:                                     }
  358:                                     else
  359:                                     {
  360:                                         // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17
  361:                                         match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+),$", RegexOptions.Singleline);
  362:  
  363:                                         if (match.Success)
  364:                                         {
  365:                                             level = "5-";
  366:  
  367:                                             serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  368:                                             serviceAddress.Street = match.Groups[3].Value;
  369:                                             serviceAddress.Boulevard = string.Empty;
  370:                                             serviceAddress.PremisesOld = match.Groups[4].Value;
  371:                                             serviceAddress.PremisesNew = string.Empty;
  372:                                         }
  373:                                         else
  374:                                         {
  375:                                             // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5
  376:                                             match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+),$", RegexOptions.Singleline);
  377:  
  378:                                             if (match.Success)
  379:                                             {
  380:                                                 level = "6-";
  381:  
  382:                                                 serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  383:                                                 serviceAddress.Street = match.Groups[3].Value;
  384:                                                 serviceAddress.Boulevard = match.Groups[4].Value;
  385:                                                 serviceAddress.PremisesOld = string.Empty;
  386:                                                 serviceAddress.PremisesNew = string.Empty;
  387:                                             }
  388:                                             else
  389:                                             {
  390:                                                 // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17, منزل 17
  391:                                                 match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
  392:  
  393:                                                 if (match.Success)
  394:                                                 {
  395:                                                     level = "7-";
  396:  
  397:                                                     serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  398:                                                     serviceAddress.Street = string.Empty;
  399:                                                     serviceAddress.Boulevard = string.Empty;
  400:                                                     serviceAddress.PremisesOld = match.Groups[3].Value;
  401:                                                     serviceAddress.PremisesNew = match.Groups[4].Value;
  402:                                                 }
  403:                                                 else
  404:                                                 {
  405:                                                     // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17
  406:                                                     match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+),$", RegexOptions.Singleline);
  407:  
  408:                                                     if (match.Success)
  409:                                                     {
  410:                                                         level = "8-";
  411:  
  412:                                                         serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  413:                                                         serviceAddress.Street = string.Empty;
  414:                                                         serviceAddress.Boulevard = string.Empty;
  415:                                                         serviceAddress.PremisesOld = match.Groups[3].Value;
  416:                                                         serviceAddress.PremisesNew = string.Empty;
  417:                                                     }
  418:                                                     else
  419:                                                     {
  420:                                                         // الجهراء الجهراء المدينة,قطعة 79, منزل 17
  421:                                                         match = Regex.Match(customerAddress, @"^(.+),قطعة (.+), منزل (.+)$", RegexOptions.Singleline);
  422:  
  423:                                                         if (match.Success)
  424:                                                         {
  425:                                                             level = "9-";
  426:  
  427:                                                             serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  428:                                                             serviceAddress.Street = string.Empty;
  429:                                                             serviceAddress.Boulevard = string.Empty;
  430:                                                             serviceAddress.PremisesOld = string.Empty;
  431:                                                             serviceAddress.PremisesNew = match.Groups[3].Value;
  432:                                                         }
  433:                                                         else
  434:                                                         {
  435:                                                             // الجهراء الجهراء المدينة,قطعة 79 شارع 5
  436:                                                             match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+)$", RegexOptions.Singleline);
  437:  
  438:                                                             if (match.Success)
  439:                                                             {
  440:                                                                 level = "10-";
  441:  
  442:                                                                 serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  443:                                                                 serviceAddress.Street = match.Groups[3].Value;
  444:                                                                 serviceAddress.Boulevard = string.Empty;
  445:                                                                 serviceAddress.PremisesOld = string.Empty;
  446:                                                                 serviceAddress.PremisesNew = string.Empty;
  447:                                                             }
  448:                                                             else
  449:                                                             {
  450:                                                                 // الجهراء الجهراء المدينة,قطعة 79
  451:                                                                 match = Regex.Match(customerAddress, @"^(.+),قطعة (.+),$", RegexOptions.Singleline);
  452:  
  453:                                                                 if (match.Success)
  454:                                                                 {
  455:                                                                     level = "11-";
  456:  
  457:                                                                     serviceAddress.Block = Ia.Ftn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
  458:                                                                     serviceAddress.Street = string.Empty;
  459:                                                                     serviceAddress.Boulevard = string.Empty;
  460:                                                                     serviceAddress.PremisesOld = string.Empty;
  461:                                                                     serviceAddress.PremisesNew = string.Empty;
  462:                                                                 }
  463:                                                                 else
  464:                                                                 {
  465:                                                                     // حولي السلام,,
  466:                                                                     match = Regex.Match(customerAddress, @"^(.+),,$", RegexOptions.Singleline);
  467:  
  468:                                                                     if (match.Success)
  469:                                                                     {
  470:                                                                         level = "12-";
  471:  
  472:                                                                         serviceAddress.Block = string.Empty;
  473:                                                                         serviceAddress.Street = string.Empty;
  474:                                                                         serviceAddress.Boulevard = string.Empty;
  475:                                                                         serviceAddress.PremisesOld = string.Empty;
  476:                                                                         serviceAddress.PremisesNew = string.Empty;
  477:                                                                     }
  478:                                                                     else
  479:                                                                     {
  480:                                                                         level = "13";
  481:                                                                     }
  482:                                                                 }
  483:                                                             }
  484:                                                         }
  485:                                                     }
  486:                                                 }
  487:                                             }
  488:                                         }
  489:                                     }
  490:                                 }
  491:                             }
  492:                         }
  493:  
  494:                         // below: we will try to store integers in integer format
  495:  
  496:                         //serviceAddress.Block this is already in int format
  497:                         serviceAddress.Street = int.TryParse(serviceAddress.Street, out int i) ? i.ToString() : serviceAddress.Street;
  498:                         serviceAddress.Boulevard = int.TryParse(serviceAddress.Boulevard, out i) ? i.ToString() : serviceAddress.Boulevard;
  499:                         serviceAddress.PremisesOld = int.TryParse(serviceAddress.PremisesOld, out i) ? i.ToString() : serviceAddress.PremisesOld;
  500:                         serviceAddress.PremisesNew = int.TryParse(serviceAddress.PremisesNew, out i) ? i.ToString() : serviceAddress.PremisesNew;
  501:  
  502:                         // I will change all 0 entries to string.Empty
  503:  
  504:                         if (serviceAddress.Block == "0") serviceAddress.Block = string.Empty;
  505:                         if (serviceAddress.Street == "0") serviceAddress.Street = string.Empty;
  506:                         if (serviceAddress.Boulevard == "0") serviceAddress.Boulevard = string.Empty;
  507:                         if (serviceAddress.PremisesOld == "0") serviceAddress.PremisesOld = string.Empty;
  508:                         if (serviceAddress.PremisesNew == "0") serviceAddress.PremisesNew = string.Empty;
  509:                     }
  510:                     else
  511:                     {
  512:                         level = "0";
  513:  
  514:                         serviceAddress.AreaId = 0;
  515:                         serviceAddress.Block = string.Empty;
  516:                         serviceAddress.Street = string.Empty;
  517:                         serviceAddress.Boulevard = string.Empty;
  518:                         serviceAddress.PremisesOld = string.Empty;
  519:                         serviceAddress.PremisesNew = string.Empty;
  520:                     }
  521:                 }
  522:                 else
  523:                 {
  524:                     level = "0";
  525:  
  526:                     serviceAddress.AreaId = 0;
  527:                     serviceAddress.Block = string.Empty;
  528:                     serviceAddress.Street = string.Empty;
  529:                     serviceAddress.Boulevard = string.Empty;
  530:                     serviceAddress.PremisesOld = string.Empty;
  531:                     serviceAddress.PremisesNew = string.Empty;
  532:                 }
  533:             }
  534:             else
  535:             {
  536:                 level = "0";
  537:  
  538:                 serviceAddress.AreaId = 0;
  539:                 serviceAddress.Block = string.Empty;
  540:                 serviceAddress.Street = string.Empty;
  541:                 serviceAddress.Boulevard = string.Empty;
  542:                 serviceAddress.PremisesOld = string.Empty;
  543:                 serviceAddress.PremisesNew = string.Empty;
  544:             }
  545:  
  546:             return serviceAddress;
  547:         }
  548:  
  549:         ////////////////////////////////////////////////////////////////////////////    
  550:  
  551:         /// <summary>
  552:         ///
  553:         /// </summary>
  554:         public static bool ServiceRequestIdIsAllowedForProcessing(int serviceRequestId)
  555:         {
  556:             bool b;
  557:  
  558:             // see ServiceRequestIsAllowedProcessing in authority.cs
  559:  
  560:             if (serviceRequestId == 2390979) b = false; // Violation of PRIMARY KEY constraint 'PK_dbo.ServiceRequests'. Cannot insert duplicate key in object 'dbo.ServiceRequests'. The duplicate key value is (2390979).
  561:             else if (serviceRequestId == 2391097) b = false; // Violation of PRIMARY KEY constraint 'PK_dbo.ServiceRequests'. Cannot insert duplicate key in object 'dbo.ServiceRequests'. The duplicate key value is (2391097).
  562:             //else if (serviceRequestId == 2316113) b = false; // 2316113 problamatic causes duplicate primary key error
  563:             else b = true;
  564:  
  565:             return b;
  566:         }
  567:  
  568:         ////////////////////////////////////////////////////////////////////////////
  569:  
  570:         /// <summary>
  571:         /// Generate a OptimizedStartEndRangeList() but with a range buffer before start and after end.
  572:         /// </summary>
  573:         public static List<Tuple<int, int>> OptimizedStartEndRangeBufferedList(List<int> list, int count, int bufferRange)
  574:         {
  575:             int start, end;
  576:             List<Tuple<int, int>> tupleList;
  577:  
  578:             tupleList = OptimizedStartEndRangeTupleList(list, count);
  579:  
  580:             if (tupleList != null && tupleList.Count > 0)
  581:             {
  582:                 start = tupleList[0].Item1;
  583:                 end = tupleList[tupleList.Count - 1].Item2;
  584:  
  585:                 tupleList.Insert(tupleList.Count, new Tuple<int, int>(end + 1, end + bufferRange + 1));
  586:                 tupleList.Insert(0, new Tuple<int, int>((start - bufferRange) > 0 ? (start - bufferRange) : 0, start - 1)); // keep order
  587:             }
  588:  
  589:             tupleList.Sort();
  590:  
  591:             return tupleList;
  592:         }
  593:  
  594:         ////////////////////////////////////////////////////////////////////////////
  595:  
  596:         /// <summary>
  597:         /// Generate a list of start-end count optimized to read around count number of values from passed list. 
  598:         /// </summary>
  599:         public static List<Tuple<int, int>> OptimizedStartEndRangeTupleList(List<int> list, int count)
  600:         {
  601:             bool started, done;
  602:             int c, start, end;
  603:             Tuple<int, int> tuple;
  604:             List<Tuple<int, int>> tupleList;
  605:  
  606:             tupleList = new List<Tuple<int, int>>();
  607:  
  608:             started = true;
  609:             done = false;
  610:             c = start = 0;
  611:  
  612:             if (list.Count > 0 && count > 0)
  613:             {
  614:                 foreach (int item in list)
  615:                 {
  616:                     if (started)
  617:                     {
  618:                         start = item;
  619:                         started = false;
  620:                     }
  621:  
  622:                     if (c == 0)
  623:                     {
  624:                         done = false;
  625:                     }
  626:  
  627:                     if (c == count - 1)
  628:                     {
  629:                         end = item;
  630:  
  631:                         tuple = new Tuple<int, int>(start, end);
  632:  
  633:                         tupleList.Add(tuple);
  634:  
  635:                         start = item + 1;
  636:                         done = true;
  637:                         c = 0;
  638:                     }
  639:                     else c++;
  640:                 }
  641:  
  642:                 if (!done)
  643:                 {
  644:                     end = list[list.Count - 1];
  645:  
  646:                     tuple = new Tuple<int, int>(start, end);
  647:  
  648:                     tupleList.Add(tuple);
  649:                 }
  650:             }
  651:             else throw new System.ArgumentException("List empty or range too short. ");
  652:  
  653:             tupleList.Sort();
  654:  
  655:             return tupleList;
  656:         }
  657:  
  658:         ////////////////////////////////////////////////////////////////////////////    
  659:         ////////////////////////////////////////////////////////////////////////////    
  660:     }
  661:  
  662:     ////////////////////////////////////////////////////////////////////////////    
  663:     ////////////////////////////////////////////////////////////////////////////
  664:  
  665:     /// <summary>
  666:     ///
  667:     /// </summary>
  668:     public static class ServiceRequestExtension
  669:     {
  670:         ////////////////////////////////////////////////////////////////////////////
  671:  
  672:         /// <summary>
  673:         /// Extension method: Collect number list
  674:         /// </summary>
  675:         public static List<int> NumberList(this List<Ia.Ftn.Cl.Model.ServiceRequest> serviceRequestList)
  676:         {
  677:             List<int> numberList;
  678:  
  679:             if (serviceRequestList.Count > 0)
  680:             {
  681:                 numberList = (from n in serviceRequestList select n.Number).Distinct().ToList<int>();
  682:             }
  683:             else numberList = new List<int>();
  684:  
  685:             return numberList;
  686:         }
  687:  
  688:         ////////////////////////////////////////////////////////////////////////////
  689:  
  690:         /// <summary>
  691:         /// Extension method: Collect distinct number-serials into NumberSerial list
  692:         /// </summary>
  693:         public static List<Ia.Ftn.Cl.Model.Business.ServiceRequest.NumberSerial> DistinctNumberSerialList(this List<Ia.Ftn.Cl.Model.ServiceRequest> sourceList)
  694:         {
  695:             List<Ia.Ftn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList;
  696:  
  697:             if (sourceList.Count > 0)
  698:             {
  699:                 numberSerialList = (from n in sourceList
  700:                                     select new Ia.Ftn.Cl.Model.Business.ServiceRequest.NumberSerial { Number = n.Number, Serial = n.Serial }).Distinct().ToList();
  701:             }
  702:             else numberSerialList = new List<Ia.Ftn.Cl.Model.Business.ServiceRequest.NumberSerial>();
  703:  
  704:             return numberSerialList;
  705:         }
  706:  
  707:         ////////////////////////////////////////////////////////////////////////////
  708:         ////////////////////////////////////////////////////////////////////////////
  709:     }
  710:  
  711:     ////////////////////////////////////////////////////////////////////////////
  712:     ////////////////////////////////////////////////////////////////////////////
  713: }