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

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