Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Administration

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

Administration support class of Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Web;
   3:  using System.Xml;
   4:  using System.Xml.Linq;
   5:  using System.IO;
   6:  using System.Configuration;
   7:  using System.Text;
   8:  using System.Text.RegularExpressions;
   9:  using System.Data;
  10:  using System.Data.SqlClient;
  11:  using System.Web.UI;
  12:  using System.Web.UI.WebControls;
  13:  using System.Collections;
  14:  using System.Collections.Generic;
  15:  using System.Linq;
  16:  using System.Reflection;
  17:   
  18:  namespace Ia.Ngn.Cl.Model.Business
  19:  {
  20:      ////////////////////////////////////////////////////////////////////////////
  21:   
  22:      /// <summary publish="true">
  23:      /// Administration support class of Next Generation Network'a (NGN's) business model.
  24:      /// </summary>
  25:      /// 
  26:      /// <remarks> 
  27:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  28:      ///
  29:      /// 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
  30:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  31:      ///
  32:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  33:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  34:      /// 
  35:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  36:      /// 
  37:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  38:      /// </remarks> 
  39:      public class Administration
  40:      {
  41:          private const int initialFrameworkListLength = 100;
  42:   
  43:          /// <summary/>
  44:          public static DateTime OfficialMorningStartOfWorkTime = DateTime.Parse("07:00");
  45:          /// <summary/>
  46:          public static DateTime OfficialMorningEndOfWorkTime = DateTime.Parse("14:00");
  47:          /// <summary/>
  48:          public static DateTime OfficialEveningStartOfWorkTime = DateTime.Parse("16:00");
  49:          /// <summary/>
  50:          public static DateTime OfficialEveningEndOfWorkTime = DateTime.Parse("20:00");
  51:   
  52:          /// <summary/>
  53:          public static DateTime EarliestServiceRequestDate = DateTime.Parse("2000-01-01");
  54:   
  55:          /// <summary/>
  56:          public static int InitialFrameworkListLength { get { return initialFrameworkListLength; } }
  57:   
  58:          ////////////////////////////////////////////////////////////////////////////
  59:   
  60:          /// <summary>
  61:          ///
  62:          /// </summary>
  63:          public class Statistic
  64:          {
  65:              /// <summary/>
  66:              public Statistic() { }
  67:   
  68:              public class Site
  69:              {
  70:                  /// <summary/>
  71:                  public string Id { get; set; }
  72:                  /// <summary/>
  73:                  public string Name { get; set; }
  74:                  /// <summary/>
  75:                  public string Symbol { get; set; }
  76:                  /// <summary/>
  77:                  public string KuwaitAreaNameListString { get; set; }
  78:                  /// <summary/>
  79:                  public string DomainListString { get; set; }
  80:                  /// <summary/>
  81:                  public string SymbolListString { get; set; }
  82:   
  83:                  /// <summary/>
  84:                  public int SiteAccessCapacity { get; set; }
  85:   
  86:                  /// <summary/>
  87:                  public int NddOntNokiaAccessCount { get; set; }
  88:                  /// <summary/>
  89:                  public int NddOntHuaweiAccessCount { get; set; }
  90:                  /// <summary/>
  91:                  public int NddOntAccessCount { get; set; }
  92:   
  93:   
  94:   
  95:                  /// <summary/>
  96:                  public int AccessCapacity { get; set; }
  97:                  /// <summary/>
  98:                  public int AccessInstalledContractor { get; set; }
  99:                  /// <summary/>
 100:                  public int AccessInstalledContractorWithSerial { get; set; }
 101:                  /// <summary/>
 102:                  public int AccessProvisioned { get; set; }
 103:                  /// <summary/>
 104:                  public int AccessReadyForService { get; set; }
 105:                  /// <summary/>
 106:                  public int AccessDefinedInCustomerDepartment { get; set; }
 107:                  /// <summary/>
 108:                  public int AccessUtilized { get; set; }
 109:                  /// <summary/>
 110:                  public int AccessUtilizedNoService { get; set; }
 111:                  /// <summary/>
 112:                  public int AccessUtilizedOneService { get; set; }
 113:                  /// <summary/>
 114:                  public int AccessUtilizedTwoServices { get; set; }
 115:                  /// <summary/>
 116:                  public int AccessUtilizedThreeServices { get; set; }
 117:                  /// <summary/>
 118:                  public int AccessUtilizedFourServices { get; set; }
 119:                  /// <summary/>
 120:                  public int AccessUtilizedFiveOrMoreServices { get; set; }
 121:              }
 122:   
 123:              public class KuwaitArea
 124:              {
 125:                  /// <summary/>
 126:                  public KuwaitArea() { }
 127:   
 128:                  /// <summary/>
 129:                  public KuwaitArea(string name, string arabicName)
 130:                  {
 131:                      this.Name = name + " (" + arabicName + ")";
 132:                  }
 133:   
 134:                  /// <summary/>
 135:                  public string Id { get; set; }
 136:                  /// <summary/>
 137:                  public string Name { get; set; }
 138:                  /// <summary/>
 139:                  public string Symbol { get; set; }
 140:   
 141:                  /// <summary/>
 142:                  public int NokiaOnt { get; set; }
 143:                  /// <summary/>
 144:                  public int HuaweiOnt { get; set; }
 145:                  /// <summary/>
 146:                  public string OntTotalNokiaHuawei { get; set; }
 147:   
 148:                  /// <summary/>
 149:                  public int NokiaAccess { get; set; }
 150:                  /// <summary/>
 151:                  public int HuaweiAccess { get; set; }
 152:                  /// <summary/>
 153:                  public string AccessTotalNokiaHuawei { get; set; }
 154:   
 155:   
 156:                  /// <summary/>
 157:                  public int NokiaHsi { get; set; }
 158:                  /// <summary/>
 159:                  public int HuaweiHsi { get; set; }
 160:                  /// <summary/>
 161:                  public string HsiTotalNokiaHuawei { get; set; }
 162:   
 163:                  /// <summary/>
 164:                  public int ServiceRequestService { get; set; }
 165:                  /// <summary/>
 166:                  public int Service { get; set; }
 167:                  /// <summary/>
 168:                  public string ServiceRequestServiceService { get; set; }
 169:   
 170:                  /// <summary/>
 171:                  public int AccessReadyForService { get; set; }
 172:   
 173:                  ////////////////////////////////////////////////////////////////////////////
 174:   
 175:                  /// <summary>
 176:                  ///
 177:                  /// </summary>
 178:                  public string ToSimpleTextString()
 179:                  {
 180:                      StringBuilder sb;
 181:   
 182:                      sb = new StringBuilder();
 183:   
 184:                      sb.AppendLine("Name: " + this.Name);
 185:                      sb.AppendLine("Symbol: " + this.Symbol);
 186:                      sb.AppendLine("Service: " + this.Service);
 187:                      sb.AppendLine("Access: " + this.AccessTotalNokiaHuawei);
 188:                      //sb.AppendLine("ONT: " + this.OntTotalNokiaHuawei);
 189:                      //sb.AppendLine("Ready: " + this.AccessReadyForService);
 190:                      //sb.AppendLine("HSI: " + this.HsiTotalNokiaHuawei);
 191:   
 192:                      return sb.ToString();
 193:                  }
 194:   
 195:                  ////////////////////////////////////////////////////////////////////////////
 196:                  ////////////////////////////////////////////////////////////////////////////
 197:              }
 198:   
 199:          }
 200:   
 201:          ////////////////////////////////////////////////////////////////////////////
 202:   
 203:          /// <summary>
 204:          ///
 205:          /// </summary>
 206:          public Administration() { }
 207:   
 208:          /// <summary/>
 209:          public static bool NowIsOfficialWorkingTime
 210:          {
 211:              get
 212:              {
 213:                  bool b;
 214:                  DateTime now;
 215:   
 216:                  now = DateTime.UtcNow.AddHours(3);
 217:   
 218:                  b = now.DayOfWeek != DayOfWeek.Friday && now.DayOfWeek != DayOfWeek.Saturday && 
 219:                      (
 220:                      now.TimeOfDay >= OfficialMorningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialMorningEndOfWorkTime.TimeOfDay
 221:                      ||
 222:                      now.TimeOfDay >= OfficialEveningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialEveningEndOfWorkTime.TimeOfDay
 223:                      );
 224:   
 225:                  return b;
 226:              }
 227:          }
 228:   
 229:          ////////////////////////////////////////////////////////////////////////////    
 230:   
 231:          /// <summary>
 232:          /// Tests a given Guid value to see if it has a special format used in framework items. Framework ites will have 00000000- prefixed to them
 233:          /// </summary>
 234:          public static bool IsFrameworkGuid(Guid guid)
 235:          {
 236:              bool isFrameworkGuid;
 237:   
 238:              isFrameworkGuid = (guid.ToString().Substring(0, 9) == "00000000-") ? true : false;
 239:   
 240:              return isFrameworkGuid;
 241:          }
 242:   
 243:          ////////////////////////////////////////////////////////////////////////////    
 244:   
 245:          /// <summary>
 246:          ///
 247:          /// </summary>
 248:          public static List<Ia.Ngn.Cl.Model.Data.Administration.Framework> FrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Staff staff)
 249:          {
 250:              List<Ia.Ngn.Cl.Model.Data.Administration.Framework> frameworkList;
 251:   
 252:              frameworkList = new List<Ia.Ngn.Cl.Model.Data.Administration.Framework>();
 253:   
 254:              frameworkList.AddRange(staff.Framework.Children);
 255:              frameworkList.AddRange(staff.Framework.Siblings);
 256:   
 257:              return frameworkList;
 258:          }
 259:   
 260:          ////////////////////////////////////////////////////////////////////////////    
 261:   
 262:          /// <summary>
 263:          ///
 264:          /// </summary>
 265:          public static bool StaffHasOpenPendingReportAndReportHistory(Ia.Ngn.Cl.Model.Staff staff)
 266:          {
 267:              bool hasOpenReport;
 268:              List<Ia.Ngn.Cl.Model.Report> reportList;
 269:   
 270:              reportList = Ia.Ngn.Cl.Model.Data.Report.ReadOpenStatusAndClosedStatusWithinLast24HourReportList();
 271:   
 272:              reportList = Ia.Ngn.Cl.Model.Data.Report.FilterReportListForSpecificUserIdOrHisFrameworkAncestorOrDescendantUserIdWithNoStaffHistoryReportOrHisSubordinateStaffReportList(reportList, staff);
 273:   
 274:              // I will exclude closed reports
 275:              // <status id="1" name="Open" arabicName="مفتوح"/>
 276:              // <status id="2" name="Closed" arabicName="مغلق"/>
 277:   
 278:              reportList = (from r in reportList where r.Status == 1 select r).ToList();
 279:   
 280:              hasOpenReport = (reportList.Count > 0) ? true : false;
 281:   
 282:              return hasOpenReport;
 283:          }
 284:   
 285:          ////////////////////////////////////////////////////////////////////////////    
 286:   
 287:          /// <summary>
 288:          ///
 289:          /// </summary>
 290:          public static List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> StaffFrameworkWithOpenStatusAndClosedStatusWithinLast24HourReportList(List<Ia.Ngn.Cl.Model.Report> defaultReportList)
 291:          {
 292:              Hashtable userIdHashtable;
 293:              List<Guid> userIdList;
 294:              List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> list;
 295:              List<Ia.Ngn.Cl.Model.Report> reportList;
 296:   
 297:              userIdHashtable = new Hashtable();
 298:              userIdList = new List<Guid>();
 299:   
 300:              foreach (Ia.Ngn.Cl.Model.Data.Administration.StaffFramework sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList)
 301:              {
 302:                  if (sf.IsStaff)
 303:                  {
 304:                      reportList = Ia.Ngn.Cl.Model.Data.Report.FilterReportListForSpecificUserIdOrHisFrameworkAncestorOrDescendantUserIdWithNoStaffHistoryReportOrHisSubordinateStaffReportList(defaultReportList, sf.Id);
 305:   
 306:                      if (reportList.Count > 0) userIdHashtable[sf.Id] = 1;
 307:                  }
 308:                  else //if (sf.IsFramework)
 309:                  {
 310:                      reportList = Ia.Ngn.Cl.Model.Data.Report.FilterReportListForSpecificFrameworkUserIdOrItsFrameworkAncestorOrDescendantFrameworkUserIdWithNoStaffHistoryReportList(defaultReportList, sf.Id);
 311:   
 312:                      if (reportList.Count > 0) userIdHashtable[sf.Id] = 1;
 313:                  }
 314:              }
 315:   
 316:              foreach (Guid userId in userIdHashtable.Keys) userIdList.Add(userId);
 317:   
 318:              list = (from u in userIdList
 319:                      join sf in Ia.Ngn.Cl.Model.Data.Administration.StaffFrameworkList on u equals sf.Id
 320:                      where sf.IsFramework == true && Ia.Ngn.Cl.Model.Business.Authority.FrameworkParentOfAllReportsThatWillBeHandledInReportSection.Descendants.Any(u => u.Guid == sf.Id)
 321:                      select sf).OrderBy(c => c.Name).ToList(); //.OrderByDescending(c => c.IsStaff).ThenBy(c => c.FrameworkId).ToList();
 322:   
 323:              return list;
 324:          }
 325:   
 326:          ////////////////////////////////////////////////////////////////////////////
 327:   
 328:          /// <summary>
 329:          ///
 330:          /// </summary>
 331:          public class StaffContact
 332:          {
 333:              private Ia.Ngn.Cl.Model.Staff staff;
 334:              private Ia.Ngn.Cl.Model.Contact contact;
 335:              private string email;
 336:              private string apiKey;
 337:              private Guid userId;
 338:   
 339:              /// <summary/>
 340:              public StaffContact() { }
 341:   
 342:              /// <summary/>
 343:              public Ia.Ngn.Cl.Model.Staff Staff
 344:              {
 345:                  get
 346:                  {
 347:                      return staff;
 348:                  }
 349:   
 350:                  set
 351:                  {
 352:                      staff = value;
 353:   
 354:                      var v = this.FullName;
 355:                      var w = this.Email;
 356:                      var x = this.UserId;
 357:                      var y = this.ApiKey;
 358:                  }
 359:              }
 360:   
 361:              /// <summary/>
 362:              public Ia.Ngn.Cl.Model.Contact Contact
 363:              {
 364:                  get
 365:                  {
 366:                      return contact;
 367:                  }
 368:   
 369:                  set
 370:                  {
 371:                      contact = value;
 372:   
 373:                      var v = this.FullName;
 374:                      var w = this.Email;
 375:                      var x = this.UserId;
 376:                      var y = this.ApiKey;
 377:                  }
 378:              }
 379:   
 380:              /// <summary/>
 381:              public string FullName
 382:              {
 383:                  get
 384:                  {
 385:                      string name;
 386:   
 387:                      if (staff != null) name = staff.FullName;
 388:                      else if (contact != null) name = contact.FullName;
 389:                      else name = string.Empty;
 390:   
 391:                      return name;
 392:                  }
 393:              }
 394:   
 395:              /// <summary/>
 396:              public string Email
 397:              {
 398:                  get
 399:                  {
 400:                      if (staff != null && staff.User != null) email = staff.User.Email;
 401:                      else if (contact != null) email = contact.Email;
 402:                      else email = string.Empty;
 403:   
 404:                      return email;
 405:                  }
 406:              }
 407:   
 408:              /// <summary/>
 409:              public Guid UserId
 410:              {
 411:                  get
 412:                  {
 413:                      if (staff != null) userId = staff.UserId;
 414:                      else if (contact != null) userId = contact.UserId;
 415:                      else userId = Guid.Empty;
 416:   
 417:                      return userId;
 418:                  }
 419:              }
 420:   
 421:              /// <summary/>
 422:              public string ApiKey
 423:              {
 424:                  get
 425:                  {
 426:                      if (staff != null && staff.User != null) apiKey = UserId.ToString().Substring(0, 8);
 427:                      else if (contact != null) apiKey = UserId.ToString().Substring(0, 8);
 428:                      else apiKey = string.Empty;
 429:   
 430:                      return apiKey;
 431:                  }
 432:              }
 433:   
 434:              /// <summary/>
 435:              public bool IsApproved
 436:              {
 437:                  get
 438:                  {
 439:                      return !string.IsNullOrEmpty(email); // && contact.IsApproved;
 440:                  }
 441:              }
 442:   
 443:              ////////////////////////////////////////////////////////////////////////////
 444:              ////////////////////////////////////////////////////////////////////////////    
 445:          }
 446:      }
 447:   
 448:      ////////////////////////////////////////////////////////////////////////////
 449:      ////////////////////////////////////////////////////////////////////////////   
 450:  }