)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » HomeController (Ia.Hsb.Pregnalact.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.Pregnalact.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.Pregnalact.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.Pregnalact.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 void Information(ref Ia.Hsb.Pregnalact.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: UNION
  103: SELECT * FROM ia_pregnancy_lactation WHERE
  104:             (title LIKE '" + searchTerm.ToLower() + @"') OR (brand LIKE '" + searchTerm.ToLower() + @"') OR
  105:             (title LIKE '" + searchTerm.ToLower() + @"[ ,]%') OR (brand LIKE '" + searchTerm.ToLower() + @"[ ,]%') OR
  106:             (title LIKE '%[ ,]" + searchTerm.ToLower() + @"[ ,]%') OR (brand LIKE '%[ ,]" + searchTerm.ToLower() + @"[ ,]%') OR
  107:             (title LIKE '%[ ,]" + searchTerm.ToLower() + @"') OR (brand LIKE '%[ ,]" + searchTerm.ToLower() + @"')";
  108: */
  109:  
  110:             dataTable = oleDb.Select(sql);
  111:  
  112:             if (dataTable.Rows.Count == 0)
  113:             {
  114:                 homeViewModel.Result.AddWarning("No data records were found for \"" + inputText + "\".");
  115:             }
  116:             else
  117:             {
  118:                 if (dataTable.Rows.Count == 1)
  119:                 {
  120:                     homeViewModel.Result.AddSuccess("Search for \"" + inputText + "\" found one drug.");
  121:                 }
  122:                 else
  123:                 {
  124:                     homeViewModel.Result.AddSuccess("Search for \"" + inputText + "\" found " + dataTable.Rows.Count + " drugs.");
  125:                 }
  126:  
  127:                 homeViewModel.List = new List<Models.HomeViewModelItem>();
  128:  
  129:                 foreach (DataRow dataRow in dataTable.Rows)
  130:                 {
  131:                     dataRowView = dataTable.DefaultView[dataTable.Rows.IndexOf(dataRow)];
  132:  
  133:                     var item = new Models.HomeViewModelItem();
  134:  
  135:                     item.Title = dataRowView["title"].ToString();
  136:                     item.Brand = Ia.Cl.Models.Html.StripHtml(dataRowView["brand"].ToString());
  137:                     item.TherapeuticCategory = Ia.Cl.Models.Html.StripHtml(dataRowView["therapeutic_category"].ToString());
  138:                     item.IndicationIndex = Ia.Cl.Models.Html.StripHtml(dataRowView["indication_index"].ToString());
  139:                     item.Indication = Ia.Cl.Models.Html.StripHtml(dataRowView["indication"].ToString());
  140:                     item.Pregnancy = Ia.Hsb.Cl.Model.Default.PregnancyRiskFactorPopup(Ia.Cl.Models.Html.StripHtml(dataRowView["pregnancy"].ToString()));
  141:                     item.Lactation = Ia.Cl.Models.Html.StripHtml(dataRowView["lactation"].ToString());
  142:                     item.ContraIndication = Ia.Cl.Models.Html.StripHtml(dataRowView["contraindication"].ToString());
  143:                     item.WarningCaution = Ia.Cl.Models.Html.StripHtml(dataRowView["warning_caution"].ToString());
  144:                     item.AdverseReaction = Ia.Cl.Models.Html.StripHtml(dataRowView["adverse_reaction"].ToString());
  145:                     item.Interaction = Ia.Cl.Models.Html.StripHtml(dataRowView["interaction"].ToString());
  146:                     item.MechanismOfAction = Ia.Cl.Models.Html.StripHtml(dataRowView["mechanism_of_action"].ToString());
  147:                     item.Dosage = Ia.Cl.Models.Html.StripHtml(dataRowView["dosage"].ToString());
  148:                     item.DosageForm = Ia.Cl.Models.Html.StripHtml(dataRowView["dosage_form"].ToString());
  149:  
  150:                     homeViewModel.List.Add(item);
  151:                 }
  152:             }
  153:         }
  154:  
  155:         ////////////////////////////////////////////////////////////////////////////
  156:  
  157:         /// <summary>
  158:         ///
  159:         /// </summary>
  160:         [Route("/pregnancy")]
  161:         public IActionResult Pregnancy()
  162:         {
  163:             return View();
  164:         }
  165:  
  166:         ////////////////////////////////////////////////////////////////////////////
  167:  
  168:         /// <summary>
  169:         ///
  170:         /// </summary>
  171:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  172:         public IActionResult Error()
  173:         {
  174:             return View(new Ia.Hsb.Pregnalact.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  175:         }
  176:  
  177:         ////////////////////////////////////////////////////////////////////////////
  178:         ////////////////////////////////////////////////////////////////////////////
  179:     }
  180:  
  181:     ////////////////////////////////////////////////////////////////////////////
  182:     ////////////////////////////////////////////////////////////////////////////
  183: }