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

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

Koran Reference Network Windows Form support functions: Business model

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Xml.Linq;
    5: using System.Text;
    6: using System.Text.RegularExpressions;
    7: using System.Data;
    8: using Microsoft.EntityFrameworkCore;
    9: using System.Linq.Expressions;
   10:  
   11: namespace Ia.Islamic.Koran.Wfa.Model.Business
   12: {
   13:     ////////////////////////////////////////////////////////////////////////////
   14:  
   15:     /// <summary publish="true">
   16:     /// Koran Reference Network Windows Form support functions: Business model
   17:     /// </summary>
   18:     /// <value>
   19:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   20:     /// </value>
   21:     /// <remarks> 
   22:     /// Copyright © 1995-2024 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   23:     ///
   24:     /// 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
   25:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   26:     ///
   27:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   28:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   29:     /// 
   30:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   31:     /// 
   32:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   33:     /// </remarks> 
   34:     public class Default
   35:     {
   36:         private static readonly string websiteFilePath = @"C:\Users\Jasem\Documents\Visual Studio 2022\Projects\Islamic\krn.org\wwwroot\app_data\";
   37:  
   38:         ////////////////////////////////////////////////////////////////////////////
   39:  
   40:         /// <summary>
   41:         ///
   42:         /// </summary>
   43:         public Default()
   44:         {
   45:         }
   46:  
   47:         ////////////////////////////////////////////////////////////////////////////
   48:  
   49:         /// <summary>
   50:         ///
   51:         /// </summary>
   52:         public static void BuildLanguageComboBox(ref System.Windows.Forms.ComboBox cb)
   53:         {
   54:             cb.Items.Clear();
   55:  
   56:             var list = (from l in Ia.Cl.Models.Language.List
   57:                         where Ia.Islamic.Cl.Model.Data.Default.UsedKoranLanguageSymbolList.Contains(l.Iso6391)
   58:                         orderby l.Name
   59:                         select new
   60:                         {
   61:                             Symbol = l.Iso6391,
   62:                             l.Name
   63:                         }).ToList();
   64:  
   65:             cb.DataSource = list;
   66:             cb.DisplayMember = "Name";
   67:             cb.ValueMember = "Symbol";
   68:  
   69:             cb.SelectedIndex = 0;
   70:         }
   71:  
   72:         ////////////////////////////////////////////////////////////////////////////
   73:  
   74:         /// <summary>
   75:         /// 
   76:         /// </summary>
   77:         public static void CreateDatabaseTableRecords(Ia.Cl.Models.Language language, out Ia.Cl.Models.Result result)
   78:         {
   79:             int chapterNumber, verseNumber;
   80:             string name, arabicName, revealed, introduction;
   81:             string regularExpression, word0, content;
   82:             MatchCollection matchCollection;
   83:             Ia.Islamic.Cl.Model.Koran koran;
   84:             Ia.Islamic.Cl.Model.Chapter chapter;
   85:             Ia.Islamic.Cl.Model.Verse verse;
   86:             Ia.Islamic.Cl.Model.Word word;
   87:             Ia.Islamic.Cl.Model.WordVerse wordVerse;
   88:             List<Ia.Islamic.Cl.Model.Word> words;
   89:             List<Ia.Islamic.Cl.Model.WordVerse> wordVerses;
   90:  
   91:             arabicName = revealed = string.Empty;
   92:  
   93:             result = new Ia.Cl.Models.Result();
   94:  
   95:             var koranXDocument = Ia.Islamic.Koran.Wfa.Model.Data.Default.ReturnKoranByLanguage(language);
   96:  
   97:             var wordToVerseIdDictionary = new Dictionary<string, string>(10000); // assuming max num of words and derivatives in any one version of koran
   98:             var verseIdToVerseDictionary = new Dictionary<string, Ia.Islamic.Cl.Model.Verse>(10000);
   99:  
  100:             using (var db = new Ia.Islamic.Cl.KoranDbContext())
  101:             {
  102:                 db.Database.EnsureCreated();
  103:  
  104:                 db.Database.SetCommandTimeout(120); // process is complex, so I needed to increase timeout from 30 to 120
  105:  
  106:                 db.Database.ExecuteSqlRaw("delete from Words where Id like '" + Ia.Islamic.Cl.Model.Business.Word.WordId(language.Id, string.Empty) + "%'");
  107:  
  108:                 db.Database.ExecuteSqlRaw("delete from WordVerses where VerseId like '" + language.Id + "%'");
  109:                 db.Database.ExecuteSqlRaw("delete from WordVerses where WordId like '" + language.Id + "%'");
  110:  
  111:                 db.Database.ExecuteSqlRaw("delete from Verses where Id like '" + language.Id + "%'");
  112:                 db.Database.ExecuteSqlRaw("delete from Chapters where Id like '" + language.Id + "%'");
  113:                 db.Database.ExecuteSqlRaw("delete from Korans where Id like '" + language.Id + "%'");
  114:  
  115:                 if (language.Id == "ja" || language.Id == "ko" || language.Id == "zh")
  116:                 {
  117:                     regularExpression = Ia.Cl.Models.Language.BasicWordsRegularExpression(language.Symbol) + "|[" + Ia.Cl.Models.Language.Ideograph(language.Symbol) + "]{1}";
  118:                     regularExpression = regularExpression.Replace("|[]{1}", string.Empty);
  119:                 }
  120:                 else regularExpression = Ia.Cl.Models.Language.BasicWordsRegularExpression(language.Symbol);
  121:  
  122:                 /*
  123:                 // below: words regular
  124:                 mc = Regex.Matches(content, @"(" + s + ")", RegexOptions.Compiled);
  125:                 foreach (Match m in mc)
  126:                 {
  127:                     word0 = m.Groups[1].Captures[0].Value;
  128:  
  129:                     if (ht[word0] == null) ht[word0] = verse.Id + " ";
  130:                     else if (ht[word0].ToString().IndexOf(verse.Id) == -1) ht[word0] = ht[word0].ToString() + verse.Id + " ";
  131:                     // above: exclude duplicate verse location values
  132:                 }
  133:                 */
  134:  
  135:                 /*
  136:                 mc = Regex.Matches(Ia.Cl.Models.Language.RemoveAccent(content), @"(" + s + ")", RegexOptions.Compiled);
  137:                 foreach (Match m in mc)
  138:                 {
  139:                     word0 = m.Groups[1].Captures[0].Value;
  140:  
  141:                     if (ht[word0] == null) ht[word0] = verse.Id + " ";
  142:                     else if (ht[word0].ToString().IndexOf(verse.Id) == -1) ht[word0] = ht[word0].ToString() + verse.Id + " ";
  143:                 }
  144:                 */
  145:  
  146:                 koran = new Ia.Islamic.Cl.Model.Koran
  147:                 {
  148:                     Id = language.Id,
  149:                     Name = koranXDocument.Descendants("قرءان").Attributes("name").First().Value,
  150:                     Introduction = string.Empty,
  151:                     LanguageIso = language.Id
  152:                 };
  153:  
  154:                 db.Korans.Add(koran);
  155:  
  156:                 chapterNumber = 1;
  157:  
  158:                 foreach (XElement xe in koranXDocument.Descendants("قرءان").Descendants("سورة"))
  159:                 {
  160:                     if (chapterNumber == int.Parse(xe.Attributes("id").First().Value))
  161:                     {
  162:                         name = xe.Attributes("name").First().Value;
  163:  
  164:                         if (language.Symbol != "ar")
  165:                         {
  166:                             arabicName = xe.Attributes("arabicName").First().Value;
  167:                             revealed = xe.Attributes("revealed").First().Value;
  168:                         }
  169:  
  170:                         introduction = xe.Descendants("مقدمة").FirstOrDefault().Value;
  171:  
  172:                         chapter = new Ia.Islamic.Cl.Model.Chapter
  173:                         {
  174:                             Id = language.Id + xe.Attributes("id").First().Value.PadLeft(3, '0'),
  175:                             Number = chapterNumber,
  176:                             Name = name,
  177:                             Koran = (from q in db.Korans where q.Id == koran.Id select q).SingleOrDefault()
  178:                         };
  179:  
  180:                         // below: handle revealed according to language
  181:                         if (revealed == "before") chapter.Revealed = false;
  182:                         else chapter.Revealed = true;
  183:  
  184:                         if (language.Symbol != "ar") chapter.ArabicName = arabicName;
  185:  
  186:                         chapter.Introduction = introduction;
  187:  
  188:                         koran.Chapters.Add(chapter);
  189:  
  190:                         verseNumber = 1;
  191:  
  192:                         foreach (XElement xElement in xe.Descendants("ءاية"))
  193:                         {
  194:                             if (verseNumber == int.Parse(xElement.Attributes("id").First().Value))
  195:                             {
  196:                                 content = xElement.Value;
  197:  
  198:                                 verse = new Ia.Islamic.Cl.Model.Verse
  199:                                 {
  200:                                     Id = chapter.Id + xElement.Attributes("id").First().Value.PadLeft(3, '0'),
  201:                                     Chapter = chapter,
  202:                                     Number = verseNumber,
  203:                                     Content = content
  204:                                 };
  205:  
  206:                                 verseIdToVerseDictionary[verse.Id] = verse;
  207:  
  208:                                 // below: basic form lower case, no accents
  209:                                 matchCollection = Regex.Matches(Ia.Cl.Models.Language.BasicForm(content), @"(" + regularExpression + ")", RegexOptions.Compiled);
  210:  
  211:                                 foreach (Match match in matchCollection)
  212:                                 {
  213:                                     word0 = match.Groups[1].Captures[0].Value;
  214:  
  215:                                     if (!wordToVerseIdDictionary.ContainsKey(word0)) wordToVerseIdDictionary[word0] = verse.Id + " ";
  216:                                     else if (wordToVerseIdDictionary[word0].IndexOf(verse.Id) == -1) wordToVerseIdDictionary[word0] = wordToVerseIdDictionary[word0].ToString() + verse.Id + " ";
  217:                                     // above: this skips adding word if it already exists in this same verseId
  218:                                 }
  219:  
  220:                                 chapter.Verses.Add(verse);
  221:  
  222:                                 verseNumber++;
  223:                             }
  224:                             else
  225:                             {
  226:                                 throw new ArgumentException("Inconsistant verse counter verse id=" + xElement.Attributes("id").First().Value + ", chapter id=" + xe.Attributes("id").First().Value);
  227:                             }
  228:                         }
  229:  
  230:                         chapterNumber++;
  231:                     }
  232:                     else
  233:                     {
  234:                         throw new ArgumentException("Inconsistant chapter counter chapter id=" + xe.Attributes("id").First().Value);
  235:                     }
  236:                 }
  237:  
  238:                 words = new List<Ia.Islamic.Cl.Model.Word>();
  239:                 wordVerses = new List<Ia.Islamic.Cl.Model.WordVerse>();
  240:  
  241:                 // below: populate the word table
  242:                 foreach (string content2 in wordToVerseIdDictionary.Keys)
  243:                 {
  244:                     word = new Ia.Islamic.Cl.Model.Word
  245:                     {
  246:                         Id = Ia.Islamic.Cl.Model.Business.Word.WordId(language.Id, content2),
  247:                         Content = content2
  248:                     };
  249:  
  250:                     // below: remove last " "
  251:                     regularExpression = wordToVerseIdDictionary[content2].ToString().Trim();
  252:  
  253:                     //foreach (string t in regularExpression.Split(' ')) word.Verses.Add((Ia.Islamic.Cl.Model.Verse)verseHashtable[t]);
  254:                     foreach (string verseId in regularExpression.Split(' '))
  255:                     {
  256:                         wordVerse = new Ia.Islamic.Cl.Model.WordVerse
  257:                         {
  258:                             WordId = word.Id,
  259:                             Word = word,
  260:                             VerseId = verseId,
  261:                             Verse = verseIdToVerseDictionary[verseId]
  262:                         };
  263:  
  264:                         wordVerses.Add(wordVerse);
  265:                     }
  266:  
  267:                     words.Add(word);
  268:                 }
  269:  
  270:                 db.Korans.Add(koran);
  271:                 db.Words.AddRange(words);
  272:                 db.WordVerses.AddRange(wordVerses);
  273:  
  274:                 db.SaveChanges();
  275:             }
  276:         }
  277:  
  278:         ////////////////////////////////////////////////////////////////////////////
  279:  
  280:         /// <summary>
  281:         ///
  282:         /// </summary>
  283:         public static void DeleteDatabase(out Ia.Cl.Models.Result result)
  284:         {
  285:             bool databaseDeleted;
  286:  
  287:             result = new Ia.Cl.Models.Result();
  288:  
  289:             try
  290:             {
  291:                 using (var db = new Ia.Islamic.Cl.KoranDbContext())
  292:                 {
  293:                     databaseDeleted = db.Database.EnsureDeleted();
  294:  
  295:                     if (databaseDeleted) result.AddSuccess("Database deleted");
  296:                     else result.AddError("Database delete error");
  297:                 }
  298:             }
  299:             catch (Exception ex)
  300:             {
  301:                 result.AddError("Database delete error. Exception: " + ex.ToString());
  302:             }
  303:         }
  304:  
  305:         ////////////////////////////////////////////////////////////////////////////
  306:  
  307:         /// <summary>
  308:         ///
  309:         /// </summary>
  310:         public static void WriteChapterFiles(Ia.Cl.Models.Language language, out Ia.Cl.Models.Result result)
  311:         {
  312:             bool b;
  313:             string className, fileName, u, content;
  314:  
  315:             result = new Ia.Cl.Models.Result();
  316:             var sb = new StringBuilder();
  317:  
  318:             var translation = new Ia.Islamic.Cl.Model.Translation(language.Id);
  319:             u = Ia.Cl.Models.Default.FirstLetterToUpper(language.Symbol);
  320:  
  321:             using (var db = new Ia.Islamic.Cl.KoranDbContext())
  322:             {
  323:                 // db.Database.Connection.Open();
  324:  
  325:                 var chapters = (from q in db.Chapters
  326:                                 where q.Koran.LanguageIso == language.Id
  327:                                 orderby q.Number
  328:                                 select q).ToList<Ia.Islamic.Cl.Model.Chapter>();
  329:  
  330:                 if (chapters.Count() > 0)
  331:                 {
  332:                     foreach (var chapter in chapters)
  333:                     {
  334:                         sb.Length = 0;
  335:  
  336:                         className = u + "_" + chapter.Number;
  337:  
  338:                         //fileName = chapter.Number + ".aspx.cs";
  339:                         sb.Append(ChapterFileHeader(className, translation.MainHome, translation.MainTitle, translation.MainBismillah, language, chapter.Number, chapter.Name, chapter.ArabicName, chapter.Revealed, chapter.Introduction));
  340:  
  341:                         // below: handle revealed according to language
  342:                         //if (revealed == "before") revealed = "1";
  343:                         //else if (revealed == "after") revealed = "2";
  344:                         //else revealed = "0";
  345:  
  346:                         var verses = (from q in db.Verses
  347:                                       where q.Chapter.Koran.LanguageIso == language.Id && q.Chapter.Id == chapter.Id
  348:                                       orderby q.Number
  349:                                       select q).ToList<Ia.Islamic.Cl.Model.Verse>();
  350:  
  351:                         foreach (var verse in verses)
  352:                         {
  353:                             content = verse.Content;
  354:  
  355:                             sb.Append(ChapterFileVerse(language, verse.Number, content));
  356:  
  357:                             // below: if a حزب, ربع, نصف, ثلاث occures here will will add a space
  358:                             // جزء/حزب/ربع/نصف/ثلاث/
  359:  
  360:                             /*
  361:                             if (verseString != "1")
  362:                             {
  363:                                 //xd = jza_xd.SelectSingleNode("جزء/جزء/descendant::*[@سورة='" + chapter + "' and @ءاية='" + verse + "']");
  364:  
  365:                                 verseStartsHizb = data.Jza.Elements("جزء").Elements("جزء").DescendantsAndSelf().Where(x => x.HasAttributes && x.Attribute("سورة").Value == chapter && x.Attribute("ءاية").Value == verseString).Any();
  366:  
  367:                                 if (verseStartsHizb) sb.Append(ChapterFileSpace(language));
  368:                             }
  369:                              */
  370:  
  371:                             //dr["id"] = long.Parse(ch_id.ToString().PadLeft(3, '0') + v_id.ToString().PadLeft(3, '0'));
  372:                         }
  373:  
  374:                         sb.Append(ChapterFileFooter(language));
  375:  
  376:                         // below: write to webpage file
  377:  
  378:                         fileName = websiteFilePath + language.Symbol + @"\" + chapter.Number + ".html";
  379:  
  380:                         b = Ia.Cl.Models.File.Write(fileName, sb.ToString());
  381:  
  382:                         if (!b) { result.AddError("WriteChapterFiles: Can't write file " + fileName); break; }
  383:  
  384:                         // below: write *.aspx.cs file in webpage
  385:                         sb = new StringBuilder(100000)
  386:                         {
  387:                             Length = 0
  388:                         };
  389:  
  390:                         //sb.Append(ChapterFileCs(language, className));
  391:                         //fileName = websiteFilePath + language.Symbol + @"\" + chapter.Number + ".aspx.cs";
  392:  
  393:                         //b = Ia.Cl.Models.File.Write(fileName, sb.ToString());
  394:  
  395:                         if (!b) { result.AddError("WriteChapterFiles: Can't write file " + fileName); break; }
  396:                     }
  397:                 }
  398:                 else
  399:                 {
  400:                     result.AddError("No chapter files read from database");
  401:                 }
  402:             }
  403:         }
  404:  
  405:         ////////////////////////////////////////////////////////////////////////////
  406:  
  407:         /// <summary>
  408:         ///
  409:         /// </summary>
  410:         public static string ChapterFileHeader(string className, string home, string koran, string bismilla, Ia.Cl.Models.Language language, int chapter, string name, string arabicName, bool revealed, string intro)
  411:         {
  412:             string s, title;
  413:  
  414:             title = string.Empty;
  415:  
  416:             if (language.Id == "ar") title = name;
  417:             else
  418:             {
  419:                 if (name.Length > 0 && arabicName.Length > 0) title = name + " (" + arabicName + ")";
  420:                 else if (name.Length > 0) title = name;
  421:                 else if (arabicName.Length > 0) title = arabicName;
  422:             }
  423:  
  424:             s = @"<a href=""/"">" + home + @"</a> » <a href=""/" + language.Symbol + @""">" + koran + @"</a> » " + title;
  425:  
  426:             if (intro.Length > 0) s += @"<div class=""intro"">" + intro + @"</div>";
  427:  
  428:             s += @"<div class=""chapter"">";
  429:  
  430:             if (chapter != 1 && chapter != 9)
  431:             {
  432:                 s += @"<span class=""bismilla"">" + bismilla + @"</span>&nbsp;&nbsp;";
  433:             }
  434:  
  435:             // <p><a name=""1"">1</a>. In the name of Allah, Most Gracious, Most Merciful.</p>";
  436:  
  437:             return s;
  438:         }
  439:  
  440:         ////////////////////////////////////////////////////////////////////////////
  441:  
  442:         /// <summary>
  443:         ///
  444:         /// </summary>
  445:         public static string ChapterFileVerse(Ia.Cl.Models.Language language, int verse, string content)
  446:         {
  447:             string s;
  448:  
  449:             // below: I will keep no space between verse and number
  450:             if (language.Symbol == "ja") s = @"<div class=""verse"">" + content + @"<span class=""number""><a id=""" + verse + @""">" + verse + @"</a></span></div>&nbsp;&nbsp;&nbsp;";
  451:             else s = @"<div class=""verse"">" + content + @" <span class=""number""><a id=""" + verse + @""">" + verse + @"</a></span></div>&nbsp;&nbsp;";
  452:  
  453:             return s;
  454:         }
  455:  
  456:         ////////////////////////////////////////////////////////////////////////////
  457:  
  458:         /// <summary>
  459:         ///
  460:         /// </summary>
  461:         public string ChapterFileSpace(Ia.Cl.Models.Language language)
  462:         {
  463:             string s;
  464:  
  465:             s = @"<p><br/></p>";
  466:  
  467:             return s;
  468:         }
  469:  
  470:         ////////////////////////////////////////////////////////////////////////////
  471:  
  472:         /// <summary>
  473:         ///
  474:         /// </summary>
  475:         public static string ChapterFileFooter(Ia.Cl.Models.Language language)
  476:         {
  477:             string s;
  478:  
  479:             s = @"</div>";
  480:  
  481:             return s;
  482:         }
  483:  
  484:         ////////////////////////////////////////////////////////////////////////////
  485:         ////////////////////////////////////////////////////////////////////////////
  486:  
  487:         /// <summary>
  488:         ///
  489:         /// </summary>
  490:         public static void WriteDefaultAndSearchFiles(Ia.Cl.Models.Language language, out Ia.Cl.Models.Result result)
  491:         {
  492:             bool b;
  493:             string u, fileName;
  494:  
  495:             result = new Ia.Cl.Models.Result();
  496:             var sb = new StringBuilder(100000);
  497:  
  498:             var translation = new Ia.Islamic.Cl.Model.Translation(language.Id);
  499:  
  500:             u = Ia.Cl.Models.Default.FirstLetterToUpper(language.Symbol);
  501:  
  502:             /*
  503:             - "chapter": (id,chapter,language_id,name,arabicName,revealed_id,introduction)
  504:             */
  505:  
  506:             // below: write default.aspx file in webpage
  507:             sb = new StringBuilder(100000);
  508:             sb.Append(BuildDefaultFile(language, translation, u + "_Default"));
  509:             fileName = websiteFilePath + language.Symbol + @"\default.html";
  510:             b = Ia.Cl.Models.File.Write(fileName, sb.ToString());
  511:             if (!b) result.AddError("WriteDefaultAndSearchFiles: Can't write file " + fileName);
  512:         }
  513:  
  514:         ////////////////////////////////////////////////////////////////////////////
  515:  
  516:         /// <summary>
  517:         ///
  518:         /// </summary>
  519:         public static string DefaultFileHeader(Ia.Cl.Models.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
  520:         {
  521:             string s;
  522:  
  523:             // below is similar to Search.cshtml
  524:  
  525:             s = @"<a href=""/"">" + translation.MainHome + "</a> » " + translation.MainTitle + @"
  526:  
  527: <p class=""enter-words"">" + translation.SearchInstruction + @"</p>
  528:  
  529: <form method=""post"" action=""/" + language.Symbol + @"/search"" enctype=""multipart/form-data"">
  530:     <table class=""form"">
  531:         <tr>
  532:             <td>
  533:                 <input name=""searchTextInput"" type=""text"" maxlength=""32"" />
  534:                 <input name=""iso2"" type=""hidden"" value=""" + language.Symbol + @""" />
  535:             </td>
  536:             <td>
  537:                 <input type=""submit"" value=""" + translation.SearchButton + @""" />
  538:             </td>
  539:         </tr>
  540:     </table>
  541: </form>
  542:  
  543: <p class=""hint"">
  544:     <span class=""head"">" + translation.SearchHintName + @"</span>: " + translation.SearchHint + @"
  545: </p>
  546:  
  547: <ol>
  548: ";
  549:  
  550:             return s;
  551:         }
  552:  
  553:         ////////////////////////////////////////////////////////////////////////////
  554:  
  555:         /// <summary>
  556:         ///
  557:         /// </summary>
  558:         public static string DefaultAndSearchFileChapterTitle(Ia.Cl.Models.Language language, Ia.Islamic.Cl.Model.Translation translation, Ia.Islamic.Cl.Model.Chapter chapter)
  559:         {
  560:             string s;
  561:  
  562:             if (language.Id == "ar")
  563:             {
  564:                 s = @"<li><a href=""/" + language.Symbol + "/" + chapter.Number + @""">" + chapter.Name + @"</a></li>" + "\r\n";
  565:  
  566:                 //if (language.Symbol == "ar" && chapter % 38 == 0) s += @"</td><td style=""vertical-align:top;"">";
  567:                 //else if (language != "ar" && n % 57 == 0) s += @"</td><td style=""vertical-align:top;"">";
  568:             }
  569:             else
  570:             {
  571:                 if (chapter.Name.Length > 0 && chapter.ArabicName.Length > 0) s = @"<li><a href=""/" + language.Symbol + "/" + chapter.Number + @""">" + chapter.Name + @"</a> (<a href=""/" + language.Symbol + "/" + chapter.Number + @""">" + chapter.ArabicName + @"</a>)</li>" + "\r\n";
  572:                 else if (chapter.Name.Length > 0) s = @"<li><a href=""/" + language.Symbol + "/" + chapter.Number + @""">" + chapter.Name + @"</a></li>" + "\r\n";
  573:                 else /*if (arabicName.Length > 0)*/ s = @"<li><a href=""/" + language.Symbol + "/" + chapter.Number + @""">" + chapter.ArabicName + @"</a></li>" + "\r\n";
  574:             }
  575:  
  576:             return s;
  577:         }
  578:  
  579:         ////////////////////////////////////////////////////////////////////////////
  580:  
  581:         /// <summary>
  582:         ///
  583:         /// </summary>
  584:         public static string DefaultFileFooter(Ia.Cl.Models.Language language, Ia.Islamic.Cl.Model.Translation translation)
  585:         {
  586:             string s;
  587:  
  588:             s = @"
  589: </ol>";
  590:  
  591:             return s;
  592:         }
  593:  
  594:         ////////////////////////////////////////////////////////////////////////////
  595:  
  596:         /// <summary>
  597:         ///
  598:         /// </summary>
  599:         public static string BuildDefaultFile(Ia.Cl.Models.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
  600:         {
  601:             var sb = new StringBuilder(100000);
  602:             sb.Length = 0;
  603:  
  604:             sb.Append(DefaultFileHeader(language, translation, className));
  605:  
  606:             using (var db = new Ia.Islamic.Cl.KoranDbContext())
  607:             {
  608:                 var chapters = (from q in db.Chapters
  609:                                 where q.Koran.LanguageIso == language.Id
  610:                                 orderby q.Number
  611:                                 select q).ToList<Ia.Islamic.Cl.Model.Chapter>();
  612:  
  613:                 foreach (Ia.Islamic.Cl.Model.Chapter chapter in chapters)
  614:                 {
  615:                     sb.Append(DefaultAndSearchFileChapterTitle(language, translation, chapter));
  616:                 }
  617:             }
  618:  
  619:             sb.Append(DefaultFileFooter(language, translation));
  620:  
  621:             return sb.ToString();
  622:         }
  623:  
  624:         ////////////////////////////////////////////////////////////////////////////
  625:         ////////////////////////////////////////////////////////////////////////////
  626:     }
  627:  
  628:     ////////////////////////////////////////////////////////////////////////////
  629:     ////////////////////////////////////////////////////////////////////////////
  630: }