)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ServiceStatus (Ia.Ftn.Wa.Models.Administration)

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

    1: using Microsoft.AspNetCore.Identity;
    2: using Microsoft.AspNetCore.Mvc.Rendering;
    3: using System.Text;
    4: using System.Text.RegularExpressions;
    5:  
    6: namespace Ia.Ftn.Wa.Models.Administration
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     ///
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public static class ServiceStatus
   28:     {
   29:         ////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         ///
   33:         /// </summary>
   34:         public static void Categorize(ref Ia.Ftn.Wa.Models.Administration.ServiceStatusViewModel serviceStatusViewModel)
   35:         {
   36:             serviceStatusViewModel.Result = new Ia.Cl.Models.Result();
   37:  
   38:             if (!string.IsNullOrEmpty(serviceStatusViewModel.DomainSelectedValue.ToString()))
   39:             {
   40:                 var domain = serviceStatusViewModel.DomainSelectedValue;
   41:                 var state = serviceStatusViewModel.StateSelectedValue;
   42:  
   43:                 var singleColumnFormat = serviceStatusViewModel.SingleColumnFormatSelectedValue;
   44:  
   45:                 Categorize(domain, state, singleColumnFormat, out int count, out string display, out string result);
   46:  
   47:                 serviceStatusViewModel.CountText = "A total of <u>" + count + "</u> service numbers satisfy filter condition.";
   48:  
   49:                 if (count > 0)
   50:                 {
   51:                     if (display.Length == 0)
   52:                     {
   53:                         serviceStatusViewModel.Result.AddError("Error in filter (خطأ في الإجراء).");
   54:                     }
   55:  
   56:                     serviceStatusViewModel.DisplayText = display;
   57:                 }
   58:                 else
   59:                 {
   60:                     serviceStatusViewModel.DisplayText = "No service number satisfy filter condition (لا يوجد أي رقم يتوافق مع البحث المشروط).";
   61:                 }
   62:             }
   63:             else
   64:             {
   65:                 serviceStatusViewModel.Result.AddError("You did not select a domain range (لم تختر مجالاً).");
   66:             }
   67:         }
   68:  
   69:         ////////////////////////////////////////////////////////////////////////////
   70:  
   71:         /// <summary>
   72:         ///
   73:         /// </summary>
   74:         private static void Categorize(string domain, string state, bool singleColumn, out int count, out string display, out string result)
   75:         {
   76:             bool categorize;
   77:             int length;
   78:             string sa;
   79:             StringBuilder sb = new StringBuilder(100000);
   80:             List<string> serviceList;
   81:  
   82:             length = domain.Length;
   83:             count = 0;
   84:  
   85:             result = display = string.Empty;
   86:  
   87:             // below: if looking for occupied numbers, the list will not be categorize
   88:             if (state == "occupied")
   89:             {
   90:                 serviceList = Ia.Ftn.Cl.Models.Data.Service.ActiveServiceRequestServiceNumbersWithinDomainList(domain);
   91:  
   92:                 categorize = false;
   93:             }
   94:             else
   95:             {
   96:                 serviceList = Ia.Ftn.Cl.Models.Data.Service.InactiveServiceRequestServiceNumbersWithinDomainList(domain);
   97:  
   98:                 categorize = true;
   99:             }
  100:  
  101:             if (serviceList.Count != 0)
  102:             {
  103:                 foreach (string i in serviceList)
  104:                 {
  105:                     sa = i.ToString() + " ";
  106:                     sb.Append(sa);
  107:                     count++;
  108:                 }
  109:  
  110:                 if (sb.Length > 0)
  111:                 {
  112:                     // below: remove last ' ' char
  113:                     sb.Remove(sb.Length - 1, 1);
  114:  
  115:                     if (categorize) display = CategorizeNumbers(serviceList, singleColumn);
  116:                     else display = sb.ToString();
  117:                 }
  118:                 else
  119:                 {
  120:                 }
  121:             }
  122:             else
  123:             {
  124:                 count = 0;
  125:                 display = null;
  126:             }
  127:         }
  128:  
  129:         ////////////////////////////////////////////////////////////////////////////
  130:  
  131:         /// <summary>
  132:         ///
  133:         /// </summary>
  134:         private static string CategorizeNumbers(List<string> serviceList, bool singleColumn)
  135:         {
  136:             int i, count;
  137:             string na, u;
  138:             var sb = new StringBuilder(100000);
  139:             var sbi = new StringBuilder(100000);
  140:             List<string> list;
  141:             Regex regex;
  142:  
  143:             list = new List<string>(10000);
  144:  
  145:             foreach (string t in serviceList) list.Add(t);
  146:  
  147:             foreach (Ia.Ftn.Cl.Models.Business.Administration.Category category in Ia.Ftn.Cl.Models.Data.Administration.CategoryList)
  148:             {
  149:                 count = 0; sbi.Length = 0;
  150:                 regex = new Regex(category.Regex);
  151:  
  152:                 for (i = 0; i < list.Count; i++)
  153:                 {
  154:                     u = list[i].ToString();
  155:  
  156:                     if (regex.IsMatch(u))
  157:                     {
  158:                         if (singleColumn) sbi.Append(u + "<br />");
  159:                         else sbi.Append(u + " ");
  160:  
  161:                         list.RemoveAt(i);
  162:                         count++; i--;
  163:                     }
  164:                 }
  165:  
  166:                 na = @"<p style=""color:" + category.Color + @""">" + category.Name + ": " + category.Description + "</p>";
  167:  
  168:                 if (count == 0) na += "No match found (لا يوجد تطابق). ";
  169:                 else if (count == 1) na += "Found 1 (one) match (وجد تطابق واحد). ";
  170:                 else if (count > 1 && count <= 10) na += "Found " + count + " matches (وجد " + count + " تطابقات). ";
  171:                 else if (count >= 11) na += "Found " + count + " matches (وجد " + count + " تطابقاً). ";
  172:  
  173:                 sb.Append(na + "\n<p>" + sbi.ToString() + "</p>");
  174:             }
  175:  
  176:             return sb.ToString();
  177:         }
  178:  
  179:         ////////////////////////////////////////////////////////////////////////////
  180:  
  181:         /// <summary>
  182:         ///
  183:         /// </summary>
  184:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Administration.ServiceStatusViewModel serviceStatusViewModel)
  185:         {
  186:             var now = DateTime.UtcNow.AddHours(3).ToString("yyyyMMddHHmmss");
  187:  
  188:             var domainList = Ia.Ftn.Cl.Models.Data.Service.DomainList;
  189:             var list = domainList.ConvertAll(delegate (int i) { return i.ToString(); });
  190:  
  191:             list.Sort();
  192:  
  193:             serviceStatusViewModel.DomainSelectList = new SelectList(list);
  194:         }
  195:  
  196:         ////////////////////////////////////////////////////////////////////////////
  197:         ////////////////////////////////////////////////////////////////////////////
  198:     }
  199:  
  200:     ////////////////////////////////////////////////////////////////////////////
  201:     ////////////////////////////////////////////////////////////////////////////
  202: }