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

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

    1: using Ia.Cl.Models;
    2: using Microsoft.AspNetCore.Mvc;
    3: using System.Data;
    4: using System.Diagnostics;
    5: using System.Net;
    6: using System.Text.RegularExpressions;
    7:  
    8: namespace Ia.Hsb.DrugOnCall.Wa.Controllers
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     ///
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright � 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// 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
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class HomeController : Controller
   30:     {
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         [Route("/")]
   37:         public IActionResult Index()
   38:         {
   39:             var homeViewModel = new Ia.Hsb.DrugOnCall.Wa.Models.HomeViewModel();
   40:  
   41:             return View(homeViewModel);
   42:         }
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         [HttpPost]
   50:         [Route("/search")]
   51:         public IActionResult Search(Ia.Hsb.DrugOnCall.Wa.Models.HomeViewModel homeViewModel)
   52:         {
   53:             var inputText = WebUtility.HtmlEncode(homeViewModel.SearchTextInput);
   54:  
   55:             homeViewModel.Result = new Ia.Cl.Models.Result();
   56:  
   57:             inputText = Regex.Replace(inputText, @"^\s+", string.Empty);
   58:             inputText = Regex.Replace(inputText, @"\s+$", string.Empty);
   59:  
   60:             if (inputText.Length >= 4 || Regex.IsMatch(inputText, @"^\d{1,3}$"))
   61:             {
   62:                 homeViewModel.SearchTextInput = inputText;
   63:  
   64:                 Information(ref homeViewModel);
   65:             }
   66:             else if (inputText.Length > 0)
   67:             {
   68:                 homeViewModel.Result.AddError("Search term is too short.");
   69:             }
   70:             else
   71:             {
   72:                 homeViewModel.Result.AddError("Nothing was entered.");
   73:             }
   74:  
   75:             return View("Index", homeViewModel);
   76:         }
   77:  
   78:         ////////////////////////////////////////////////////////////////////////////
   79:  
   80:         /// <summary>
   81:         ///
   82:         /// </summary>
   83:         private Ia.Cl.Models.Result Information(ref Ia.Hsb.DrugOnCall.Wa.Models.HomeViewModel homeViewModel)
   84:         {
   85:             string sql;
   86:             DataTable dataTable;
   87:             DataRowView dataRowView;
   88:             Ia.Cl.Models.Db.OleDb oleDb;
   89:  
   90:             var inputText = homeViewModel.SearchTextInput;
   91:  
   92:             var result = new Ia.Cl.Models.Result();
   93:  
   94:             oleDb = new Ia.Cl.Models.Db.OleDb(Ia.Cl.Models.ApplicationConfiguration.GetSetting("ConnectionStrings:DefaultConnection"));
   95:  
   96:             sql = @"SELECT * FROM ia_drug WHERE
   97:                 (title LIKE '" + inputText.ToLower() + @"') OR (brand LIKE '" + inputText.ToLower() + @"') OR
   98:                 (title LIKE '" + inputText.ToLower() + @"[ ,]%') OR (brand LIKE '" + inputText.ToLower() + @"[ ,]%') OR
   99:                 (title LIKE '%[ ,]" + inputText.ToLower() + @"[ ,]%') OR (brand LIKE '%[ ,]" + inputText.ToLower() + @"[ ,]%') OR
  100:                 (title LIKE '%[ ,]" + inputText.ToLower() + @"') OR (brand LIKE '%[ ,]" + inputText.ToLower() + @"')";
  101:  
  102:             dataTable = oleDb.Select(sql);
  103:  
  104:             if (dataTable.Rows.Count == 0)
  105:             {
  106:                 homeViewModel.Result.AddWarning("No data records were found for \"" + inputText + "\".");
  107:             }
  108:             else
  109:             {
  110:                 if (dataTable.Rows.Count == 1)
  111:                 {
  112:                     homeViewModel.Result.AddSuccess("Search for \"" + inputText + "\" found one drug.");
  113:                 }
  114:                 else
  115:                 {
  116:                     homeViewModel.Result.AddSuccess("Search for \"" + inputText + "\" found " + dataTable.Rows.Count + " drugs.");
  117:                 }
  118:  
  119:                 homeViewModel.List = new List<Models.HomeViewModelItem>();
  120:  
  121:                 foreach (DataRow dataRow in dataTable.Rows)
  122:                 {
  123:                     dataRowView = dataTable.DefaultView[dataTable.Rows.IndexOf(dataRow)];
  124:  
  125:                     var item = new Models.HomeViewModelItem();
  126:  
  127:                     item.Title = dataRowView["title"].ToString();
  128:                     item.Brand = Ia.Cl.Models.Html.StripHtml(dataRowView["brand"].ToString());
  129:                     item.TherapeuticCategory = Ia.Cl.Models.Html.StripHtml(dataRowView["therapeutic_category"].ToString());
  130:                     item.IndicationIndex = Ia.Cl.Models.Html.StripHtml(dataRowView["indication_index"].ToString());
  131:                     item.Indication = Ia.Cl.Models.Html.StripHtml(dataRowView["indication"].ToString());
  132:                     item.Pregnancy = Ia.Hsb.Cl.Model.Default.PregnancyRiskFactorPopup(Ia.Cl.Models.Html.StripHtml(dataRowView["pregnancy"].ToString()));
  133:                     item.Lactation = Ia.Cl.Models.Html.StripHtml(dataRowView["lactation"].ToString());
  134:                     item.ContraIndication = Ia.Cl.Models.Html.StripHtml(dataRowView["contraindication"].ToString());
  135:                     item.WarningCaution = Ia.Cl.Models.Html.StripHtml(dataRowView["warning_caution"].ToString());
  136:                     item.AdverseReaction = Ia.Cl.Models.Html.StripHtml(dataRowView["adverse_reaction"].ToString());
  137:                     item.Interaction = Ia.Cl.Models.Html.StripHtml(dataRowView["interaction"].ToString());
  138:                     item.MechanismOfAction = Ia.Cl.Models.Html.StripHtml(dataRowView["mechanism_of_action"].ToString());
  139:                     item.Dosage = Ia.Cl.Models.Html.StripHtml(dataRowView["dosage"].ToString());
  140:                     item.DosageForm = Ia.Cl.Models.Html.StripHtml(dataRowView["dosage_form"].ToString());
  141:  
  142:                     homeViewModel.List.Add(item);
  143:                 }
  144:             }
  145:  
  146:             return result;
  147:         }
  148:  
  149:         ////////////////////////////////////////////////////////////////////////////
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         [Route("/pregnancy")]
  155:         public IActionResult Pregnancy()
  156:         {
  157:             return View();
  158:         }
  159:  
  160:         ////////////////////////////////////////////////////////////////////////////
  161:  
  162:         /// <summary>
  163:         ///
  164:         /// </summary>
  165:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  166:         public IActionResult Error()
  167:         {
  168:             return View(new Ia.Hsb.DrugOnCall.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:         ////////////////////////////////////////////////////////////////////////////
  173:     }
  174:  
  175:     ////////////////////////////////////////////////////////////////////////////
  176:     ////////////////////////////////////////////////////////////////////////////
  177: }