1: using Ia.Ngn.Cl.Model.Business; // Needed for ServerExtension
2: using Ia.Ngn.Cl.Model.Ui;
3: using Microsoft.EntityFrameworkCore;
4: using System;
5: using System.Collections;
6: using System.Collections.Generic;
7: using System.Data;
8: using System.Data.Objects.SqlClient;
9: using System.IO;
10: using System.Linq;
11: using System.Reflection;
12: using System.Text;
13: using System.Text.RegularExpressions;
14: using System.Xml.Linq;
15:
16: namespace Ia.Ngn.Cl.Model.Data
17: {
18: ////////////////////////////////////////////////////////////////////////////
19:
20: /// <summary publish="true">
21: /// Service Request support class for Optical Fiber Network (OFN) data model.
22: /// </summary>
23: ///
24: /// <remarks>
25: /// Copyright © 2006-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
26: ///
27: /// 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
28: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
29: ///
30: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
31: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
32: ///
33: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
34: ///
35: /// Copyright notice: This notice may not be removed or altered from any source distribution.
36: /// </remarks>
37: public class ServiceRequest
38: {
39: private static int serviceRequestIdStartEndRangeBufferedListIndex, serviceRequestIdLatestStartEndRangeBufferedListIndex, serviceRequestIdLatestStartEndRangeBufferedListCount = 0;
40: private static SortedList serviceCategorySortedList, serviceSortedList, customerCategorySortedList, statusSortedList;
41: private static XDocument xDocument;
42: private static List<int> serviceIdAllowedForProcessingList, serviceRequestDomainList;
43: private static Dictionary<int, string> systemCode;
44: private static List<Tuple<int, int>> serviceRequestIdStartEndRangeBufferedTupleList;
45: private static Dictionary<string, string> serviceToDbNameDictionary, serviceToCustomerAddressDictionary;
46: private static Dictionary<int, List<int>> changedServiceNumberToChangedToServiceNumberListDictionary;
47: private static Dictionary<int, List<int>> pbxServiceKeyToPbxServiceBranchListDictionary;
48: private static Dictionary<string, List<string>> changedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary;
49: private static DateTime serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp;
50: private static Dictionary<string, List<string>> dbNameToServiceListDictionary, accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
51: private static DateTime dbNameToServiceListDictionaryTimestamp, accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp;
52: private static Dictionary<string, string> serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
53:
54: private static readonly object objectLock = new object();
55:
56: ////////////////////////////////////////////////////////////////////////////
57:
58: /// <summary>
59: ///
60: /// </summary>
61: public ServiceRequest() { }
62:
63: ////////////////////////////////////////////////////////////////////////////
64:
65: /// <summary>
66: ///
67: /// </summary>
68: public static Dictionary<int, string> SystemCode
69: {
70: get
71: {
72: if (systemCode == null || systemCode.Count == 0)
73: {
74: lock (objectLock)
75: {
76: systemCode = Ia.Ngn.Cl.Model.Data.ServiceRequest._SystemCode;
77: }
78: }
79:
80: return systemCode;
81: }
82: }
83:
84: ////////////////////////////////////////////////////////////////////////////
85:
86: /// <summary>
87: ///
88: /// </summary>
89: private static Dictionary<int, string> _SystemCode
90: {
91: get
92: {
93: // select code_id, code_name from system_codes
94:
95: systemCode = new Dictionary<int, string>(100)
96: {
97: [6008] = "قطع مطالبات",
98: [6009] = "قطع إدارى",
99: [4007] = "إفراج",
100: [4008] = "قيد التجديد",
101: [4009] = "قيد إخطار الجهة",
102: [4010] = "تسيل جزئي",
103: [1001] = "جديد",
104: [1002] = "مطلوب",
105: [1003] = "متاح",
106: [2001] = "قيد الموافقة الفنية",
107: [2002] = "قيد الدفع",
108: [2003] = "قيد التنفيذ",
109: [2004] = "تعذر التنفيذ",
110: [2005] = "تم التنفيذ",
111: [3001] = "نقل من رصيد خدمة - دائن",
112: [3002] = "نقل من رصيد خدمة - مدين",
113: [4001] = "سارية",
114: [4002] = "منتهية",
115: [4003] = "مستردة",
116: [4004] = "تسييل",
117: [5001] = "سارية",
118: [5002] = "منتهية",
119: [5003] = "ملغاة",
120: [4005] = "ملغاة",
121: [5004] = "مبدئية",
122: [6001] = "قيد التنفيذ",
123: [6002] = "تم التنفيذ",
124: [6003] = "تعذر التنفيذ",
125: [4006] = "جديدة",
126: [7001] = "يعمل",
127: [7002] = "قطع مؤقت",
128: [7003] = "قطع مبرمج",
129: [1004] = "مقطوع",
130: [5005] = "متأخرة السداد",
131: [7004] = "قيد التنفيذ",
132: [8001] = "قيد التنفيذ",
133: [8002] = "تم التنفيذ",
134: [8003] = "تعذر التنفيذ",
135: [1005] = "يعمل",
136: [7005] = "تعذر التنفيذ",
137: [9001] = "دائن",
138: [9002] = "مدين",
139: [7006] = "رفع نهائي",
140: [1203] = "مبدئية",
141: [1201] = "سارية",
142: [1202] = "ملغاة",
143: [1101] = "انهاء",
144: [1102] = "قطع مؤقت",
145: [1301] = "قطع مبرمج",
146: [1302] = "أمر عمل",
147: [7007] = "رفع محاسبة",
148: [1401] = "نص",
149: [1402] = "رقم",
150: [1403] = "تاريخ",
151: [1404] = "تاريخ/وقت",
152: [7008] = "قطع معاكسة",
153: [1501] = "خدمة أساسية",
154: [1502] = "تشغيل خدمة فرعية",
155: [1503] = "إيقاف خدمة فرعية",
156: [1504] = "عملية",
157: [1505] = "منتج",
158: [1510] = "خدمات متنوعة",
159: [1103] = "إعادة",
160: [1506] = "خدمة اساسية - مجموعة",
161: [1507] = "خدمة تابعة",
162: [1508] = "خدمة مدمجة",
163: [2101] = "جديد",
164: [2102] = "تم الحساب",
165: [2103] = "نسخة جديدة",
166: [2201] = "ملف المكالمات الدولية",
167: [6004] = "إعادة الحالة",
168: [1601] = "مبدئية",
169: [1602] = "نهائية",
170: [1603] = "ملغاة",
171: [2006] = "ملغاة",
172: [7009] = "ملغى",
173: [7010] = "لا يعمل",
174: [2104] = "مفقود",
175: [5006] = "سارية - مؤقتة",
176: [5007] = "مرحلة",
177: [1701] = "عادي",
178: [1702] = "نطاق",
179: [1509] = "إيقاف خدمة أساسية"
180: };
181:
182: return systemCode;
183: }
184: }
185:
186: ////////////////////////////////////////////////////////////////////////////
187:
188: /// <summary>
189: ///
190: /// </summary>
191: public static SortedList ServiceCategorySortedList
192: {
193: get
194: {
195: if (serviceCategorySortedList == null || serviceCategorySortedList.Count == 0)
196: {
197: lock (objectLock)
198: {
199: serviceCategorySortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceCategorySortedList;
200: }
201: }
202:
203: return serviceCategorySortedList;
204: }
205: }
206:
207: ////////////////////////////////////////////////////////////////////////////
208:
209: /// <summary>
210: ///
211: /// </summary>
212: private static SortedList _ServiceCategorySortedList
213: {
214: get
215: {
216: int id;
217:
218: serviceCategorySortedList = new SortedList(10);
219:
220: foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("categoryList").Elements("category"))
221: {
222: id = int.Parse(x.Attribute("id").Value);
223:
224: serviceCategorySortedList[id] = x.Attribute("arabicName").Value;
225: }
226:
227: return serviceCategorySortedList;
228: }
229: }
230:
231: ////////////////////////////////////////////////////////////////////////////
232:
233: /// <summary>
234: ///
235: /// </summary>
236: public static SortedList ServiceSortedList
237: {
238: get
239: {
240: if (serviceSortedList == null || serviceSortedList.Count == 0)
241: {
242: lock (objectLock)
243: {
244: serviceSortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceSortedList;
245: }
246: }
247:
248: return serviceSortedList;
249: }
250: }
251:
252: ////////////////////////////////////////////////////////////////////////////
253:
254: /// <summary>
255: ///
256: /// </summary>
257: private static SortedList _ServiceSortedList
258: {
259: get
260: {
261: int id;
262:
263: serviceSortedList = new SortedList(10);
264:
265: foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("serviceList").Elements("service"))
266: {
267: id = int.Parse(x.Attribute("id").Value);
268:
269: serviceSortedList[id] = x.Attribute("arabicName").Value;
270: }
271:
272: return serviceSortedList;
273: }
274: }
275:
276: ////////////////////////////////////////////////////////////////////////////
277:
278: /// <summary>
279: ///
280: /// </summary>
281: public static SortedList CustomerCategorySortedList
282: {
283: get
284: {
285: if (customerCategorySortedList == null || customerCategorySortedList.Count == 0)
286: {
287: lock (objectLock)
288: {
289: customerCategorySortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._CustomerCategorySortedList;
290: }
291: }
292:
293: return customerCategorySortedList;
294: }
295: }
296:
297: ////////////////////////////////////////////////////////////////////////////
298:
299: /// <summary>
300: ///
301: /// </summary>
302: private static SortedList _CustomerCategorySortedList
303: {
304: get
305: {
306: int id;
307:
308: customerCategorySortedList = new SortedList(10);
309:
310: foreach (XElement x in XDocument.Element("serviceRequest").Elements("customer").Elements("categoryList").Elements("category"))
311: {
312: id = int.Parse(x.Attribute("id").Value);
313:
314: customerCategorySortedList[id] = x.Attribute("arabicName").Value;
315: }
316:
317: return customerCategorySortedList;
318: }
319: }
320:
321: ////////////////////////////////////////////////////////////////////////////
322:
323: /// <summary>
324: ///
325: /// </summary>
326: public static SortedList StatusSortedList
327: {
328: get
329: {
330: if (statusSortedList == null || statusSortedList.Count == 0)
331: {
332: lock (objectLock)
333: {
334: statusSortedList = Ia.Ngn.Cl.Model.Data.ServiceRequest._StatusSortedList;
335: }
336: }
337:
338: return statusSortedList;
339: }
340: }
341:
342: ////////////////////////////////////////////////////////////////////////////
343:
344: /// <summary>
345: ///
346: /// </summary>
347: private static SortedList _StatusSortedList
348: {
349: get
350: {
351: int id;
352:
353: statusSortedList = new SortedList(10);
354:
355: foreach (XElement x in XDocument.Element("serviceRequest").Elements("statusList").Elements("status"))
356: {
357: id = int.Parse(x.Attribute("id").Value);
358:
359: statusSortedList[id] = x.Attribute("arabicName").Value;
360: }
361:
362: return statusSortedList;
363: }
364: }
365:
366: ////////////////////////////////////////////////////////////////////////////
367:
368: /// <summary>
369: ///
370: /// </summary>
371: public static List<int> ServiceIdAllowedForProcessingList
372: {
373: get
374: {
375: if (serviceIdAllowedForProcessingList == null || serviceIdAllowedForProcessingList.Count == 0)
376: {
377: lock (objectLock)
378: {
379: serviceIdAllowedForProcessingList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceIdAllowedForProcessingList;
380: }
381: }
382:
383: return serviceIdAllowedForProcessingList;
384: }
385: }
386:
387: ////////////////////////////////////////////////////////////////////////////
388:
389: /// <summary>
390: ///
391: /// </summary>
392: private static List<int> _ServiceIdAllowedForProcessingList
393: {
394: get
395: {
396: int id;
397:
398: serviceIdAllowedForProcessingList = new List<int>(100);
399:
400: foreach (XElement x in XDocument.Element("serviceRequest").Elements("service").Elements("serviceList").Elements("service"))
401: {
402: if (x.HasAttributes && x.Attribute("allowProcessing") != null)
403: {
404: if (x.Attribute("allowProcessing").Value == "true")
405: {
406: id = int.Parse(x.Attribute("id").Value);
407: serviceIdAllowedForProcessingList.Add(id);
408: }
409: }
410: }
411:
412: return serviceIdAllowedForProcessingList;
413: }
414: }
415:
416: ////////////////////////////////////////////////////////////////////////////
417: ////////////////////////////////////////////////////////////////////////////
418:
419: /// <summary>
420: ///
421: /// </summary>
422: public static Tuple<int, int> ServiceRequestIdStartEndRangeManager(ref int index, out string result)
423: {
424: int count, edgeBufferRange, latestFromNDaysBeforeNow;
425: Tuple<int, int> tuple;
426: List<int> serviceRequestIdList;
427:
428: count = 40;
429: edgeBufferRange = 400;
430: latestFromNDaysBeforeNow = 7;
431:
432: if (serviceRequestIdStartEndRangeBufferedTupleList == null || serviceRequestIdStartEndRangeBufferedListIndex == 0)
433: {
434: serviceRequestIdStartEndRangeBufferedListIndex = index;
435:
436: using (var db = new Ia.Ngn.Cl.Model.Ngn())
437: {
438: serviceRequestIdList = (from sr in db.ServiceRequests
439: orderby sr.Id ascending
440: select sr.Id).ToList();
441: }
442:
443: serviceRequestIdStartEndRangeBufferedTupleList = Ia.Ngn.Cl.Model.Business.ServiceRequest.OptimizedStartEndRangeBufferedList(serviceRequestIdList, count, edgeBufferRange);
444:
445: var firstServiceRequestIdAfterDateTime = Ia.Ngn.Cl.Model.Data.ServiceRequest.FirstIdAfterDateTime(DateTime.UtcNow.AddHours(3).AddDays(-latestFromNDaysBeforeNow));
446:
447: serviceRequestIdLatestStartEndRangeBufferedListCount = 0;
448: for (int i = serviceRequestIdStartEndRangeBufferedTupleList.Count - 1; i > 0; i--)
449: {
450: if (serviceRequestIdStartEndRangeBufferedTupleList[i].Item1 < firstServiceRequestIdAfterDateTime) break;
451:
452: serviceRequestIdLatestStartEndRangeBufferedListCount++;
453: }
454: }
455:
456: if (serviceRequestIdStartEndRangeBufferedTupleList.Count > 0)
457: {
458: if (Ia.Ngn.Cl.Model.Business.Administration.NowIsOfficialWorkingTime)
459: {
460: // flip between last and latest range to favor reading fresh work orders quickly
461: if (Ia.Cl.Model.Default.RandomBool)
462: {
463: serviceRequestIdLatestStartEndRangeBufferedListIndex = serviceRequestIdStartEndRangeBufferedTupleList.Count - Ia.Cl.Model.Default.Random(serviceRequestIdLatestStartEndRangeBufferedListCount) - 1;
464: serviceRequestIdLatestStartEndRangeBufferedListIndex = (serviceRequestIdLatestStartEndRangeBufferedListIndex >= 0) ? serviceRequestIdLatestStartEndRangeBufferedListIndex : 0;
465: }
466: else serviceRequestIdLatestStartEndRangeBufferedListIndex = serviceRequestIdStartEndRangeBufferedTupleList.Count - 1;
467:
468: tuple = serviceRequestIdStartEndRangeBufferedTupleList[serviceRequestIdLatestStartEndRangeBufferedListIndex];
469:
470: if (serviceRequestIdLatestStartEndRangeBufferedListIndex == serviceRequestIdStartEndRangeBufferedTupleList.Count - 1)
471: {
472: tuple = new Tuple<int, int>(tuple.Item1, tuple.Item2 + edgeBufferRange);
473: }
474:
475: result = "(latest:" + tuple.Item1 + "-" + tuple.Item2 + " " + serviceRequestIdLatestStartEndRangeBufferedListIndex + "/" + serviceRequestIdStartEndRangeBufferedTupleList.Count + ")";
476: }
477: else
478: {
479: tuple = serviceRequestIdStartEndRangeBufferedTupleList[serviceRequestIdStartEndRangeBufferedListIndex];
480:
481: result = "(historic:" + tuple.Item1 + "-" + tuple.Item2 + " " + serviceRequestIdStartEndRangeBufferedListIndex + "/" + serviceRequestIdStartEndRangeBufferedTupleList.Count + ")";
482:
483: serviceRequestIdStartEndRangeBufferedListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(serviceRequestIdStartEndRangeBufferedTupleList, serviceRequestIdStartEndRangeBufferedListIndex);
484: }
485: }
486: else
487: {
488: result = "(0-0 0/0)";
489:
490: tuple = null;
491: }
492:
493: index = serviceRequestIdStartEndRangeBufferedListIndex;
494:
495: return tuple;
496: }
497:
498: ////////////////////////////////////////////////////////////////////////////
499:
500: /// <summary>
501: ///
502: /// </summary>
503: public static string AlterSessionOfCustomerDepartmentOracleDatabase
504: {
505: get
506: {
507: return @"alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS'";
508: }
509: }
510:
511: ////////////////////////////////////////////////////////////////////////////
512:
513: /// <summary>
514: /// Return list of service requests
515: /// </summary>
516: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List()
517: {
518: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
519:
520: using (var db = new Ia.Ngn.Cl.Model.Ngn())
521: {
522: serviceRequestList = (from sr in db.ServiceRequests select sr).ToList();
523: }
524:
525: return serviceRequestList;
526: }
527:
528: ////////////////////////////////////////////////////////////////////////////
529:
530: /// <summary>
531: ///
532: /// </summary>
533: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(int number)
534: {
535: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
536:
537: using (var db = new Ia.Ngn.Cl.Model.Ngn())
538: {
539: serviceRequestList = (from sr in db.ServiceRequests where sr.Number == number select sr).ToList();
540: }
541:
542: return serviceRequestList;
543: }
544:
545: ////////////////////////////////////////////////////////////////////////////
546:
547: /// <summary>
548: ///
549: /// </summary>
550: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(string service)
551: {
552: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
553:
554: if (!string.IsNullOrEmpty(service))
555: {
556: if (int.TryParse(service, out int number))
557: {
558: using (var db = new Ia.Ngn.Cl.Model.Ngn())
559: {
560: serviceRequestList = (from sr in db.ServiceRequests
561: where sr.Number == number
562: select sr).ToList();
563: }
564: }
565: else
566: {
567: throw new ArgumentException(@"List(): service is not a number, service: " + service);
568: }
569: }
570: else serviceRequestList = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
571:
572: return serviceRequestList;
573: }
574:
575: ////////////////////////////////////////////////////////////////////////////
576:
577: /// <summary>
578: ///
579: /// </summary>
580: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListById(int id)
581: {
582: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
583:
584: if (id > 0)
585: {
586: using (var db = new Ia.Ngn.Cl.Model.Ngn())
587: {
588: serviceRequestList = (from sr in db.ServiceRequests where sr.Id == id select sr).ToList();
589: }
590: }
591: else serviceRequestList = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
592:
593: return serviceRequestList;
594: }
595:
596: ////////////////////////////////////////////////////////////////////////////
597:
598: /// <summary>
599: ///
600: /// </summary>
601: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<int> numberList)
602: {
603: List<string> serviceList;
604:
605: serviceList = (from n in numberList select n.ToString()).ToList();
606:
607: return List(serviceList);
608: }
609:
610: ////////////////////////////////////////////////////////////////////////////
611:
612: /// <summary>
613: ///
614: /// </summary>
615: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<string> serviceList)
616: {
617: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList, viaServiceRequestTypeList;
618:
619: using (var db = new Ia.Ngn.Cl.Model.Ngn())
620: {
621: if (serviceList.Count > 0)
622: {
623: serviceRequestList = (from sr in db.ServiceRequests
624: where serviceList.Contains(sr.Number.ToString())
625: select sr).Include(a => a.ServiceRequestService).Include(a => a.ServiceRequestTypes).ToList();
626:
627: viaServiceRequestTypeList = (from srt in db.ServiceRequestTypes
628: join sr in db.ServiceRequests on srt.ServiceRequest.Id equals sr.Id
629: where srt.TypeId == 11 && serviceList.Contains(srt.Value)
630: select sr).Include(a => a.ServiceRequestService).ToList();
631:
632: serviceRequestList = serviceRequestList.Union(viaServiceRequestTypeList).Distinct().ToList();
633: }
634: else serviceRequestList = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
635: }
636:
637: return serviceRequestList.ToList();
638: }
639:
640: ////////////////////////////////////////////////////////////////////////////
641:
642: /// <summary>
643: ///
644: /// </summary>
645: public static List<Ia.Ngn.Cl.Model.ServiceRequest> List(List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList)
646: {
647: List<long> idList;
648: List<Ia.Ngn.Cl.Model.ServiceRequest> list;
649:
650: if (numberSerialList.Count > 0)
651: {
652: idList = numberSerialList.IdList();
653:
654: using (var db = new Ia.Ngn.Cl.Model.Ngn())
655: {
656: list = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
657: where
658: //numberSerialList.Contains(q.Number, q.Serial) does not work
659: //((from r in numberSerialList where r.Number == q.Number && r.Serial == q.Serial select r) != null) does not work
660: //numberList.Any<int>(i=> i == q.Number) does not work
661: idList.Contains((long)sr.Number * 100 + sr.Serial)
662: select sr).ToList();
663: }
664: }
665: else list = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
666:
667: return list;
668: }
669:
670: ////////////////////////////////////////////////////////////////////////////
671:
672: /// <summary>
673: ///
674: /// </summary>
675: public static int FirstIdAfterDateTime(DateTime dateTime)
676: {
677: int serviceRequestId;
678:
679: using (var db = new Ia.Ngn.Cl.Model.Ngn())
680: {
681: serviceRequestId = (from sr in db.ServiceRequests
682: where sr.RequestDateTime >= dateTime
683: select sr.Id).FirstOrDefault();
684: }
685:
686: return serviceRequestId;
687: }
688:
689: /*
690: ////////////////////////////////////////////////////////////////////////////
691:
692: /// <summary>
693: ///
694: /// </summary>
695: [Obsolete]
696: public static List<int> OldNumberAndChangedAndChangedToList(List<int> numberList)
697: {
698: List<int> number1List, number2List, number3List;//, number4List, number5List;
699: List<string> serviceList; //, service1List, service2List, service3List, service4List, service5List;
700: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList, serviceRequest1List, serviceRequest2List, serviceRequest3List, serviceRequest4List, serviceRequest5List;
701:
702: using (var db = new Ia.Ngn.Cl.Model.Ngn())
703: {
704: if (numberList.Count > 0)
705: {
706: serviceList = (from n in numberList select n.ToString()).ToList();
707:
708: serviceRequest1List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
709: where numberList.Contains(sr.Number)
710: select sr).ToList();
711:
712: if (serviceRequest1List.Count > 0)
713: {
714: number1List = (from sr in serviceRequest1List select sr.Number).Distinct().ToList();
715:
716: number2List = new List<int>();
717:
718: foreach (var srt in serviceRequest1List.SelectMany(u => u.ServiceRequestTypes))
719: {
720: if (srt.TypeId == 11 && int.TryParse(srt.Value, out int i)) number2List.Add(i);
721: }
722:
723: // below: this is the collect first changed-to number information
724: if (number2List.Count > 0)
725: {
726: serviceRequest2List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
727: where number2List.Contains(sr.Number)
728: select sr).ToList();
729:
730: if (serviceRequest2List.Count > 0)
731: {
732: number1List = (from sr in serviceRequest2List select sr.Number).Distinct().ToList();
733:
734: number3List = new List<int>();
735:
736: foreach (var srt in serviceRequest2List.SelectMany(u => u.ServiceRequestTypes))
737: {
738: if (srt.TypeId == 11 && int.TryParse(srt.Value, out int i)) number3List.Add(i);
739: }
740:
741: // below: this is the collect second changed-to number information
742: if (number3List.Count > 0)
743: {
744: serviceRequest3List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
745: where number3List.Contains(sr.Number)
746: select sr).ToList();
747: }
748: else serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
749: }
750: else
751: {
752: serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
753: serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
754: }
755: }
756: else
757: {
758: serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
759: serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
760: }
761: }
762: else
763: {
764: serviceRequest2List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
765: serviceRequest3List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
766: }
767:
768:
769: //
770: serviceRequest4List = (from srt in db.ServiceRequestTypes.Include(a => a.ServiceRequest)
771: where srt.TypeId == 11 && serviceList.Contains(srt.Value)
772: select srt.ServiceRequest).ToList();
773:
774: if (serviceRequest4List.Count > 0)
775: {
776: number1List = (from sr in serviceRequest4List select sr.Number).Distinct().ToList();
777:
778: serviceRequest5List = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestTypes)
779: where number1List.Contains(sr.Number)
780: select sr).ToList();
781: }
782: else serviceRequest5List = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
783:
784: //
785: serviceRequestList = serviceRequest1List.Union(serviceRequest2List).Union(serviceRequest3List).Union(serviceRequest4List).Union(serviceRequest5List).Distinct().ToList();
786:
787: if (serviceRequestList.Count > 0)
788: {
789: numberList = (from n in serviceRequestList select n.Number).Distinct().ToList();
790: }
791: else numberList = new List<int>();
792: }
793: else numberList = new List<int>();
794: }
795:
796: return numberList.ToList();
797: }
798: */
799:
800: ////////////////////////////////////////////////////////////////////////////
801:
802: /// <summary>
803: ///
804: /// </summary>
805: public static List<int> NumberAndChangedNumberAndChangedToNumberList(List<int> numberList)
806: {
807: List<int> list;
808:
809: if (numberList.Count > 0)
810: {
811: var changedServiceNumberToChangedToServiceNumberDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedServiceNumberToChangedToServiceNumberListDictionary();
812:
813: list = new List<int>();
814:
815: foreach (var kvp in changedServiceNumberToChangedToServiceNumberDictionary)
816: {
817: if (numberList.Contains(kvp.Key) || list.Contains(kvp.Key))
818: {
819: list.Add(kvp.Key);
820:
821: foreach (var i in kvp.Value) list.Add(i);
822: }
823: else
824: {
825: foreach (var i in kvp.Value)
826: {
827: if (numberList.Contains(i)) list.Add(i);
828: }
829: }
830: }
831:
832: list.AddRange(numberList);
833: }
834: else list = new List<int>();
835:
836: return list.Distinct().ToList();
837: }
838:
839: /*
840: ////////////////////////////////////////////////////////////////////////////
841:
842: /// <summary>
843: ///
844: /// </summary>
845: [Obsolete]
846: private static void IterativeNumberAndChangedAndChangedToList(List<int> numberList, ref List<int> list)
847: {
848: List<int> list0, changedList, changedToList, changedExceptList, changedToExceptList;
849: List<string> serviceList;
850:
851: using (var db = new Ia.Ngn.Cl.Model.Ngn())
852: {
853: if (numberList.Count > 0)
854: {
855: changedList = new List<int>();
856: changedToList = new List<int>();
857:
858: serviceList = numberList.ConvertAll(delegate (int i) { return i.ToString(); });
859:
860: // list
861: var serviceRequestNumberAndSrtTypeIdAndSrtValueList = (from srt in db.ServiceRequestTypes
862: where srt.ServiceRequest != null && numberList.Contains(srt.ServiceRequest.Number)
863: select new { srt.ServiceRequest.Number, srt.TypeId, srt.Value }).AsNoTracking().ToList();
864:
865: list0 = (from sr in serviceRequestNumberAndSrtTypeIdAndSrtValueList select sr.Number).Distinct().ToList();
866:
867: list = list.Union(list0).Distinct().ToList();
868:
869: // changedToList
870: foreach (var srntv in serviceRequestNumberAndSrtTypeIdAndSrtValueList)
871: {
872: if (srntv.TypeId == 11 && int.TryParse(srntv.Value, out int i)) changedToList.Add(i);
873: }
874:
875: // changedList
876: changedList = (from srt in db.ServiceRequestTypes
877: where srt.TypeId == 11 && serviceList.Contains(srt.Value)
878: select srt.ServiceRequest.Number).Distinct().ToList();
879:
880: changedToExceptList = changedToList.Except(list).ToList();
881: if (changedToExceptList.Count > 0) IterativeNumberAndChangedAndChangedToList(changedToExceptList, ref list);
882:
883: list = list.Union(changedToExceptList).Distinct().ToList();
884:
885: changedExceptList = changedList.Except(list).ToList();
886: if (changedExceptList.Count > 0) IterativeNumberAndChangedAndChangedToList(changedExceptList, ref list);
887:
888: list = list.Union(changedExceptList).Distinct().ToList();
889: }
890: else
891: {
892:
893: }
894: }
895: }
896: */
897:
898: ////////////////////////////////////////////////////////////////////////////
899:
900: /// <summary>
901: ///
902: /// </summary>
903: public static Dictionary<string, List<string>> ChangedServiceToChangedToServiceListDictionary()
904: {
905: Dictionary<string, List<string>> dictionary;
906:
907: dictionary = new Dictionary<string, List<string>>();
908:
909: var list = ChangedServiceNumberToChangedToServiceNumberListDictionary();
910:
911: foreach (var kvp in list)
912: {
913: dictionary[kvp.Key.ToString()] = kvp.Value.ConvertAll<string>(x => x.ToString());
914: }
915:
916: return dictionary;
917: }
918:
919: ////////////////////////////////////////////////////////////////////////////
920:
921: /// <summary>
922: ///
923: /// </summary>
924: public static Dictionary<int, List<int>> ChangedServiceNumberToChangedToServiceNumberListDictionary()
925: {
926: if (changedServiceNumberToChangedToServiceNumberListDictionary == null || changedServiceNumberToChangedToServiceNumberListDictionary.Count == 0)
927: {
928: lock (objectLock)
929: {
930: changedServiceNumberToChangedToServiceNumberListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._ChangedServiceNumberToChangedToServiceNumberListDictionary();
931: }
932: }
933:
934: return changedServiceNumberToChangedToServiceNumberListDictionary;
935: }
936:
937: ////////////////////////////////////////////////////////////////////////////
938:
939: /// <summary>
940: ///
941: /// </summary>
942: private static Dictionary<int, List<int>> _ChangedServiceNumberToChangedToServiceNumberListDictionary()
943: {
944: int i;
945: Dictionary<int, List<int>> dictionary;
946:
947: using (var db = new Ia.Ngn.Cl.Model.Ngn())
948: {
949: /*
950: * select sr.Number, srt.Value from ServiceRequests as sr
951: * left outer join ServiceRequestTypes as srt on srt.ServiceRequest_Id = sr.Id
952: * where srt.TypeId = 11 and srt.Value is not null
953: */
954:
955: dictionary = new Dictionary<int, List<int>>();
956:
957: // <status id="2003" arabicName="قيد التنفيذ" />
958: // <status id="2005" arabicName="تم التنفيذ" />
959:
960: var list = (from sr in db.ServiceRequests
961: join srt in db.ServiceRequestTypes on sr.Id equals srt.ServiceRequest.Id
962: where srt.TypeId == 11 && srt.Value != null && (sr.Status == 2003 || sr.Status == 2005)
963: select new { Changed = sr.Number, ChangedTo = srt.Value }).ToList();
964:
965: foreach (var v in list)
966: {
967: if (!dictionary.ContainsKey(v.Changed)) dictionary[v.Changed] = new List<int>();
968:
969: i = int.Parse(v.ChangedTo);
970:
971: if (!dictionary[v.Changed].Contains(i)) dictionary[v.Changed].Add(i);
972: }
973: }
974:
975: return dictionary;
976: }
977:
978: ////////////////////////////////////////////////////////////////////////////
979:
980: /// <summary>
981: ///
982: /// </summary>
983: public static Dictionary<int, List<int>> PbxServiceKeyToPbxServiceBranchListDictionary()
984: {
985: if (pbxServiceKeyToPbxServiceBranchListDictionary == null || pbxServiceKeyToPbxServiceBranchListDictionary.Count == 0)
986: {
987: lock (objectLock)
988: {
989: pbxServiceKeyToPbxServiceBranchListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._PbxServiceKeyToPbxServiceBranchListDictionary();
990: }
991: }
992:
993: return pbxServiceKeyToPbxServiceBranchListDictionary;
994: }
995:
996: ////////////////////////////////////////////////////////////////////////////
997:
998: /// <summary>
999: ///
1000: /// </summary>
1001: private static Dictionary<int, List<int>> _PbxServiceKeyToPbxServiceBranchListDictionary()
1002: {
1003: int key, branch;
1004: string s, key0;
1005: Match match;
1006: List<int> branchList;
1007: Dictionary<int, List<int>> dictionary;
1008:
1009: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1010: {
1011: /*
1012: select sr.Number, srt.Value from ServiceRequests as sr
1013: left outer join ServiceRequestTypes as srt on srt.ServiceRequest_Id = sr.Id
1014: where srt.TypeId = 12 and srt.Value is not null
1015: */
1016:
1017: var dictionary0 = new Dictionary<string, List<int>>();
1018: dictionary = new Dictionary<int, List<int>>();
1019:
1020: // <status id="2003" arabicName="قيد التنفيذ" />
1021: // <status id="2005" arabicName="تم التنفيذ" />
1022:
1023: var list = (from sr in db.ServiceRequests
1024: join srt in db.ServiceRequestTypes on sr.Id equals srt.ServiceRequest.Id
1025: where srt.TypeId == 12 && srt.Value != null && (sr.Status == 2003 || sr.Status == 2005)
1026: select new { ServiceBranch = sr.Number, ServiceKey = srt.Value }).ToList();
1027:
1028: foreach (var l in list)
1029: {
1030: branch = l.ServiceBranch;
1031: key0 = l.ServiceKey;
1032:
1033: // pad the single digit serial with a 0 because serials might have two digits, to preserve order
1034: key0 = Regex.Replace(key0, @"(\d{8})\/(\d)", @"$1/0$2");
1035:
1036: if (!dictionary0.ContainsKey(key0)) dictionary0[key0] = new List<int>();
1037:
1038: if (!dictionary0[key0].Contains(branch)) dictionary0[key0].Add(branch);
1039: }
1040:
1041: foreach (var l in dictionary0.Keys.OrderBy(u => u))
1042: {
1043: match = Regex.Match(l, @"(\d+)");
1044:
1045: if (match.Groups[1].Success)
1046: {
1047: s = match.Groups[1].Captures[0].Value;
1048: key = int.Parse(s);
1049:
1050: branchList = dictionary0[l];
1051:
1052: // this will replace numbers with earlier serials
1053: dictionary[key] = branchList;
1054: }
1055: else
1056: {
1057: }
1058: }
1059:
1060: }
1061:
1062: return dictionary;
1063: }
1064:
1065: ////////////////////////////////////////////////////////////////////////////
1066:
1067: /// <summary>
1068: ///
1069: /// </summary>
1070: public static Dictionary<string, List<string>> ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary()
1071: {
1072: if (changedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary == null || changedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary.Count == 0)
1073: {
1074: lock (objectLock)
1075: {
1076: changedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary();
1077: }
1078: }
1079:
1080: return changedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary;
1081: }
1082:
1083: ////////////////////////////////////////////////////////////////////////////
1084:
1085: /// <summary>
1086: ///
1087: /// </summary>
1088: private static Dictionary<string, List<string>> _ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary()
1089: {
1090: var dictionary0 = new Dictionary<string, List<string>>();
1091:
1092: var changedServiceToChangedToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedServiceToChangedToServiceListDictionary();
1093:
1094: foreach (var kvp in changedServiceToChangedToServiceListDictionary)
1095: {
1096: var changed = kvp.Key;
1097: var changedToList = kvp.Value;
1098:
1099: if (!dictionary0.ContainsKey(changed)) dictionary0[changed] = new List<string>();
1100:
1101: if (!dictionary0[changed].Contains(changed)) dictionary0[changed].Add(changed);
1102:
1103: foreach (var changedTo in changedToList)
1104: {
1105: if (!dictionary0[changed].Contains(changedTo)) dictionary0[changed].Add(changedTo);
1106: }
1107: }
1108:
1109: foreach (var kvp in changedServiceToChangedToServiceListDictionary)
1110: {
1111: var changed = kvp.Key;
1112: var changedToList = kvp.Value;
1113:
1114: foreach (var changedTo in changedToList)
1115: {
1116: if (!dictionary0.ContainsKey(changedTo)) dictionary0[changedTo] = new List<string>();
1117:
1118: if (!dictionary0[changedTo].Contains(changedTo)) dictionary0[changedTo].Add(changedTo);
1119:
1120: if (!dictionary0[changedTo].Contains(changed)) dictionary0[changedTo].Add(changed);
1121: }
1122: }
1123:
1124:
1125: var dictionary = new Dictionary<string, List<string>>();
1126:
1127: foreach (var kvp in dictionary0)
1128: {
1129: var changed = kvp.Key;
1130: var changedToList = kvp.Value;
1131:
1132: if (!dictionary.ContainsKey(changed)) dictionary[changed] = new List<string>();
1133:
1134: if (!dictionary[changed].Contains(changed)) dictionary[changed].Add(changed);
1135:
1136: foreach (var changedTo in changedToList)
1137: {
1138: if (!dictionary[changed].Contains(changedTo)) dictionary[changed].Add(changedTo);
1139:
1140: var s = dictionary0[changedTo];
1141:
1142: foreach (var t in s)
1143: {
1144: if (!dictionary[changed].Contains(t)) dictionary[changed].Add(t);
1145: }
1146:
1147: }
1148: }
1149:
1150: return dictionary;
1151: }
1152:
1153: ////////////////////////////////////////////////////////////////////////////
1154:
1155: /// <summary>
1156: ///
1157: /// </summary>
1158: public static List<string> RelatedChangedAndChangedToServiceListByService(string service)
1159: {
1160: List<string> list;
1161:
1162: var dictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary();
1163:
1164: if (dictionary.ContainsKey(service))
1165: {
1166: list = dictionary[service];
1167: }
1168: else list = new List<string>();
1169:
1170: list = list.Distinct().ToList();
1171:
1172: return list;
1173: }
1174:
1175: ////////////////////////////////////////////////////////////////////////////
1176:
1177: /// <summary>
1178: ///
1179: /// </summary>
1180: public static List<int> RelatedChangedAndChangedToServiceNumberListByServiceNumber(int serviceNumber)
1181: {
1182: List<int> list;
1183: List<string> list0;
1184:
1185: var dictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary();
1186:
1187: var service = serviceNumber.ToString();
1188:
1189: if (dictionary.ContainsKey(service))
1190: {
1191: list0 = dictionary[service];
1192: }
1193: else list0 = new List<string>();
1194:
1195: list0 = list0.Distinct().ToList();
1196:
1197: list = list0.Select(int.Parse).ToList();
1198:
1199: return list;
1200: }
1201:
1202: ////////////////////////////////////////////////////////////////////////////
1203:
1204: /// <summary>
1205: ///
1206: /// </summary>
1207: public static List<string> ServiceListAndRelatedChangedAndChangedToServiceListByServiceList(List<string> serviceList)
1208: {
1209: List<string> list;
1210:
1211: if (serviceList.Count > 0)
1212: {
1213: var dictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary();
1214:
1215: list = new List<string>();
1216:
1217: foreach (var service in serviceList)
1218: {
1219: if (dictionary.ContainsKey(service))
1220: {
1221: list.AddRange(dictionary[service]);
1222: }
1223: }
1224:
1225: list = list.Distinct().ToList();
1226:
1227: list.AddRange(serviceList);
1228: }
1229: else list = new List<string>();
1230:
1231: return list.Distinct().ToList();
1232: }
1233:
1234: ////////////////////////////////////////////////////////////////////////////
1235:
1236: /// <summary>
1237: ///
1238: /// </summary>
1239: public static List<int> ServiceNumberListAndRelatedChangedAndChangedToServiceNumberListByServiceNumberList(List<int> serviceNumberList)
1240: {
1241: List<int> list;
1242: List<string> list0;
1243:
1244: if (serviceNumberList.Count > 0)
1245: {
1246: var dictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceToRelatedChangedAndChangedToServiceListDictionary();
1247:
1248: var serviceList = serviceNumberList.ConvertAll<string>(delegate (int i) { return i.ToString(); });
1249:
1250: list0 = new List<string>();
1251:
1252: foreach (var service in serviceList)
1253: {
1254: if (dictionary.ContainsKey(service))
1255: {
1256: list0.AddRange(dictionary[service]);
1257: }
1258: }
1259:
1260: list0 = list0.Distinct().ToList();
1261:
1262: list = list0.Select(int.Parse).ToList();
1263:
1264: list.AddRange(serviceNumberList);
1265: }
1266: else list = new List<int>();
1267:
1268: return list.Distinct().ToList();
1269: }
1270:
1271: ////////////////////////////////////////////////////////////////////////////
1272:
1273: /// <summary>
1274: ///
1275: /// </summary>
1276: public static List<string> ChangedAndChangedToServiceList()
1277: {
1278: var changedServiceToChangedToServiceDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedServiceNumberToChangedToServiceNumberListDictionary();
1279:
1280: var list = new List<string>();
1281:
1282: foreach (var kvp in changedServiceToChangedToServiceDictionary)
1283: {
1284: var changed = kvp.Key;
1285: var changedToList = kvp.Value;
1286:
1287: if (!list.Contains(changed.ToString())) list.Add(changed.ToString());
1288:
1289: foreach (var changedTo in changedToList)
1290: {
1291: if (!list.Contains(changedTo.ToString())) list.Add(changedTo.ToString());
1292: }
1293: }
1294:
1295: list.Sort();
1296:
1297: return list;
1298: }
1299:
1300: ////////////////////////////////////////////////////////////////////////////
1301:
1302: /// <summary>
1303: ///
1304: /// </summary>
1305: public static List<string> ChangedAndChangedToServiceIdList()
1306: {
1307: string serviceId;
1308: var changedAndChangedToServiceList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceList();
1309:
1310: var serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.ImsService;
1311:
1312: var list = new List<string>();
1313:
1314: foreach (var service in changedAndChangedToServiceList)
1315: {
1316: serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
1317:
1318: list.Add(serviceId);
1319: }
1320:
1321: list.Sort();
1322:
1323: return list;
1324: }
1325:
1326: ////////////////////////////////////////////////////////////////////////////
1327: ////////////////////////////////////////////////////////////////////////////
1328:
1329: /// <summary>
1330: ///
1331: /// </summary>
1332: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListByDomain(List<int> domainList)
1333: {
1334: List<string> stringDomainList;
1335: List<Ia.Ngn.Cl.Model.ServiceRequest> list;
1336:
1337: stringDomainList = new List<string>();
1338:
1339: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1340: {
1341: if (domainList.Count > 0)
1342: {
1343: foreach (int i in domainList) stringDomainList.Add(i.ToString());
1344:
1345: list = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
1346: where domainList.Any(u => sr.Number.ToString().StartsWith(u.ToString()))
1347: select sr).ToList();
1348: }
1349: else list = new List<Ia.Ngn.Cl.Model.ServiceRequest>();
1350: }
1351:
1352: return list;
1353: }
1354:
1355: ////////////////////////////////////////////////////////////////////////////
1356:
1357: /// <summary>
1358: ///
1359: /// </summary>
1360: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListWithinDateTimeRange(DateTime startDateTime, DateTime endDateTime)
1361: {
1362: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1363:
1364: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1365: {
1366: serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
1367: where sr.RequestDateTime >= startDateTime && sr.RequestDateTime < endDateTime
1368: select sr).ToList();
1369: }
1370:
1371: return serviceRequestList;
1372: }
1373:
1374: ////////////////////////////////////////////////////////////////////////////
1375:
1376: /// <summary>
1377: ///
1378: /// </summary>
1379: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListWithinIdRange(int start, int end)
1380: {
1381: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1382:
1383: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1384: {
1385: serviceRequestList = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService)
1386: where sr.Id >= start && sr.Id <= end
1387: select sr)/*.AsNoTracking()*/.ToList(); // do not use .AsNoTracking() here, it will cause exception: The instance of entity type 'ServiceRequestService' cannot be tracked because another instance with the same key value for {'Id'} is ...
1388: }
1389:
1390: return serviceRequestList;
1391: }
1392:
1393: ////////////////////////////////////////////////////////////////////////////
1394:
1395: /// <summary>
1396: ///
1397: /// </summary>
1398: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ListWithinIdRangeWithoutInclude(int start, int end)
1399: {
1400: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1401:
1402: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1403: {
1404: serviceRequestList = (from sr in db.ServiceRequests
1405: where sr.Id >= start && sr.Id <= end
1406: select sr).ToList();
1407: }
1408:
1409: return serviceRequestList;
1410: }
1411:
1412: ////////////////////////////////////////////////////////////////////////////
1413: ////////////////////////////////////////////////////////////////////////////
1414:
1415: /// <summary>
1416: ///
1417: /// </summary>
1418: public static void UpdateWithServiceList(List<string> serviceList, List<Ia.Ngn.Cl.Model.ServiceRequest> newServiceRequestList, out string result)
1419: {
1420: int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, serviceRequestId;
1421: string serviceRequestServiceId;
1422: Ia.Ngn.Cl.Model.ServiceRequest serviceRequest;
1423:
1424: readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1425: result = string.Empty;
1426:
1427: readItemCount = newServiceRequestList.Count;
1428:
1429: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1430: {
1431: foreach (Ia.Ngn.Cl.Model.ServiceRequest newServiceRequest in newServiceRequestList)
1432: {
1433: serviceRequestId = newServiceRequest.Id;
1434:
1435: serviceRequest = (from sr in db.ServiceRequests
1436: where sr.Id == serviceRequestId
1437: select sr).SingleOrDefault();
1438:
1439: if (serviceRequest != null) existingItemCount++;
1440:
1441: try
1442: {
1443: if (newServiceRequest.ServiceRequestService != null)
1444: {
1445: serviceRequestServiceId = newServiceRequest.ServiceRequestService.Id;
1446:
1447: newServiceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices
1448: where srs.Id == serviceRequestServiceId
1449: select srs).SingleOrDefault();
1450: }
1451:
1452: if (serviceRequest.Update(newServiceRequest))
1453: {
1454: db.ServiceRequests.Attach(serviceRequest);
1455: db.Entry(serviceRequest).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1456:
1457: updatedItemCount++;
1458: }
1459: }
1460: catch (Exception)// e)
1461: {
1462:
1463: }
1464: }
1465:
1466: db.SaveChanges();
1467:
1468: result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")";
1469: }
1470: }
1471:
1472: ////////////////////////////////////////////////////////////////////////////
1473:
1474: /// <summary>
1475: ///
1476: /// </summary>
1477: public static bool UpdateServiceRequestService(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, out string result)
1478: {
1479: bool b;
1480:
1481: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1482: {
1483: serviceRequest = (from sr in db.ServiceRequests where sr.Id == serviceRequest.Id select sr).SingleOrDefault();
1484:
1485: if (serviceRequest.ServiceRequestService != serviceRequestService)
1486: {
1487: serviceRequest.ServiceRequestService = (from srs in db.ServiceRequestServices where srs.Id == serviceRequestService.Id select srs).SingleOrDefault();
1488:
1489: db.ServiceRequests.Attach(serviceRequest);
1490: db.Entry(serviceRequest).Property(u => u.ServiceRequestService).IsModified = true;
1491:
1492: db.SaveChanges();
1493:
1494: result = "Success: ServiceRequests ServiceRequestService updated. ";
1495: b = true;
1496: }
1497: else
1498: {
1499: result = "Warning: ServiceRequests ServiceRequestService value was not updated because its the same. ";
1500:
1501: b = false;
1502: }
1503: }
1504:
1505: return b;
1506: }
1507:
1508: ////////////////////////////////////////////////////////////////////////////
1509:
1510: /// <summary>
1511: ///
1512: /// </summary>
1513: public static void UpdateForADateTimeRangeWithOutputDataTable(DataTable dataTable, DateTime dateTime, out string result)
1514: {
1515: // below: the SQL statement should be within the dataTable.TableName variable
1516: int number, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
1517: int serviceRequestId;
1518: string sql, r, customerAddress;
1519: ArrayList newServiceRequestIdArryList;
1520: DateTime startDateTime, endDateTime;
1521: Match match;
1522: Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1523: Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
1524: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1525: List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
1526:
1527: readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1528: result = r = string.Empty;
1529:
1530: startDateTime = DateTime.MinValue;
1531:
1532: if (dataTable != null)
1533: {
1534: sql = dataTable.TableName;
1535:
1536: // select * from SRV_REQ_FIPER where REQ_DATE >= 'dd/MM/yyyy' and REQ_DATE < 'dd/MM/yyyy' order by REQ_DATE ASC, SRV_REQ_ID ASC;
1537: // select * from SRV_REQ_FIPER where REQ_DATE >= '01-10-2006' and REQ_DATE < '02-10-2006' order by REQ_DATE asc, SRV_REQ_ID asc;
1538:
1539: match = Regex.Match(sql, @".+'(\d{2})\/(\d{2})\/(\d{4})'.+'(\d{2})\/(\d{2})\/(\d{4})'.+", RegexOptions.Singleline);
1540: // 1 2 3 4 5 6
1541:
1542: if (match.Success)
1543: {
1544: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1545: {
1546: readItemCount = dataTable.Rows.Count;
1547:
1548: //if (dataTable.Rows.Count > 0)
1549: //{
1550: startDateTime = DateTime.Parse(match.Groups[3].Value + "-" + match.Groups[2].Value + "-" + match.Groups[1].Value);
1551: endDateTime = DateTime.Parse(match.Groups[6].Value + "-" + match.Groups[5].Value + "-" + match.Groups[4].Value);
1552:
1553: serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ListWithinDateTimeRange(startDateTime, endDateTime);
1554: existingItemCount = serviceRequestList.Count;
1555:
1556: newServiceRequestIdArryList = new ArrayList(dataTable.Rows.Count + 1);
1557:
1558: foreach (DataRow dataRow in dataTable.Rows)
1559: {
1560: number = int.Parse(dataRow["SRV_NO"].ToString());
1561:
1562: if (Ia.Ngn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
1563: {
1564: serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
1565:
1566: customerAddress = dataRow["ADDRESS"].ToString();
1567: serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
1568:
1569: newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
1570: {
1571: Id = serviceRequestId,
1572: Number = number,
1573:
1574: CustomerAddress = customerAddress,
1575: AreaId = serviceAddress.AreaId,
1576:
1577: CustomerCategoryId = int.Parse(dataRow["CUST_CAT_ID"].ToString()),
1578: CustomerId = int.Parse(dataRow["ACCOUNT_NO"].ToString()),
1579: CustomerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString()),
1580: RequestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString()),
1581: Serial = int.Parse(dataRow["SRV_SER_NO"].ToString()),
1582: ServiceCategoryId = int.Parse(dataRow["SRV_CAT_ID"].ToString()),
1583: ServiceId = int.Parse(dataRow["SRV_ID"].ToString()),
1584: Balance = double.Parse(dataRow["BALANCE"].ToString()),
1585: Status = int.Parse(dataRow["STATUS"].ToString())
1586: };
1587:
1588: serviceRequest = (from sr in serviceRequestList where sr.Id == newServiceRequest.Id select sr).SingleOrDefault();
1589:
1590: if (serviceRequest == null)
1591: {
1592: newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1593:
1594: db.ServiceRequests.Add(newServiceRequest);
1595:
1596: insertedItemCount++;
1597: }
1598: else
1599: {
1600: // below: copy values from newServiceRequest to serviceRequest
1601:
1602: if (serviceRequest.Update(newServiceRequest))
1603: {
1604: db.ServiceRequests.Attach(serviceRequest);
1605: db.Entry(serviceRequest).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1606:
1607: updatedItemCount++;
1608: }
1609: }
1610:
1611: newServiceRequestIdArryList.Add(serviceRequestId);
1612: }
1613: else
1614: {
1615: r += "Number: " + number + " is not within allowed domain list, ";
1616: }
1617: }
1618:
1619: // below: this function will remove values that were not present in the reading
1620: if (serviceRequestList.Count > 0)
1621: {
1622: foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
1623: {
1624: if (!newServiceRequestIdArryList.Contains(sr.Id))
1625: {
1626: serviceRequest = (from sr2 in db.ServiceRequests where sr2.Id == sr.Id select sr2).SingleOrDefault();
1627:
1628: db.ServiceRequests.Remove(serviceRequest);
1629:
1630: // below: we will also remove SRT records referensing this SR
1631: serviceRequestTypeList = (from srt in db.ServiceRequestTypes where srt.ServiceRequest.Id == sr.Id select srt).ToList();
1632:
1633: foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
1634:
1635: deletedItemCount++;
1636: }
1637: }
1638: }
1639:
1640: db.SaveChanges();
1641:
1642: result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")" + r;
1643: //}
1644: //else
1645: //{
1646: // result = "(" + readItemCount + "/?/?)";
1647: //}
1648: }
1649: }
1650: else
1651: {
1652: result = "(?/?/?: SQL in TableName is unmatched)";
1653: }
1654: }
1655: else
1656: {
1657: result = "(dataTable == null/?/?)";
1658: }
1659: }
1660:
1661: ////////////////////////////////////////////////////////////////////////////
1662:
1663: /// <summary>
1664: ///
1665: /// </summary>
1666: public static string UpdateForServiceRequestWithOutputDataTableAndIdRange(DataTable dataTable, out List<string> insertedOrUpdatedOrDeletedServiceList)
1667: {
1668: // below: the SQL statement should be within the dataTable.TableName variable
1669: int serviceRequestId, start, end, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
1670: string sql, r, customerAddress, result;
1671: ArrayList newServiceRequestIdArrayList;
1672: Match match;
1673: Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1674: Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
1675: List<int> numbersNotWithinAllowedDomainList;
1676: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1677: List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
1678:
1679: readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1680: result = r = string.Empty;
1681: numbersNotWithinAllowedDomainList = new List<int>();
1682:
1683: insertedOrUpdatedOrDeletedServiceList = new List<string>();
1684:
1685: if (dataTable != null)
1686: {
1687: sql = dataTable.TableName;
1688:
1689: // select * from SRV_REQ_FIPER where SRV_REQ_ID >= 110000 and SRV_REQ_ID <= 321203 order by REQ_DATE asc, SRV_REQ_ID asc
1690: match = Regex.Match(sql, @"SRV_REQ_ID >= (\d+) and SRV_REQ_ID <= (\d+) ", RegexOptions.Singleline);
1691: // 1 2
1692:
1693: if (match.Success)
1694: {
1695: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1696: {
1697: readItemCount = dataTable.Rows.Count;
1698:
1699: start = int.Parse(match.Groups[1].Value);
1700: end = int.Parse(match.Groups[2].Value);
1701:
1702: serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ListWithinIdRange(start, end);
1703: existingItemCount = serviceRequestList.Count;
1704:
1705: newServiceRequestIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
1706:
1707: foreach (DataRow dataRow in dataTable.Rows)
1708: {
1709: if (int.TryParse(dataRow["SRV_NO"].ToString(), out int number))
1710: {
1711: if (Ia.Ngn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
1712: {
1713: serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
1714:
1715: if (Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceRequestIdIsAllowedForProcessing(serviceRequestId))
1716: {
1717: customerAddress = dataRow["ADDRESS"].ToString();
1718:
1719: serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
1720:
1721: newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
1722: {
1723: Id = serviceRequestId,
1724: Number = number,
1725:
1726: CustomerAddress = customerAddress,
1727: AreaId = serviceAddress.AreaId,
1728:
1729: CustomerCategoryId = int.TryParse(dataRow["CUST_CAT_ID"].ToString(), out int i) ? i : 0,
1730: CustomerId = int.TryParse(dataRow["ACCOUNT_NO"].ToString(), out i) ? i : 0,
1731: CustomerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString()),
1732: RequestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString()),
1733: Serial = int.TryParse(dataRow["SRV_SER_NO"].ToString(), out i) ? i : 0,
1734: ServiceCategoryId = int.TryParse(dataRow["SRV_CAT_ID"].ToString(), out i) ? i : 0,
1735: ServiceId = int.TryParse(dataRow["SRV_ID"].ToString(), out i) ? i : 0,
1736: Balance = double.Parse(dataRow["BALANCE"].ToString()),
1737:
1738: Status = int.TryParse(dataRow["STATUS"].ToString(), out i) ? i : 0
1739: };
1740:
1741: serviceRequest = (from sr in serviceRequestList
1742: where sr.Id == newServiceRequest.Id
1743: select sr).SingleOrDefault();
1744:
1745: if (serviceRequest == null)
1746: {
1747: newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1748:
1749: db.ServiceRequests.Add(newServiceRequest);
1750:
1751: insertedOrUpdatedOrDeletedServiceList.Add(newServiceRequest.Number.ToString());
1752: insertedItemCount++;
1753: }
1754: else
1755: {
1756: // below: copy values from newServiceRequest to serviceRequest
1757:
1758: if (serviceRequest.UpdateSkipServiceRequestServiceAndCheckIfOnlyBalanceWasUpdated(newServiceRequest, out bool onlyBalanceWasUpdated))
1759: {
1760: db.ServiceRequests.Attach(serviceRequest);
1761: db.Entry(serviceRequest).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1762:
1763: if (!onlyBalanceWasUpdated) insertedOrUpdatedOrDeletedServiceList.Add(serviceRequest.Number.ToString());
1764:
1765: updatedItemCount++;
1766: }
1767: }
1768:
1769: newServiceRequestIdArrayList.Add(serviceRequestId); // keep at the end
1770: }
1771: else
1772: {
1773:
1774: }
1775: }
1776: else
1777: {
1778: numbersNotWithinAllowedDomainList.Add(number);
1779: }
1780: }
1781: else
1782: {
1783: //
1784: }
1785: }
1786:
1787: /*
1788: if (numbersNotWithinAllowedDomainList.Count > 0)
1789: {
1790: r = "Numbers not within allowed domain list: ";
1791:
1792: foreach (int n in numbersNotWithinAllowedDomainList) r += n + ",";
1793:
1794: r = r.Trim(',');
1795: }
1796: */
1797:
1798: // below: this function will remove values that were not present in the reading
1799: if (serviceRequestList.Count > 0)
1800: {
1801: foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
1802: {
1803: if (!newServiceRequestIdArrayList.Contains(sr.Id))
1804: {
1805: serviceRequest = (from sr2 in db.ServiceRequests
1806: where sr2.Id == sr.Id
1807: select sr2).SingleOrDefault();
1808:
1809: db.ServiceRequests.Remove(serviceRequest);
1810:
1811: // below: we will also remove SRT records referensing this SR
1812: serviceRequestTypeList = (from srt in db.ServiceRequestTypes
1813: where srt.ServiceRequest.Id == sr.Id
1814: select srt).ToList();
1815:
1816: foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
1817:
1818: insertedOrUpdatedOrDeletedServiceList.Add(serviceRequest.Number.ToString());
1819: deletedItemCount++;
1820: }
1821: }
1822: }
1823:
1824: db.SaveChanges();
1825:
1826: //if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
1827: //else isUpdated = false;
1828:
1829: result = "(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")" + r;
1830: }
1831: }
1832: else
1833: {
1834: result = "(?/?/?: SQL in TableName is unmatched)";
1835: }
1836: }
1837: else
1838: {
1839: result = "(dataTable == null/?/?)";
1840: }
1841:
1842: return result;
1843: }
1844:
1845: ////////////////////////////////////////////////////////////////////////////
1846:
1847: /// <summary>
1848: ///
1849: /// </summary>
1850: public static void UpdateForServiceRequestWithOutputDataTableAndService(DataTable dataTable, string service, out bool isUpdated, out Ia.Cl.Model.Result result)
1851: {
1852: int serviceRequestId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
1853: string sql, sqlService, r;
1854:
1855: int id, number, areaId, customerCategoryId, customerId, serial, serviceCategoryId, serviceId, statusId;
1856: double balance;
1857: string customerAddress, customerName;
1858: DateTime requestDateTime;
1859:
1860: ArrayList newServiceRequestIdArrayList;
1861: Match match;
1862:
1863: Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
1864: Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, newServiceRequest;
1865: List<int> numbersNotWithinAllowedDomainList;
1866: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
1867: List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
1868:
1869: isUpdated = false;
1870: readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
1871: numbersNotWithinAllowedDomainList = new List<int>();
1872:
1873: result = new Ia.Cl.Model.Result();
1874:
1875: if (dataTable != null)
1876: {
1877: // below: the SQL statement should be within the dataTable.TableName variable
1878: sql = dataTable.TableName;
1879:
1880: // select * from SRV_REQ_FIPER where SRV_NO = 23632222 order by SRV_REQ_ID asc
1881: match = Regex.Match(sql, @"SRV_NO = (\d+) order by SRV_REQ_ID asc", RegexOptions.Singleline);
1882:
1883: if (match.Success)
1884: {
1885: using (var db = new Ia.Ngn.Cl.Model.Ngn())
1886: {
1887: readItemCount = dataTable.Rows.Count;
1888:
1889: sqlService = match.Groups[1].Value;
1890:
1891: if (service == sqlService)
1892: {
1893: serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(service);
1894: existingItemCount = serviceRequestList.Count;
1895:
1896: newServiceRequestIdArrayList = new ArrayList(dataTable.Rows.Count + 1);
1897:
1898: foreach (DataRow dataRow in dataTable.Rows)
1899: {
1900: if (int.TryParse(dataRow["SRV_NO"].ToString(), out number))
1901: {
1902: if (Ia.Ngn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
1903: {
1904: serviceRequestId = int.Parse(dataRow["SRV_REQ_ID"].ToString());
1905: customerAddress = dataRow["ADDRESS"].ToString();
1906:
1907: customerCategoryId = int.TryParse(dataRow["CUST_CAT_ID"].ToString(), out int i) ? i : 0;
1908: customerId = int.TryParse(dataRow["ACCOUNT_NO"].ToString(), out i) ? i : 0;
1909: customerName = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerName(dataRow["NAME"].ToString());
1910: requestDateTime = DateTime.Parse(dataRow["REQ_DATE"].ToString());
1911: serial = int.TryParse(dataRow["SRV_SER_NO"].ToString(), out i) ? i : 0;
1912: serviceCategoryId = int.TryParse(dataRow["SRV_CAT_ID"].ToString(), out i) ? i : 0;
1913: serviceId = int.TryParse(dataRow["SRV_ID"].ToString(), out i) ? i : 0;
1914: balance = double.Parse(dataRow["BALANCE"].ToString());
1915: statusId = int.TryParse(dataRow["STATUS"].ToString(), out i) ? i : 0;
1916:
1917: if (Ia.Ngn.Cl.Model.Data.ServiceRequest.StatusSortedList.ContainsKey(statusId))
1918: {
1919: if (Ia.Ngn.Cl.Model.Data.ServiceRequest.CustomerCategorySortedList.ContainsKey(customerCategoryId))
1920: {
1921: if (Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceCategorySortedList.ContainsKey(serviceCategoryId))
1922: {
1923: if (Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceSortedList.ContainsKey(serviceId))
1924: {
1925: serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(number.ToString(), customerAddress, out string level);
1926:
1927: newServiceRequest = new Ia.Ngn.Cl.Model.ServiceRequest()
1928: {
1929: Id = serviceRequestId,
1930: Number = number,
1931: CustomerAddress = customerAddress,
1932: AreaId = serviceAddress.AreaId,
1933: CustomerCategoryId = customerCategoryId,
1934: CustomerId = customerId,
1935: CustomerName = customerName,
1936: RequestDateTime = requestDateTime,
1937: Serial = serial,
1938: ServiceCategoryId = serviceCategoryId,
1939: ServiceId = serviceId,
1940: Balance = balance,
1941: Status = statusId
1942: };
1943:
1944: serviceRequest = (from sr in serviceRequestList
1945: where sr.Id == newServiceRequest.Id
1946: select sr).SingleOrDefault();
1947:
1948: if (serviceRequest == null)
1949: {
1950: newServiceRequest.Created = newServiceRequest.Updated = DateTime.UtcNow.AddHours(3);
1951:
1952: db.ServiceRequests.Add(newServiceRequest);
1953:
1954: insertedItemCount++;
1955: }
1956: else
1957: {
1958: // below: copy values from newServiceRequest to serviceRequest
1959:
1960: if (serviceRequest.UpdateSkipServiceRequestService(newServiceRequest))
1961: {
1962: db.ServiceRequests.Attach(serviceRequest);
1963: db.Entry(serviceRequest).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
1964:
1965: updatedItemCount++;
1966: }
1967: }
1968:
1969: newServiceRequestIdArrayList.Add(serviceRequestId); // keep at the end
1970: }
1971: else result.AddError("Service " + serviceId + " is undefined.");
1972: }
1973: else result.AddError("ServiceCategory " + serviceCategoryId + " is undefined.");
1974: }
1975: else result.AddError("CustomerCategory " + customerCategoryId + " is undefined.");
1976: }
1977: else result.AddError("Status " + statusId + " is undefined.");
1978: }
1979: else numbersNotWithinAllowedDomainList.Add(number);
1980: }
1981: else
1982: {
1983: //
1984: }
1985: }
1986:
1987: /*
1988: if (numbersNotWithinAllowedDomainList.Count > 0)
1989: {
1990: r = "Numbers not within allowed domain list: ";
1991:
1992: foreach (int n in numbersNotWithinAllowedDomainList) r += n + ",";
1993:
1994: r = r.Trim(',');
1995: }
1996: */
1997:
1998: // below: this function will remove values that were not present in the reading
1999: if (serviceRequestList.Count > 0)
2000: {
2001: foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList)
2002: {
2003: if (!newServiceRequestIdArrayList.Contains(sr.Id))
2004: {
2005: serviceRequest = (from sr2 in db.ServiceRequests
2006: where sr2.Id == sr.Id
2007: select sr2).SingleOrDefault();
2008:
2009: db.ServiceRequests.Remove(serviceRequest);
2010:
2011: // below: we will also remove SRT records referencing this SR
2012: serviceRequestTypeList = (from srt in db.ServiceRequestTypes
2013: where srt.ServiceRequest.Id == sr.Id
2014: select srt).ToList();
2015:
2016: foreach (Ia.Ngn.Cl.Model.ServiceRequestType srt in serviceRequestTypeList) db.ServiceRequestTypes.Remove(srt);
2017:
2018: deletedItemCount++;
2019: }
2020: }
2021: }
2022:
2023: db.SaveChanges();
2024:
2025: if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
2026: else isUpdated = false;
2027:
2028: result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
2029: }
2030: else
2031: {
2032: throw new ArgumentException(@"UpdateForServiceRequestWithOutputDataTableAndService(): service != sqlService, service: " + service + ", sqlService: " + sqlService);
2033: }
2034: }
2035: }
2036: else result.AddError("(?/?/?: SQL in TableName is unmatched)");
2037: }
2038: else result.AddError("(dataTable == null/?/?)");
2039: }
2040:
2041: ////////////////////////////////////////////////////////////////////////////
2042:
2043: /// <summary>
2044: ///
2045: /// </summary>
2046: public static Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest> ServiceToServiceRequestDictionary(List<int> domainList)
2047: {
2048: string key;
2049: List<string> stringDomainList;
2050: List<Ia.Ngn.Cl.Model.ServiceRequest> list;
2051: Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest> dictionary;
2052:
2053: stringDomainList = new List<string>();
2054:
2055: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2056: {
2057: if (domainList.Count > 0)
2058: {
2059: foreach (int i in domainList) stringDomainList.Add(i.ToString());
2060:
2061: list = (from sr in db.ServiceRequests.Include(a => a.ServiceRequestService).Include(a => a.ServiceRequestTypes) where domainList.Any(u => sr.Number.ToString().StartsWith(u.ToString())) orderby sr.RequestDateTime ascending select sr).ToList();
2062:
2063: dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest>(list.Count);
2064:
2065: foreach (var sr in list)
2066: {
2067: key = sr.Number.ToString();
2068:
2069: if (dictionary.ContainsKey(key))
2070: {
2071: dictionary[key] = sr;
2072: }
2073: else dictionary[key] = sr;
2074: }
2075: }
2076: else dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.ServiceRequest>();
2077: }
2078:
2079: return dictionary;
2080: }
2081:
2082: ////////////////////////////////////////////////////////////////////////////
2083:
2084: /// <summary>
2085: ///
2086: /// </summary>
2087: public static Hashtable NumberToCustomerAddressHashtable(List<int> domainList)
2088: {
2089: Hashtable hashtable;
2090: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
2091:
2092: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2093: {
2094: if (domainList.Count > 0)
2095: {
2096: serviceRequestList = (from sr in db.ServiceRequests
2097: where domainList.Contains(sr.Number / 10000) || domainList.Contains(sr.Number / 1000)
2098: select sr).AsNoTracking().ToList();
2099:
2100: hashtable = new Hashtable(serviceRequestList.Count);
2101:
2102: foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList.OrderBy(u => u.Id)) hashtable[sr.Number.ToString()] = sr.CustomerAddress;
2103: }
2104: else hashtable = new Hashtable();
2105: }
2106:
2107: return hashtable;
2108: }
2109:
2110: ////////////////////////////////////////////////////////////////////////////
2111:
2112: /// <summary>
2113: ///
2114: /// </summary>
2115: public static DateTime LatestRequestDateTime(int number)
2116: {
2117: DateTime dateTime;
2118: Ia.Ngn.Cl.Model.ServiceRequest serviceRequest;
2119: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
2120:
2121: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2122: {
2123: serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(number);
2124:
2125: if (serviceRequestList.Count > 0)
2126: {
2127: serviceRequest = serviceRequestList.OrderByDescending(u => u.Id).FirstOrDefault();
2128:
2129: dateTime = serviceRequest.RequestDateTime;
2130: }
2131: else
2132: {
2133: dateTime = DateTime.MinValue;
2134: }
2135: }
2136:
2137: return dateTime;
2138: }
2139:
2140: ////////////////////////////////////////////////////////////////////////////
2141:
2142: /// <summary>
2143: ///
2144: /// </summary>
2145: public static List<Ia.Ngn.Cl.Model.ServiceRequest> LastN(int numberOfServiceRequests)
2146: {
2147: // below:
2148: List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
2149:
2150: serviceRequestList = null;
2151:
2152: try
2153: {
2154: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2155: {
2156: serviceRequestList = (from sr in db.ServiceRequests orderby sr.RequestDateTime descending select sr).Take(numberOfServiceRequests).ToList();
2157: }
2158: }
2159: catch (Exception)
2160: {
2161: //resultLabel.Text = "Error during retrieval of data for \"" + ip + "\": " + ex.Message + ". ";
2162: //resultLabel.CssClass = "error";
2163: }
2164:
2165: return serviceRequestList;
2166: }
2167:
2168: ////////////////////////////////////////////////////////////////////////////
2169:
2170: /// <summary>
2171: ///
2172: /// </summary>
2173: public static List<Ia.Ngn.Cl.Model.ServiceRequest> ForRequestDate(DateTime requestDate)
2174: {
2175: DateTime nextDate;
2176: List<Ia.Ngn.Cl.Model.ServiceRequest> list;
2177:
2178: // below: 00:00 time values
2179: requestDate = requestDate.Date;
2180:
2181: nextDate = requestDate.AddDays(1);
2182:
2183: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2184: {
2185: list = (from sr in db.ServiceRequests
2186: where sr.RequestDateTime >= requestDate && sr.RequestDateTime < nextDate
2187: orderby sr.RequestDateTime descending
2188: select sr).AsNoTracking().ToList();
2189: }
2190:
2191: return list;
2192: }
2193:
2194: ////////////////////////////////////////////////////////////////////////////
2195: ////////////////////////////////////////////////////////////////////////////
2196:
2197: /// <summary>
2198: ///
2199: /// </summary>
2200: public static Dictionary<string, string> ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary
2201: {
2202: get
2203: {
2204: if (serviceToAccessNameWithinAllowedToBeMigratedOltDictionary == null || serviceToAccessNameWithinAllowedToBeMigratedOltDictionary.Count == 0)
2205: {
2206: lock (objectLock)
2207: {
2208: serviceToAccessNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary;
2209: }
2210: }
2211:
2212: return serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
2213: }
2214: }
2215:
2216: ////////////////////////////////////////////////////////////////////////////
2217:
2218: /// <summary>
2219: ///
2220: /// </summary>
2221: private static Dictionary<string, string> _ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary
2222: {
2223: get
2224: {
2225: Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
2226: Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceAddress> serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary;
2227:
2228: var areaSymbolList = Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList;
2229:
2230: var kuwaitOfnAreaList = (from k in Ia.Ngn.Cl.Model.Data.Service.KuwaitOfnAreaList
2231: where areaSymbolList.Contains(k.Symbol)
2232: select k.Id).ToList();
2233:
2234: var serviceToDbNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceToDbNameWithinAllowedToBeMigratedOltDictionary;
2235: var serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceToCustomerAddressWithinAllowedToBeMigratedOltDictionary;
2236:
2237: serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceAddress>(serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary.Count);
2238:
2239: foreach (KeyValuePair<string, string> kvp in serviceToCustomerAddressWithinAllowedToBeMigratedOltDictionary)
2240: {
2241: var service = kvp.Key;
2242: var address = kvp.Value;
2243: serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.ServiceAddress(service, address, out string level);
2244:
2245: serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary[service] = serviceAddress;
2246: }
2247:
2248: serviceToAccessNameWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, string>(serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary.Count);
2249: var ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary;
2250:
2251: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2252: {
2253: var accessList = (from a in db.Accesses
2254: where kuwaitOfnAreaList.Contains(a.AreaId)
2255: select new Ia.Ngn.Cl.Model.Ui.Access { Id = a.Id, AreaId = a.AreaId, Block = a.Block, Street = a.Street, PremisesOld = a.PremisesOld, PremisesNew = a.PremisesNew }).ToList();
2256:
2257: foreach (var access in accessList)
2258: {
2259: if (ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary.ContainsKey(access.Id))
2260: {
2261: access.Name = ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary[access.Id];
2262: }
2263: else access.Name = string.Empty;
2264: }
2265:
2266: foreach (var kvp in serviceToServiceAddressWithinAllowedToBeMigratedOltDictionary)
2267: {
2268: serviceAddress = new Ia.Ngn.Cl.Model.Business.ServiceAddress();
2269:
2270: serviceAddress.AreaId = kvp.Value.AreaId;
2271: serviceAddress.Block = kvp.Value.Block;
2272: serviceAddress.Street = kvp.Value.Street;
2273: serviceAddress.Boulevard = kvp.Value.Boulevard;
2274: serviceAddress.PremisesOld = kvp.Value.PremisesOld;
2275: serviceAddress.PremisesNew = kvp.Value.PremisesNew;
2276: serviceAddress.Paci = kvp.Value.Paci;
2277:
2278: var statisticalAccess = Ia.Ngn.Cl.Model.Data.Access.StatisticalAccess(serviceAddress, ref accessList, out string note2);
2279: if (statisticalAccess != null) statisticalAccess.Note = note2;
2280:
2281: serviceToAccessNameWithinAllowedToBeMigratedOltDictionary[kvp.Key] = statisticalAccess != null ? statisticalAccess.Name : string.Empty;
2282: }
2283: }
2284:
2285: return serviceToAccessNameWithinAllowedToBeMigratedOltDictionary;
2286: }
2287: }
2288:
2289: ////////////////////////////////////////////////////////////////////////////
2290:
2291: /// <summary>
2292: ///
2293: /// </summary>
2294: public static Dictionary<string, List<string>> AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary
2295: {
2296: get
2297: {
2298: DateTime now;
2299: Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
2300:
2301: now = DateTime.UtcNow.AddHours(3);
2302: validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
2303:
2304: if (accessNameToServiceListWithinAllowedToBeMigratedOltDictionary == null || accessNameToServiceListWithinAllowedToBeMigratedOltDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp))
2305: {
2306: lock (objectLock)
2307: {
2308: accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary();
2309: }
2310: }
2311:
2312: return accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
2313: }
2314: }
2315:
2316: ////////////////////////////////////////////////////////////////////////////
2317:
2318: /// <summary>
2319: ///
2320: /// </summary>
2321: private static Dictionary<string, List<string>> _AccessNameToServiceListWithinAllowedToBeMigratedOltDictionary()
2322: {
2323: string key, value;
2324: List<string> valueList;
2325:
2326: var now = DateTime.UtcNow.AddHours(3);
2327:
2328: var serviceToAccessNameDictionary = ServiceToAccessNameWithinAllowedToBeMigratedOltDictionary;
2329:
2330: accessNameToServiceListWithinAllowedToBeMigratedOltDictionary = new Dictionary<string, List<string>>(serviceToAccessNameDictionary.Count);
2331:
2332: foreach (var kvp in serviceToAccessNameDictionary)
2333: {
2334: key = kvp.Value;
2335:
2336: if (!string.IsNullOrEmpty(key))
2337: {
2338: value = kvp.Key;
2339:
2340: valueList = new List<string>();
2341:
2342: if (!accessNameToServiceListWithinAllowedToBeMigratedOltDictionary.ContainsKey(key))
2343: {
2344: valueList.Add(value);
2345:
2346: accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key] = valueList;
2347: }
2348: else
2349: {
2350: valueList = accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key];
2351: valueList.Add(value);
2352:
2353: accessNameToServiceListWithinAllowedToBeMigratedOltDictionary[key] = valueList;
2354: }
2355: }
2356: }
2357:
2358: accessNameToServiceListWithinAllowedToBeMigratedOltDictionaryTimestamp = now;
2359:
2360: return accessNameToServiceListWithinAllowedToBeMigratedOltDictionary;
2361: }
2362:
2363: ////////////////////////////////////////////////////////////////////////////
2364:
2365: /// <summary>
2366: ///
2367: /// </summary>
2368: public static List<string> DbPeerServiceList(List<string> serviceList)
2369: {
2370: List<string> list;
2371:
2372: if (serviceList.Count > 0)
2373: {
2374: var dbNameToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest.DbNameToServiceListDictionary;
2375:
2376: var listList = (from d in dbNameToServiceListDictionary
2377: where serviceList.Any(u => d.Value.Contains(u))
2378: select d.Value).ToList();
2379:
2380: var list0 = listList.SelectMany(x => x).ToList();
2381:
2382: list = list0.Distinct().ToList();
2383: }
2384: else list = new List<string>();
2385:
2386: return list;
2387: }
2388:
2389: ////////////////////////////////////////////////////////////////////////////
2390:
2391: /// <summary>
2392: ///
2393: /// </summary>
2394: public static Dictionary<string, List<string>> DbNameToServiceListDictionary
2395: {
2396: get
2397: {
2398: Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
2399:
2400: var dateTime = DateTime.UtcNow.AddHours(3);
2401: validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
2402:
2403: if (dbNameToServiceListDictionary == null || dbNameToServiceListDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, dateTime, dbNameToServiceListDictionaryTimestamp))
2404: {
2405: lock (objectLock)
2406: {
2407: dbNameToServiceListDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequest._DbNameToServiceListDictionary();
2408: }
2409: }
2410:
2411: return dbNameToServiceListDictionary;
2412: }
2413: }
2414:
2415: ////////////////////////////////////////////////////////////////////////////
2416:
2417: /// <summary>
2418: ///
2419: /// </summary>
2420: private static Dictionary<string, List<string>> _DbNameToServiceListDictionary()
2421: {
2422: string key, value;
2423: DateTime now;
2424:
2425: List<string> valueList;
2426:
2427: now = DateTime.UtcNow.AddHours(3);
2428:
2429: var serviceToDbNameDictionary = ServiceToDbNameWithinAllowedToBeMigratedOltDictionary;
2430:
2431: dbNameToServiceListDictionary = new Dictionary<string, List<string>>(serviceToDbNameDictionary.Count);
2432:
2433: foreach (KeyValuePair<string, string> kvp in serviceToDbNameDictionary)
2434: {
2435: key = kvp.Value;
2436:
2437: if (!string.IsNullOrEmpty(key) && key != ":")
2438: {
2439: value = kvp.Key;
2440:
2441: valueList = new List<string>();
2442:
2443: if (!dbNameToServiceListDictionary.ContainsKey(key))
2444: {
2445: valueList.Add(value);
2446:
2447: dbNameToServiceListDictionary[key] = valueList;
2448: }
2449: else
2450: {
2451: valueList = dbNameToServiceListDictionary[key];
2452: valueList.Add(value);
2453:
2454: dbNameToServiceListDictionary[key] = valueList;
2455: }
2456: }
2457: }
2458:
2459: dbNameToServiceListDictionaryTimestamp = now;
2460:
2461: return dbNameToServiceListDictionary;
2462: }
2463:
2464: ////////////////////////////////////////////////////////////////////////////
2465:
2466: /// <summary>
2467: ///
2468: /// </summary>
2469: public static Dictionary<string, string> ServiceToDbNameWithinAllowedToBeMigratedOltDictionary
2470: {
2471: get
2472: {
2473: DateTime now;
2474: Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
2475:
2476: now = DateTime.UtcNow.AddHours(3);
2477: validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.TwelveHours;
2478:
2479: if (serviceToDbNameDictionary == null || serviceToDbNameDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp))
2480: {
2481: lock (objectLock)
2482: {
2483: Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(out serviceToDbNameDictionary, out serviceToCustomerAddressDictionary);
2484: }
2485: }
2486:
2487: return serviceToDbNameDictionary;
2488: }
2489: }
2490:
2491: ////////////////////////////////////////////////////////////////////////////
2492:
2493: /// <summary>
2494: ///
2495: /// </summary>
2496: public static Dictionary<string, string> ServiceToCustomerAddressWithinAllowedToBeMigratedOltDictionary
2497: {
2498: get
2499: {
2500: DateTime now;
2501: Ia.Ngn.Cl.Model.Business.Default.ValidityOfData validityOfData;
2502:
2503: now = DateTime.UtcNow.AddHours(3);
2504: validityOfData = Ia.Ngn.Cl.Model.Business.Default.ValidityOfData.Day;
2505:
2506: if (serviceToCustomerAddressDictionary == null || serviceToCustomerAddressDictionary.Count == 0 || !Ia.Ngn.Cl.Model.Business.Default.DataIsValid(validityOfData, now, serviceToDbNameDictionaryAndServiceToCustomerAddressDictionaryTimestamp))
2507: {
2508: lock (objectLock)
2509: {
2510: Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(out serviceToDbNameDictionary, out serviceToCustomerAddressDictionary);
2511: }
2512: }
2513:
2514: return serviceToCustomerAddressDictionary;
2515: }
2516: }
2517:
2518: ////////////////////////////////////////////////////////////////////////////
2519:
2520: /// <summary>
2521: ///
2522: /// </summary>
2523: private static void _ServiceToDbNameDictionaryAndServiceToCustomerAddressDictionary(out Dictionary<string, string> serviceToDbNameDictionary, out Dictionary<string, string> serviceToCustomerAddressDictionary)
2524: {
2525: Dictionary<string, int> serviceToLastSerialDictionary;
2526:
2527: var areaSymbolList = Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList;
2528:
2529: var areaIdList = (from k in Ia.Ngn.Cl.Model.Data.Service.KuwaitOfnAreaList
2530: where areaSymbolList.Contains(k.Symbol)
2531: select k.Id).ToList();
2532:
2533: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2534: {
2535: var statisticalVariableList = (from sr in db.ServiceRequests
2536: //join srs in db.ServiceRequestServices on sr.Number.ToString() equals srs.Service // on sr.ServiceRequestService.Id equals srs.Id
2537: join srt in db.ServiceRequestTypes on sr.Id equals srt.ServiceRequest.Id into srts
2538: from srt in srts.DefaultIfEmpty()
2539: where areaIdList.Contains(sr.AreaId) && (srt == null || srt.TypeId == 1 || srt.TypeId == 2)
2540: select new Ia.Ngn.Cl.Model.Business.ServiceRequestStatisticalVariable
2541: {
2542: //Provisioned = srs.Provisioned,
2543: ServiceRequestId = sr.Id,
2544: Service = sr.Number.ToString(),
2545: Serial = sr.Serial,
2546: AreaId = sr.AreaId,
2547: CustomerAddress = sr.CustomerAddress,
2548: /* CustomerName = sr.CustomerName, */
2549: ServiceRequestTypeValue = srt == null ? string.Empty : srt.Value,
2550: }).ToList();
2551:
2552: serviceToLastSerialDictionary = new Dictionary<string, int>(statisticalVariableList.Count);
2553: serviceToDbNameDictionary = new Dictionary<string, string>(statisticalVariableList.Count);
2554: serviceToCustomerAddressDictionary = new Dictionary<string, string>(statisticalVariableList.Count);
2555:
2556: foreach (var sv in statisticalVariableList/*.Where(u => u.Provisioned)*/.OrderBy(u => u.ServiceRequestId))
2557: {
2558: serviceToLastSerialDictionary[sv.Service] = sv.Serial;
2559: }
2560:
2561: foreach (var sv in statisticalVariableList/*.Where(u => u.Provisioned)*/.OrderBy(u => u.ServiceRequestId))
2562: {
2563: if (serviceToLastSerialDictionary[sv.Service] == sv.Serial)
2564: {
2565: if (serviceToDbNameDictionary.ContainsKey(sv.Service))
2566: {
2567: // ServiceRequestTypes values do not contain ":"
2568: if (!serviceToDbNameDictionary[sv.Service].Contains(":")) serviceToDbNameDictionary[sv.Service] += ":" + sv.ServiceRequestTypeValue;
2569: }
2570: else serviceToDbNameDictionary[sv.Service] = sv.ServiceRequestTypeValue;
2571:
2572: if (!serviceToCustomerAddressDictionary.ContainsKey(sv.Service)) serviceToCustomerAddressDictionary[sv.Service] = sv.CustomerAddress;
2573: }
2574: }
2575: }
2576: }
2577:
2578: ////////////////////////////////////////////////////////////////////////////
2579: ////////////////////////////////////////////////////////////////////////////
2580:
2581: /// <summary>
2582: ///
2583: /// </summary>
2584: public static List<int> ServiceRequestDomainList
2585: {
2586: get
2587: {
2588: if (serviceRequestDomainList == null || serviceRequestDomainList.Count == 0)
2589: {
2590: lock (objectLock)
2591: {
2592: serviceRequestDomainList = Ia.Ngn.Cl.Model.Data.ServiceRequest._ServiceRequestDomainList;
2593: }
2594: }
2595:
2596: return serviceRequestDomainList;
2597: }
2598: }
2599:
2600: ////////////////////////////////////////////////////////////////////////////
2601:
2602: /// <summary>
2603: ///
2604: /// </summary>
2605: private static List<int> _ServiceRequestDomainList
2606: {
2607: get
2608: {
2609: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2610: {
2611: var fourDigitList = (from sr in db.ServiceRequests select sr.Number.ToString().Substring(0, 4)).Distinct().ToList();
2612: var fiveDigitList = (from sr in db.ServiceRequests select sr.Number.ToString().Substring(0, 5)).Distinct().ToList();
2613:
2614: var list = new List<string>();
2615:
2616: foreach (var fourDigit in fourDigitList)
2617: {
2618: if (
2619: fiveDigitList.Any(u => u == fourDigit + "0")
2620: && fiveDigitList.Any(u => u == fourDigit + "1")
2621: && fiveDigitList.Any(u => u == fourDigit + "2")
2622: && fiveDigitList.Any(u => u == fourDigit + "3")
2623: && fiveDigitList.Any(u => u == fourDigit + "4")
2624: && fiveDigitList.Any(u => u == fourDigit + "5")
2625: && fiveDigitList.Any(u => u == fourDigit + "6")
2626: && fiveDigitList.Any(u => u == fourDigit + "7")
2627: && fiveDigitList.Any(u => u == fourDigit + "8")
2628: && fiveDigitList.Any(u => u == fourDigit + "9")
2629: ) list.Add(fourDigit);
2630: else
2631: {
2632: foreach (var fiveDigit in fiveDigitList)
2633: {
2634: if (fiveDigit.StartsWith(fourDigit)) list.Add(fiveDigit);
2635: }
2636: }
2637: }
2638:
2639: serviceRequestDomainList = list.Select(int.Parse).ToList();
2640:
2641: serviceRequestDomainList.Sort();
2642: }
2643:
2644: return serviceRequestDomainList;
2645: }
2646: }
2647:
2648: ////////////////////////////////////////////////////////////////////////////
2649:
2650: /// <summary>
2651: ///
2652: /// </summary>
2653: public static Dictionary<DateTime, int> RequestDateTimeWeekToCountDictionary()
2654: {
2655: var dictionary = new Dictionary<DateTime, int>();
2656:
2657: using (var db = new Ia.Ngn.Cl.Model.Ngn())
2658: {
2659: // too complicated
2660: /*
2661: dictionary = (from sr in db.ServiceRequests
2662: group sr by SqlFunctions.DateAdd("ww", SqlFunctions.DateDiff("ww", DateTime.MinValue, sr.RequestDateTime), DateTime.MinValue) into sr1
2663: select new { RequestDateTime = sr1.Key }).ToList();//, ServiceCount = sr1.Count() }).AsNoTracking().ToDictionary(t => t.RequestDateTime, t => t.ServiceCount);
2664: */
2665: }
2666:
2667: return dictionary;
2668: }
2669:
2670: ////////////////////////////////////////////////////////////////////////////
2671: ////////////////////////////////////////////////////////////////////////////
2672:
2673: /// <summary>
2674: ///
2675: /// </summary>
2676: public static string ToSimpleTextString(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
2677: {
2678: StringBuilder sb;
2679:
2680: sb = new StringBuilder();
2681:
2682: // Id Number Serial Status RequestDateTime Service ServiceCategory CustomerId CustomerName CustomerCategory CustomerAddress Balance
2683: sb.AppendLine("Id: " + serviceRequest.Id);
2684: sb.AppendLine("Number: " + serviceRequest.Number + "/" + serviceRequest.Serial);
2685: //sb.AppendLine("Serial: " + serviceRequest.Serial);
2686: sb.AppendLine("Status: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.StatusSortedList[serviceRequest.Status].ToString());
2687: sb.AppendLine("RequestDateTime: " + serviceRequest.RequestDateTime.ToString("yyyy-MM-dd HH:mm"));
2688: sb.AppendLine("Service: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceSortedList[serviceRequest.ServiceId].ToString());
2689: //sb.AppendLine("ServiceCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceCategorySortedList[serviceRequest.ServiceCategoryId].ToString());
2690: //sb.AppendLine("CustomerId: " + serviceRequest.CustomerId);
2691: sb.AppendLine("CustomerName: " + serviceRequest.CustomerName);
2692: //sb.AppendLine("CustomerCategory: " + Ia.Ngn.Cl.Model.Data.ServiceRequest.CustomerCategorySortedList[serviceRequest.CustomerCategoryId].ToString());
2693:
2694: sb.AppendLine("CustomerAddress: " + serviceRequest.CustomerAddress);
2695: //sb.AppendLine("Balance: " + serviceRequest.Balance);
2696:
2697: return sb.ToString();
2698: }
2699:
2700: ////////////////////////////////////////////////////////////////////////////
2701:
2702: /// <summary>
2703: ///
2704: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
2705: ///
2706: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
2707: /// 2. Add "using System.Reflection".
2708: /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
2709: ///
2710: /// </summary>
2711:
2712: private static XDocument XDocument
2713: {
2714: get
2715: {
2716: if (xDocument == null)
2717: {
2718: lock (objectLock)
2719: {
2720: Assembly _assembly;
2721: StreamReader streamReader;
2722:
2723: _assembly = Assembly.GetExecutingAssembly();
2724: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.service-request.xml"));
2725:
2726: try
2727: {
2728: if (streamReader.Peek() != -1)
2729: {
2730: xDocument = System.Xml.Linq.XDocument.Load(streamReader);
2731: }
2732: }
2733: catch (Exception)
2734: {
2735: }
2736: finally
2737: {
2738: }
2739: }
2740: }
2741:
2742: return xDocument;
2743: }
2744: }
2745:
2746: ////////////////////////////////////////////////////////////////////////////
2747: ////////////////////////////////////////////////////////////////////////////
2748: }
2749:
2750: ////////////////////////////////////////////////////////////////////////////
2751: ////////////////////////////////////////////////////////////////////////////
2752: }