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