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