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

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:   
 547:                                      if (!string.IsNullOrEmpty(accessId))
 548:                                      {
 549:                                          reportAccessServiceRequest.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 550:                                      }
 551:                                      else reportAccessServiceRequest.Access = null;
 552:   
 553:                                      reportAccessServiceRequest.Port = 0;
 554:                                  }
 555:   
 556:                                  reportAccessServiceRequestList.Add(reportAccessServiceRequest);
 557:                              }
 558:                          }
 559:                      }
 560:                      else
 561:                      {
 562:                      }
 563:                  }
 564:                  else
 565:                  {
 566:                  }
 567:              }
 568:   
 569:              return reportAccessServiceRequestList;
 570:          }
 571:   
 572:          ////////////////////////////////////////////////////////////////////////////
 573:          ////////////////////////////////////////////////////////////////////////////
 574:   
 575:          /// <summary>
 576:          ///
 577:          /// </summary>
 578:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourReportList
 579:          {
 580:              get
 581:              {
 582:                  lock (objectLock)
 583:                  {
 584:                      if (openStatusOrClosedStatusWithinLast24HourReportList == null || openStatusOrClosedStatusWithinLast24HourReportList.Count == 0) openStatusOrClosedStatusWithinLast24HourReportList = Ia.Ngn.Cl.Model.Data.Report._OpenStatusOrClosedStatusWithinLast24HourReportList();
 585:   
 586:                      return openStatusOrClosedStatusWithinLast24HourReportList;
 587:                  }
 588:              }
 589:          }
 590:   
 591:          ////////////////////////////////////////////////////////////////////////////
 592:   
 593:          /// <summary>
 594:          ///
 595:          /// </summary>
 596:          public static void OpenStatusOrClosedStatusWithinLast24HourReportListClear()
 597:          {
 598:              openStatusOrClosedStatusWithinLast24HourReportList = null;
 599:          }
 600:   
 601:          ////////////////////////////////////////////////////////////////////////////
 602:   
 603:          /// <summary>
 604:          ///
 605:          /// </summary>
 606:          private static List<Ia.Ngn.Cl.Model.Report> _OpenStatusOrClosedStatusWithinLast24HourReportList()
 607:          {
 608:              DateTime before24Hour;
 609:   
 610:              List<Ia.Ngn.Cl.Model.Report> list;
 611:   
 612:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 613:              {
 614:                  before24Hour = DateTime.UtcNow.AddHours(3).AddDays(-1);
 615:   
 616:                  list = (from r in db.Reports
 617:                          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)
 618:                          orderby r.Created
 619:                          select r).Include(x => x.ReportHistories).ToList();
 620:              }
 621:   
 622:              return list;
 623:          }
 624:   
 625:          ////////////////////////////////////////////////////////////////////////////
 626:   
 627:          /// <summary>
 628:          ///
 629:          /// </summary>
 630:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourByReportIdReportList(List<int> reportIdList)
 631:          {
 632:              return (from r in OpenStatusOrClosedStatusWithinLast24HourReportList 
 633:                      join rid in reportIdList on r.Id equals rid 
 634:                      select r).ToList();
 635:          }
 636:   
 637:          ////////////////////////////////////////////////////////////////////////////
 638:          ////////////////////////////////////////////////////////////////////////////
 639:   
 640:          /// <summary>
 641:          ///
 642:          /// </summary>
 643:          public static Dictionary<Guid, List<int>> ReportResponsibilityByStaffGuidDictionary
 644:          {
 645:              get
 646:              {
 647:                  lock (objectLock)
 648:                  {
 649:                      if (reportResponsibilityByStaffGuidDictionary == null || reportResponsibilityByStaffGuidDictionary.Count == 0) reportResponsibilityByStaffGuidDictionary = Ia.Ngn.Cl.Model.Data.Report._ReportResponsibilityByStaffGuidDictionary();
 650:   
 651:                      return reportResponsibilityByStaffGuidDictionary;
 652:                  }
 653:              }
 654:          }
 655:   
 656:          ////////////////////////////////////////////////////////////////////////////
 657:   
 658:          /// <summary>
 659:          ///
 660:          /// </summary>
 661:          public static void ReportResponsibilityByStaffGuidDictionaryClear()
 662:          {
 663:              reportResponsibilityByStaffGuidDictionary = null;
 664:          }
 665:   
 666:          ////////////////////////////////////////////////////////////////////////////
 667:   
 668:          /// <summary>
 669:          ///
 670:          /// </summary>
 671:          private static Dictionary<Guid, List<int>> _ReportResponsibilityByStaffGuidDictionary()
 672:          {
 673:              Dictionary<Guid, List<int>> dictionary;
 674:   
 675:              dictionary = new Dictionary<Guid, List<int>>();
 676:   
 677:              var staffList = Ia.Ngn.Cl.Model.Data.Staff.List;
 678:   
 679:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 680:   
 681:              // I will exclude closed reports
 682:              reportList = (from r in reportList where r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open select r).ToList();
 683:   
 684:              foreach (var staff in staffList)
 685:              {
 686:                  if (staff.UserId != Guid.Empty)
 687:                  {
 688:                      StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(staff, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList);
 689:   
 690:                      var re = (from r in reportList
 691:                                where r.LastReportHistory == null && Ia.Ngn.Cl.Model.Business.Authority.StaffIsResponsibleForAllOpenReportWithNoReportHistory(staff)
 692:                                || r.LastReportHistory == null && r.UserId == staff.UserId
 693:                                || r.LastReportHistory == null && staffSubordinatesUserIdList.Contains(r.UserId)
 694:                                || r.LastReportHistory == null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
 695:                                || r.LastReportHistory != null && r.LastReportHistory.UserId == staff.UserId
 696:                                || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
 697:                                || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
 698:                                select r).ToList();
 699:   
 700:                      if (re.Count > 0) dictionary[staff.UserId] = re.Select(r => r.Id).ToList();
 701:                  }
 702:              }
 703:   
 704:              return dictionary;
 705:          }
 706:   
 707:          ////////////////////////////////////////////////////////////////////////////
 708:          ////////////////////////////////////////////////////////////////////////////
 709:   
 710:          /// <summary>
 711:          ///
 712:          /// </summary>
 713:          public static Dictionary<Guid, List<int>> ReportReadabilityByFrameworkGuidDictionary
 714:          {
 715:              get
 716:              {
 717:                  lock (objectLock)
 718:                  {
 719:                      if (reportReadabilityByFrameworkGuidDictionary == null || reportReadabilityByFrameworkGuidDictionary.Count == 0) reportReadabilityByFrameworkGuidDictionary = Ia.Ngn.Cl.Model.Data.Report._ReportReadabilityByFrameworkGuidDictionary();
 720:   
 721:                      return reportReadabilityByFrameworkGuidDictionary;
 722:                  }
 723:              }
 724:          }
 725:   
 726:          ////////////////////////////////////////////////////////////////////////////
 727:   
 728:          /// <summary>
 729:          ///
 730:          /// </summary>
 731:          public static void ReportReadabilityByFrameworkGuidDictionaryClear()
 732:          {
 733:              reportReadabilityByFrameworkGuidDictionary = null;
 734:          }
 735:   
 736:          ////////////////////////////////////////////////////////////////////////////
 737:   
 738:          /// <summary>
 739:          ///
 740:          /// </summary>
 741:          private static Dictionary<Guid, List<int>> _ReportReadabilityByFrameworkGuidDictionary()
 742:          {
 743:              Dictionary<Guid, List<int>> dic;
 744:   
 745:              dic = new Dictionary<Guid, List<int>>();
 746:   
 747:              var frameworkList = Ia.Ngn.Cl.Model.Data.Administration.FrameworkList;
 748:   
 749:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 750:   
 751:              // will add all reports to the Guid.Empty framework
 752:              dic[Guid.Empty] = reportList.Select(r => r.Id).ToList();
 753:   
 754:              foreach (var framework in frameworkList)
 755:              {
 756:                  if (framework.Guid != Guid.Empty)
 757:                  {
 758:                      FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(framework, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList);
 759:   
 760:                      var re = (from r in reportList
 761:                                where r.LastReportHistory == null && Ia.Ngn.Cl.Model.Business.Authority.FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(framework)
 762:                                || r.LastReportHistory == null && r.UserId == framework.Guid
 763:                                || staffSubordinatesUserIdList.Contains(r.UserId)
 764:                                || staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
 765:                                || r.LastReportHistory != null && r.LastReportHistory.UserId == framework.Guid
 766:                                || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
 767:                                || r.ReportHistories != null && r.ReportHistories.Any(u => staffSubordinatesUserIdList.Contains(u.UserId))
 768:                                || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
 769:                                select r).ToList();
 770:   
 771:                      if (re.Count > 0) dic[framework.Guid] = re.Select(r => r.Id).ToList();
 772:                  }
 773:              }
 774:   
 775:              return dic;
 776:          }
 777:   
 778:          ////////////////////////////////////////////////////////////////////////////    
 779:   
 780:          /// <summary>
 781:          ///
 782:          /// </summary>
 783:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Framework> ReportReadabilityByFrameworkList
 784:          {
 785:              get
 786:              {
 787:                  return (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList 
 788:                          join r in ReportReadabilityByFrameworkGuidDictionary on f.Guid equals r.Key 
 789:                          select f).ToList();
 790:              }
 791:   
 792:   
 793:              /*
 794:              Hashtable frameworkGuidHashtable;
 795:              //Ia.Ngn.Cl.Model.Staff staff;
 796:              List<Guid> userIdList;
 797:              List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework> list;
 798:  
 799:              frameworkGuidHashtable = new Hashtable();
 800:              userIdList = new List<Guid>();
 801:  
 802:              var reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
 803:  
 804:              foreach (Ia.Ngn.Cl.Model.Business.Administration.StaffFramework sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList)
 805:              {
 806:                  if (sf.IsFramework)
 807:                  {
 808:                      var rl = Ia.Ngn.Cl.Model.Data.Report.FrameworkReadabilityReportList(reportList, sf.Guid);
 809:  
 810:                      if (rl.Count > 0) frameworkGuidHashtable[sf.Guid] = 1;
 811:                  }
 812:              }
 813:  
 814:              foreach (Guid userId in frameworkGuidHashtable.Keys) userIdList.Add(userId);
 815:  
 816:              list = (from u in userIdList
 817:                      join sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList on u equals sf.Guid
 818:                      where sf.IsFramework == true && Ia.Ngn.Cl.Model.Business.Authority.FrameworkParentOfAllReportsThatWillBeHandledInReportSection.Descendants.Any(u => u.Guid == sf.Guid)
 819:                      select sf).OrderBy(c => c.Name).ToList(); //.OrderByDescending(c => c.IsStaff).ThenBy(c => c.FrameworkId).ToList();
 820:  
 821:              // convert StaffFramework to Framework
 822:              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();
 823:  
 824:              return list2;
 825:              */
 826:          }
 827:   
 828:          ////////////////////////////////////////////////////////////////////////////
 829:          ////////////////////////////////////////////////////////////////////////////
 830:   
 831:          /// <summary>
 832:          /// When a report list is updated I will reset local lists to null to generate new list
 833:          /// </summary>
 834:          public static void OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear()
 835:          {
 836:              OpenStatusOrClosedStatusWithinLast24HourReportListClear();
 837:              ReportResponsibilityByStaffGuidDictionaryClear();
 838:              ReportReadabilityByFrameworkGuidDictionaryClear();
 839:          }
 840:   
 841:          ////////////////////////////////////////////////////////////////////////////
 842:          ////////////////////////////////////////////////////////////////////////////
 843:   
 844:          /*
 845:          ////////////////////////////////////////////////////////////////////////////
 846:  
 847:          /// <summary>
 848:          ///
 849:          /// </summary>
 850:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusAndClosedStatusWithinLast24HourWithNonEmptyReportHistoryReportList()
 851:          {
 852:              var reportList = OpenStatusOrClosedStatusWithinLast24HourReportList;
 853:  
 854:              var lastReportHistoryNotNullReportList = (from r in reportList where r.LastReportHistory != null select r).ToList();
 855:  
 856:              return lastReportHistoryNotNullReportList;
 857:          }
 858:          */
 859:   
 860:          ////////////////////////////////////////////////////////////////////////////
 861:   
 862:          /// <summary>
 863:          ///
 864:          /// </summary>
 865:          public static List<Ia.Ngn.Cl.Model.Report> ReadOpenStatusReportList
 866:          {
 867:              get
 868:              {
 869:                  List<Ia.Ngn.Cl.Model.Report> reportList;
 870:   
 871:                  reportList = (from r in OpenStatusOrClosedStatusWithinLast24HourReportList 
 872:                                where r.Status == (int)Ia.Ngn.Cl.Model.Business.Report.Status.Open 
 873:                                orderby r.Created 
 874:                                select r).ToList();
 875:   
 876:                  return reportList;
 877:              }
 878:          }
 879:   
 880:          ////////////////////////////////////////////////////////////////////////////
 881:   
 882:          /// <summary>
 883:          ///
 884:          /// </summary>
 885:          public static List<Ia.Ngn.Cl.Model.Report> ReadSingleAsList(int reportId)
 886:          {
 887:              List<Ia.Ngn.Cl.Model.Report> reportList;
 888:   
 889:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 890:              {
 891:                  reportList = (from r in db.Reports where r.Id == reportId select r).Include(x => x.ReportHistories).ToList();
 892:              }
 893:   
 894:              return reportList;
 895:          }
 896:   
 897:          /*
 898:          ////////////////////////////////////////////////////////////////////////////
 899:  
 900:          /// <summary>
 901:          ///
 902:          /// </summary>
 903:          public static DateTime LastUpdatedDateTime()
 904:          {
 905:              DateTime lastUpdatedDateTime;
 906:  
 907:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 908:              {
 909:                  try
 910:                  {
 911:                      lastUpdatedDateTime = (from r in db.Reports orderby r.Updated descending select r.Updated).Take(1).Single();
 912:                  }
 913:                  catch
 914:                  {
 915:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 916:                  }
 917:              }
 918:  
 919:              return lastUpdatedDateTime;
 920:          }
 921:  
 922:          ////////////////////////////////////////////////////////////////////////////
 923:  
 924:          /// <summary>
 925:          ///
 926:          /// </summary>
 927:          public static DateTime LastUpdatedDateTimeOfHistory()
 928:          {
 929:              DateTime lastUpdatedDateTime;
 930:  
 931:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 932:              {
 933:                  try
 934:                  {
 935:                      lastUpdatedDateTime = (from rh in db.ReportHistories orderby rh.Updated descending select rh.Updated).Take(1).Single();
 936:                  }
 937:                  catch
 938:                  {
 939:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
 940:                  }
 941:              }
 942:  
 943:              return lastUpdatedDateTime;
 944:          }
 945:          */
 946:   
 947:          ////////////////////////////////////////////////////////////////////////////
 948:   
 949:          /// <summary>
 950:          ///
 951:          /// </summary>
 952:          public static Dictionary<int, string> CategoryDictionary
 953:          {
 954:              get
 955:              {
 956:                  Dictionary<int, string> dictionary;
 957:   
 958:                  dictionary = new Dictionary<int, string>(100);
 959:   
 960:                  dictionary = (from c in XDocument.Elements("report").Elements("category")
 961:                                select new { Id = int.Parse(c.Attribute("id").Value), Name = c.Attribute("name").Value }).ToDictionary(r => r.Id, r => r.Name);
 962:   
 963:                  return dictionary;
 964:              }
 965:          }
 966:   
 967:          ////////////////////////////////////////////////////////////////////////////
 968:   
 969:          /// <summary>
 970:          ///
 971:          /// </summary>
 972:          public static Dictionary<int, string> CategoryAreaIndicationDictionary(int categoryId, int areaId)
 973:          {
 974:              Dictionary<int, string> dictionary;
 975:   
 976:              dictionary = new Dictionary<int, string>(100);
 977:   
 978:              dictionary = (from i in XDocument.Elements("report").Elements("category").Elements("area").Elements("indicationList")
 979:                            where i.Parent.Parent.Attribute("id").Value == categoryId.ToString() && i.Parent.Attribute("id").Value == areaId.ToString()
 980:                            select new { Id = int.Parse(i.Attribute("id").Value), Name = i.Attribute("id").Value }).ToDictionary(r => r.Id, r => r.Name);
 981:   
 982:              return dictionary;
 983:          }
 984:   
 985:          ////////////////////////////////////////////////////////////////////////////
 986:   
 987:          /// <summary>
 988:          ///
 989:          /// </summary>
 990:          public static Dictionary<int, string> IndicationColoredDictionary
 991:          {
 992:              get
 993:              {
 994:                  return Dictionary(false, true, "category", "area", "indicationList", "indication").Concat(GeneralIndicationColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
 995:              }
 996:          }
 997:   
 998:          ////////////////////////////////////////////////////////////////////////////
 999:   
1000:          /// <summary>
1001:          ///
1002:          /// </summary>
1003:          public static Dictionary<int, string> ActionDictionary
1004:          {
1005:              get
1006:              {
1007:                  return Dictionary(false, false, "category", "area", "actionList", "action").Concat(GeneralActionDictionary).ToDictionary(q => q.Key, q => q.Value);
1008:              }
1009:          }
1010:   
1011:          ////////////////////////////////////////////////////////////////////////////
1012:   
1013:          /// <summary>
1014:          ///
1015:          /// </summary>
1016:          public static Dictionary<int, string> ActionColoredDictionary
1017:          {
1018:              get
1019:              {
1020:                  return Dictionary(false, true, "category", "area", "actionList", "action").Concat(GeneralActionColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1021:              }
1022:          }
1023:   
1024:          ////////////////////////////////////////////////////////////////////////////
1025:   
1026:          /// <summary>
1027:          ///
1028:          /// </summary>
1029:          public static Dictionary<int, string> ResolutionColoredDictionary
1030:          {
1031:              get
1032:              {
1033:                  return Dictionary(false, true, "resolution");
1034:              }
1035:          }
1036:   
1037:          ////////////////////////////////////////////////////////////////////////////
1038:   
1039:          /// <summary>
1040:          ///
1041:          /// </summary>
1042:          public static Dictionary<int, string> ResolutionEnglishAndArabicColoredDictionary
1043:          {
1044:              get
1045:              {
1046:                  return Dictionary(true, true, "resolution");
1047:              }
1048:          }
1049:   
1050:          ////////////////////////////////////////////////////////////////////////////
1051:   
1052:          /// <summary>
1053:          ///
1054:          /// </summary>
1055:          public static Dictionary<int, string> ResolutionDictionary
1056:          {
1057:              get
1058:              {
1059:                  return Dictionary(false, false, "resolution");
1060:              }
1061:          }
1062:   
1063:          ////////////////////////////////////////////////////////////////////////////
1064:   
1065:          /// <summary>
1066:          ///
1067:          /// </summary>
1068:          public static Dictionary<int, string> GeneralActionDictionary
1069:          {
1070:              get
1071:              {
1072:                  return Dictionary(false, false, "action");
1073:              }
1074:          }
1075:   
1076:          ////////////////////////////////////////////////////////////////////////////
1077:   
1078:          /// <summary>
1079:          ///
1080:          /// </summary>
1081:          public static Dictionary<int, string> GeneralActionColoredDictionary
1082:          {
1083:              get
1084:              {
1085:                  return Dictionary(false, true, "action");
1086:              }
1087:          }
1088:   
1089:          ////////////////////////////////////////////////////////////////////////////
1090:   
1091:          /// <summary>
1092:          ///
1093:          /// </summary>
1094:          public static Dictionary<int, string> GeneralIndicationDictionary
1095:          {
1096:              get
1097:              {
1098:                  return Dictionary(false, false, "indication");
1099:              }
1100:          }
1101:   
1102:          ////////////////////////////////////////////////////////////////////////////
1103:   
1104:          /// <summary>
1105:          ///
1106:          /// </summary>
1107:          public static Dictionary<int, string> GeneralIndicationColoredDictionary
1108:          {
1109:              get
1110:              {
1111:                  return Dictionary(false, true, "indication");
1112:              }
1113:          }
1114:   
1115:          ////////////////////////////////////////////////////////////////////////////
1116:   
1117:          /// <summary>
1118:          ///
1119:          /// </summary>
1120:          public static Dictionary<int, string> EstimateDictionary
1121:          {
1122:              get
1123:              {
1124:                  return Dictionary(false, false, "estimate");
1125:              }
1126:          }
1127:   
1128:          ////////////////////////////////////////////////////////////////////////////
1129:   
1130:          /// <summary>
1131:          ///
1132:          /// </summary>
1133:          public static Dictionary<int, string> EstimateColoredDictionary
1134:          {
1135:              get
1136:              {
1137:                  return Dictionary(false, true, "estimate");
1138:              }
1139:          }
1140:   
1141:          ////////////////////////////////////////////////////////////////////////////
1142:   
1143:          /// <summary>
1144:          ///
1145:          /// </summary>
1146:          public static Dictionary<int, string> EstimateEnglishAndArabicDictionary
1147:          {
1148:              get
1149:              {
1150:                  return Dictionary(true, false, "estimate");
1151:              }
1152:          }
1153:   
1154:          ////////////////////////////////////////////////////////////////////////////
1155:   
1156:          /// <summary>
1157:          ///
1158:          /// </summary>
1159:          public static Dictionary<int, string> EstimateEnglishAndArabicColoredDictionary
1160:          {
1161:              get
1162:              {
1163:                  return Dictionary(true, true, "estimate");
1164:              }
1165:          }
1166:   
1167:          ////////////////////////////////////////////////////////////////////////////
1168:   
1169:          /// <summary>
1170:          ///
1171:          /// </summary>
1172:          public static Dictionary<int, string> StatusDictionary
1173:          {
1174:              get
1175:              {
1176:                  return Dictionary(false, false, "status");
1177:              }
1178:          }
1179:   
1180:          ////////////////////////////////////////////////////////////////////////////
1181:   
1182:          /// <summary>
1183:          ///
1184:          /// </summary>
1185:          public static Dictionary<int, string> StatusColoredDictionary
1186:          {
1187:              get
1188:              {
1189:                  return Dictionary(false, true, "status");
1190:              }
1191:          }
1192:   
1193:          ////////////////////////////////////////////////////////////////////////////
1194:   
1195:          /// <summary>
1196:          ///
1197:          /// </summary>
1198:          public static Dictionary<int, string> PriorityDictionary
1199:          {
1200:              get
1201:              {
1202:                  return Dictionary(false, false, "priority");
1203:              }
1204:          }
1205:   
1206:          ////////////////////////////////////////////////////////////////////////////
1207:   
1208:          /// <summary>
1209:          ///
1210:          /// </summary>
1211:          public static Dictionary<int, string> PriorityColoredDictionary
1212:          {
1213:              get
1214:              {
1215:                  return Dictionary(false, true, "priority");
1216:              }
1217:          }
1218:   
1219:          ////////////////////////////////////////////////////////////////////////////
1220:   
1221:          /// <summary>
1222:          ///
1223:          /// </summary>
1224:          public static Dictionary<int, string> SeverityDictionary
1225:          {
1226:              get
1227:              {
1228:                  return Dictionary(false, false, "severity");
1229:              }
1230:          }
1231:   
1232:          ////////////////////////////////////////////////////////////////////////////
1233:   
1234:          /// <summary>
1235:          ///
1236:          /// </summary>
1237:          public static Dictionary<int, string> SeverityColoredDictionary
1238:          {
1239:              get
1240:              {
1241:                  return Dictionary(false, true, "severity");
1242:              }
1243:          }
1244:   
1245:          ////////////////////////////////////////////////////////////////////////////
1246:   
1247:          /// <summary>
1248:          ///
1249:          /// </summary>
1250:          public static Dictionary<int, string> CategoryAreaDictionary()
1251:          {
1252:              return Dictionary(false, false, "category", "area");
1253:          }
1254:   
1255:          ////////////////////////////////////////////////////////////////////////////
1256:   
1257:          /// <summary>
1258:          ///
1259:          /// </summary>
1260:          public static Dictionary<int, string> CategoryAreaDictionary(int categoryId)
1261:          {
1262:              return ColoredDictionary("category", "area", categoryId, false);
1263:          }
1264:   
1265:          ////////////////////////////////////////////////////////////////////////////
1266:   
1267:          /// <summary>
1268:          ///
1269:          /// </summary>
1270:          public static Dictionary<int, string> CategoryAreaColoredDictionary
1271:          {
1272:              get
1273:              {
1274:                  return Dictionary(false, true, "category", "area");
1275:              }
1276:          }
1277:   
1278:          ////////////////////////////////////////////////////////////////////////////
1279:   
1280:          /// <summary>
1281:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1282:          /// </summary>
1283:          private static Dictionary<int, string> Dictionary(bool englishAndArabicName, bool isColored, params string[] elementList)
1284:          {
1285:              int id;
1286:              string name, color;
1287:              Dictionary<int, string> dictionary;
1288:              IEnumerable<XElement> xElementIenumerable;
1289:   
1290:              dictionary = new Dictionary<int, string>(10);
1291:              xElementIenumerable = null;
1292:   
1293:              try
1294:              {
1295:                  switch (elementList.Length)
1296:                  {
1297:                      case 1: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]); break;
1298:                      case 2: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]); break;
1299:                      case 3: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]); break;
1300:                      case 4: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]).Elements(elementList[3]); break;
1301:                      default: break;
1302:                  }
1303:   
1304:                  foreach (XElement x in xElementIenumerable)
1305:                  {
1306:                      id = int.Parse(x.Attribute("id").Value);
1307:   
1308:                      if (englishAndArabicName)
1309:                      {
1310:                          if (x.Attribute("arabicName") != null)
1311:                          {
1312:                              name = x.Attribute("name").Value + " (" + x.Attribute("arabicName").Value + ")";
1313:                          }
1314:                          else name = x.Attribute("name").Value;
1315:                      }
1316:                      else name = x.Attribute("name").Value;
1317:   
1318:                      color = x.Attribute("color")?.Value;
1319:   
1320:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1321:                  }
1322:              }
1323:              catch (Exception e)
1324:              {
1325:   
1326:              }
1327:   
1328:              return dictionary;
1329:          }
1330:   
1331:          ////////////////////////////////////////////////////////////////////////////
1332:   
1333:          /// <summary>
1334:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1335:          /// </summary>
1336:          private static Dictionary<int, string> ColoredDictionary(string element, string secondElement, int categoryId, bool isColored)
1337:          {
1338:              int id;
1339:              string name, color;
1340:              Dictionary<int, string> dictionary;
1341:   
1342:              dictionary = new Dictionary<int, string>(100);
1343:   
1344:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement))
1345:              {
1346:                  if (x.Parent.Attribute("id").Value == categoryId.ToString())
1347:                  {
1348:                      id = int.Parse(x.Attribute("id").Value);
1349:                      name = x.Attribute("name").Value;
1350:                      color = x.Attribute("color")?.Value;
1351:   
1352:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1353:                  }
1354:              }
1355:   
1356:              return dictionary;
1357:          }
1358:   
1359:          ////////////////////////////////////////////////////////////////////////////
1360:   
1361:          /// <summary>
1362:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1363:          /// </summary>
1364:          private static Dictionary<int, string> Dictionary(string element, string secondElement, string thirdElement, string fourthElement, int categoryId, int categoryAreaId, bool isColored)
1365:          {
1366:              int id;
1367:              string name, color;
1368:              Dictionary<int, string> dictionary;
1369:   
1370:              dictionary = new Dictionary<int, string>(100);
1371:   
1372:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement).Elements(thirdElement).Elements(fourthElement))
1373:              {
1374:                  if (x.Parent.Parent.Parent.Attribute("id").Value == categoryId.ToString() && x.Parent.Parent.Attribute("id").Value == categoryAreaId.ToString())
1375:                  {
1376:                      id = int.Parse(x.Attribute("id").Value);
1377:                      name = x.Attribute("name").Value;
1378:                      color = x.Attribute("color")?.Value; // same as color = (x.Attribute("color") != null) ? x.Attribute("color").Value : null;
1379:   
1380:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1381:                  }
1382:              }
1383:   
1384:              return dictionary;
1385:          }
1386:   
1387:          ////////////////////////////////////////////////////////////////////////////
1388:   
1389:          /// <summary>
1390:          ///
1391:          /// </summary>
1392:          private static void ColoredDictionaryItem(ref Dictionary<int, string> dictionary, bool isColored, int id, string name, string color)
1393:          {
1394:              List<string> lightBackgroundColorList;
1395:   
1396:              if (isColored)
1397:              {
1398:                  // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1399:                  name = name.Replace(" ", "&nbsp;");
1400:   
1401:                  if (!string.IsNullOrEmpty(color))
1402:                  {
1403:                      dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
1404:                  }
1405:                  else
1406:                  {
1407:                      lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1408:   
1409:                      dictionary.Add(id, @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>");
1410:                  }
1411:              }
1412:              else
1413:              {
1414:                  dictionary.Add(id, name);
1415:              }
1416:          }
1417:   
1418:          ////////////////////////////////////////////////////////////////////////////
1419:   
1420:          /// <summary>
1421:          ///
1422:          /// </summary>
1423:          private static string ColoredName(int id, string name)
1424:          {
1425:              return ColoredName(id, name, null);
1426:          }
1427:   
1428:          ////////////////////////////////////////////////////////////////////////////
1429:   
1430:          /// <summary>
1431:          ///
1432:          /// </summary>
1433:          private static string ColoredName(int id, string name, string color)
1434:          {
1435:              string coloredName;
1436:              List<string> lightBackgroundColorList;
1437:   
1438:              lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1439:   
1440:              if (!string.IsNullOrEmpty(color)) coloredName = @"<span style=""color:" + color + @""">" + name + "</span>";
1441:              else coloredName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>";
1442:   
1443:              return coloredName;
1444:          }
1445:   
1446:          ////////////////////////////////////////////////////////////////////////////
1447:          ////////////////////////////////////////////////////////////////////////////
1448:   
1449:          /// <summary>
1450:          ///
1451:          /// </summary>
1452:          public static List<Ia.Ngn.Cl.Model.Business.Report.Category> CategoryList
1453:          {
1454:              get
1455:              {
1456:                  if (categoryList == null || categoryList.Count == 0)
1457:                  {
1458:                      int id;
1459:                      Ia.Ngn.Cl.Model.Business.Report.Category category;
1460:   
1461:                      categoryList = new List<Ia.Ngn.Cl.Model.Business.Report.Category>();
1462:   
1463:                      foreach (XElement x in XDocument.Element("report").Elements("category"))
1464:                      {
1465:                          category = new Ia.Ngn.Cl.Model.Business.Report.Category();
1466:   
1467:                          id = int.Parse(x.Attribute("id").Value);
1468:   
1469:                          category.Id = id;
1470:                          category.Name = x.Attribute("name").Value;
1471:                          category.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
1472:   
1473:                          categoryList.Add(category);
1474:                      }
1475:                  }
1476:   
1477:                  return categoryList;
1478:              }
1479:          }
1480:   
1481:          ////////////////////////////////////////////////////////////////////////////
1482:   
1483:          /// <summary>
1484:          ///
1485:          /// </summary>
1486:          public static List<Ia.Ngn.Cl.Model.Business.Report.Area> AreaList
1487:          {
1488:              get
1489:              {
1490:                  if (areaList == null || areaList.Count == 0)
1491:                  {
1492:                      int categoryId, id;
1493:                      Ia.Ngn.Cl.Model.Business.Report.Area area;
1494:   
1495:                      areaList = new List<Ia.Ngn.Cl.Model.Business.Report.Area>();
1496:   
1497:                      foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1498:                      {
1499:                          area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1500:                          area.Category = new Ia.Ngn.Cl.Model.Business.Report.Category();
1501:   
1502:                          categoryId = int.Parse(x.Parent.Attribute("id").Value);
1503:                          id = int.Parse(x.Attribute("id").Value);
1504:   
1505:                          area.Id = area.AreaId(categoryId, id);
1506:                          area.XmlId = id;
1507:                          area.Category = (from c in CategoryList where c.Id == categoryId select c).SingleOrDefault();
1508:                          area.Name = x.Attribute("name").Value;
1509:                          area.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
1510:   
1511:                          if (x.Attribute("framework") != null)
1512:                          {
1513:                              area.Frameworks = new List<string>(100);
1514:   
1515:                              foreach (string s in x.Attribute("framework").Value.Split(',')) area.Frameworks.Add(s);
1516:                          }
1517:   
1518:                          areaList.Add(area);
1519:                      }
1520:                  }
1521:   
1522:                  return areaList;
1523:              }
1524:          }
1525:   
1526:          ////////////////////////////////////////////////////////////////////////////
1527:   
1528:          /// <summary>
1529:          ///
1530:          /// </summary>
1531:          public static List<Ia.Ngn.Cl.Model.Business.Report.Indication> IndicationList
1532:          {
1533:              get
1534:              {
1535:                  lock (objectLock)
1536:                  {
1537:                      if (indicationList == null || indicationList.Count == 0) indicationList = Ia.Ngn.Cl.Model.Data.Report._IndicationList;
1538:   
1539:                      return indicationList;
1540:                  }
1541:              }
1542:          }
1543:   
1544:          ////////////////////////////////////////////////////////////////////////////
1545:   
1546:          /// <summary>
1547:          ///
1548:          /// </summary>
1549:          private static List<Ia.Ngn.Cl.Model.Business.Report.Indication> _IndicationList
1550:          {
1551:              get
1552:              {
1553:                  int categoryId, areaId, id;
1554:                  Ia.Ngn.Cl.Model.Business.Report.Indication indication;
1555:   
1556:                  indicationList = new List<Ia.Ngn.Cl.Model.Business.Report.Indication>();
1557:   
1558:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("indicationList").Elements("indication"))
1559:                  {
1560:                      indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
1561:                      indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1562:   
1563:                      categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1564:                      areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1565:                      id = int.Parse(x.Attribute("id").Value);
1566:   
1567:                      areaId = indication.Area.AreaId(categoryId, areaId);
1568:   
1569:                      indication.Id = indication.IndicationId(areaId, id);
1570:                      indication.XmlId = id;
1571:                      indication.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1572:   
1573:                      // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1574:                      if (x.Attribute("obsolete") != null) indication.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1575:                      else indication.Obsolete = false;
1576:   
1577:                      // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1578:                      if (x.Attribute("canInsert") != null) indication.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1579:                      else indication.CanInsert = true;
1580:   
1581:                      indication.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1582:   
1583:                      // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1584:                      indication.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1585:                      indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
1586:   
1587:                      if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1588:                      {
1589:                          indication.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1590:                          indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
1591:                      }
1592:                      else
1593:                      {
1594:                          indication.ArabicName = string.Empty;
1595:                          indication.ColoredArabicName = string.Empty;
1596:                      }
1597:   
1598:                      if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
1599:                      else indication.EnglishAndArabicName = indication.Name;
1600:   
1601:                      if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
1602:                      else indication.ColoredEnglishAndArabicName = indication.ColoredName;
1603:   
1604:                      if (x.Parent.Attribute("framework") != null)
1605:                      {
1606:                          indication.Frameworks = new List<string>(100);
1607:   
1608:                          foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) indication.Frameworks.Add(s);
1609:                      }
1610:   
1611:                      indicationList.Add(indication);
1612:                  }
1613:   
1614:                  // below: add the general indications to all areas
1615:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1616:                  {
1617:                      foreach (XElement y in XDocument.Element("report").Elements("indication"))
1618:                      {
1619:                          indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
1620:                          indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1621:   
1622:                          categoryId = int.Parse(x.Parent.Attribute("id").Value);
1623:                          areaId = int.Parse(x.Attribute("id").Value);
1624:                          id = int.Parse(y.Attribute("id").Value); // y
1625:   
1626:                          areaId = indication.Area.AreaId(categoryId, areaId);
1627:   
1628:                          indication.Id = indication.IndicationId(areaId, id);
1629:                          indication.XmlId = id;
1630:                          indication.Area = null;// (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
1631:   
1632:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1633:                          if (y.Attribute("obsolete") != null) indication.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1634:                          else indication.Obsolete = false;
1635:   
1636:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1637:                          if (y.Attribute("canInsert") != null) indication.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1638:                          else indication.CanInsert = true;
1639:   
1640:                          indication.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1641:   
1642:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1643:                          indication.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1644:                          indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
1645:   
1646:                          if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1647:                          {
1648:                              indication.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1649:                              indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
1650:                          }
1651:                          else
1652:                          {
1653:                              indication.ArabicName = string.Empty;
1654:                              indication.ColoredArabicName = string.Empty;
1655:                          }
1656:   
1657:                          if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
1658:                          else indication.EnglishAndArabicName = indication.Name;
1659:   
1660:                          if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
1661:                          else indication.ColoredEnglishAndArabicName = indication.ColoredName;
1662:   
1663:                          indicationList.Add(indication);
1664:                      }
1665:                  }
1666:   
1667:                  return indicationList;
1668:              }
1669:          }
1670:   
1671:          ////////////////////////////////////////////////////////////////////////////
1672:   
1673:          /// <summary>
1674:          ///
1675:          /// </summary>
1676:          public static List<Ia.Ngn.Cl.Model.Business.Report.Action> ActionList
1677:          {
1678:              get
1679:              {
1680:                  lock (objectLock)
1681:                  {
1682:                      if (actionList == null || actionList.Count == 0) actionList = Ia.Ngn.Cl.Model.Data.Report._ActionList;
1683:   
1684:                      return actionList;
1685:                  }
1686:              }
1687:          }
1688:   
1689:          ////////////////////////////////////////////////////////////////////////////
1690:   
1691:          /// <summary>
1692:          ///
1693:          /// </summary>
1694:          private static List<Ia.Ngn.Cl.Model.Business.Report.Action> _ActionList
1695:          {
1696:              get
1697:              {
1698:                  int categoryId, areaId, id;
1699:                  Ia.Ngn.Cl.Model.Business.Report.Action action;
1700:   
1701:                  actionList = new List<Ia.Ngn.Cl.Model.Business.Report.Action>();
1702:   
1703:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("actionList").Elements("action"))
1704:                  {
1705:                      action = new Ia.Ngn.Cl.Model.Business.Report.Action();
1706:                      action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1707:   
1708:                      categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1709:                      areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1710:                      id = int.Parse(x.Attribute("id").Value);
1711:   
1712:                      areaId = action.Area.AreaId(categoryId, areaId);
1713:   
1714:                      action.Id = action.ActionId(areaId, id);
1715:                      action.XmlId = id;
1716:                      action.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1717:   
1718:                      // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1719:                      if (x.Attribute("obsolete") != null) action.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1720:                      else action.Obsolete = false;
1721:   
1722:                      // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1723:                      if (x.Attribute("canInsert") != null) action.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1724:                      else action.CanInsert = true;
1725:   
1726:                      action.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1727:   
1728:                      // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1729:                      action.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1730:                      action.ColoredName = ColoredName(id, action.Name, action.Color);
1731:   
1732:                      if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1733:                      {
1734:                          action.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1735:                          action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
1736:                      }
1737:                      else
1738:                      {
1739:                          action.ArabicName = string.Empty;
1740:                          action.ColoredArabicName = string.Empty;
1741:                      }
1742:   
1743:                      if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
1744:                      else action.EnglishAndArabicName = action.Name;
1745:   
1746:                      if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
1747:                      else action.ColoredEnglishAndArabicName = action.ColoredName;
1748:   
1749:                      if (x.Parent.Attribute("framework") != null)
1750:                      {
1751:                          action.Frameworks = new List<string>(100);
1752:   
1753:                          foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) action.Frameworks.Add(s);
1754:                      }
1755:   
1756:                      actionList.Add(action);
1757:                  }
1758:   
1759:                  // below: add the general actions to all areas
1760:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1761:                  {
1762:                      foreach (XElement y in XDocument.Element("report").Elements("action"))
1763:                      {
1764:                          action = new Ia.Ngn.Cl.Model.Business.Report.Action();
1765:                          action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1766:   
1767:                          categoryId = int.Parse(x.Parent.Attribute("id").Value);
1768:                          areaId = int.Parse(x.Attribute("id").Value);
1769:                          id = int.Parse(y.Attribute("id").Value); // y
1770:   
1771:                          areaId = action.Area.AreaId(categoryId, areaId);
1772:   
1773:                          action.Id = action.ActionId(areaId, id);
1774:                          action.XmlId = id;
1775:                          action.Area = null; // (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
1776:   
1777:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1778:                          if (y.Attribute("obsolete") != null) action.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1779:                          else action.Obsolete = false;
1780:   
1781:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1782:                          if (y.Attribute("canInsert") != null) action.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1783:                          else action.CanInsert = true;
1784:   
1785:                          action.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1786:   
1787:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1788:                          action.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1789:                          action.ColoredName = ColoredName(id, action.Name, action.Color);
1790:   
1791:                          if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1792:                          {
1793:                              action.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1794:                              action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
1795:                          }
1796:                          else
1797:                          {
1798:                              action.ArabicName = string.Empty;
1799:                              action.ColoredArabicName = string.Empty;
1800:                          }
1801:   
1802:                          if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
1803:                          else action.EnglishAndArabicName = action.Name;
1804:   
1805:                          if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
1806:                          else action.ColoredEnglishAndArabicName = action.ColoredName;
1807:   
1808:                          actionList.Add(action);
1809:                      }
1810:                  }
1811:   
1812:                  return actionList;
1813:              }
1814:          }
1815:   
1816:          ////////////////////////////////////////////////////////////////////////////
1817:   
1818:          /// <summary>
1819:          ///
1820:          /// </summary>
1821:          public static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> ResolutionList
1822:          {
1823:              get
1824:              {
1825:                  lock (objectLock)
1826:                  {
1827:                      if (resolutionList == null || resolutionList.Count == 0) resolutionList = Ia.Ngn.Cl.Model.Data.Report._ResolutionList;
1828:   
1829:                      return resolutionList;
1830:                  }
1831:              }
1832:          }
1833:   
1834:          ////////////////////////////////////////////////////////////////////////////
1835:   
1836:          /// <summary>
1837:          ///
1838:          /// </summary>
1839:          private static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> _ResolutionList
1840:          {
1841:              get
1842:              {
1843:                  int categoryId, areaId, id;
1844:                  Ia.Ngn.Cl.Model.Business.Report.Resolution resolution;
1845:   
1846:                  resolutionList = new List<Ia.Ngn.Cl.Model.Business.Report.Resolution>();
1847:   
1848:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("resolutionList").Elements("resolution"))
1849:                  {
1850:                      resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
1851:                      resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1852:   
1853:                      categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
1854:                      areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
1855:                      id = int.Parse(x.Attribute("id").Value);
1856:   
1857:                      areaId = resolution.Area.AreaId(categoryId, areaId);
1858:   
1859:                      resolution.Id = resolution.ResolutionId(areaId, id);
1860:                      resolution.XmlId = id;
1861:                      resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1862:   
1863:                      // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1864:                      if (x.Attribute("obsolete") != null) resolution.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
1865:                      else resolution.Obsolete = false;
1866:   
1867:                      // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1868:                      if (x.Attribute("canInsert") != null) resolution.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
1869:                      else resolution.CanInsert = true;
1870:   
1871:                      resolution.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
1872:   
1873:                      // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1874:                      resolution.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
1875:                      resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
1876:   
1877:                      if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
1878:                      {
1879:                          resolution.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1880:                          resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
1881:                      }
1882:                      else
1883:                      {
1884:                          resolution.ArabicName = string.Empty;
1885:                          resolution.ColoredArabicName = string.Empty;
1886:                      }
1887:   
1888:                      if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
1889:                      else resolution.EnglishAndArabicName = resolution.Name;
1890:   
1891:                      if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
1892:                      else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
1893:   
1894:                      resolutionList.Add(resolution);
1895:                  }
1896:   
1897:                  // below: add the general resolutions to all areas
1898:                  foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
1899:                  {
1900:                      foreach (XElement y in XDocument.Element("report").Elements("resolution"))
1901:                      {
1902:                          resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
1903:                          resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
1904:   
1905:                          categoryId = int.Parse(x.Parent.Attribute("id").Value);
1906:                          areaId = int.Parse(x.Attribute("id").Value);
1907:                          id = int.Parse(y.Attribute("id").Value); // y
1908:   
1909:                          areaId = resolution.Area.AreaId(categoryId, areaId);
1910:   
1911:                          resolution.Id = resolution.ResolutionId(areaId, id);
1912:                          resolution.XmlId = id;
1913:                          resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
1914:   
1915:                          // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
1916:                          if (y.Attribute("obsolete") != null) resolution.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
1917:                          else resolution.Obsolete = false;
1918:   
1919:                          // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
1920:                          if (y.Attribute("canInsert") != null) resolution.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
1921:                          else resolution.CanInsert = true;
1922:   
1923:                          resolution.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
1924:   
1925:                          // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1926:                          resolution.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
1927:                          resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
1928:   
1929:                          if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
1930:                          {
1931:                              resolution.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
1932:                              resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
1933:                          }
1934:                          else
1935:                          {
1936:                              resolution.ArabicName = string.Empty;
1937:                              resolution.ColoredArabicName = string.Empty;
1938:                          }
1939:   
1940:                          if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
1941:                          else resolution.EnglishAndArabicName = resolution.Name;
1942:   
1943:                          if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
1944:                          else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
1945:   
1946:                          resolutionList.Add(resolution);
1947:                      }
1948:                  }
1949:   
1950:                  return resolutionList;
1951:              }
1952:          }
1953:   
1954:          ////////////////////////////////////////////////////////////////////////////
1955:          ////////////////////////////////////////////////////////////////////////////
1956:   
1957:          /// <summary>
1958:          /// 
1959:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
1960:          /// 
1961:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
1962:          /// 2. Add "using System.Reflection".
1963:          /// 3. See sample below.
1964:          /// 
1965:          /// </summary>
1966:   
1967:          public static XDocument XDocument
1968:          {
1969:              get
1970:              {
1971:                  if (xDocument == null)
1972:                  {
1973:                      Assembly _assembly;
1974:                      StreamReader streamReader;
1975:   
1976:                      _assembly = Assembly.GetExecutingAssembly();
1977:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.report.xml"));
1978:   
1979:                      try
1980:                      {
1981:                          if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
1982:                      }
1983:                      catch (Exception)
1984:                      {
1985:                      }
1986:                      finally
1987:                      {
1988:                      }
1989:                  }
1990:   
1991:                  return xDocument;
1992:              }
1993:          }
1994:   
1995:          ////////////////////////////////////////////////////////////////////////////
1996:          ////////////////////////////////////////////////////////////////////////////    
1997:      }
1998:   
1999:      ////////////////////////////////////////////////////////////////////////////
2000:      ////////////////////////////////////////////////////////////////////////////   
2001:  }