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

Integrated Applications Programming Company

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-2019 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 DateTime SqlFriendlyJanuary1st1753NullDateTime = new DateTime(1753, 1, 1);
  57:   
  58:          /// <summary/>
  59:          public static DateTime EarliestRequestDateTime = new DateTime(1970, 1, 1); 
  60:   
  61:          /// <summary/>
  62:          public static int InitialFrameworkListLength { get { return initialFrameworkListLength; } }
  63:   
  64:   
  65:          ////////////////////////////////////////////////////////////////////////////
  66:   
  67:          /// <summary>
  68:          ///
  69:          /// </summary>
  70:          public class Framework
  71:          {
  72:              public Framework() { }
  73:   
  74:              /// <summary/>
  75:              public int Id { get; set; }
  76:              /// <summary/>
  77:              public int Level { get; set; }
  78:              /// <summary/>
  79:              public Guid Guid { get; set; }
  80:              /// <summary/>
  81:              public string Type { get; set; }
  82:              /// <summary/>
  83:              public string Name { get; set; }
  84:              /// <summary/>
  85:              public string ArabicName { get; set; }
  86:              /// <summary/>
  87:              public string ColoredArabicName { get; set; }
  88:              /// <summary/>
  89:              public Framework Parent { get; set; }
  90:              /// <summary/>
  91:              public List<Framework> Ancestors { get; set; }
  92:              /// <summary/>
  93:              public List<Framework> Siblings { get; set; }
  94:              /// <summary/>
  95:              public List<Framework> Children { get; set; }
  96:              /// <summary/>
  97:              public List<Framework> Descendants { get; set; }
  98:              /// <summary/>
  99:              public List<Authority> Authorities { get; set; }
 100:   
 101:              /// <summary/>
 102:              public Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site Site { get; set; }
 103:   
 104:              /// <summary/>
 105:              //public Ia.Cl.Model.Identity.User Role { get; set; }
 106:   
 107:              /// <summary/>
 108:              public static bool operator ==(Framework fa, Framework fb)
 109:              {
 110:                  bool b;
 111:   
 112:                  // if both are null, or both are same instance, return true.
 113:                  if (System.Object.ReferenceEquals(fa, fb)) b = true;
 114:                  // if one is null, but not both, return false.
 115:                  else if (((object)fa == null) || ((object)fb == null)) b = false;
 116:                  // true if the fields match:
 117:                  else b = fa.Id == fb.Id;
 118:   
 119:                  return b;
 120:              }
 121:   
 122:              /// <summary/>
 123:              public static bool operator !=(Framework fa, Framework fb)
 124:              {
 125:                  return !(fa == fb);
 126:              }
 127:   
 128:              /// <summary/>
 129:              public string FullyQualifiedArabicName
 130:              {
 131:                  get
 132:                  {
 133:                      string s;
 134:   
 135:                      s = string.Empty;
 136:   
 137:                      foreach (var f in this.Ancestors) s += f.ArabicName + " | ";
 138:   
 139:                      s = s + this.ArabicName;
 140:   
 141:                      return s;
 142:                  }
 143:              }
 144:   
 145:              ////////////////////////////////////////////////////////////////////////////
 146:   
 147:              /// <summary>
 148:              ///
 149:              /// </summary>
 150:              public override bool Equals(object value)
 151:              {
 152:                  return value != null && Equals(value as Framework);
 153:              }
 154:   
 155:              /// <summary/>
 156:              public int FrameworkId(int parentId, int frameworkId)
 157:              {
 158:                  return parentId * 10 + frameworkId;
 159:              }
 160:   
 161:              /// <summary/>
 162:              public static int ParentId(long frameworkId)
 163:              {
 164:                  int i;
 165:                  string s;
 166:   
 167:                  s = frameworkId.ToString();
 168:   
 169:                  if (s.Length > 2)
 170:                  {
 171:                      s = s.Substring(0, s.Length - 2);
 172:   
 173:                      i = (int.TryParse(s, out i)) ? i : 0;
 174:                  }
 175:                  else i = 0;
 176:   
 177:                  return i;
 178:              }
 179:          }
 180:   
 181:          ////////////////////////////////////////////////////////////////////////////
 182:   
 183:          /// <summary>
 184:          ///
 185:          /// </summary>
 186:          public class Category
 187:          {
 188:              /// <summary/>
 189:              public Category() { }
 190:              /// <summary/>
 191:              public string Name { get; set; }
 192:              /// <summary/>
 193:              public string Description { get; set; }
 194:              /// <summary/>
 195:              public string Regex { get; set; }
 196:              /// <summary/>
 197:              public string Color { get; set; }
 198:          }
 199:   
 200:          ////////////////////////////////////////////////////////////////////////////
 201:   
 202:          /// <summary>
 203:          ///
 204:          /// </summary>
 205:          public class StaffFramework
 206:          {
 207:              private bool isStaff;
 208:   
 209:              /// <summary/>
 210:              public StaffFramework() { }
 211:              /// <summary/>
 212:              public Guid Guid { get; set; }
 213:              /// <summary/>
 214:              public long FrameworkId { get; set; }
 215:              /// <summary/>
 216:              public string Name { get; set; }
 217:              /// <summary/>
 218:              public bool IsStaff
 219:              {
 220:                  get { return isStaff; }
 221:                  set { isStaff = true; }
 222:              }
 223:              /// <summary/>
 224:              public bool IsFramework
 225:              {
 226:                  get { return !isStaff; }
 227:                  set { isStaff = false; }
 228:              }
 229:          }
 230:   
 231:   
 232:          ////////////////////////////////////////////////////////////////////////////
 233:          ////////////////////////////////////////////////////////////////////////////
 234:   
 235:          /// <summary>
 236:          ///
 237:          /// </summary>
 238:          public class Statistic
 239:          {
 240:              /// <summary/>
 241:              public Statistic() { }
 242:   
 243:              public class Site
 244:              {
 245:                  /// <summary/>
 246:                  public string Id { get; set; }
 247:                  /// <summary/>
 248:                  public string Name { get; set; }
 249:                  /// <summary/>
 250:                  public string Symbol { get; set; }
 251:                  /// <summary/>
 252:                  public string KuwaitAreaNameListString { get; set; }
 253:                  /// <summary/>
 254:                  public string DomainListString { get; set; }
 255:                  /// <summary/>
 256:                  public string SymbolListString { get; set; }
 257:   
 258:                  /// <summary/>
 259:                  public int SiteAccessCapacity { get; set; }
 260:   
 261:                  /// <summary/>
 262:                  public int NddOntNokiaAccessCount { get; set; }
 263:                  /// <summary/>
 264:                  public int NddOntHuaweiAccessCount { get; set; }
 265:                  /// <summary/>
 266:                  public int NddOntAccessCount { get; set; }
 267:   
 268:   
 269:   
 270:                  /// <summary/>
 271:                  public int AccessCapacity { get; set; }
 272:                  /// <summary/>
 273:                  public int AccessInstalledContractor { get; set; }
 274:                  /// <summary/>
 275:                  public int AccessInstalledContractorWithSerial { get; set; }
 276:                  /// <summary/>
 277:                  public int AccessProvisioned { get; set; }
 278:                  /// <summary/>
 279:                  public int AccessReadyForService { get; set; }
 280:                  /// <summary/>
 281:                  public int AccessDefinedInCustomerDepartment { get; set; }
 282:                  /// <summary/>
 283:                  public int AccessUtilized { get; set; }
 284:                  /// <summary/>
 285:                  public int AccessUtilizedNoService { get; set; }
 286:                  /// <summary/>
 287:                  public int AccessUtilizedOneService { get; set; }
 288:                  /// <summary/>
 289:                  public int AccessUtilizedTwoServices { get; set; }
 290:                  /// <summary/>
 291:                  public int AccessUtilizedThreeServices { get; set; }
 292:                  /// <summary/>
 293:                  public int AccessUtilizedFourServices { get; set; }
 294:                  /// <summary/>
 295:                  public int AccessUtilizedFiveOrMoreServices { get; set; }
 296:   
 297:                  /// <summary/>
 298:                  public int ServiceCapacity { get; set; }
 299:                  public int ServiceCount { get; set; }
 300:   
 301:                  ////////////////////////////////////////////////////////////////////////////
 302:   
 303:                  /// <summary>
 304:                  ///
 305:                  /// </summary>
 306:                  public string ToSimpleTextString()
 307:                  {
 308:                      string per;
 309:   
 310:                      StringBuilder sb;
 311:   
 312:                      sb = new StringBuilder();
 313:   
 314:                      per = (this.ServiceCount != 0) ? "%" + (int) (100 * ((float)(this.ServiceCount) / (float)(this.ServiceCapacity))) : per = "%";
 315:   
 316:                      sb.AppendLine("Site: " + this.Name);
 317:                      sb.AppendLine("Areas: " + this.KuwaitAreaNameListString);
 318:                      sb.AppendLine("Symbols: " + this.SymbolListString);
 319:                      sb.AppendLine("Access Capacity: " + this.AccessCapacity);
 320:                      sb.AppendLine("Service Capacity: " + this.ServiceCapacity);
 321:                      sb.AppendLine("Service Count: " + this.ServiceCount + " (" + per + ")");
 322:   
 323:                      return sb.ToString();
 324:                  }
 325:   
 326:                  ////////////////////////////////////////////////////////////////////////////
 327:                  ////////////////////////////////////////////////////////////////////////////
 328:              }
 329:   
 330:              public class KuwaitArea
 331:              {
 332:                  /// <summary/>
 333:                  public KuwaitArea() { }
 334:   
 335:                  /// <summary/>
 336:                  public KuwaitArea(string name, string arabicName)
 337:                  {
 338:                      this.Name = name + " (" + arabicName + ")";
 339:                  }
 340:   
 341:                  /// <summary/>
 342:                  public string Id { get; set; }
 343:                  /// <summary/>
 344:                  public string Name { get; set; }
 345:                  /// <summary/>
 346:                  public string Symbol { get; set; }
 347:   
 348:                  /// <summary/>
 349:                  public int AccessCapacity { get; set; }
 350:   
 351:                  /// <summary/>
 352:                  public int NokiaOnt { get; set; }
 353:                  /// <summary/>
 354:                  public int HuaweiOnt { get; set; }
 355:                  /// <summary/>
 356:                  public string OntTotalNokiaHuawei { get; set; }
 357:   
 358:                  /// <summary/>
 359:                  public int NokiaAccess { get; set; }
 360:                  /// <summary/>
 361:                  public int HuaweiAccess { get; set; }
 362:                  /// <summary/>
 363:                  public string AccessTotalNokiaHuawei { get; set; }
 364:   
 365:                  /// <summary/>
 366:                  public int ServiceRequestService { get; set; }
 367:                  /// <summary/>
 368:                  public int Service { get; set; }
 369:                  /// <summary/>
 370:                  public string ServiceRequestServiceService { get; set; }
 371:   
 372:                  /// <summary/>
 373:                  public int AccessReadyForService { get; set; }
 374:   
 375:                  ////////////////////////////////////////////////////////////////////////////
 376:   
 377:                  /// <summary>
 378:                  ///
 379:                  /// </summary>
 380:                  public string ToSimpleTextString()
 381:                  {
 382:                      StringBuilder sb;
 383:   
 384:                      sb = new StringBuilder();
 385:   
 386:                      sb.AppendLine("Name: " + this.Name);
 387:                      sb.AppendLine("Symbol: " + this.Symbol);
 388:                      sb.AppendLine("Access Capacity: " + this.AccessCapacity);
 389:                      sb.AppendLine("Access (Nokia/Huawei): " + this.AccessTotalNokiaHuawei);
 390:                      sb.AppendLine("ONT/ONU (Nokia/Huawei): " + this.OntTotalNokiaHuawei);
 391:                      sb.AppendLine("Access ready for service: " + this.AccessReadyForService);
 392:                      sb.AppendLine("Services (installed): " + this.ServiceRequestServiceService);
 393:   
 394:                      return sb.ToString();
 395:                  }
 396:   
 397:                  ////////////////////////////////////////////////////////////////////////////
 398:                  ////////////////////////////////////////////////////////////////////////////
 399:              }
 400:   
 401:          }
 402:   
 403:          ////////////////////////////////////////////////////////////////////////////
 404:   
 405:          /// <summary>
 406:          ///
 407:          /// </summary>
 408:          public Administration() { }
 409:   
 410:          /// <summary/>
 411:          public static bool NowIsOfficialWorkingTime
 412:          {
 413:              get
 414:              {
 415:                  bool b;
 416:                  DateTime now;
 417:   
 418:                  now = DateTime.UtcNow.AddHours(3);
 419:   
 420:                  b = now.DayOfWeek != DayOfWeek.Friday && now.DayOfWeek != DayOfWeek.Saturday &&
 421:                      (
 422:                      now.TimeOfDay >= OfficialMorningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialMorningEndOfWorkTime.TimeOfDay
 423:                      ||
 424:                      now.TimeOfDay >= OfficialEveningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialEveningEndOfWorkTime.TimeOfDay
 425:                      );
 426:   
 427:                  return b;
 428:              }
 429:          }
 430:   
 431:          ////////////////////////////////////////////////////////////////////////////    
 432:   
 433:          /// <summary>
 434:          /// 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
 435:          /// </summary>
 436:          public static bool IsFrameworkGuid(Guid guid)
 437:          {
 438:              bool isFrameworkGuid;
 439:   
 440:              isFrameworkGuid = (guid.ToString().Substring(0, 9) == "00000000-") ? true : false;
 441:   
 442:              return isFrameworkGuid;
 443:          }
 444:   
 445:          ////////////////////////////////////////////////////////////////////////////    
 446:   
 447:          /// <summary>
 448:          ///
 449:          /// </summary>
 450:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Framework> FrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Staff staff)
 451:          {
 452:              List<Ia.Ngn.Cl.Model.Business.Administration.Framework> frameworkList;
 453:   
 454:              frameworkList = new List<Ia.Ngn.Cl.Model.Business.Administration.Framework>();
 455:   
 456:              frameworkList.AddRange(staff.Framework.Children);
 457:              frameworkList.AddRange(staff.Framework.Siblings);
 458:   
 459:              return frameworkList;
 460:          }
 461:   
 462:          ////////////////////////////////////////////////////////////////////////////
 463:   
 464:          /// <summary>
 465:          ///
 466:          /// </summary>
 467:          public class StaffContact
 468:          {
 469:              private Ia.Ngn.Cl.Model.Staff staff;
 470:              private Ia.Ngn.Cl.Model.Contact contact;
 471:              private string email;
 472:              private string apiKey;
 473:              private Guid userId;
 474:   
 475:              /// <summary/>
 476:              public StaffContact() { }
 477:   
 478:              /// <summary/>
 479:              public Ia.Ngn.Cl.Model.Staff Staff
 480:              {
 481:                  get
 482:                  {
 483:                      return staff;
 484:                  }
 485:   
 486:                  set
 487:                  {
 488:                      staff = value;
 489:   
 490:                      var v = this.FullName;
 491:                      var w = this.Email;
 492:                      var x = this.UserId;
 493:                      var y = this.ApiKey;
 494:                  }
 495:              }
 496:   
 497:              /// <summary/>
 498:              public Ia.Ngn.Cl.Model.Contact Contact
 499:              {
 500:                  get
 501:                  {
 502:                      return contact;
 503:                  }
 504:   
 505:                  set
 506:                  {
 507:                      contact = value;
 508:   
 509:                      var v = this.FullName;
 510:                      var w = this.Email;
 511:                      var x = this.UserId;
 512:                      var y = this.ApiKey;
 513:                  }
 514:              }
 515:   
 516:              /// <summary/>
 517:              public string FullName
 518:              {
 519:                  get
 520:                  {
 521:                      string name;
 522:   
 523:                      if (staff != null) name = staff.FullName;
 524:                      else if (contact != null) name = contact.FullName;
 525:                      else name = string.Empty;
 526:   
 527:                      return name;
 528:                  }
 529:              }
 530:   
 531:              /// <summary/>
 532:              public string Email
 533:              {
 534:                  get
 535:                  {
 536:                      if (staff != null && staff.User != null) email = staff.User.Email;
 537:                      else if (contact != null) email = contact.Email;
 538:                      else email = string.Empty;
 539:   
 540:                      return email;
 541:                  }
 542:              }
 543:   
 544:              /// <summary/>
 545:              public Guid UserId
 546:              {
 547:                  get
 548:                  {
 549:                      if (staff != null) userId = staff.UserId;
 550:                      else if (contact != null) userId = contact.UserId;
 551:                      else userId = Guid.Empty;
 552:   
 553:                      return userId;
 554:                  }
 555:              }
 556:   
 557:              /// <summary/>
 558:              public string ApiKey
 559:              {
 560:                  get
 561:                  {
 562:                      if (staff != null && staff.User != null) apiKey = UserId.ToString().Substring(0, 8);
 563:                      else if (contact != null) apiKey = UserId.ToString().Substring(0, 8);
 564:                      else apiKey = string.Empty;
 565:   
 566:                      return apiKey;
 567:                  }
 568:              }
 569:   
 570:              /// <summary/>
 571:              public bool IsApproved
 572:              {
 573:                  get
 574:                  {
 575:                      return !string.IsNullOrEmpty(email); // && contact.IsApproved;
 576:                  }
 577:              }
 578:   
 579:              ////////////////////////////////////////////////////////////////////////////
 580:              ////////////////////////////////////////////////////////////////////////////    
 581:          }
 582:      }
 583:   
 584:      ////////////////////////////////////////////////////////////////////////////
 585:      ////////////////////////////////////////////////////////////////////////////   
 586:  }