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

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

Default class for TentPlay Memorise data model

    1: using System.Data;
    2: using System;
    3: using System.Linq;
    4: using System.Collections.Generic;
    5: using System.IO;
    6:  
    7: namespace Ia.TentPlay.Cl.Model.Memorise
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Default class for TentPlay Memorise data model
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2018 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 static class Default
   29:     {
   30:         ////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public static void GenerateSpecificApplicationSqliteDatabaseFileFromSqlServer(Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application application, out Ia.Cl.Models.Result result)
   36:         {
   37:             int count;
   38:             string fileName, sql, filePath, scalar;
   39:             DataTable dataTable;
   40:             FileInfo file;
   41:             Ia.Cl.Models.Db.Sqlite sqlite;
   42:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
   43:  
   44:             fileName = Ia.TentPlay.Cl.Model.Memorise.Default.SqliteDatabaseFileName(application.Id, application.VersionName);
   45:  
   46:             filePath = global::Ia.Cl.Models.Default.AbsolutePath(true) + fileName;
   47:  
   48:             file = new FileInfo(filePath);
   49:  
   50:             if (file.Exists)
   51:             {
   52:                 // delete file if it exists
   53:                 File.Delete(filePath);
   54:             }
   55:  
   56:             sqlite = new Ia.Cl.Models.Db.Sqlite(filePath); //, filePassword);
   57:  
   58:             // below: drop table if exists
   59:             sql = "drop table if exists scores"; // first because of foreign keys
   60:             sqlite.Sql(sql);
   61:  
   62:             // regular table
   63:             sql = Ia.TentPlay.Cl.Model.Memorise.Default.SqliteDatabaseFileCreateScoresTableString(false);
   64:             sqlite.Sql(sql);
   65:  
   66:             // You can not use index with virtual tables
   67:             //sqlite.Sql("create index if not exists noDiacriticLowerCaseNameIndex on features (noDiacriticLowerCaseName)");
   68:  
   69:             scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.List(application.TestTopic, out result);
   70:  
   71:             dataTable = Ia.Cl.Models.Default.GenerateDataTableFromGenericClassList<Ia.TentPlay.Cl.Model.Memorise.Score>(scoreList, "Scores");
   72:  
   73:             sqlite.SqlBulkCopy(dataTable, out result);
   74:  
   75:             sql = "select count(0) from scores";
   76:             scalar = sqlite.Scalar(sql);
   77:  
   78:             if (!string.IsNullOrEmpty(scalar))
   79:             {
   80:                 count = int.Parse(scalar);
   81:  
   82:                 if (count == scoreList.Count)
   83:                 {
   84:                     result.AddSuccess("Score count: " + count + ". ");
   85:                 }
   86:             }
   87:             else
   88:             {
   89:                 result.AddError("dt is null or dt.Rows.Count == 0 for Scores. ");
   90:             }
   91:         }
   92:  
   93:         ////////////////////////////////////////////////////////////////////////////
   94:  
   95:         /// <summary>
   96:         /// Define the SQLite database file name according to the application file name
   97:         /// </summary>
   98:         public static string SqliteDatabaseFileName(string applicationId, string applicationVersion)
   99:         {
  100:             return applicationId + "." + applicationVersion + ".sqlite";
  101:         }
  102:  
  103:         ////////////////////////////////////////////////////////////////////////////
  104:  
  105:         /// <summary>
  106:         /// 
  107:         /// </summary>
  108:         public static string SqliteDatabaseFileCreateScoresTableString(bool createVirtualTable)
  109:         {
  110:             string sql, entryList;
  111:  
  112:             // for Andriod, the database tables should use the identifier _id for the primary key of the table. Several Android functions rely on this standard.
  113:             // note the "Designation_Id" because Designation is an EF entity represented here by text Designation_Id
  114:  
  115:             entryList = "_id int primary key, testId int, typeId int, question text, answer text, numberOfTimesAsked int, cumulativeAnswerCorrectnessIndicator int, numberOfConsecutiveCorrects int, created dateTime, updated dateTime, viewed dateTime";
  116:  
  117:             if (createVirtualTable) sql = @"create virtual table scoresFts using fts3(" + entryList + ")";
  118:             else sql = @"create table scores (" + entryList + ")";
  119:  
  120:             return sql;
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:  
  125:         /// <summary>
  126:         ///
  127:         /// </summary>
  128:         public static void DownloadSpecificApplicationSqliteDatabaseFileFromTempFolder(Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application application, /*System.Web.UI.Page page,*/ out Ia.Cl.Models.Result result)
  129:         {
  130:             string fileName, filePath;
  131:             FileInfo file;
  132:  
  133:             result = new Ia.Cl.Models.Result();
  134:  
  135:             fileName = Ia.TentPlay.Cl.Model.Memorise.Default.SqliteDatabaseFileName(application.Id, application.VersionName);
  136:  
  137:             filePath = global::Ia.Cl.Models.Default.AbsolutePath(true) + fileName;
  138:  
  139:             file = new FileInfo(filePath);
  140:  
  141:             if (file.Exists)
  142:             {
  143:                 /*
  144:                 page.Response.Clear();
  145:                 page.Response.ClearHeaders();
  146:                 page.Response.ClearContent();
  147:                 page.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
  148:                 page.Response.AddHeader("Content-Length", file.Length.ToString());
  149:                 page.Response.ContentType = "text/plain";
  150:                 page.Response.Flush();
  151:                 page.Response.TransmitFile(file.FullName);
  152:                 page.Response.End();
  153:                 */
  154:  
  155:                 result.AddSuccess("Download complete. ");
  156:             }
  157:             else
  158:             {
  159:                 result.AddError("Download file does not exists. ");
  160:             }
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:         ////////////////////////////////////////////////////////////////////////////
  165:     }
  166: }