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

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

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

    1: using Microsoft.AspNetCore.Identity;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Business
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Report support class of Fixed Telecommunications Network (FTN) business model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class Report
   29:     {
   30:         public enum Status { Open = 1, Closed = 2 }
   31:  
   32:         public enum ServiceType { Unspecified = 0, Dn = 1, AccessName = 2, AccessUnknown = 3 }
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public Report() { }
   40:  
   41:         ////////////////////////////////////////////////////////////////////////////
   42:  
   43:         /// <summary>
   44:         ///
   45:         /// </summary>
   46:         public class Category
   47:         {
   48:             /// <summary/>
   49:             public Category() { }
   50:  
   51:             /// <summary/>
   52:             public int Id { get; set; }
   53:  
   54:             /// <summary/>
   55:             public string Name { get; set; }
   56:  
   57:             /// <summary/>
   58:             public string ArabicName { get; set; }
   59:  
   60:             /// <summary/>
   61:             public virtual ICollection<Ia.Ftn.Cl.Models.Business.Report.Area> Areas
   62:             {
   63:                 get
   64:                 {
   65:                     return (from a in Ia.Ftn.Cl.Models.Data.Report.AreaList
   66:                             where a.Category.Id == this.Id
   67:                             select a).ToList();
   68:                 }
   69:             }
   70:         }
   71:  
   72:         ////////////////////////////////////////////////////////////////////////////
   73:  
   74:         /// <summary>
   75:         ///
   76:         /// </summary>
   77:         public class Area
   78:         {
   79:             /// <summary/>
   80:             public Area() { }
   81:  
   82:             /// <summary/>
   83:             public int Id { get; set; }
   84:  
   85:             /// <summary/>
   86:             public int XmlId { get; set; }
   87:  
   88:             /// <summary/>
   89:             public string Name { get; set; }
   90:  
   91:             /// <summary/>
   92:             public string ArabicName { get; set; }
   93:  
   94:             /// <summary/>
   95:             public List<string> Frameworks { get; set; }
   96:  
   97:             /// <summary/>
   98:             public virtual Category Category { get; set; }
   99:  
  100:             /// <summary/>
  101:             public virtual ICollection<Indication> Indications
  102:             {
  103:                 get
  104:                 {
  105:                     return (from i in Ia.Ftn.Cl.Models.Data.Report.IndicationList
  106:                             where i.Area.Id == this.Id
  107:                             select i).ToList();
  108:                 }
  109:             }
  110:             /// <summary/>
  111:             public virtual ICollection<Action> Actions
  112:             {
  113:                 get
  114:                 {
  115:                     return (from a in Ia.Ftn.Cl.Models.Data.Report.ActionList
  116:                             where a.Area.Id == this.Id
  117:                             select a).ToList();
  118:                 }
  119:             }
  120:             /// <summary/>
  121:             public virtual ICollection<Resolution> Resolutions
  122:             {
  123:                 get
  124:                 {
  125:                     return (from r in Ia.Ftn.Cl.Models.Data.Report.ResolutionList
  126:                             where r.Area.Id == this.Id
  127:                             select r).ToList();
  128:                 }
  129:             }
  130:  
  131:             /// <summary/>
  132:             public int AreaId(int categoryId, int areaId)
  133:             {
  134:                 return categoryId * 100 + areaId;
  135:             }
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////
  139:  
  140:         /// <summary>
  141:         ///
  142:         /// </summary>
  143:         public class Indication
  144:         {
  145:             /// <summary/>
  146:             public Indication() { }
  147:  
  148:             /// <summary/>
  149:             public int Id { get; set; }
  150:  
  151:             /// <summary/>
  152:             public int XmlId { get; set; }
  153:  
  154:             /// <summary/>
  155:             public bool Obsolete { get; set; }
  156:  
  157:             /// <summary/>
  158:             public bool CanInsert { get; set; }
  159:  
  160:             /// <summary/>
  161:             public string Name { get; set; }
  162:  
  163:             /// <summary/>
  164:             public string ArabicName { get; set; }
  165:  
  166:             /// <summary/>
  167:             public string ColoredName { get; set; }
  168:  
  169:             /// <summary/>
  170:             public string ColoredArabicName { get; set; }
  171:  
  172:             /// <summary/>
  173:             public string EnglishAndArabicName { get; set; }
  174:  
  175:             /// <summary/>
  176:             public string ColoredEnglishAndArabicName { get; set; }
  177:  
  178:             /// <summary/>
  179:             public string Color { get; set; }
  180:  
  181:             /// <summary/>
  182:             public List<string> Frameworks { get; set; }
  183:  
  184:             /// <summary/>
  185:             public virtual Area Area { get; set; }
  186:  
  187:             /// <summary/>
  188:             public int IndicationId(int areaId, int indicationId)
  189:             {
  190:                 return areaId * 10000 + indicationId;
  191:             }
  192:         }
  193:  
  194:         ////////////////////////////////////////////////////////////////////////////
  195:  
  196:         /// <summary>
  197:         ///
  198:         /// </summary>
  199:         public class Action
  200:         {
  201:             /// <summary/>
  202:             public Action() { }
  203:  
  204:             /// <summary/>
  205:             public int Id { get; set; }
  206:  
  207:             /// <summary/>
  208:             public int XmlId { get; set; }
  209:  
  210:             /// <summary/>
  211:             public bool Obsolete { get; set; }
  212:  
  213:             /// <summary/>
  214:             public bool CanInsert { get; set; }
  215:  
  216:             /// <summary/>
  217:             public string Name { get; set; }
  218:  
  219:             /// <summary/>
  220:             public string ArabicName { get; set; }
  221:  
  222:             /// <summary/>
  223:             public string ColoredName { get; set; }
  224:  
  225:             /// <summary/>
  226:             public string ColoredArabicName { get; set; }
  227:  
  228:             /// <summary/>
  229:             public string EnglishAndArabicName { get; set; }
  230:  
  231:             /// <summary/>
  232:             public string ColoredEnglishAndArabicName { get; set; }
  233:  
  234:             /// <summary/>
  235:             public string Color { get; set; }
  236:  
  237:             /// <summary/>
  238:             public List<string> Frameworks { get; set; }
  239:  
  240:             /// <summary/>
  241:             public virtual Area Area { get; set; }
  242:  
  243:             /// <summary/>
  244:             public int ActionId(int areaId, int actionId)
  245:             {
  246:                 return areaId * 10000 + actionId;
  247:             }
  248:         }
  249:  
  250:         ////////////////////////////////////////////////////////////////////////////
  251:  
  252:         /// <summary>
  253:         ///
  254:         /// </summary>
  255:         public class Resolution
  256:         {
  257:             /// <summary/>
  258:             public Resolution() { }
  259:  
  260:             /// <summary/>
  261:             public int Id { get; set; }
  262:  
  263:             /// <summary/>
  264:             public int XmlId { get; set; }
  265:  
  266:             /// <summary/>
  267:             public bool Obsolete { get; set; }
  268:  
  269:             /// <summary/>
  270:             public bool CanInsert { get; set; }
  271:  
  272:             /// <summary/>
  273:             public string Name { get; set; }
  274:  
  275:             /// <summary/>
  276:             public string ArabicName { get; set; }
  277:  
  278:             /// <summary/>
  279:             public string ColoredName { get; set; }
  280:  
  281:             /// <summary/>
  282:             public string ColoredArabicName { get; set; }
  283:  
  284:             /// <summary/>
  285:             public string EnglishAndArabicName { get; set; }
  286:  
  287:             /// <summary/>
  288:             public string ColoredEnglishAndArabicName { get; set; }
  289:  
  290:             /// <summary/>
  291:             public string Color { get; set; }
  292:  
  293:             /// <summary/>
  294:             public virtual Area Area { get; set; }
  295:  
  296:             /// <summary/>
  297:             public int ResolutionId(int areaId, int resolutionId)
  298:             {
  299:                 return areaId * 10000 + resolutionId;
  300:             }
  301:         }
  302:  
  303:         ////////////////////////////////////////////////////////////////////////////
  304:         ////////////////////////////////////////////////////////////////////////////
  305:  
  306:         /// <summary>
  307:         ///
  308:         /// </summary>
  309:         public static bool StaffHasResponsibilityReport(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  310:         {
  311:             bool has;
  312:  
  313:             if (Ia.Ftn.Cl.Models.Data.Report.ReportResponsibilityByStaffIdDictionary().ContainsKey(staff.Id))
  314:             {
  315:                 var list = Ia.Ftn.Cl.Models.Data.Report.ReportResponsibilityByStaffIdDictionary()[staff.Id];
  316:  
  317:                 has = list.Count > 0;
  318:             }
  319:             else has = false;
  320:  
  321:             return has;
  322:         }
  323:  
  324:         ////////////////////////////////////////////////////////////////////////////
  325:  
  326:         /// <summary>
  327:         ///
  328:         /// </summary>
  329:         public static bool StaffHasResponsibilityLic(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  330:         {
  331:             bool has;
  332:  
  333:             var list = Ia.Ftn.Cl.Models.Data.Report.LicResponsibilityByStaff(staff);
  334:  
  335:             has = list.Count > 0;
  336:  
  337:             return has;
  338:         }
  339:  
  340:         ////////////////////////////////////////////////////////////////////////////
  341:  
  342:         /// <summary>
  343:         ///
  344:         /// </summary>
  345:         public static bool FrameworkHasReadabilityReport(string frameworkId)
  346:         {
  347:             bool has;
  348:  
  349:             if (!string.IsNullOrEmpty(frameworkId))
  350:             {
  351:                 if (Ia.Ftn.Cl.Models.Data.Report.ReportReadabilityByFrameworkIdDictionary().ContainsKey(frameworkId))
  352:                 {
  353:                     var reportIdList = Ia.Ftn.Cl.Models.Data.Report.ReportReadabilityByFrameworkIdDictionary()[frameworkId];
  354:  
  355:                     has = reportIdList.Count > 0;
  356:                 }
  357:                 else has = false;
  358:             }
  359:             else has = false;
  360:  
  361:             return has;
  362:         }
  363:  
  364:  
  365:         ////////////////////////////////////////////////////////////////////////////
  366:  
  367:         /// <summary>
  368:         ///
  369:         /// </summary>
  370:         public static void CloseLastUpdatedOverNDaysReportsWithNegligenceResolution(int numberOfPastDays)
  371:         {
  372:             bool reportInserted, reportClosed;
  373:             int area, indication, resolution, action, estimate;
  374:             string detail, note;
  375:             string userId;
  376:             DateTime now;
  377:             Ia.Cl.Models.Result result;
  378:  
  379:             now = DateTime.UtcNow.AddHours(3);
  380:  
  381:             var reportList = Ia.Ftn.Cl.Models.Data.Report.ListWhereStatusIsOpenAndNoReportHistoriesAndUpdatedBeforeDateTime(now.AddDays(-numberOfPastDays));
  382:  
  383:             if (reportList.Count > 0)
  384:             {
  385:                 indication = 1000;
  386:                 // <indication id="1000" name="Unspecified" arabicName="غير محدد"/>
  387:  
  388:                 resolution = 1026;
  389:                 // <resolution id="1026" name="Negligence" arabicName="إهمال" color="DarkOrange" />
  390:  
  391:                 action = 1000;
  392:                 // <action id="1000" name="Unspecified" arabicName="غير محدد"/>
  393:  
  394:                 estimate = 0;
  395:  
  396:                 userId = string.Empty;
  397:  
  398:                 result = new Ia.Cl.Models.Result();
  399:  
  400:                 area = 11; // <area id="11" name="Service"
  401:  
  402:                 foreach (var report in reportList)
  403:                 {
  404:                     detail = string.Empty; // StaffFrameworkArabicName(report);
  405:                     note = string.Empty;
  406:  
  407:                     var reportHistory = new Ia.Ftn.Cl.Models.ReportHistory
  408:                     {
  409:                         Report = Ia.Ftn.Cl.Models.Data.Report.Read(report.Id),
  410:                         Area = area,
  411:                         Indication = indication,
  412:                         Resolution = resolution,
  413:                         Action = action,
  414:                         Estimate = estimate,
  415:                         Detail = detail,
  416:                         StaffIdentityUser = null,
  417:                         Note = note,
  418:                         Created = now,
  419:                         Updated = now
  420:                     };
  421:  
  422:                     reportInserted = Ia.Ftn.Cl.Models.Data.ReportHistory.Create(reportHistory, out _);
  423:  
  424:                     if (reportInserted)
  425:                     {
  426:                         reportClosed = Ia.Ftn.Cl.Models.Data.Report.CloseStatus(report);
  427:  
  428:                         if (reportClosed)
  429:                         {
  430:                             result.AddSuccess("Report history for report.Id: " + report.Id + " successfully inserted and report closed.");
  431:                         }
  432:                         else
  433:                         {
  434:                             result.AddWarning("Report history for report.Id: " + report.Id + " successfully inserted but report not closed.");
  435:                         }
  436:                     }
  437:                     else
  438:                     {
  439:                         result.AddError("Report history for report.Id: " + report.Id + " not inserted.");
  440:                     }
  441:                 }
  442:  
  443:                 Ia.Ftn.Cl.Models.Data.Report.OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  444:             }
  445:         }
  446:  
  447:         ////////////////////////////////////////////////////////////////////////////
  448:  
  449:         /// <summary>
  450:         ///
  451:         /// </summary>
  452:         private static string StaffFrameworkArabicName(Ia.Ftn.Cl.Models.Report report)
  453:         {
  454:             string text;
  455:  
  456:             if (report.LastReportHistory != null)
  457:             {
  458:                 if (Ia.Ftn.Cl.Models.Business.Administration.IsFrameworkId(report.LastReportHistory.StaffIdentityUser.Id))
  459:                 {
  460:                     text = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  461:                             where f.Id == report.LastReportHistory.StaffIdentityUser.Id
  462:                             select f.ArabicName).SingleOrDefault();
  463:                 }
  464:                 else
  465:                 {
  466:                     text = (from _s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
  467:                             where _s.Id == report.LastReportHistory.StaffIdentityUser.Id
  468:                             select _s.Framework.ArabicName).SingleOrDefault();
  469:                 }
  470:             }
  471:             else
  472:             {
  473:                 text = string.Empty;
  474:             }
  475:  
  476:             return text;
  477:         }
  478:  
  479:         ////////////////////////////////////////////////////////////////////////////
  480:         ////////////////////////////////////////////////////////////////////////////   
  481:     }
  482:  
  483:     ////////////////////////////////////////////////////////////////////////////
  484:     ////////////////////////////////////////////////////////////////////////////   
  485: }