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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Report

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

Report support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Data.Entity;
   5:  using System.IO;
   6:  using System.Linq;
   7:  using System.Reflection;
   8:  using System.Web;
   9:  using System.Xml.Linq;
  10:   
  11:  namespace Ia.Ngn.Cl.Model.Data
  12:  {
  13:      ////////////////////////////////////////////////////////////////////////////
  14:   
  15:      /// <summary publish="true">
  16:      /// Report support class for Next Generation Network (NGN) data model.
  17:      /// </summary>
  18:      /// 
  19:      /// <remarks> 
  20:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  21:      ///
  22:      /// 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
  23:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  24:      ///
  25:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  26:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  27:      /// 
  28:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  29:      /// 
  30:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  31:      /// </remarks> 
  32:      public partial class Report
  33:      {
  34:          private static XDocument xDocument;
  35:          private static List<Ia.Ngn.Cl.Model.Business.Report.Category> categoryList;
  36:          private static List<Ia.Ngn.Cl.Model.Business.Report.Area> areaList;
  37:          private static List<Ia.Ngn.Cl.Model.Business.Report.Indication> indicationList;
  38:          private static List<Ia.Ngn.Cl.Model.Business.Report.Action> actionList;
  39:          private static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> resolutionList;
  40:          /*
  41:          private static List<Ia.Ngn.Cl.Model.Business.Report.Severity> severityList;
  42:          private static List<Ia.Ngn.Cl.Model.Business.Report.Priority> priorityList;
  43:          private static List<Ia.Ngn.Cl.Model.Business.Report.Status> statusList;
  44:          private static List<Ia.Ngn.Cl.Model.Business.Report.Estimate> estimateList;
  45:          private static List<Ia.Ngn.Cl.Model.Business.Report.ServiceType> serviceTypeList;
  46:          private static List<Ia.Ngn.Cl.Model.Business.Report.CustomerCare> customerCare;
  47:           */
  48:   
  49:          private static List<Ia.Ngn.Cl.Model.Report> openStatusOrClosedStatusWithinLast24HourReportList;
  50:          private static Dictionary<Guid, List<int>> reportResponsibilityByStaffGuidDictionary, reportReadabilityByFrameworkGuidDictionary;
  51:          private static readonly object objectLock = new object();
  52:   
  53:          ////////////////////////////////////////////////////////////////////////////
  54:   
  55:          /// <summary>
  56:          ///
  57:          /// </summary>
  58:          public Report() { }
  59:   
  60:          ////////////////////////////////////////////////////////////////////////////
  61:          ////////////////////////////////////////////////////////////////////////////
  62:   
  63:          /// <summary>
  64:          ///
  65:          /// </summary>
  66:          public static int Create(Ia.Ngn.Cl.Model.Report report, out string result)
  67:          {
  68:              int id;
  69:   
  70:              id = -1;
  71:              result = string.Empty;
  72:   
  73:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  74:              {
  75:                  report.Created = report.Updated = DateTime.UtcNow.AddHours(3);
  76:   
  77:                  db.Reports.Add(report);
  78:                  db.SaveChanges();
  79:   
  80:                  id = report.Id;
  81:              }
  82:   
  83:              OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  84:   
  85:              return id;
  86:          }
  87:   
  88:          ////////////////////////////////////////////////////////////////////////////
  89:   
  90:          /// <summary>
  91:          ///
  92:          /// </summary>
  93:          public static Ia.Ngn.Cl.Model.Report Read(int reportId)
  94:          {
  95:              Ia.Ngn.Cl.Model.Report report;
  96:   
  97:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  98:              {
  99:                  report = (from r in db.Reports where r.Id == reportId select r).Include(r => r.ReportHistories).SingleOrDefault();
 100:              }
 101:   
 102:              return report;
 103:          }
 104:   
 105:          ////////////////////////////////////////////////////////////////////////////
 106:   
 107:          /// <summary>
 108:          ///
 109:          /// </summary>
 110:          public static List<Ia.Ngn.Cl.Model.Report> ReadList(string service)
 111:          {
 112:              List<Ia.Ngn.Cl.Model.Report> reportList;
 113:   
 114:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 115:              {
 116:                  try
 117:                  {
 118:                      reportList = (from r in db.Reports where r.Service == service select r).Include(r => r.ReportHistories).ToList();
 119:                  }
 120:                  catch
 121:                  {
 122:                      reportList = null;
 123:                  }
 124:              }
 125:   
 126:              return reportList;
 127:          }
 128:   
 129:          ////////////////////////////////////////////////////////////////////////////
 130:   
 131:          /// <summary>
 132:          ///
 133:          /// </summary>
 134:          public static List<Ia.Ngn.Cl.Model.Report> ReadListForServiceFromReportId(int reportId)
 135:          {
 136:              List<Ia.Ngn.Cl.Model.Report> reportList;
 137:   
 138:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 139:              {
 140:                  try
 141:                  {
 142:                      reportList = (from _r in db.Reports join r in db.Reports on _r.Service equals r.Service where r.Id == reportId select r).Include(r => r.ReportHistories).ToList();
 143:                  }
 144:                  catch
 145:                  {
 146:                      reportList = null;
 147:                  }
 148:              }
 149:   
 150:              return reportList;
 151:          }
 152:   
 153:          /*
 154:          ////////////////////////////////////////////////////////////////////////////
 155:  
 156:          /// <summary>
 157:          ///
 158:          /// </summary>
 159:          public static bool UpdateMigratedList(List<Ia.Ngn.Cl.Model.Report> reportList, out string result)
 160:          {
 161:              bool b;
 162:              Ia.Ngn.Cl.Model.Report report;
 163:  
 164:              b = false;
 165:              result = string.Empty;
 166:  
 167:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 168:              {
 169:                  foreach (Ia.Ngn.Cl.Model.Report updatedReport in reportList)
 170:                  {
 171:                      report = (from r in db.Reports where r.Id == updatedReport.Id select r).SingleOrDefault();
 172:  
 173:                      if (report == null)
 174:                      {
 175:                          //updatedReport.Created = updatedReport.Updated = DateTime.UtcNow.AddHours(3);
 176:  
 177:                          db.Reports.Add(updatedReport);
 178:                      }
 179:                      else
 180:                      {
 181:                          // below: copy values from updatedReport to report
 182:  
 183:                          report.UpdateMigrated(updatedReport);
 184:  
 185:                          db.Reports.Attach(report);
 186:  
 187:                          db.Entry(report).State = System.Data.Entity.EntityState.Modified;
 188:                      }
 189:  
 190:                      b = true;
 191:  
 192:                  }
 193:  
 194:                  db.SaveChanges();
 195:  
 196:                  DbContextProbablyUpdated();
 197:  
 198:                  b = true;
 199:              }
 200:  
 201:              return b;
 202:          }
 203:          */
 204:   
 205:          ////////////////////////////////////////////////////////////////////////////
 206:   
 207:          /// <summary>
 208:          ///
 209:          /// </summary>
 210:          public static bool CloseStatus(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 211:          {
 212:              bool b;
 213:   
 214:              b = false;
 215:   
 216:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 217:              {
 218:                  report.Status = (int)Ia.Ngn.Cl.Model.Business.Report.Status.Closed;
 219:   
 220:                  report.Updated = DateTime.UtcNow.AddHours(3);
 221:                  //this.UserId = staff.UserId;
 222:                  // above: can't do that because it will remove the name of the record inserter
 223:   
 224:                  db.Reports.Attach(report);
 225:                  db.Entry(report).State = System.Data.Entity.EntityState.Modified;
 226:                  db.SaveChanges();
 227:   
 228:                  OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
 229:   
 230:                  b = true;
 231:              }
 232:   
 233:              return b;
 234:          }
 235:   
 236:          ////////////////////////////////////////////////////////////////////////////
 237:   
 238:          /// <summary>
 239:          ///
 240:          /// </summary>
 241:          public static bool OpenStatus(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 242:          {
 243:              bool b;
 244:   
 245:              b = false;
 246:   
 247:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 248:              {
 249:                  report.Status = (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open;
 250:   
 251:                  report.Updated = DateTime.UtcNow.AddHours(3);
 252:                  //this.UserId = staff.UserId;
 253:                  // above: can't do that because it will remove the name of the record inserter
 254:   
 255:                  db.Reports.Attach(report);
 256:                  db.Entry(report).State = System.Data.Entity.EntityState.Modified;
 257:                  db.SaveChanges();
 258:   
 259:                  OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
 260:   
 261:                  b = true;
 262:              }
 263:   
 264:              return b;
 265:          }
 266:   
 267:          ////////////////////////////////////////////////////////////////////////////
 268:   
 269:          /// <summary>
 270:          ///
 271:          /// </summary>
 272:          public static bool NullifyUserId(Guid userId, out int numberOfRecordsUpdated)
 273:          {
 274:              return MoveUserId(userId, Guid.Empty, out numberOfRecordsUpdated);
 275:          }
 276:   
 277:          ////////////////////////////////////////////////////////////////////////////
 278:   
 279:          /// <summary>
 280:          ///
 281:          /// </summary>
 282:          public static bool MoveUserId(Guid fromUserId, Guid toUserId, out int numberOfRecordsUpdated)
 283:          {
 284:              bool b;
 285:   
 286:              b = false;
 287:              numberOfRecordsUpdated = 0;
 288:   
 289:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 290:              {
 291:                  var query = (from r in db.Reports where r.UserId == fromUserId select r).ToList();
 292:   
 293:                  foreach (var v in query)
 294:                  {
 295:                      v.UserId = toUserId;
 296:                      numberOfRecordsUpdated++;
 297:                  }
 298:   
 299:                  db.SaveChanges();
 300:   
 301:                  OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
 302:   
 303:                  b = true;
 304:              }
 305:   
 306:              return b;
 307:          }
 308:   
 309:          ////////////////////////////////////////////////////////////////////////////
 310:   
 311:          /// <summary>
 312:          ///
 313:          /// </summary>
 314:          public static bool Delete(int id/*, out string result*/)
 315:          {
 316:              bool b;
 317:   
 318:              b = false;
 319:              //result = string.Empty;
 320:   
 321:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 322:              {
 323:                  var v = (from r in db.Reports where r.Id == id select r).FirstOrDefault();
 324:   
 325:                  db.Reports.Remove(v);
 326:                  db.SaveChanges();
 327:   
 328:                  OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
 329:   
 330:                  b = true;
 331:              }
 332:   
 333:              return b;
 334:          }
 335:   
 336:          ////////////////////////////////////////////////////////////////////////////
 337:          ////////////////////////////////////////////////////////////////////////////
 338:   
 339:          /// <summary>
 340:          ///
 341:          /// </summary>
 342:          public static bool StaffHasResponsibilityReport(Ia.Ngn.Cl.Model.Staff staff)
 343:          {
 344:              bool has;
 345:   
 346:              if (Ia.Ngn.Cl.Model.Data.Report.ReportResponsibilityByStaffGuidDictionary.ContainsKey(staff.UserId))
 347:              {
 348:                  var reportIdList = Ia.Ngn.Cl.Model.Data.Report.ReportResponsibilityByStaffGuidDictionary[staff.UserId];
 349:   
 350:                  has = reportIdList.Count > 0;
 351:              }
 352:              else has = false;
 353:   
 354:              return has;
 355:          }
 356:   
 357:          ////////////////////////////////////////////////////////////////////////////
 358:   
 359:          /// <summary>
 360:          ///
 361:          /// </summary>
 362:          public static bool FrameworkHasReadabilityReport(Guid guid)
 363:          {
 364:              bool has;
 365:   
 366:              if (Ia.Ngn.Cl.Model.Data.Report.ReportReadabilityByFrameworkGuidDictionary.ContainsKey(guid))
 367:              {
 368:                  var reportIdList = Ia.Ngn.Cl.Model.Data.Report.ReportReadabilityByFrameworkGuidDictionary[guid];
 369:   
 370:                  has = reportIdList.Count > 0;
 371:              }
 372:              else has = false;
 373:   
 374:              return has;
 375:          }
 376:   
 377:          ////////////////////////////////////////////////////////////////////////////
 378:   
 379:          /// <summary>
 380:          ///
 381:          /// </summary>
 382:          private static void StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(Ia.Ngn.Cl.Model.Staff staff, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList)
 383:          {
 384:              staffFrameworkAncestorAndDescendantUserIdList = new List<Guid>();
 385:              staffSubordinatesUserIdList = new List<Guid>();
 386:   
 387:              // below: add self framework
 388:              staffFrameworkAncestorAndDescendantUserIdList.Add(staff.Framework.Guid);
 389:   
 390:              // below: add ancestor frameworks
 391:              if (staff.Framework.Ancestors != null)
 392:              {
 393:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework ancestor in staff.Framework.Ancestors.ToList())
 394:                      staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Guid);
 395:              }
 396:   
 397:              // below: add decendant frameworks
 398:              if (staff.Framework.Descendants != null)
 399:              {
 400:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework descendant in staff.Framework.Descendants.ToList())
 401:                      staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Guid);
 402:              }
 403:   
 404:              // below: add children staff
 405:              if (staff.Subordinates != null)
 406:              {
 407:                  foreach (Ia.Ngn.Cl.Model.Staff subordinate in staff.Subordinates.ToList()) staffSubordinatesUserIdList.Add(subordinate.UserId);
 408:              }
 409:          }
 410:   
 411:          ////////////////////////////////////////////////////////////////////////////
 412:   
 413:          /// <summary>
 414:          ///
 415:          /// </summary>
 416:          private static void FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList)
 417:          {
 418:              staffFrameworkAncestorAndDescendantUserIdList = new List<Guid>();
 419:              staffSubordinatesUserIdList = new List<Guid>();
 420:   
 421:              // below: add self framework
 422:              staffFrameworkAncestorAndDescendantUserIdList.Add(framework.Guid);
 423:   
 424:              if (framework.Ancestors != null)
 425:              {
 426:                  // below: add ancestor frameworks
 427:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework ancestor in framework.Ancestors) staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Guid);
 428:              }
 429:   
 430:              if (framework.Descendants != null)
 431:              {
 432:                  // below: add decendants
 433:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework descendant in framework.Descendants) staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Guid);
 434:              }
 435:   
 436:              // below: add children staff of any of the list of frameworks collected
 437:              staffSubordinatesUserIdList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 438:                                             join sfadu in staffFrameworkAncestorAndDescendantUserIdList on s.Framework.Guid equals sfadu
 439:                                             select s.UserId).ToList();
 440:          }
 441:   
 442:          ////////////////////////////////////////////////////////////////////////////
 443:          ////////////////////////////////////////////////////////////////////////////
 444:   
 445:          /// <summary>
 446:          ///
 447:          /// </summary>
 448:          public static List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> ReadSpecificUserIdListAndSiteIdReportWithReportOpenStatusList(List<Guid> userIdList, int siteId)
 449:          {
 450:              List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> reportAccessServiceRequestList;
 451:   
 452:              if (siteId == 0) reportAccessServiceRequestList = _ReadSpecificUserIdListReportWithReportOpenStatusList(userIdList);
 453:              else
 454:              {
 455:                  var v = _ReadSpecificUserIdListReportWithReportOpenStatusList(userIdList);
 456:   
 457:                  if (v != null)
 458:                  {
 459:                      reportAccessServiceRequestList = (from rasr in v
 460:                                                        join s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList on siteId equals s.Id
 461:                                                        where rasr.Access != null && s.KuwaitNgnAreas.Any(u => u.Id == rasr.Access.AreaId)
 462:                                                        select rasr).ToList();
 463:                  }
 464:                  else
 465:                  {
 466:                      reportAccessServiceRequestList = new List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest>();
 467:                  }
 468:              }
 469:   
 470:              return reportAccessServiceRequestList;
 471:          }
 472:   
 473:          ////////////////////////////////////////////////////////////////////////////
 474:   
 475:          /// <summary>
 476:          ///
 477:          /// </summary>
 478:          private static List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> _ReadSpecificUserIdListReportWithReportOpenStatusList(List<Guid> userIdList)
 479:          {
 480:              string prividUser, accessId;
 481:              List<string> serviceIdList, prividUserList;
 482:              Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest reportAccessServiceRequest;
 483:              List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> reportAccessServiceRequestList;
 484:              List<Ia.Ngn.Cl.Model.Report> reportList;
 485:              List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
 486:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 487:   
 488:              reportAccessServiceRequestList = null;
 489:   
 490:              serviceIdList = new List<string>();
 491:              prividUserList = new List<string>();
 492:   
 493:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 494:              {
 495:                  if (userIdList != null && userIdList.Count > 0)
 496:                  {
 497:                      reportList = (from r in db.Reports
 498:                                    join srs in db.ServiceRequestServices on r.Service equals srs.Service into gj
 499:                                    where (r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open && (r.ReportHistories.Any(y => userIdList.Any(z => z == y.UserId))))
 500:                                    orderby r.Created
 501:                                    from sub in gj.DefaultIfEmpty()
 502:                                    select r).Include(x => x.ReportHistories).ToList();
 503:   
 504:                      if (reportList.Count > 0)
 505:                      {
 506:                          foreach (var v in reportList)
 507:                          {
 508:                              serviceIdList.Add(v.Service);
 509:   
 510:                              prividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(v.Service);
 511:                              prividUserList.Add(prividUser);
 512:                          }
 513:   
 514:                          serviceRequestServiceList = (from srs in db.ServiceRequestServices
 515:                                                       where serviceIdList.Contains(srs.Service)
 516:                                                       select srs).ToList();
 517:   
 518:                          agcfEndpointList = (from ep in db.AgcfEndpoints
 519:                                              where prividUserList.Contains(ep.PrividUser)
 520:                                              select ep).ToList();
 521:   
 522:                          reportAccessServiceRequestList = new List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest>();
 523:   
 524:                          foreach (Ia.Ngn.Cl.Model.Report report in reportList)
 525:                          {
 526:                              // below: the aggregate function will check the last entry
 527:                              if (userIdList.Contains(report.ReportHistories.Aggregate((i, j) => i.Id > j.Id ? i : j).UserId))
 528:                              {
 529:                                  reportAccessServiceRequest = new Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest();
 530:   
 531:                                  reportAccessServiceRequest.Report = report;
 532:                                  reportAccessServiceRequest.Report.ReportHistories = report.ReportHistories; // this to force inclusion of ReportHistories
 533:   
 534:                                  if (report.ServiceType == 1)
 535:                                  {
 536:                                      reportAccessServiceRequest.Access = (from srs in serviceRequestServiceList where srs.Service == report.Service select srs.Access).FirstOrDefault();
 537:   
 538:                                      prividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(report.Service);
 539:                                      reportAccessServiceRequest.Port = (from ep in agcfEndpointList where ep.Id == prividUser select ep.FlatTermID).SingleOrDefault();
 540:                                  }
 541:                                  else //if(report.ServiceType == 2)
 542:                                  {
 543:                                      accessId = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == report.Service select o.Access.Id).SingleOrDefault();
 544:   
 545:                                      if (!string.IsNullOrEmpty(accessId))
 546:                                      {
 547:                                          reportAccessServiceRequest.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 548:                                      }
 549:                                      else reportAccessServiceRequest.Access = null;
 550:   
 551:                                      reportAccessServiceRequest.Port = 0;
 552:                                  }
 553:   
 554:                                  reportAccessServiceRequestList.Add(reportAccessServiceRequest);
 555:                              }
 556:                          }
 557:                      }
 558:                      else
 559:                      {
 560:                      }
 561:                  }
 562:                  else
 563:                  {
 564:                  }
 565:              }
 566:   
 567:              return reportAccessServiceRequestList;
 568:          }
 569:   
 570:          ////////////////////////////////////////////////////////////////////////////
 571:          ////////////////////////////////////////////////////////////////////////////
 572:   
 573:          /// <summary>
 574:          ///
 575:          /// </summary>
 576:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourReportList
 577:          {
 578:              get
 579:              {
 580:                  if (openStatusOrClosedStatusWithinLast24HourReportList == null || openStatusOrClosedStatusWithinLast24HourReportList.Count == 0)
 581:                  {
 582:                      if (HttpContext.Current != null && HttpContext.Current.Application["openStatusOrClosedStatusWithinLast24HourReportList"] != null)
 583:                      {
 584:                          openStatusOrClosedStatusWithinLast24HourReportList = HttpContext.Current.Application["openStatusOrClosedStatusWithinLast24HourReportList"] as List<Ia.Ngn.Cl.Model.Report>;
 585:                      }
 586:                      else
 587:                      {
 588:                          lock (objectLock)
 589:                          {
 590:                              openStatusOrClosedStatusWithinLast24HourReportList = Ia.Ngn.Cl.Model.Data.Report._OpenStatusOrClosedStatusWithinLast24HourReportList();
 591:   
 592:                              if (HttpContext.Current != null) HttpContext.Current.Application["openStatusOrClosedStatusWithinLast24HourReportList"] = openStatusOrClosedStatusWithinLast24HourReportList;
 593:                          }
 594:                      }
 595:                  }
 596:   
 597:                  return openStatusOrClosedStatusWithinLast24HourReportList;
 598:              }
 599:          }
 600:   
 601:          ////////////////////////////////////////////////////////////////////////////
 602:   
 603:          /// <summary>
 604:          ///
 605:          /// </summary>
 606:          public static void OpenStatusOrClosedStatusWithinLast24HourReportListClear()
 607:          {
 608:              openStatusOrClosedStatusWithinLast24HourReportList = null;
 609:   
 610:              if (HttpContext.Current != null) HttpContext.Current.Application.Remove("openStatusOrClosedStatusWithinLast24HourReportList");
 611:          }
 612:   
 613:          ////////////////////////////////////////////////////////////////////////////
 614:   
 615:          /// <summary>
 616:          ///
 617:          /// </summary>
 618:          private static List<Ia.Ngn.Cl.Model.Report> _OpenStatusOrClosedStatusWithinLast24HourReportList()
 619:          {
 620:              DateTime before24Hour;
 621:   
 622:              List<Ia.Ngn.Cl.Model.Report> list;
 623:   
 624:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 625:              {
 626:                  before24Hour = DateTime.UtcNow.AddHours(3).AddDays(-1);
 627:   
 628:                  list = (from r in db.Reports
 629:                          where r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open || (r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Closed && r.Updated >= before24Hour)
 630:                          orderby r.Created
 631:                          select r).Include(x => x.ReportHistories).ToList();
 632:              }
 633:   
 634:              return list;
 635:          }
 636:   
 637:          ////////////////////////////////////////////////////////////////////////////
 638:   
 639:          /// <summary>
 640:          ///
 641:          /// </summary>
 642:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourByReportIdReportList(List<int> reportIdList)
 643:          {
 644:              return (from r in OpenStatusOrClosedStatusWithinLast24HourReportList join rid in reportIdList on r.Id equals rid select r).ToList();
 645:          }
 646:   
 647:          ////////////////////////////////////////////////////////////////////////////
 648:          ////////////////////////////////////////////////////////////////////////////
 649:   
 650:          /// <summary>
 651:          ///
 652:          /// </summary>
 653:          public static Dictionary<Guid, List<int>> ReportResponsibilityByStaffGuidDictionary
 654:          {
 655:              get
 656:              {
 657:                  if (reportResponsibilityByStaffGuidDictionary == null || reportResponsibilityByStaffGuidDictionary.Count == 0)
 658:                  {
 659:                      if (HttpContext.Current != null && HttpContext.Current.Application["reportResponsibilityByStaffGuidDictionary"] != null)
 660:                      {
 661:                          reportResponsibilityByStaffGuidDictionary = HttpContext.Current.Application["reportResponsibilityByStaffGuidDictionary"] as Dictionary<Guid, List<int>>;
 662:                      }
 663:                      else
 664:                      {
 665:                          lock (objectLock)
 666:                          {
 667:                              reportResponsibilityByStaffGuidDictionary = Ia.Ngn.Cl.Model.Data.Report._ReportResponsibilityByStaffGuidDictionary();
 668:   
 669:                              if (HttpContext.Current != null) HttpContext.Current.Application["reportResponsibilityByStaffGuidDictionary"] = reportResponsibilityByStaffGuidDictionary;
 670:                          }
 671:                      }
 672:                  }
 673:   
 674:                  return reportResponsibilityByStaffGuidDictionary;
 675:              }
 676:          }
 677:   
 678:          ////////////////////////////////////////////////////////////////////////////
 679:   
 680:          /// <summary>
 681:          ///
 682:          /// </summary>
 683:          public static void ReportResponsibilityByStaffGuidDictionaryClear()
 684:          {
 685:              reportResponsibilityByStaffGuidDictionary = null;
 686:   
 687:              if (HttpContext.Current != null) HttpContext.Current.Application.Remove("reportResponsibilityByStaffGuidDictionary");
 688:          }
 689:   
 690:          ////////////////////////////////////////////////////////////////////////////
 691:   
 692:          /// <summary>
 693:          ///
 694:          /// </summary>
 695:          private static Dictionary<Guid, List<int>> _ReportResponsibilityByStaffGuidDictionary()
 696:          {
 697:              Dictionary<Guid, List<int>> dictionary;
 698:   
 699:              dictionary = new Dictionary<Guid, List<int>>();
 700:   
 701:              var staffList = Ia.Ngn.Cl.Model.Data.Staff.List;
 702:   
 703:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 704:   
 705:              // I will exclude closed reports
 706:              reportList = (from r in reportList where r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open select r).ToList();
 707:   
 708:              foreach (var staff in staffList)
 709:              {
 710:                  if (staff.UserId != Guid.Empty)
 711:                  {
 712:                      StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(staff, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList);
 713:   
 714:                      var re = (from r in reportList
 715:                                where r.LastReportHistory == null && Ia.Ngn.Cl.Model.Business.Authority.StaffIsResponsibleForAllOpenReportWithNoReportHistory(staff)
 716:                                || r.LastReportHistory == null && r.UserId == staff.UserId
 717:                                || r.LastReportHistory == null && staffSubordinatesUserIdList.Contains(r.UserId)
 718:                                || r.LastReportHistory == null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
 719:                                || r.LastReportHistory != null && r.LastReportHistory.UserId == staff.UserId
 720:                                || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
 721:                                || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
 722:                                select r).ToList();
 723:   
 724:                      if (re.Count > 0) dictionary[staff.UserId] = re.Select(r => r.Id).ToList();
 725:                  }
 726:              }
 727:   
 728:              return dictionary;
 729:          }
 730:   
 731:          ////////////////////////////////////////////////////////////////////////////
 732:          ////////////////////////////////////////////////////////////////////////////
 733:   
 734:          /// <summary>
 735:          ///
 736:          /// </summary>
 737:          public static Dictionary<Guid, List<int>> ReportReadabilityByFrameworkGuidDictionary
 738:          {
 739:              get
 740:              {
 741:                  if (reportReadabilityByFrameworkGuidDictionary == null || reportReadabilityByFrameworkGuidDictionary.Count == 0)
 742:                  {
 743:                      if (HttpContext.Current != null && HttpContext.Current.Application["reportReadabilityByFrameworkGuidDictionary"] != null)
 744:                      {
 745:                          reportReadabilityByFrameworkGuidDictionary = HttpContext.Current.Application["reportReadabilityByFrameworkGuidDictionary"] as Dictionary<Guid, List<int>>;
 746:                      }
 747:                      else
 748:                      {
 749:                          lock (objectLock)
 750:                          {
 751:                              reportReadabilityByFrameworkGuidDictionary = Ia.Ngn.Cl.Model.Data.Report._ReportReadabilityByFrameworkGuidDictionary();
 752:   
 753:                              if (HttpContext.Current != null) HttpContext.Current.Application["reportReadabilityByFrameworkGuidDictionary"] = reportReadabilityByFrameworkGuidDictionary;
 754:                          }
 755:                      }
 756:                  }
 757:   
 758:                  return reportReadabilityByFrameworkGuidDictionary;
 759:              }
 760:          }
 761:   
 762:          ////////////////////////////////////////////////////////////////////////////
 763:   
 764:          /// <summary>
 765:          ///
 766:          /// </summary>
 767:          public static void ReportReadabilityByFrameworkGuidDictionaryClear()
 768:          {
 769:              reportReadabilityByFrameworkGuidDictionary = null;
 770:   
 771:              if (HttpContext.Current != null) HttpContext.Current.Application.Remove("reportReadabilityByFrameworkGuidDictionary");
 772:          }
 773:   
 774:          ////////////////////////////////////////////////////////////////////////////
 775:   
 776:          /// <summary>
 777:          ///
 778:          /// </summary>
 779:          private static Dictionary<Guid, List<int>> _ReportReadabilityByFrameworkGuidDictionary()
 780:          {
 781:              Dictionary<Guid, List<int>> dic;
 782:   
 783:              dic = new Dictionary<Guid, List<int>>();
 784:   
 785:              var frameworkList = Ia.Ngn.Cl.Model.Data.Administration.FrameworkList;
 786:   
 787:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 788:   
 789:              // will add all reports to the Guid.Empty framework
 790:              dic[Guid.Empty] = reportList.Select(r => r.Id).ToList();
 791:   
 792:              foreach (var framework in frameworkList)
 793:              {
 794:                  if (framework.Guid != Guid.Empty)
 795:                  {
 796:                      FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(framework, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList);
 797:   
 798:                      var re = (from r in reportList
 799:                                where r.LastReportHistory == null && Ia.Ngn.Cl.Model.Business.Authority.FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(framework)
 800:                                || r.LastReportHistory == null && r.UserId == framework.Guid
 801:                                || staffSubordinatesUserIdList.Contains(r.UserId)
 802:                                || staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
 803:                                || r.LastReportHistory != null && r.LastReportHistory.UserId == framework.Guid
 804:                                || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
 805:                                || r.ReportHistories != null && r.ReportHistories.Any(u => staffSubordinatesUserIdList.Contains(u.UserId))
 806:                                || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
 807:                                select r).ToList();
 808:   
 809:                      if (re.Count > 0) dic[framework.Guid] = re.Select(r => r.Id).ToList();
 810:                  }
 811:              }
 812:   
 813:              return dic;
 814:          }
 815:   
 816:          ////////////////////////////////////////////////////////////////////////////    
 817:   
 818:          /// <summary>
 819:          ///
 820:          /// </summary>
 821:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Framework> ReportReadabilityByFrameworkList
 822:          {
 823:              get
 824:              {
 825:                  return (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList join r in ReportReadabilityByFrameworkGuidDictionary on f.Guid equals r.Key select f).ToList();
 826:              }
 827:   
 828:   
 829:              /*
 830:              Hashtable frameworkGuidHashtable;
 831:              //Ia.Ngn.Cl.Model.Staff staff;
 832:              List<Guid> userIdList;
 833:              List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework> list;
 834:  
 835:              frameworkGuidHashtable = new Hashtable();
 836:              userIdList = new List<Guid>();
 837:  
 838:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 839:  
 840:              foreach (Ia.Ngn.Cl.Model.Business.Administration.StaffFramework sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList)
 841:              {
 842:                  if (sf.IsFramework)
 843:                  {
 844:                      var rl = Ia.Ngn.Cl.Model.Data.Report.FrameworkReadabilityReportList(reportList, sf.Guid);
 845:  
 846:                      if (rl.Count > 0) frameworkGuidHashtable[sf.Guid] = 1;
 847:                  }
 848:              }
 849:  
 850:              foreach (Guid userId in frameworkGuidHashtable.Keys) userIdList.Add(userId);
 851:  
 852:              list = (from u in userIdList
 853:                      join sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList on u equals sf.Guid
 854:                      where sf.IsFramework == true && Ia.Ngn.Cl.Model.Business.Authority.FrameworkParentOfAllReportsThatWillBeHandledInReportSection.Descendants.Any(u => u.Guid == sf.Guid)
 855:                      select sf).OrderBy(c => c.Name).ToList(); //.OrderByDescending(c => c.IsStaff).ThenBy(c => c.FrameworkId).ToList();
 856:  
 857:              // convert StaffFramework to Framework
 858:              var list2 = (from l in list join f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList on l.FrameworkId equals f.Id select f).ToList();
 859:  
 860:              return list2;
 861:              */
 862:          }
 863:   
 864:          ////////////////////////////////////////////////////////////////////////////
 865:          ////////////////////////////////////////////////////////////////////////////
 866:   
 867:          /// <summary>
 868:          /// When a report list is updated I will reset local lists to null to generate new list
 869:          /// </summary>
 870:          public static void OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear()
 871:          {
 872:              OpenStatusOrClosedStatusWithinLast24HourReportListClear();
 873:              ReportResponsibilityByStaffGuidDictionaryClear();
 874:              ReportReadabilityByFrameworkGuidDictionaryClear();
 875:          }
 876:   
 877:          ////////////////////////////////////////////////////////////////////////////
 878:          ////////////////////////////////////////////////////////////////////////////
 879:   
 880:          /*
 881:          ////////////////////////////////////////////////////////////////////////////
 882:  
 883:          /// <summary>
 884:          ///
 885:          /// </summary>
 886:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusAndClosedStatusWithinLast24HourWithNonEmptyReportHistoryReportList()
 887:          {
 888:              var reportList = OpenStatusOrClosedStatusWithinLast24HourReportList;
 889:  
 890:              var lastReportHistoryNotNullReportList = (from r in reportList where r.LastReportHistory != null select r).ToList();
 891:  
 892:              return lastReportHistoryNotNullReportList;
 893:          }
 894:          */
 895:   
 896:          ////////////////////////////////////////////////////////////////////////////
 897:   
 898:          /// <summary>
 899:          ///
 900:          /// </summary>
 901:          public static List<Ia.Ngn.Cl.Model.Report> ReadOpenStatusReportList
 902:          {
 903:              get
 904:              {
 905:                  List<Ia.Ngn.Cl.Model.Report> reportList;
 906:   
 907:                  reportList = (from r in OpenStatusOrClosedStatusWithinLast24HourReportList where r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open orderby r.Created select r).ToList();
 908:   
 909:                  return reportList;
 910:              }
 911:          }
 912:   
 913:          ////////////////////////////////////////////////////////////////////////////
 914:   
 915:          /// <summary>
 916:          ///
 917:          /// </summary>
 918:          public static List<Ia.Ngn.Cl.Model.Report> ReadSingleAsList(int reportId)
 919:          {
 920:              List<Ia.Ngn.Cl.Model.Report> reportList;
 921:   
 922:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 923:              {
 924:                  reportList = (from r in db.Reports where r.Id == reportId select r).Include(x => x.ReportHistories).ToList();
 925:              }
 926:   
 927:              return reportList;
 928:          }
 929:   
 930:          /*
 931:          ////////////////////////////////////////////////////////////////////////////
 932:  
 933:          /// <summary>
 934:          ///
 935:          /// </summary>
 936:          public static DateTime LastUpdatedDateTime()
 937:          {
 938:              DateTime lastUpdatedDateTime;
 939:  
 940:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 941:              {
 942:                  try
 943:                  {
 944:                      lastUpdatedDateTime = (from r in db.Reports orderby r.Updated descending select r.Updated).Take(1).Single();
 945:                  }
 946:                  catch
 947:                  {
 948:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 949:                  }
 950:              }
 951:  
 952:              return lastUpdatedDateTime;
 953:          }
 954:  
 955:          ////////////////////////////////////////////////////////////////////////////
 956:  
 957:          /// <summary>
 958:          ///
 959:          /// </summary>
 960:          public static DateTime LastUpdatedDateTimeOfHistory()
 961:          {
 962:              DateTime lastUpdatedDateTime;
 963:  
 964:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 965:              {
 966:                  try
 967:                  {
 968:                      lastUpdatedDateTime = (from rh in db.ReportHistories orderby rh.Updated descending select rh.Updated).Take(1).Single();
 969:                  }
 970:                  catch
 971:                  {
 972:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 973:                  }
 974:              }
 975:  
 976:              return lastUpdatedDateTime;
 977:          }
 978:          */
 979:   
 980:          ////////////////////////////////////////////////////////////////////////////
 981:   
 982:          /// <summary>
 983:          ///
 984:          /// </summary>
 985:          public static Dictionary<int, string> CategoryDictionary
 986:          {
 987:              get
 988:              {
 989:                  Dictionary<int, string> dictionary;
 990:   
 991:                  dictionary = new Dictionary<int, string>(100);
 992:   
 993:                  dictionary = (from c in XDocument.Elements("report").Elements("category")
 994:                                select new { Id = int.Parse(c.Attribute("id").Value), Name = c.Attribute("name").Value }).ToDictionary(r => r.Id, r => r.Name);
 995:   
 996:                  return dictionary;
 997:              }
 998:          }
 999:   
