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

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

    1: using System.Collections.Generic;
    2: using System;
    3: using System.Text;
    4: using System.Linq;
    5: using System.Web;
    6:  
    7: namespace Ia.Statistics.Cl.Models
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     ///
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public abstract class Default
   29:     {
   30:         ////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public const int MaximumReasonableStockValue = 3000;
   36:  
   37:         ////////////////////////////////////////////////////////////////////////////
   38:  
   39:         /// <summary>
   40:         ///
   41:         /// </summary>
   42:         public const int MaximumReasonableStockValueToPreventCodeDelays = 100;
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         public const int StockValueUnAvailable = -1;
   50:  
   51:         ////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         public const int UndefinedOrInvalidOrUnknown = -1;
   57:  
   58:         ////////////////////////////////////////////////////////////////////////////
   59:  
   60:         /// <summary>
   61:         ///
   62:         /// </summary>
   63:         public static TimeSpan TimeoutTimeSpan = TimeSpan.FromSeconds(10);
   64:  
   65:         ////////////////////////////////////////////////////////////////////////////
   66:  
   67:         /// <summary>
   68:         ///
   69:         /// </summary>
   70:         public const int AverageNumberOfProductsPerCategory = 5;
   71:  
   72:         ////////////////////////////////////////////////////////////////////////////
   73:  
   74:         /// <summary>
   75:         ///
   76:         /// </summary>
   77:         public Default() { }
   78:  
   79:         ////////////////////////////////////////////////////////////////////////////
   80:  
   81:         /// <summary>
   82:         ///
   83:         /// </summary>
   84:         public static string NormalizeName(string name)
   85:         {
   86:             if (!string.IsNullOrEmpty(name))
   87:             {
   88:                 // below: convert occatinal "أرز بسمتي أبيض عضوى" to UTF8 Arabic
   89:                 //name = Encoding.UTF8.GetString(Encoding.Default.GetBytes(name));
   90:  
   91:                 name = System.Net.WebUtility.HtmlDecode(name);
   92:  
   93:                 // change \u0026 to &
   94:                 name = name.Replace(@"\u0026", "&");
   95:                 name = name.Replace(@"\U0026", "&");
   96:                 name = name.Replace(@"\u00ae", "®");
   97:                 name = name.Replace(@"\U00ae", "®");
   98:                 name = name.Replace(@"\u2019", "’");
   99:                 name = name.Replace(@"\U2019", "’");
  100:  
  101:                 name = Ia.Cl.Models.Default.ToTitleCase(name);
  102:             }
  103:  
  104:             return name;
  105:         }
  106:  
  107:         ////////////////////////////////////////////////////////////////////////////
  108:  
  109:         /// <summary>
  110:         ///
  111:         /// </summary>
  112:         public static void Analyze(int siteId, out List<Ia.Statistics.Cl.Models.ProductPriceStockQuantitySold> productPriceStockQuantitySoldList, out DateTime? startDateTime, out DateTime? endDateTime)
  113:         {
  114:             productPriceStockQuantitySoldList = Ia.Statistics.Cl.Models.ProductPriceStockQuantitySold.ListBySiteId(siteId);
  115:  
  116:             Ia.Statistics.Cl.Models.ProductPriceSpot.EarliestAndLatestRecordDateTimeBySiteId(siteId, out DateTime? earliestPriceRecordDateTime, out DateTime? latestPriceRecordDateTime);
  117:             Ia.Statistics.Cl.Models.ProductStockSpot.EarliestAndLatestRecordDateTimeBySiteId(siteId, out DateTime? earliestStockRecordDateTime, out DateTime? latestStockRecordDateTime);
  118:  
  119:             startDateTime = (earliestPriceRecordDateTime > earliestStockRecordDateTime ? earliestPriceRecordDateTime : earliestStockRecordDateTime);
  120:             endDateTime = (latestPriceRecordDateTime > latestStockRecordDateTime ? latestPriceRecordDateTime : latestStockRecordDateTime);
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:  
  125:         /// <summary>
  126:         ///
  127:         /// </summary>
  128:         public static void Search(string input, out List<Ia.Statistics.Cl.Models.ProductPriceStockQuantitySold> productPriceStockQuantitySoldList, out Ia.Cl.Models.Result result)
  129:         {
  130:             productPriceStockQuantitySoldList = Ia.Statistics.Cl.Models.ProductPriceStockQuantitySold.Search(input, out result);
  131:         }
  132:  
  133:         ////////////////////////////////////////////////////////////////////////////
  134:  
  135:         /// <summary>
  136:         ///
  137:         /// </summary>
  138:         public static bool ProcessIsActiveWithinLast20MinutesBySiteId(int siteId)
  139:         {
  140:             bool isActive;
  141:  
  142:             var siteShortName = Ia.Statistics.Cl.Models.Site.SiteShortNameFromId(siteId);
  143:  
  144:             var nowDateTime = DateTime.UtcNow.AddHours(3);
  145:  
  146:             using (var db = new Ia.Statistics.Cl.Models.StatisticsDbContext())
  147:             {
  148:                 var list = (from pss in db.ProductStockSpots
  149:                                             where pss.Id.StartsWith(siteShortName)
  150:                                             select pss);
  151:  
  152:                 DateTime? latestRecordDateTime = list.Count() > 0 ? list.Max(u => u.Created) : null;
  153:  
  154:                 if (latestRecordDateTime.HasValue) isActive = (nowDateTime - latestRecordDateTime) < TimeSpan.FromMinutes(20);
  155:                 else isActive = false;
  156:             }
  157:  
  158:             return isActive;
  159:         }
  160:  
  161:         ////////////////////////////////////////////////////////////////////////////
  162:  
  163:         /// <summary>
  164:         ///
  165:         /// </summary>
  166:         public static string SitetUrl(Site site)
  167:         {
  168:             return "/default?siteId=" + HttpUtility.UrlEncode(site.Id.ToString());
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:  
  173:         /// <summary>
  174:         ///
  175:         /// </summary>
  176:         public static string ProductUrl(Product product)
  177:         {
  178:             return "/product?productId=" + HttpUtility.UrlEncode(product.Id);
  179:         }
  180:  
  181:         ////////////////////////////////////////////////////////////////////////////
  182:         ////////////////////////////////////////////////////////////////////////////
  183:     }
  184: }