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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Report

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

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

   1:  using System;
   2:  using System.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:                  // bug: always hang the first time I call the page
1038:                  ReportResponsibilityByStaffGuidListDictionary[staff.UserId] = (from r in reportList select r.Id).ToList();
1039:              }
1040:              else reportList = null;
1041:   
1042:              return reportList;
1043:          }
1044:   
1045:          ////////////////////////////////////////////////////////////////////////////
1046:   
1047:          /// <summary>
1048:          ///
1049:          /// </summary>
1050:          private static void StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(ref Ia.Ngn.Cl.Model.Staff staff, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList)
1051:          {
1052:              staffFrameworkAncestorAndDescendantUserIdList = new List<Guid>();
1053:              staffSubordinatesUserIdList = new List<Guid>();
1054:   
1055:              // below: add self framework
1056:              staffFrameworkAncestorAndDescendantUserIdList.Add(staff.Framework.Guid);
1057:   
1058:              // below: add ancestor frameworks
1059:              if (staff.Framework.Ancestors != null)
1060:              {
1061:                  foreach (Ia.Ngn.Cl.Model.Data.Administration.Framework ancestor in staff.Framework.Ancestors.ToList())
1062:                      staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Guid);
1063:              }
1064:   
1065:              // below: add decendant frameworks
1066:              if (staff.Framework.Descendants != null)
1067:              {
1068:                  foreach (Ia.Ngn.Cl.Model.Data.Administration.Framework descendant in staff.Framework.Descendants.ToList())
1069:                      staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Guid);
1070:              }
1071:   
1072:              // below: add children staff
1073:              if (staff.Subordinates != null)
1074:              {
1075:                  foreach (Ia.Ngn.Cl.Model.Staff subordinate in staff.Subordinates.ToList()) staffSubordinatesUserIdList.Add(subordinate.UserId);
1076:              }
1077:          }
1078:   
1079:          ////////////////////////////////////////////////////////////////////////////
1080:   
1081:          /// <summary>
1082:          ///
1083:          /// </summary>
1084:          public static List<Ia.Ngn.Cl.Model.Report> FrameworkReadabilityReportList(Guid frameworkGuid)
1085:          {
1086:              Ia.Ngn.Cl.Model.Data.Administration.Framework framework;
1087:              List<Guid> staffFrameworkAncestorAndDescendantUserIdList;
1088:              List<Guid> staffSubordinatesUserIdList;
1089:              List<Ia.Ngn.Cl.Model.Report> reportList;
1090:   
1091:              framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.Guid == frameworkGuid select f).SingleOrDefault();
1092:   
1093:              if (framework != null)
1094:              {
1095:                  FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(ref framework, out staffFrameworkAncestorAndDescendantUserIdList, out staffSubordinatesUserIdList);
1096:   
1097:                  reportList = Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
1098:   
1099:                  reportList = (from r in reportList
1100:                                where r.LastReportHistory == null && Ia.Ngn.Cl.Model.Business.Authority.FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(framework)
1101:                                || r.LastReportHistory == null && r.UserId == framework.Guid
1102:                                || staffSubordinatesUserIdList.Contains(r.UserId)
1103:                                || staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
1104:                                || r.LastReportHistory != null && r.LastReportHistory.UserId == framework.Guid
1105:                                || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
1106:                                || r.ReportHistories != null && r.ReportHistories.Any(u => staffSubordinatesUserIdList.Contains(u.UserId))
1107:                                || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
1108:   
1109:                                select r).ToList();
1110:              }
1111:              else reportList = null;
1112:   
1113:              return reportList;
1114:          }
1115:   
1116:          ////////////////////////////////////////////////////////////////////////////
1117:   
1118:          /// <summary>
1119:          ///
1120:          /// </summary>
1121:          private static void FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(ref Ia.Ngn.Cl.Model.Data.Administration.Framework framework, out List<Guid> staffFrameworkAncestorAndDescendantUserIdList, out List<Guid> staffSubordinatesUserIdList)
1122:          {
1123:              staffFrameworkAncestorAndDescendantUserIdList = new List<Guid>();
1124:              staffSubordinatesUserIdList = new List<Guid>();
1125:   
1126:              // below: add self framework
1127:              staffFrameworkAncestorAndDescendantUserIdList.Add(framework.Guid);
1128:   
1129:              if (framework.Ancestors != null)
1130:              {
1131:                  // below: add ancestor frameworks
1132:                  foreach (Ia.Ngn.Cl.Model.Data.Administration.Framework ancestor in framework.Ancestors) staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Guid);
1133:              }
1134:   
1135:              if (framework.Descendants != null)
1136:              {
1137:                  // below: add decendants
1138:                  foreach (Ia.Ngn.Cl.Model.Data.Administration.Framework descendant in framework.Descendants) staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Guid);
1139:              }
1140:   
1141:              // below: add children staff of any of the list of frameworks collected
1142:              staffSubordinatesUserIdList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
1143:                                             join sfadu in staffFrameworkAncestorAndDescendantUserIdList on s.Framework.Guid equals sfadu
1144:                                             select s.UserId).ToList();
1145:          }
1146:   
1147:          ////////////////////////////////////////////////////////////////////////////
1148:          ////////////////////////////////////////////////////////////////////////////
1149:   
1150:          /// <summary>
1151:          ///
1152:          /// </summary>
1153:          public static List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> ReadSpecificUserIdListAndSiteIdReportWithReportOpenStatusList(List<Guid> userIdList, int siteId)
1154:          {
1155:              List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> reportAccessServiceRequestList;
1156:   
1157:              if (siteId == 0) reportAccessServiceRequestList = ReadSpecificUserIdListReportWithReportOpenStatusList_(userIdList);
1158:              else
1159:              {
1160:                  var v = ReadSpecificUserIdListReportWithReportOpenStatusList_(userIdList);
1161:   
1162:                  if (v != null)
1163:                  {
1164:                      reportAccessServiceRequestList = (from rasr in v
1165:                                                        join s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList on siteId equals s.Id
1166:                                                        where rasr.Access != null && s.KuwaitNgnAreas.Any(u => u.Id == rasr.Access.AreaId)
1167:                                                        select rasr).ToList();
1168:                  }
1169:                  else
1170:                  {
1171:                      reportAccessServiceRequestList = new List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest>();
1172:                  }
1173:              }
1174:   
1175:              return reportAccessServiceRequestList;
1176:          }
1177:   
1178:          ////////////////////////////////////////////////////////////////////////////
1179:   
1180:          /// <summary>
1181:          ///
1182:          /// </summary>
1183:          private static List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> ReadSpecificUserIdListReportWithReportOpenStatusList_(List<Guid> userIdList)
1184:          {
1185:              string prividUser, accessId;
1186:              List<string> serviceIdList, prividUserList;
1187:              Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest reportAccessServiceRequest;
1188:              List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest> reportAccessServiceRequestList;
1189:              List<Ia.Ngn.Cl.Model.Report> reportList;
1190:              List<Ia.Ngn.Cl.Model.Nokia.AgcfEndpoint> agcfEndpointList;
1191:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
1192:   
1193:              reportAccessServiceRequestList = null;
1194:   
1195:              serviceIdList = new List<string>();
1196:              prividUserList = new List<string>();
1197:   
1198:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1199:              {
1200:                  // <status id="1" name="Open" arabicName="مفتوح"/>
1201:                  // <status id="2" name="Closed" arabicName="مغلق"/>
1202:   
1203:                  if (userIdList != null && userIdList.Count > 0)
1204:                  {
1205:                      reportList = (from r in db.Reports
1206:                                    join srs in db.ServiceRequestServices on r.Service equals srs.Service into gj
1207:                                    where (r.Status == 1 && (r.ReportHistories.Any(y => userIdList.Any(z => z == y.UserId))))
1208:                                    orderby r.Created
1209:                                    from sub in gj.DefaultIfEmpty()
1210:                                    select r).Include(x => x.ReportHistories).ToList();
1211:   
1212:                      if (reportList.Count > 0)
1213:                      {
1214:                          foreach (var v in reportList)
1215:                          {
1216:                              serviceIdList.Add(v.Service);
1217:   
1218:                              prividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(v.Service);
1219:                              prividUserList.Add(prividUser);
1220:                          }
1221:   
1222:                          serviceRequestServiceList = (from srs in db.ServiceRequestServices
1223:                                                       where serviceIdList.Contains(srs.Service)
1224:                                                       select srs).ToList();
1225:   
1226:                          agcfEndpointList = (from ep in db.AgcfEndpoints
1227:                                              where prividUserList.Contains(ep.PrividUser)
1228:                                              select ep).ToList();
1229:   
1230:                          reportAccessServiceRequestList = new List<Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest>();
1231:   
1232:                          foreach (Ia.Ngn.Cl.Model.Report report in reportList)
1233:                          {
1234:                              // below: the aggregate function will check the last entry
1235:                              if (userIdList.Contains(report.ReportHistories.Aggregate((i, j) => i.Id > j.Id ? i : j).UserId))
1236:                              {
1237:                                  reportAccessServiceRequest = new Ia.Ngn.Cl.Model.Ui.ReportAccessServiceRequest();
1238:   
1239:                                  reportAccessServiceRequest.Report = report;
1240:                                  reportAccessServiceRequest.Report.ReportHistories = report.ReportHistories; // this to force inclusion of ReportHistories
1241:   
1242:                                  if (report.ServiceType == 1)
1243:                                  {
1244:                                      reportAccessServiceRequest.Access = (from srs in serviceRequestServiceList where srs.Service == report.Service select srs.Access).FirstOrDefault();
1245:   
1246:                                      prividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(report.Service);
1247:                                      reportAccessServiceRequest.FlatTermId = (from ep in agcfEndpointList where ep.Id == prividUser select ep.FlatTermID).SingleOrDefault();
1248:                                  }
1249:                                  else //if(report.ServiceType == 2)
1250:                                  {
1251:                                      accessId = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == report.Service select o.Access.Id).SingleOrDefault();
1252:   
1253:                                      if (!string.IsNullOrEmpty(accessId))
1254:                                      {
1255:                                          reportAccessServiceRequest.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
1256:                                      }
1257:                                      else reportAccessServiceRequest.Access = null;
1258:   
1259:                                      reportAccessServiceRequest.FlatTermId = 0;
1260:                                  }
1261:   
1262:                                  reportAccessServiceRequestList.Add(reportAccessServiceRequest);
1263:                              }
1264:                          }
1265:                      }
1266:                      else
1267:                      {
1268:                      }
1269:                  }
1270:                  else
1271:                  {
1272:                  }
1273:              }
1274:   
1275:              return reportAccessServiceRequestList;
1276:          }
1277:   
1278:          ////////////////////////////////////////////////////////////////////////////
1279:   
1280:          /// <summary>
1281:          /// When a report list is updated I will reset local lists to null to generate new list
1282:          /// </summary>
1283:          public static void DbContextProbablyUpdated()
1284:          {
1285:              openStatusOrClosedStatusWithinLast24HourReportList = null;
1286:          }
1287:   
1288:          ////////////////////////////////////////////////////////////////////////////
1289:   
1290:          /// <summary>
1291:          ///
1292:          /// </summary>
1293:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourReportList
1294:          {
1295:              get
1296:              {
1297:                  if (openStatusOrClosedStatusWithinLast24HourReportList == null || openStatusOrClosedStatusWithinLast24HourReportList.Count == 0)
1298:                  {
1299:                      DateTime before24Hour;
1300:   
1301:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
1302:                      {
1303:                          before24Hour = DateTime.UtcNow.AddHours(3).AddDays(-1);
1304:   
1305:                          // <status id="1" name="Open" arabicName="مفتوح"/>
1306:                          // <status id="2" name="Closed" arabicName="مغلق"/>
1307:   
1308:                          openStatusOrClosedStatusWithinLast24HourReportList = (from r in db.Reports
1309:                                                                                where r.Status == 1 || (r.Status == 2 && r.Updated >= before24Hour)
1310:                                                                                orderby r.Created
1311:                                                                                select r).Include(x => x.ReportHistories).ToList();
1312:                      }
1313:                  }
1314:   
1315:                  return openStatusOrClosedStatusWithinLast24HourReportList;
1316:              }
1317:          }
1318:   
1319:          ////////////////////////////////////////////////////////////////////////////
1320:   
1321:          /// <summary>
1322:          ///
1323:          /// </summary>
1324:          public static List<Ia.Ngn.Cl.Model.Report> OpenStatusAndClosedStatusWithinLast24HourWithNonEmptyReportHistoryReportList()
1325:          {
1326:              var reportList = OpenStatusOrClosedStatusWithinLast24HourReportList;
1327:   
1328:              var lastReportHistoryNotNullReportList = (from r in reportList where r.LastReportHistory != null select r).ToList();
1329:   
1330:              return lastReportHistoryNotNullReportList;
1331:          }
1332:   
1333:          ////////////////////////////////////////////////////////////////////////////
1334:   
1335:          /// <summary>
1336:          ///
1337:          /// </summary>
1338:          public static List<Ia.Ngn.Cl.Model.Report> ReadOpenStatusReportList
1339:          {
1340:              get
1341:              {
1342:                  List<Ia.Ngn.Cl.Model.Report> reportList;
1343:   
1344:                  reportList = (from r in OpenStatusOrClosedStatusWithinLast24HourReportList where r.Status == 1 orderby r.Created select r).ToList();
1345:   
1346:                  return reportList;
1347:              }
1348:          }
1349:   
1350:          ////////////////////////////////////////////////////////////////////////////
1351:   
1352:          /// <summary>
1353:          ///
1354:          /// </summary>
1355:          public static List<Ia.Ngn.Cl.Model.Report> ReadSingleAsList(int reportId)
1356:          {
1357:              List<Ia.Ngn.Cl.Model.Report> reportList;
1358:   
1359:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1360:              {
1361:                  reportList = (from r in db.Reports where r.Id == reportId select r).Include(x => x.ReportHistories).ToList();
1362:              }
1363:   
1364:              return reportList;
1365:          }
1366:   
1367:          ////////////////////////////////////////////////////////////////////////////
1368:   
1369:          /// <summary>
1370:          ///
1371:          /// </summary>
1372:          public static DateTime LastUpdatedDateTime()
1373:          {
1374:              DateTime lastUpdatedDateTime;
1375:   
1376:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1377:              {
1378:                  try
1379:                  {
1380:                      lastUpdatedDateTime = (from r in db.Reports orderby r.Updated descending select r.Updated).Take(1).Single();
1381:                  }
1382:                  catch
1383:                  {
1384:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
1385:                  }
1386:              }
1387:   
1388:              return lastUpdatedDateTime;
1389:          }
1390:   
1391:          ////////////////////////////////////////////////////////////////////////////
1392:   
1393:          /// <summary>
1394:          ///
1395:          /// </summary>
1396:          public static DateTime LastUpdatedDateTimeOfHistory()
1397:          {
1398:              DateTime lastUpdatedDateTime;
1399:   
1400:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1401:              {
1402:                  try
1403:                  {
1404:                      lastUpdatedDateTime = (from rh in db.ReportHistories orderby rh.Updated descending select rh.Updated).Take(1).Single();
1405:                  }
1406:                  catch
1407:                  {
1408:                      lastUpdatedDateTime = Ia.Ngn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
1409:                  }
1410:              }
1411:   
1412:              return lastUpdatedDateTime;
1413:          }
1414:   
1415:          ////////////////////////////////////////////////////////////////////////////
1416:   
1417:          /// <summary>
1418:          ///
1419:          /// </summary>
1420:          public static Dictionary<int, string> CategoryDictionary
1421:          {
1422:              get
1423:              {
1424:                  Dictionary<int, string> dictionary;
1425:   
1426:                  dictionary = new Dictionary<int, string>(100);
1427:   
1428:                  dictionary = (from c in XDocument.Elements("report").Elements("category")
1429:                                select new { Id = int.Parse(c.Attribute("id").Value), Name = c.Attribute("name").Value }).ToDictionary(r => r.Id, r => r.Name);
1430:   
1431:                  return dictionary;
1432:              }
1433:          }
1434:   
1435:          ////////////////////////////////////////////////////////////////////////////
1436:   
1437:          /// <summary>
1438:          ///
1439:          /// </summary>
1440:          public static Dictionary<int, string> CategoryAreaIndicationDictionary(int categoryId, int areaId)
1441:          {
1442:              Dictionary<int, string> dictionary;
1443:   
1444:              dictionary = new Dictionary<int, string>(100);
1445:   
1446:              dictionary = (from i in XDocument.Elements("report").Elements("category").Elements("area").Elements("indicationList")
1447:                            where i.Parent.Parent.Attribute("id").Value == categoryId.ToString() && i.Parent.Attribute("id").Value == areaId.ToString()
1448:                            select new { Id = int.Parse(i.Attribute("id").Value), Name = i.Attribute("id").Value }).ToDictionary(r => r.Id, r => r.Name);
1449:   
1450:              return dictionary;
1451:          }
1452:   
1453:          ////////////////////////////////////////////////////////////////////////////
1454:   
1455:          /// <summary>
1456:          ///
1457:          /// </summary>
1458:          public static Dictionary<int, string> IndicationColoredDictionary
1459:          {
1460:              get
1461:              {
1462:                  return Dictionary(false, true, "category", "area", "indicationList", "indication").Concat(GeneralIndicationColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1463:              }
1464:          }
1465:   
1466:          ////////////////////////////////////////////////////////////////////////////
1467:   
1468:          /// <summary>
1469:          ///
1470:          /// </summary>
1471:          public static Dictionary<int, string> _IndicationColoredDictionary(int categoryId, int categoryAreaId)
1472:          {
1473:              return Dictionary("category", "area", "indicationList", "indication", categoryId, categoryAreaId, true).Concat(GeneralIndicationColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1474:          }
1475:   
1476:          ////////////////////////////////////////////////////////////////////////////
1477:   
1478:          /// <summary>
1479:          ///
1480:          /// </summary>
1481:          public static Dictionary<int, string> ActionDictionary
1482:          {
1483:              get
1484:              {
1485:                  return Dictionary(false, false, "category", "area", "actionList", "action").Concat(GeneralActionDictionary).ToDictionary(q => q.Key, q => q.Value);
1486:              }
1487:          }
1488:   
1489:          ////////////////////////////////////////////////////////////////////////////
1490:   
1491:          /// <summary>
1492:          ///
1493:          /// </summary>
1494:          public static Dictionary<int, string> ActionColoredDictionary
1495:          {
1496:              get
1497:              {
1498:                  return Dictionary(false, true, "category", "area", "actionList", "action").Concat(GeneralActionColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1499:              }
1500:          }
1501:   
1502:          ////////////////////////////////////////////////////////////////////////////
1503:   
1504:          /// <summary>
1505:          ///
1506:          /// </summary>
1507:          public static Dictionary<int, string> _ActionColoredDictionary(int categoryId, int categoryAreaId)
1508:          {
1509:              return Dictionary("category", "area", "actionList", "action", categoryId, categoryAreaId, true).Concat(GeneralActionColoredDictionary).ToDictionary(q => q.Key, q => q.Value);
1510:          }
1511:   
1512:          ////////////////////////////////////////////////////////////////////////////
1513:   
1514:          /// <summary>
1515:          ///
1516:          /// </summary>
1517:          public static Dictionary<int, string> ResolutionColoredDictionary
1518:          {
1519:              get
1520:              {
1521:                  return Dictionary(false, true, "resolution");
1522:              }
1523:          }
1524:   
1525:          ////////////////////////////////////////////////////////////////////////////
1526:   
1527:          /// <summary>
1528:          ///
1529:          /// </summary>
1530:          public static Dictionary<int, string> ResolutionEnglishAndArabicColoredDictionary
1531:          {
1532:              get
1533:              {
1534:                  return Dictionary(true, true, "resolution");
1535:              }
1536:          }
1537:   
1538:          ////////////////////////////////////////////////////////////////////////////
1539:   
1540:          /// <summary>
1541:          ///
1542:          /// </summary>
1543:          public static Dictionary<int, string> ServiceTypeDictionary
1544:          {
1545:              get
1546:              {
1547:                  return Dictionary(false, false, "service", "typeList", "type");
1548:              }
1549:          }
1550:   
1551:          ////////////////////////////////////////////////////////////////////////////
1552:   
1553:          /// <summary>
1554:          ///
1555:          /// </summary>
1556:          public static Dictionary<int, string> ResolutionDictionary
1557:          {
1558:              get
1559:              {
1560:                  return Dictionary(false, false, "resolution");
1561:              }
1562:          }
1563:   
1564:          ////////////////////////////////////////////////////////////////////////////
1565:   
1566:          /// <summary>
1567:          ///
1568:          /// </summary>
1569:          public static Dictionary<int, string> GeneralActionDictionary
1570:          {
1571:              get
1572:              {
1573:                  return Dictionary(false, false, "action");
1574:              }
1575:          }
1576:   
1577:          ////////////////////////////////////////////////////////////////////////////
1578:   
1579:          /// <summary>
1580:          ///
1581:          /// </summary>
1582:          public static Dictionary<int, string> GeneralActionColoredDictionary
1583:          {
1584:              get
1585:              {
1586:                  return Dictionary(false, true, "action");
1587:              }
1588:          }
1589:   
1590:          ////////////////////////////////////////////////////////////////////////////
1591:   
1592:          /// <summary>
1593:          ///
1594:          /// </summary>
1595:          public static Dictionary<int, string> GeneralIndicationDictionary
1596:          {
1597:              get
1598:              {
1599:                  return Dictionary(false, false, "indication");
1600:              }
1601:          }
1602:   
1603:          ////////////////////////////////////////////////////////////////////////////
1604:   
1605:          /// <summary>
1606:          ///
1607:          /// </summary>
1608:          public static Dictionary<int, string> GeneralIndicationColoredDictionary
1609:          {
1610:              get
1611:              {
1612:                  return Dictionary(false, true, "indication");
1613:              }
1614:          }
1615:   
1616:          ////////////////////////////////////////////////////////////////////////////
1617:   
1618:          /// <summary>
1619:          ///
1620:          /// </summary>
1621:          public static Dictionary<int, string> EstimateDictionary
1622:          {
1623:              get
1624:              {
1625:                  return Dictionary(false, false, "estimate");
1626:              }
1627:          }
1628:   
1629:          ////////////////////////////////////////////////////////////////////////////
1630:   
1631:          /// <summary>
1632:          ///
1633:          /// </summary>
1634:          public static Dictionary<int, string> EstimateColoredDictionary
1635:          {
1636:              get
1637:              {
1638:                  return Dictionary(false, true, "estimate");
1639:              }
1640:          }
1641:   
1642:          ////////////////////////////////////////////////////////////////////////////
1643:   
1644:          /// <summary>
1645:          ///
1646:          /// </summary>
1647:          public static Dictionary<int, string> StatusDictionary
1648:          {
1649:              get
1650:              {
1651:                  return Dictionary(false, false, "status");
1652:              }
1653:          }
1654:   
1655:          ////////////////////////////////////////////////////////////////////////////
1656:   
1657:          /// <summary>
1658:          ///
1659:          /// </summary>
1660:          public static Dictionary<int, string> StatusColoredDictionary
1661:          {
1662:              get
1663:              {
1664:                  return Dictionary(false, true, "status");
1665:              }
1666:          }
1667:   
1668:          ////////////////////////////////////////////////////////////////////////////
1669:   
1670:          /// <summary>
1671:          ///
1672:          /// </summary>
1673:          public static Dictionary<int, string> PriorityDictionary
1674:          {
1675:              get
1676:              {
1677:                  return Dictionary(false, false, "priority");
1678:              }
1679:          }
1680:   
1681:          ////////////////////////////////////////////////////////////////////////////
1682:   
1683:          /// <summary>
1684:          ///
1685:          /// </summary>
1686:          public static Dictionary<int, string> PriorityColoredDictionary
1687:          {
1688:              get
1689:              {
1690:                  return Dictionary(false, true, "priority");
1691:              }
1692:          }
1693:   
1694:          ////////////////////////////////////////////////////////////////////////////
1695:   
1696:          /// <summary>
1697:          ///
1698:          /// </summary>
1699:          public static Dictionary<int, string> SeverityDictionary
1700:          {
1701:              get
1702:              {
1703:                  return Dictionary(false, false, "severity");
1704:              }
1705:          }
1706:   
1707:          ////////////////////////////////////////////////////////////////////////////
1708:   
1709:          /// <summary>
1710:          ///
1711:          /// </summary>
1712:          public static Dictionary<int, string> SeverityColoredDictionary
1713:          {
1714:              get
1715:              {
1716:                  return Dictionary(false, true, "severity");
1717:              }
1718:          }
1719:   
1720:          ////////////////////////////////////////////////////////////////////////////
1721:   
1722:          /// <summary>
1723:          ///
1724:          /// </summary>
1725:          public static Dictionary<int, string> CategoryAreaDictionary()
1726:          {
1727:              return Dictionary(false, false, "category", "area");
1728:          }
1729:   
1730:          ////////////////////////////////////////////////////////////////////////////
1731:   
1732:          /// <summary>
1733:          ///
1734:          /// </summary>
1735:          public static Dictionary<int, string> CategoryAreaDictionary(int categoryId)
1736:          {
1737:              return ColoredDictionary("category", "area", categoryId, false);
1738:          }
1739:   
1740:          ////////////////////////////////////////////////////////////////////////////
1741:   
1742:          /// <summary>
1743:          ///
1744:          /// </summary>
1745:          public static Dictionary<int, string> CategoryAreaColoredDictionary
1746:          {
1747:              get
1748:              {
1749:                  return Dictionary(false, true, "category", "area");
1750:              }
1751:          }
1752:   
1753:          ////////////////////////////////////////////////////////////////////////////
1754:   
1755:          /// <summary>
1756:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1757:          /// </summary>
1758:          private static Dictionary<int, string> Dictionary(bool englishAndArabicName, bool isColored, params string[] elementList)
1759:          {
1760:              int id;
1761:              string name, color;
1762:              Dictionary<int, string> dictionary;
1763:              IEnumerable<XElement> xElementIenumerable;
1764:   
1765:              dictionary = new Dictionary<int, string>(10);
1766:              xElementIenumerable = null;
1767:   
1768:              try
1769:              {
1770:                  switch (elementList.Length)
1771:                  {
1772:                      case 1: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]); break;
1773:                      case 2: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]); break;
1774:                      case 3: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]); break;
1775:                      case 4: xElementIenumerable = XDocument.Element("report").Elements(elementList[0]).Elements(elementList[1]).Elements(elementList[2]).Elements(elementList[3]); break;
1776:                      default: break;
1777:                  }
1778:   
1779:                  foreach (XElement x in xElementIenumerable)
1780:                  {
1781:                      id = int.Parse(x.Attribute("id").Value);
1782:   
1783:                      if (englishAndArabicName)
1784:                      {
1785:                          if (x.Attribute("arabicName") != null)
1786:                          {
1787:                              name = x.Attribute("name").Value + " (" + x.Attribute("arabicName").Value + ")";
1788:                          }
1789:                          else name = x.Attribute("name").Value;
1790:                      }
1791:                      else name = x.Attribute("name").Value;
1792:   
1793:                      color = (x.Attribute("color") != null) ? x.Attribute("color").Value : null;
1794:   
1795:                      // below: replace spaces ' ' with HTML fixed space "&nbsp;"
1796:                      name = name.Replace(" ", "&nbsp;");
1797:   
1798:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1799:                  }
1800:              }
1801:              catch (Exception e)
1802:              {
1803:   
1804:              }
1805:   
1806:              return dictionary;
1807:          }
1808:   
1809:          ////////////////////////////////////////////////////////////////////////////
1810:   
1811:          /// <summary>
1812:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1813:          /// </summary>
1814:          private static Dictionary<int, string> ColoredDictionary(string element, string secondElement, int categoryId, bool isColored)
1815:          {
1816:              int id;
1817:              string name, color;
1818:              Dictionary<int, string> dictionary;
1819:   
1820:              dictionary = new Dictionary<int, string>(100);
1821:   
1822:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement))
1823:              {
1824:                  if (x.Parent.Attribute("id").Value == categoryId.ToString())
1825:                  {
1826:                      id = int.Parse(x.Attribute("id").Value);
1827:                      name = x.Attribute("name").Value;
1828:                      color = (x.Attribute("color") != null) ? x.Attribute("color").Value : null;
1829:   
1830:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1831:                  }
1832:              }
1833:   
1834:              return dictionary;
1835:          }
1836:   
1837:          ////////////////////////////////////////////////////////////////////////////
1838:   
1839:          /// <summary>
1840:          /// Returns a Dictionary<int, string> dictionary of elements. If parameter isColored is true the dictionary will contain HTML formatted colored list
1841:          /// </summary>
1842:          private static Dictionary<int, string> Dictionary(string element, string secondElement, string thirdElement, string fourthElement, int categoryId, int categoryAreaId, bool isColored)
1843:          {
1844:              int id;
1845:              string name, color;
1846:              Dictionary<int, string> dictionary;
1847:   
1848:              dictionary = new Dictionary<int, string>(100);
1849:   
1850:              foreach (XElement x in XDocument.Element("report").Elements(element).Elements(secondElement).Elements(thirdElement).Elements(fourthElement))
1851:              {
1852:                  if (x.Parent.Parent.Parent.Attribute("id").Value == categoryId.ToString() && x.Parent.Parent.Attribute("id").Value == categoryAreaId.ToString())
1853:                  {
1854:                      id = int.Parse(x.Attribute("id").Value);
1855:                      name = x.Attribute("name").Value;
1856:                      color = (x.Attribute("color") != null) ? x.Attribute("color").Value : null;
1857:   
1858:                      ColoredDictionaryItem(ref dictionary, isColored, id, name, color);
1859:                  }
1860:              }
1861:   
1862:              return dictionary;
1863:          }
1864:   
1865:          ////////////////////////////////////////////////////////////////////////////
1866:   
1867:          /// <summary>
1868:          ///
1869:          /// </summary>
1870:          private static void ColoredDictionaryItem(ref Dictionary<int, string> dictionary, bool isColored, int id, string name, string color)
1871:          {
1872:              List<string> lightBackgroundColorList;
1873:   
1874:              if (isColored)
1875:              {
1876:                  if (!string.IsNullOrEmpty(color))
1877:                  {
1878:                      dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
1879:                  }
1880:                  else
1881:                  {
1882:                      lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1883:   
1884:                      dictionary.Add(id, @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>");
1885:                  }
1886:              }
1887:              else
1888:              {
1889:                  dictionary.Add(id, name);
1890:              }
1891:          }
1892:   
1893:          ////////////////////////////////////////////////////////////////////////////
1894:   
1895:          /// <summary>
1896:          ///
1897:          /// </summary>
1898:          private static string ColoredName(int id, string name)
1899:          {
1900:              return ColoredName(id, name, null);
1901:          }
1902:   
1903:          ////////////////////////////////////////////////////////////////////////////
1904:   
1905:          /// <summary>
1906:          ///
1907:          /// </summary>
1908:          private static string ColoredName(int id, string name, string color)
1909:          {
1910:              string coloredName;
1911:              List<string> lightBackgroundColorList;
1912:   
1913:              lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
1914:   
1915:              if (!string.IsNullOrEmpty(color)) coloredName = @"<span style=""color:" + color + @""">" + name + "</span>";
1916:              else coloredName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>";
1917:   
1918:              return coloredName;
1919:          }
1920:   
1921:          ////////////////////////////////////////////////////////////////////////////
1922:          ////////////////////////////////////////////////////////////////////////////
1923:   
1924:          /// <summary>
1925:          /// 
1926:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
1927:          /// 
1928:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
1929:          /// 2. Add "using System.Reflection".
1930:          /// 3. See sample below.
1931:          /// 
1932:          /// </summary>
1933:   
1934:          public static XDocument XDocument
1935:          {
1936:              get
1937:              {
1938:                  Assembly _assembly;
1939:                  StreamReader streamReader;
1940:   
1941:                  if (xDocument == null)
1942:                  {
1943:                      _assembly = Assembly.GetExecutingAssembly();
1944:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.report.xml"));
1945:   
1946:                      try
1947:                      {
1948:                          if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
1949:                      }
1950:                      catch (Exception)
1951:                      {
1952:                      }
1953:                      finally
1954:                      {
1955:                      }
1956:                  }
1957:   
1958:                  return xDocument;
1959:              }
1960:          }
1961:   
1962:          ////////////////////////////////////////////////////////////////////////////
1963:          ////////////////////////////////////////////////////////////////////////////    
1964:      }
1965:   
1966:      ////////////////////////////////////////////////////////////////////////////
1967:      ////////////////////////////////////////////////////////////////////////////   
1968:  }