1000:          ////////////////////////////////////////////////////////////////////////////
1001:   
1002:          /// <summary>
1003:          ///
1004:          /// </summary>
1005:          public static Dictionary<int, string> CategoryAreaIndicationDictionary(int categoryId, int areaId)
1006:          {
1007:              Dictionary<int, string> dictionary;
1008:   
1009:              dictionary = new Dictionary<int, string>(100);
1010:   
1011:              dictionary = (from i in XDocument.Elements("report").Elements("category").Elements("area").Elements("indicationList")
1012:                            where i.Parent.Parent.Attribute("id").Value == categoryId.ToString() && i.Parent.Attribute("id").Value == areaId.ToString()
1013:                            select new { Id = int.Parse(i.Attribute("id").Value), Name = i.Attribute("id").Value }).ToDictionary(r => r.Id, r => r.Name);
1014:   
1015:              return dictionary;
1016:          }
1017:   
1018:          ////////////////////////////////////////////////////////////////////////////
1019:   
1020:          /// <summary>
1021:          ///
1022:          /// </summary>
1023:          public static Dictionary<int, string> IndicationColoredDictionary
1024:          {
1025:              get
1026:              {
1027:                  return Dictionary(false, true, "category", "area", "indicationList", "indication").Concat(GeneralIndicationColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1028:              }
1029:          }
1030:   
1031:          ////////////////////////////////////////////////////////////////////////////
1032:   
1033:          /// <summary>
1034:          ///
1035:          /// </summary>
1036:          public static Dictionary<int, string> ActionDictionary
1037:          {
1038:              get
1039:              {
1040:                  return Dictionary(false, false, "category", "area", "actionList", "action").Concat(GeneralActionDictionary).ToDictionary(q => q.Key, q => q.Value);
1041:              }
1042:          }
1043:   
1044:          ////////////////////////////////////////////////////////////////////////////
1045:   
1046:          /// <summary>
1047:          ///
1048:          /// </summary>
1049:          public static Dictionary<int, string> ActionColoredDictionary
1050:          {
1051:              get
1052:              {
1053:                  return Dictionary(false, true, "category", "area", "actionList", "action").Concat(GeneralActionColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1054:              }
1055:          }
1056:   
1057:          ////////////////////////////////////////////////////////////////////////////
1058:   
1059:          /// <summary>
1060:          ///
1061:          /// </summary>
1062:          public static Dictionary<int, string> ResolutionColoredDictionary
1063:          {
1064:              get
1065:              {
1066:                  return Dictionary(false, true, "resolution");
1067:              }
1068:          }
1069:   
1070:          ////////////////////////////////////////////////////////////////////////////
1071:   
1072:          /// <summary>
1073:          ///
1074:          /// </summary>
1075:          public static Dictionary<int, string> ResolutionEnglishAndArabicColoredDictionary
1076:          {
1077:              get
1078:              {
1079:                  return Dictionary(true, true, "resolution");
1080:              }
1081:          }
1082:   
1083:          ////////////////////////////////////////////////////////////////////////////
1084:   
1085:          /// <summary>
1086:          ///
1087:          /// </summary>
1088:          public static Dictionary<int, string> ResolutionDictionary
1089:          {
1090:              get
1091:              {
1092:                  return Dictionary(false, false, "resolution");
1093:              }
1094:          }
1095:   
1096:          ////////////////////////////////////////////////////////////////////////////
1097:   
1098:          /// <summary>
1099:          ///
1100:          /// </summary>
1101:          public static Dictionary<int, string> GeneralActionDictionary
1102:          {
1103:              get
1104:              {
1105:                  return Dictionary(false, false, "action");
1106:              }
1107:          }
1108:   
1109:          ////////////////////////////////////////////////////////////////////////////
1110:   
1111:          /// <summary>
1112:          ///
1113:          /// </summary>
1114:          public static Dictionary<int, string> GeneralActionColoredDictionary
1115:          {
1116:              get
1117:              {
1118:                  return Dictionary(false, true, "action");
1119:              }
1120:          }
1121:   
1122:          ////////////////////////////////////////////////////////////////////////////
1123:   
1124:          /// <summary>
1125:          ///
1126:          /// </summary>
1127:          public static Dictionary<int, string> GeneralIndicationDictionary
1128:          {
1129:              get
1130:              {
1131:                  return Dictionary(false, false, "indication");
1132:              }
1133:          }
1134:   
1135:          ////////////////////////////////////////////////////////////////////////////
1136:   
1137:          /// <summary>
1138:          ///
1139:          /// </summary>
1140:          public static Dictionary<int, string> GeneralIndicationColoredDictionary
1141:          {
1142:              get
1143:              {
1144:                  return Dictionary(false, true, "indication");
1145:              }
1146:          }
1147:   
1148:          ////////////////////////////////////////////////////////////////////////////
1149:   
1150:          /// <summary>
1151:          ///
1152:          /// </summary>
1153:          public static Dictionary<int, string> EstimateDictionary
1154:          {
1155:              get
1156:              {
1157:                  return Dictionary(false, false, "estimate");
1158:              }
1159:          }
1160:   
1161:          ////////////////////////////////////////////////////////////////////////////
1162:   
1163:          /// <summary>
1164:          ///
1165:          /// </summary>
1166:          public static Dictionary<int, string> EstimateColoredDictionary
1167:          {
1168:              get
1169:              {
1170:                  return Dictionary(false, true, "estimate");
1171:              }
1172:          }
1173:   
1174:          ////////////////////////////////////////////////////////////////////////////
1175:   
1176:          /// <summary>
1177:          ///
1178:          /// </summary>
1179:          public static Dictionary<int, string> StatusDictionary
1180:          {
1181:              get
1182:              {
1183:                  return Dictionary(false, false, "status");
1184:              }
1185:          }
1186:   
1187:          ////////////////////////////////////////////////////////////////////////////
1188:   
1189:          /// <summary>
1190:          ///
1191:          /// </summary>
1192:          public static Dictionary<int, string> StatusColoredDictionary
1193:          {
1194:              get
1195:              {
1196:                  return Dictionary(false, true, "status");
1197:              }
1198:          }
1199:   
1200:          ////////////////////////////////////////////////////////////////////////////
1201:   
1202:          /// <summary>
1203:          ///
1204:          /// </summary>
1205:          public static Dictionary<int, string> PriorityDictionary
1206:          {
1207:              get
1208:              {
1209:                  return Dictionary(false, false, "priority");
1210:              }
1211:          }
1212:   
1213:          ////////////////////////////////////////////////////////////////////////////
1214:   
1215:          /// <summary>
1216:          ///
1217:          /// </summary>
1218:          public static Dictionary<int, string> PriorityColoredDictionary
1219:          {
1220:              get
1221:              {
1222:                  return Dictionary(false, true, "priority");
1223:              }
1224:          }
1225:   
1226:          ////////////////////////////////////////////////////////////////////////////
1227:   
1228:          /// <summary>
1229:          ///
1230:          /// </summary>
1231:          public static Dictionary<int, string> SeverityDictionary
1232:          {
1233:              get
1234:              {
1235:                  return Dictionary(false, false, "severity");
1236:              }
1237:          }
1238:   
1239:          ////////////////////////////////////////////////////////////////////////////
1240:   
1241:          /// <summary>
1242:          ///
1243:          /// </summary>
1244:          public static Dictionary<int, string> SeverityColoredDictionary
1245:          {
1246:              get
1247:              {
1248:                  return Dictionary(false, true, "severity");
1249:              }
1250:          }
1251:   
1252:          ////////////////////////////////////////////////////////////////////////////
1253:   
1254:          /// <summary>
1255:          ///
1256:          /// </summary>
1257:          public static Dictionary<int, string> CategoryAreaDictionary()
1258:          {
1259:              return Dictionary(false, false, "category", "area");
1260:          }
1261:   
1262:          ////////////////////////////////////////////////////////////////////////////
1263:   
1264:          /// <summary>
1265:          ///
1266:          /// </summary>
1267:          public static Dictionary<int, string> CategoryAreaDictionary(int categoryId)
1268:          {
1269:              return ColoredDictionary("category", "area", categoryId, false);
1270:          }
1271:   
1272:          ////////////////////////////////////////////////////////////////////////////
1273:   
1274:          /// <summary>
1275:          ///
1276:          /// </summary>
1277:          public static Dictionary<int, string> CategoryAreaColoredDictionary
1278:          {
1279:              get
1280:              {
1281:                  return Dictionary(false, true, "category", "area");
1282:              }
1283:          }
1284:   
1285:          ////////////////////////////////////////////////////////////////////////////
1286:   
1287:          /// <summary>
1288:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1289:          /// </summary>
1290:          private static Dictionary<int, string> Dictionary(bool englishAndArabicName, bool isColored, params string[] elementList)
1291:          {
1292:              int id;
1293:              string name, color;
1294:              Dictionary<int, string> dictionary;
1295:              IEnumerable<XElement> xElementIenumerable;
1296:   
1297:              dictionary = new Dictionary<int, string>(10);
1298:              xElementIenumerable = null;
1299:   
1300:              try
1301:              {
1302:                  switch (elementList.Length)
1303:                  {
1304:                      case 1: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]); break;
1305:                      case 2: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]); break;
1306:                      case 3: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]); break;
1307:                      case 4: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]).Elements(elementList[3]); break;
1308:                      default: break;
1309:                  }
1310:   
1311:                  foreach (XElement x in xElementIenumerable)
1312:                  {
1313:                      id = int.Parse(x.Attribute("id").Value);
1314:   
1315:                      if (englishAndArabicName)
1316:                      {
1317:                          if (x.Attribute("arabicName") != null)
1318:                          {
1319:                              name = x.Attribute("name").Value + " (" + x.Attribute("arabicName").Value + ")";
1320:                          }
1321:                          else name = x.Attribute("name").Value;
1322:                      }
1323:                      else name = x.Attribute("name").Value;
1324:   
1325:                      color = x.Attribute("color")?.Value;
1326:   
1327:                      // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1328:                      name = name.Replace(" ", "&nbsp;");
1329:   
1330:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1331:                  }
1332:              }
1333:              catch (Exception e)
1334:              {
1335:   
1336:              }
1337:   
1338:              return dictionary;
1339:          }
1340:   
1341:          ////////////////////////////////////////////////////////////////////////////
1342:   
1343:          /// <summary>
1344:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1345:          /// </summary>
1346:          private static Dictionary<int, string> ColoredDictionary(string element, string secondElement, int categoryId, bool isColored)
1347:          {
1348:              int id;
1349:              string name, color;
1350:              Dictionary<int, string> dictionary;
1351:   
1352:              dictionary = new Dictionary<int, string>(100);
1353:   
1354:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement))
1355:              {
1356:                  if (x.Parent.Attribute("id").Value == categoryId.ToString())
1357:                  {
1358:                      id = int.Parse(x.Attribute("id").Value);
1359:                      name = x.Attribute("name").Value;
1360:                      color = x.Attribute("color")?.Value;
1361:   
1362:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1363:                  }
1364:              }
1365:   
1366:              return dictionary;
1367:          }
1368:   
1369:          ////////////////////////////////////////////////////////////////////////////
1370:   
1371:          /// <summary>
1372:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1373:          /// </summary>
1374:          private static Dictionary<int, string> Dictionary(string element, string secondElement, string thirdElement, string fourthElement, int categoryId, int categoryAreaId, bool isColored)
1375:          {
1376:              int id;
1377:              string name, color;
1378:              Dictionary<int, string> dictionary;
1379:   
1380:              dictionary = new Dictionary<int, string>(100);
1381:   
1382:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement).Elements(thirdElement).Elements(fourthElement))
1383:              {
1384:                  if (x.Parent.Parent.Parent.Attribute("id").Value == categoryId.ToString() && x.Parent.Parent.Attribute("id").Value == categoryAreaId.ToString())
1385:                  {
1386:                      id = int.Parse(x.Attribute("id").Value);
1387:                      name = x.Attribute("name").Value;
1388:                      color = x.Attribute("color")?.Value; // same as color = (x.Attribute("color") != null) ? x.Attribute("color").Value : null;
1389:   
1390:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1391:                  }
1392:              }
1393:   
1394:              return dictionary;
1395:          }
1396:   
1397:          ////////////////////////////////////////////////////////////////////////////
1398:   
1399:          /// <summary>
1400:          ///
1401:          /// </summary>
1402:          private static void ColoredDictionaryItem(ref Dictionary<int, string> dictionary, bool isColored, int id, string name, string color)
1403:          {
1404:              List<string> lightBackgroundColorList;
1405:   
1406:              if (isColored)
1407:              {
1408:                  if (!string.IsNullOrEmpty(color))
1409:                  {
1410:                      dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
1411:                  }
1412:                  else
1413:                  {
1414:                      lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1415:   
1416:                      dictionary.Add(id, @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>");
1417:                  }
1418:              }
1419:              else
1420:              {
1421:                  dictionary.Add(id, name);
1422:              }
1423:          }
1424:   
1425:          ////////////////////////////////////////////////////////////////////////////
1426:   
1427:          /// <summary>
1428:          ///
1429:          /// </summary>
1430:          private static string ColoredName(int id, string name)
1431:          {
1432:              return ColoredName(id, name, null);
1433:          }
1434:   
1435:          ////////////////////////////////////////////////////////////////////////////
1436:   
1437:          /// <summary>
1438:          ///
1439:          /// </summary>
1440:          private static string ColoredName(int id, string name, string color)
1441:          {
1442:              string coloredName;
1443:              List<string> lightBackgroundColorList;
1444:   
1445:              lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1446:   
1447:              if (!string.IsNullOrEmpty(color)) coloredName = @"<span style=""color:" + color + @""">" + name + "</span>";
1448:              else coloredName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>";
1449:   
1450:              return coloredName;
1451:          }
1452:   
1453:          ////////////////////////////////////////////////////////////////////////////
1454:          ////////////////////////////////////////////////////////////////////////////
1455:   
1456:          /// <summary>
1457:          ///
1458:          /// </summary>
1459:          public static List<Ia.Ngn.Cl.Model.Business.Report.Category> CategoryList
1460:          {
1461:              get
1462:              {
1463:                  if (categoryList == null || categoryList.Count == 0)
1464:                  {
1465:                      int id;
1466:                      Ia.Ngn.Cl.Model.Business.Report.Category category;
1467:   
1468:                      categoryList = new List<Ia.Ngn.Cl.Model.Business.Report.Category>();
1469:   
1470:                      foreach (XElement x in XDocument.Element("report").Elements("category"))
1471:                      {
1472:                          category = new Ia.Ngn.Cl.Model.Business.Report.Category();
1473:   
1474:                          id = int.Parse(x.Attribute("id").Value);
1475:   
1476:                          category.Id = id;
1477:                          category.Name = x.Attribute("name").Value;
1478:                          category.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
1479:   
1480:                          categoryList.Add(category);
1481:                      }
1482:                  }
1483:   
1484:                  return categoryList;
1485:              }
1486:          }
1487:   
1488:          ////////////////////////////////////////////////////////////////////////////
1489:   
1490:          /// <summary>
1491:          ///
1492:          /// </summary>
1493:          public static List<Ia.Ngn.Cl.Model.Business.Report.Area> AreaList
1494:          {
1495:              get
1496:              {
1497:                  if (areaList == null || areaList.Count == 0)
1498:                  {
1499:                      int categoryId, id;
1500:                      Ia.Ngn.Cl.Model.Business.Report.Area area;
1501:   
1502:                      areaList = new List<Ia.Ngn.Cl.Model.Business.Report.Area>();
1503:   
1504:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1505:                      {
1506:                          area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1507:                          area.Category = new Ia.Ngn.Cl.Model.Business.Report.Category();
1508:   
1509:                          categoryId = int.Parse(x.Parent.Attribute("id").Value);
1510:                          id = int.Parse(x.Attribute("id").Value);
1511:   
1512:                          area.Id = area.AreaId(categoryId, id);
1513:                          area.XmlId = id;
1514:                          area.Category = (from c in CategoryList where c.Id == categoryId select c).SingleOrDefault();
1515:                          area.Name = x.Attribute("name").Value;
1516:                          area.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
1517:   
1518:                          if (x.Attribute("framework") != null)
1519:                          {
1520:                              area.Frameworks = new List<string>(100);
1521:   
1522:                              foreach (string s in x.Attribute("framework").Value.Split(',')) area.Frameworks.Add(s);
1523:                          }
1524:   
1525:                          areaList.Add(area);
1526:                      }
1527:                  }
1528:   
1529:                  return areaList;
1530:              }
1531:          }
1532:   
1533:          ////////////////////////////////////////////////////////////////////////////
1534:   
1535:          /// <summary>
1536:          ///
1537:          /// </summary>
1538:          public static List<Ia.Ngn.Cl.Model.Business.Report.Indication> IndicationList
1539:          {
1540:              get
1541:              {
1542:                  if (indicationList == null || indicationList.Count == 0)
1543:                  {
1544:                      int categoryId, areaId, id;
1545:                      Ia.Ngn.Cl.Model.Business.Report.Indication indication;
1546:   
1547:                      indicationList = new List<Ia.Ngn.Cl.Model.Business.Report.Indication>();
1548:   
1549:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("indicationList").Elements("indication"))
1550:                      {
1551:                          indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
1552:                          indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1553:   
1554:                          categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1555:                          areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1556:                          id = int.Parse(x.Attribute("id").Value);
1557:   
1558:                          areaId = indication.Area.AreaId(categoryId, areaId);
1559:   
1560:                          indication.Id = indication.IndicationId(areaId, id);
1561:                          indication.XmlId = id;
1562:                          indication.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1563:   
1564:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1565:                          if (x.Attribute("obsolete") != null) indication.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1566:                          else indication.Obsolete = false;
1567:   
1568:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1569:                          if (x.Attribute("canInsert") != null) indication.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1570:                          else indication.CanInsert = true;
1571:   
1572:                          indication.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1573:   
1574:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1575:                          indication.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1576:                          indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
1577:   
1578:                          if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1579:                          {
1580:                              indication.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1581:                              indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
1582:                          }
1583:                          else
1584:                          {
1585:                              indication.ArabicName = string.Empty;
1586:                              indication.ColoredArabicName = string.Empty;
1587:                          }
1588:   
1589:                          if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
1590:                          else indication.EnglishAndArabicName = indication.Name;
1591:   
1592:                          if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
1593:                          else indication.ColoredEnglishAndArabicName = indication.ColoredName;
1594:   
1595:                          if (x.Parent.Attribute("framework") != null)
1596:                          {
1597:                              indication.Frameworks = new List<string>(100);
1598:   
1599:                              foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) indication.Frameworks.Add(s);
1600:                          }
1601:   
1602:                          indicationList.Add(indication);
1603:                      }
1604:   
1605:                      // below: add the general indications to all areas
1606:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1607:                      {
1608:                          foreach (XElement y in XDocument.Element("report").Elements("indication"))
1609:                          {
1610:                              indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
1611:                              indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1612:   
1613:                              categoryId = int.Parse(x.Parent.Attribute("id").Value);
1614:                              areaId = int.Parse(x.Attribute("id").Value);
1615:                              id = int.Parse(y.Attribute("id").Value); // y
1616:   
1617:                              areaId = indication.Area.AreaId(categoryId, areaId);
1618:   
1619:                              indication.Id = indication.IndicationId(areaId, id);
1620:                              indication.XmlId = id;
1621:                              indication.Area = null;// (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
1622:   
1623:                              // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1624:                              if (y.Attribute("obsolete") != null) indication.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1625:                              else indication.Obsolete = false;
1626:   
1627:                              // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1628:                              if (y.Attribute("canInsert") != null) indication.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1629:                              else indication.CanInsert = true;
1630:   
1631:                              indication.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1632:   
1633:                              // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1634:                              indication.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1635:                              indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
1636:   
1637:                              if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1638:                              {
1639:                                  indication.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1640:                                  indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
1641:                              }
1642:                              else
1643:                              {
1644:                                  indication.ArabicName = string.Empty;
1645:                                  indication.ColoredArabicName = string.Empty;
1646:                              }
1647:   
1648:                              if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
1649:                              else indication.EnglishAndArabicName = indication.Name;
1650:   
1651:                              if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
1652:                              else indication.ColoredEnglishAndArabicName = indication.ColoredName;
1653:   
1654:                              indicationList.Add(indication);
1655:                          }
1656:                      }
1657:                  }
1658:   
1659:                  return indicationList;
1660:              }
1661:          }
1662:   
1663:          ////////////////////////////////////////////////////////////////////////////
1664:   
1665:          /// <summary>
1666:          ///
1667:          /// </summary>
1668:          public static List<Ia.Ngn.Cl.Model.Business.Report.Action> ActionList
1669:          {
1670:              get
1671:              {
1672:                  if (actionList == null || actionList.Count == 0)
1673:                  {
1674:                      int categoryId, areaId, id;
1675:                      Ia.Ngn.Cl.Model.Business.Report.Action action;
1676:   
1677:                      actionList = new List<Ia.Ngn.Cl.Model.Business.Report.Action>();
1678:   
1679:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("actionList").Elements("action"))
1680:                      {
1681:                          action = new Ia.Ngn.Cl.Model.Business.Report.Action();
1682:                          action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1683:   
1684:                          categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1685:                          areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1686:                          id = int.Parse(x.Attribute("id").Value);
1687:   
1688:                          areaId = action.Area.AreaId(categoryId, areaId);
1689:   
1690:                          action.Id = action.ActionId(areaId, id);
1691:                          action.XmlId = id;
1692:                          action.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1693:   
1694:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1695:                          if (x.Attribute("obsolete") != null) action.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1696:                          else action.Obsolete = false;
1697:   
1698:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1699:                          if (x.Attribute("canInsert") != null) action.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1700:                          else action.CanInsert = true;
1701:   
1702:                          action.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1703:   
1704:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1705:                          action.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1706:                          action.ColoredName = ColoredName(id, action.Name, action.Color);
1707:   
1708:                          if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1709:                          {
1710:                              action.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1711:                              action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
1712:                          }
1713:                          else
1714:                          {
1715:                              action.ArabicName = string.Empty;
1716:                              action.ColoredArabicName = string.Empty;
1717:                          }
1718:   
1719:                          if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
1720:                          else action.EnglishAndArabicName = action.Name;
1721:   
1722:                          if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
1723:                          else action.ColoredEnglishAndArabicName = action.ColoredName;
1724:   
1725:                          if (x.Parent.Attribute("framework") != null)
1726:                          {
1727:                              action.Frameworks = new List<string>(100);
1728:   
1729:                              foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) action.Frameworks.Add(s);
1730:                          }
1731:   
1732:                          actionList.Add(action);
1733:                      }
1734:   
1735:                      // below: add the general actions to all areas
1736:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1737:                      {
1738:                          foreach (XElement y in XDocument.Element("report").Elements("action"))
1739:                          {
1740:                              action = new Ia.Ngn.Cl.Model.Business.Report.Action();
1741:                              action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1742:   
1743:                              categoryId = int.Parse(x.Parent.Attribute("id").Value);
1744:                              areaId = int.Parse(x.Attribute("id").Value);
1745:                              id = int.Parse(y.Attribute("id").Value); // y
1746:   
1747:                              areaId = action.Area.AreaId(categoryId, areaId);
1748:   
1749:                              action.Id = action.ActionId(areaId, id);
1750:                              action.XmlId = id;
1751:                              action.Area = null; // (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
1752:   
1753:                              // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1754:                              if (y.Attribute("obsolete") != null) action.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1755:                              else action.Obsolete = false;
1756:   
1757:                              // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1758:                              if (y.Attribute("canInsert") != null) action.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1759:                              else action.CanInsert = true;
1760:   
1761:                              action.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1762:   
1763:                              // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1764:                              action.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1765:                              action.ColoredName = ColoredName(id, action.Name, action.Color);
1766:   
1767:                              if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1768:                              {
1769:                                  action.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1770:                                  action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
1771:                              }
1772:                              else
1773:                              {
1774:                                  action.ArabicName = string.Empty;
1775:                                  action.ColoredArabicName = string.Empty;
1776:                              }
1777:   
1778:                              if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
1779:                              else action.EnglishAndArabicName = action.Name;
1780:   
1781:                              if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
1782:                              else action.ColoredEnglishAndArabicName = action.ColoredName;
1783:   
1784:                              actionList.Add(action);
1785:                          }
1786:                      }
1787:                  }
1788:   
1789:                  return actionList;
1790:              }
1791:          }
1792:   
1793:          ////////////////////////////////////////////////////////////////////////////
1794:   
1795:          /// <summary>
1796:          ///
1797:          /// </summary>
1798:          public static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> ResolutionList
1799:          {
1800:              get
1801:              {
1802:                  if (resolutionList == null || resolutionList.Count == 0)
1803:                  {
1804:                      int categoryId, areaId, id;
1805:                      Ia.Ngn.Cl.Model.Business.Report.Resolution resolution;
1806:   
1807:                      resolutionList = new List<Ia.Ngn.Cl.Model.Business.Report.Resolution>();
1808:   
1809:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("resolutionList").Elements("resolution"))
1810:                      {
1811:                          resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
1812:                          resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1813:   
1814:                          categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1815:                          areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1816:                          id = int.Parse(x.Attribute("id").Value);
1817:   
1818:                          areaId = resolution.Area.AreaId(categoryId, areaId);
1819:   
1820:                          resolution.Id = resolution.ResolutionId(areaId, id);
1821:                          resolution.XmlId = id;
1822:                          resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1823:   
1824:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1825:                          if (x.Attribute("obsolete") != null) resolution.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1826:                          else resolution.Obsolete = false;
1827:   
1828:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1829:                          if (x.Attribute("canInsert") != null) resolution.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1830:                          else resolution.CanInsert = true;
1831:   
1832:                          resolution.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1833:   
1834:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1835:                          resolution.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1836:                          resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
1837:   
1838:                          if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1839:                          {
1840:                              resolution.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1841:                              resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
1842:                          }
1843:                          else
1844:                          {
1845:                              resolution.ArabicName = string.Empty;
1846:                              resolution.ColoredArabicName = string.Empty;
1847:                          }
1848:   
1849:                          if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
1850:                          else resolution.EnglishAndArabicName = resolution.Name;
1851:   
1852:                          if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
1853:                          else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
1854:   
1855:                          resolutionList.Add(resolution);
1856:                      }
1857:   
1858:                      // below: add the general resolutions to all areas
1859:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1860:                      {
1861:                          foreach (XElement y in XDocument.Element("report").Elements("resolution"))
1862:                          {
1863:                              resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
1864:                              resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1865:   
1866:                              categoryId = int.Parse(x.Parent.Attribute("id").Value);
1867:                              areaId = int.Parse(x.Attribute("id").Value);
1868:                              id = int.Parse(y.Attribute("id").Value); // y
1869:   
1870:                              areaId = resolution.Area.AreaId(categoryId, areaId);
1871:   
1872:                              resolution.Id = resolution.ResolutionId(areaId, id);
1873:                              resolution.XmlId = id;
1874:                              resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1875:   
1876:                              // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1877:                              if (y.Attribute("obsolete") != null) resolution.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1878:                              else resolution.Obsolete = false;
1879:   
1880:                              // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1881:                              if (y.Attribute("canInsert") != null) resolution.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1882:                              else resolution.CanInsert = true;
1883:   
1884:                              resolution.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1885:   
1886:                              // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1887:                              resolution.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1888:                              resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
1889:   
1890:                              if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1891:                              {
1892:                                  resolution.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1893:                                  resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
1894:                              }
1895:                              else
1896:                              {
1897:                                  resolution.ArabicName = string.Empty;
1898:                                  resolution.ColoredArabicName = string.Empty;
1899:                              }
1900:   
1901:                              if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
1902:                              else resolution.EnglishAndArabicName = resolution.Name;
1903:   
1904:                              if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
1905:                              else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
1906:   
1907:                              resolutionList.Add(resolution);
1908:                          }
1909:                      }
1910:                  }
1911:   
1912:                  return resolutionList;
1913:              }
1914:          }
1915:   
1916:          ////////////////////////////////////////////////////////////////////////////
1917:          ////////////////////////////////////////////////////////////////////////////
1918:   
1919:          /// <summary>
1920:          /// 
1921:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
1922:          /// 
1923:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
1924:          /// 2. Add "using System.Reflection".
1925:          /// 3. See sample below.
1926:          /// 
1927:          /// </summary>
1928:   
1929:          public static XDocument XDocument
1930:          {
1931:              get
1932:              {
1933:                  if (xDocument == null)
1934:                  {
1935:                      Assembly _assembly;
1936:                      StreamReader streamReader;
1937:   
1938:                      _assembly = Assembly.GetExecutingAssembly();
1939:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.report.xml"));
1940:   
1941:                      try
1942:                      {
1943:                          if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
1944:                      }
1945:                      catch (Exception)
1946:                      {
1947:                      }
1948:                      finally
1949:                      {
1950:                      }
1951:                  }
1952:   
1953:                  return xDocument;
1954:              }
1955:          }
1956:   
1957:          ////////////////////////////////////////////////////////////////////////////
1958:          ////////////////////////////////////////////////////////////////////////////    
1959:      }
1960:   
1961:      ////////////////////////////////////////////////////////////////////////////
1962:      ////////////////////////////////////////////////////////////////////////////   
1963:  }