شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Default

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-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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 2019\Projects\Islamic\krn.org\";
  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.Model.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.Model.Language language, out Ia.Cl.Model.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.Model.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.Model.Context.Koran())
 101:              {
 102:                  db.Database.EnsureCreated();
 103:   
 104:                  db.Database.ExecuteSqlRaw("delete from Words where Id like '" + Ia.Islamic.Cl.Model.Business.Word.WordId(language.Id, "") + "%'");
 105:   
 106:                  db.Database.ExecuteSqlRaw("delete from WordVerses where VerseId like '" + language.Id + "%'");
 107:                  db.Database.ExecuteSqlRaw("delete from WordVerses where WordId like '" + language.Id + "%'");
 108:   
 109:                  db.Database.ExecuteSqlRaw("delete from Verses where Id like '" + language.Id + "%'");
 110:                  db.Database.ExecuteSqlRaw("delete from Chapters where Id like '" + language.Id + "%'");
 111:                  db.Database.ExecuteSqlRaw("delete from Korans where Id like '" + language.Id + "%'");
 112:   
 113:                  if (language.Id == "ja" || language.Id == "ko" || language.Id == "zh")
 114:                  {
 115:                      regularExpression = Ia.Cl.Model.Language.BasicWordsRegularExpression(language.Symbol) + "|[" + Ia.Cl.Model.Language.Ideograph(language.Symbol) + "]{1}";
 116:                      regularExpression = regularExpression.Replace("|[]{1}", "");
 117:                  }
 118:                  else regularExpression = Ia.Cl.Model.Language.BasicWordsRegularExpression(language.Symbol);
 119:   
 120:                  /*
 121:                  // below: words regular
 122:                  mc = Regex.Matches(content, @"(" + s + ")", RegexOptions.Compiled);
 123:                  foreach (Match m in mc)
 124:                  {
 125:                      word0 = m.Groups[1].Captures[0].Value;
 126:   
 127:                      if (ht[word0] == null) ht[word0] = verse.Id + " ";
 128:                      else if (ht[word0].ToString().IndexOf(verse.Id) == -1) ht[word0] = ht[word0].ToString() + verse.Id + " ";
 129:                      // above: exclude duplicate verse location values
 130:                  }
 131:                  */
 132:   
 133:                  /*
 134:                  mc = Regex.Matches(Ia.Cl.Model.Language.RemoveAccent(content), @"(" + s + ")", RegexOptions.Compiled);
 135:                  foreach (Match m in mc)
 136:                  {
 137:                      word0 = m.Groups[1].Captures[0].Value;
 138:   
 139:                      if (ht[word0] == null) ht[word0] = verse.Id + " ";
 140:                      else if (ht[word0].ToString().IndexOf(verse.Id) == -1) ht[word0] = ht[word0].ToString() + verse.Id + " ";
 141:                  }
 142:                  */
 143:   
 144:                  koran = new Ia.Islamic.Cl.Model.Koran
 145:                  {
 146:                      Id = language.Id,
 147:                      Name = koranXDocument.Descendants("قرءان").Attributes("name").First().Value,
 148:                      Introduction = string.Empty,
 149:                      LanguageIso = language.Id
 150:                  };
 151:   
 152:                  db.Korans.Add(koran);
 153:   
 154:                  chapterNumber = 1;
 155:   
 156:                  foreach (XElement xe in koranXDocument.Descendants("قرءان").Descendants("سورة"))
 157:                  {
 158:                      if (chapterNumber == int.Parse(xe.Attributes("id").First().Value))
 159:                      {
 160:                          name = xe.Attributes("name").First().Value;
 161:   
 162:                          if (language.Symbol != "ar")
 163:                          {
 164:                              arabicName = xe.Attributes("arabicName").First().Value;
 165:                              revealed = xe.Attributes("revealed").First().Value;
 166:                          }
 167:   
 168:                          introduction = xe.Descendants("مقدمة").FirstOrDefault().Value;
 169:   
 170:                          chapter = new Ia.Islamic.Cl.Model.Chapter
 171:                          {
 172:                              Id = language.Id + xe.Attributes("id").First().Value.PadLeft(3, '0'),
 173:                              Number = chapterNumber,
 174:                              Name = name,
 175:                              Koran = (from q in db.Korans where q.Id == koran.Id select q).SingleOrDefault()
 176:                          };
 177:   
 178:                          // below: handle revealed according to language
 179:                          if (revealed == "before") chapter.Revealed = false;
 180:                          else chapter.Revealed = true;
 181:   
 182:                          if (language.Symbol != "ar") chapter.ArabicName = arabicName;
 183:   
 184:                          chapter.Introduction = introduction;
 185:   
 186:                          koran.Chapters.Add(chapter);
 187:   
 188:                          verseNumber = 1;
 189:   
 190:                          foreach (XElement xElement in xe.Descendants("ءاية"))
 191:                          {
 192:                              if (verseNumber == int.Parse(xElement.Attributes("id").First().Value))
 193:                              {
 194:                                  content = xElement.Value;
 195:   
 196:                                  verse = new Ia.Islamic.Cl.Model.Verse
 197:                                  {
 198:                                      Id = chapter.Id + xElement.Attributes("id").First().Value.PadLeft(3, '0'),
 199:                                      Chapter = chapter,
 200:                                      Number = verseNumber,
 201:                                      Content = content
 202:                                  };
 203:   
 204:                                  verseIdToVerseDictionary[verse.Id] = verse;
 205:   
 206:                                  // below: basic form lower case, no accents
 207:                                  matchCollection = Regex.Matches(Ia.Cl.Model.Language.BasicForm(content), @"(" + regularExpression + ")", RegexOptions.Compiled);
 208:   
 209:                                  foreach (Match match in matchCollection)
 210:                                  {
 211:                                      word0 = match.Groups[1].Captures[0].Value;
 212:   
 213:                                      if (!wordToVerseIdDictionary.ContainsKey(word0)) wordToVerseIdDictionary[word0] = verse.Id + " ";
 214:                                      else if (wordToVerseIdDictionary[word0].IndexOf(verse.Id) == -1) wordToVerseIdDictionary[word0] = wordToVerseIdDictionary[word0].ToString() + verse.Id + " ";
 215:                                      // above: this skips adding word if it already exists in this same verseId
 216:                                  }
 217:   
 218:                                  chapter.Verses.Add(verse);
 219:   
 220:                                  verseNumber++;
 221:                              }
 222:                              else
 223:                              {
 224:                                  throw new ArgumentException("Inconsistant verse counter verse id=" + xElement.Attributes("id").First().Value + ", chapter id=" + xe.Attributes("id").First().Value);
 225:                              }
 226:                          }
 227:   
 228:                          chapterNumber++;
 229:                      }
 230:                      else
 231:                      {
 232:                          throw new ArgumentException("Inconsistant chapter counter chapter id=" + xe.Attributes("id").First().Value);
 233:                      }
 234:                  }
 235:   
 236:                  words = new List<Ia.Islamic.Cl.Model.Word>();
 237:                  wordVerses = new List<Ia.Islamic.Cl.Model.WordVerse>();
 238:   
 239:                  // below: populate the word table
 240:                  foreach (string content2 in wordToVerseIdDictionary.Keys)
 241:                  {
 242:                      word = new Ia.Islamic.Cl.Model.Word
 243:                      {
 244:                          Id = Ia.Islamic.Cl.Model.Business.Word.WordId(language.Id, content2),
 245:                          Content = content2
 246:                      };
 247:   
 248:                      // below: remove last " "
 249:                      regularExpression = wordToVerseIdDictionary[content2].ToString().Trim();
 250:   
 251:                      //foreach (string t in regularExpression.Split(' ')) word.Verses.Add((Ia.Islamic.Cl.Model.Verse)verseHashtable[t]);
 252:                      foreach (string verseId in regularExpression.Split(' '))
 253:                      {
 254:                          wordVerse = new Ia.Islamic.Cl.Model.WordVerse
 255:                          {
 256:                              WordId = word.Id,
 257:                              Word = word,
 258:                              VerseId = verseId,
 259:                              Verse = verseIdToVerseDictionary[verseId]
 260:                          };
 261:   
 262:                          wordVerses.Add(wordVerse);
 263:                      }
 264:   
 265:                      words.Add(word);
 266:                  }
 267:   
 268:                  db.Korans.Add(koran);
 269:                  db.Words.AddRange(words);
 270:                  db.WordVerses.AddRange(wordVerses);
 271:   
 272:                  db.SaveChanges();
 273:              }
 274:          }
 275:   
 276:          ////////////////////////////////////////////////////////////////////////////
 277:   
 278:          /// <summary>
 279:          ///
 280:          /// </summary>
 281:          public static void DeleteDatabase(out Ia.Cl.Model.Result result)
 282:          {
 283:              bool databaseDeleted;
 284:   
 285:              result = new Ia.Cl.Model.Result();
 286:   
 287:              try
 288:              {
 289:                  using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
 290:                  {
 291:                      databaseDeleted = db.Database.EnsureDeleted();
 292:   
 293:                      if (databaseDeleted) result.AddSuccess("Database deleted");
 294:                      else result.AddError("Database delete error");
 295:                  }
 296:              }
 297:              catch (Exception ex)
 298:              {
 299:                  result.AddError("Database delete error. Exception: " + ex.ToString());
 300:              }
 301:          }
 302:   
 303:          ////////////////////////////////////////////////////////////////////////////
 304:   
 305:          /// <summary>
 306:          ///
 307:          /// </summary>
 308:          public static void WriteChapterFiles(Ia.Cl.Model.Language language, out Ia.Cl.Model.Result result)
 309:          {
 310:              bool b;
 311:              string className, fileName, u, content;
 312:   
 313:              result = new Ia.Cl.Model.Result();
 314:              var sb = new StringBuilder();
 315:   
 316:              var translation = new Ia.Islamic.Cl.Model.Translation(language.Id);
 317:              u = Ia.Cl.Model.Default.FirstLetterToUpper(language.Symbol);
 318:   
 319:              using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
 320:              {
 321:                  // db.Database.Connection.Open();
 322:   
 323:                  var chapters = (from q in db.Chapters where q.Koran.LanguageIso == language.Id select q).ToList<Ia.Islamic.Cl.Model.Chapter>();
 324:   
 325:                  if (chapters.Count() > 0)
 326:                  {
 327:                      foreach (Ia.Islamic.Cl.Model.Chapter chapter in chapters)
 328:                      {
 329:                          sb.Length = 0;
 330:   
 331:                          className = u + "_" + chapter.Number;
 332:   
 333:                          fileName = chapter.Number + ".aspx.cs";
 334:                          sb.Append(ChapterFileHeader(className, fileName, translation.MainHome, translation.MainTitle, translation.MainBismillah, language, chapter.Id, chapter.Number, chapter.Name, chapter.ArabicName, chapter.Revealed, chapter.Introduction));
 335:   
 336:                          // below: handle revealed according to language
 337:                          //if (revealed == "before") revealed = "1";
 338:                          //else if (revealed == "after") revealed = "2";
 339:                          //else revealed = "0";
 340:   
 341:                          var verses = (from q in db.Verses where q.Chapter.Koran.LanguageIso == language.Id && q.Chapter.Id == chapter.Id select q).ToList<Ia.Islamic.Cl.Model.Verse>();
 342:   
 343:                          foreach (Ia.Islamic.Cl.Model.Verse verse in verses)
 344:                          {
 345:                              content = verse.Content;
 346:   
 347:                              sb.Append(ChapterFileVerse(language, verse.Number, content));
 348:   
 349:                              // below: if a حزب, ربع, نصف, ثلاث occures here will will add a space
 350:                              // جزء/حزب/ربع/نصف/ثلاث/
 351:   
 352:                              /*
 353:                              if (verseString != "1")
 354:                              {
 355:                                  //xd = jza_xd.SelectSingleNode("جزء/جزء/descendant::*[@سورة='" + chapter + "' and @ءاية='" + verse + "']");
 356:   
 357:                                  verseStartsHizb = data.Jza.Elements("جزء").Elements("جزء").DescendantsAndSelf().Where(x => x.HasAttributes && x.Attribute("سورة").Value == chapter && x.Attribute("ءاية").Value == verseString).Any();
 358:   
 359:                                  if (verseStartsHizb) sb.Append(ChapterFileSpace(language));
 360:                              }
 361:                               */
 362:   
 363:                              //dr["id"] = long.Parse(ch_id.ToString().PadLeft(3, '0') + v_id.ToString().PadLeft(3, '0'));
 364:                          }
 365:   
 366:                          sb.Append(ChapterFileFooter(language));
 367:   
 368:                          // below: write to webpage file
 369:   
 370:                          fileName = websiteFilePath + language.Symbol + @"\" + chapter.Number + ".aspx";
 371:   
 372:                          b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 373:   
 374:                          if (!b) { result.AddError("WriteChapterFiles: Can't write file " + fileName); break; }
 375:   
 376:                          // below: write *.aspx.cs file in webpage
 377:                          sb = new StringBuilder(100000)
 378:                          {
 379:                              Length = 0
 380:                          };
 381:   
 382:                          sb.Append(ChapterFileCs(language, className));
 383:                          fileName = websiteFilePath + language.Symbol + @"\" + chapter.Number + ".aspx.cs";
 384:   
 385:                          b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 386:   
 387:                          if (!b) { result.AddError("WriteChapterFiles: Can't write file " + fileName); break; }
 388:                      }
 389:                  }
 390:                  else
 391:                  {
 392:                      result.AddError("No chapter files read from database");
 393:                  }
 394:              }
 395:          }
 396:   
 397:          ////////////////////////////////////////////////////////////////////////////
 398:   
 399:          /// <summary>
 400:          ///
 401:          /// </summary>
 402:          public static string ChapterFileHeader(string className, string fileName, string home, string koran, string bismilla, Ia.Cl.Model.Language language, string ch_id, int chapter, string name, string arabicName, bool revealed, string intro)
 403:          {
 404:              string s, title;
 405:   
 406:              title = "";
 407:   
 408:              if (language.Id == "ar") title = name;
 409:              else
 410:              {
 411:                  if (name.Length > 0 && arabicName.Length > 0) title = name + " (" + arabicName + ")";
 412:                  else if (name.Length > 0) title = name;
 413:                  else if (arabicName.Length > 0) title = arabicName;
 414:              }
 415:   
 416:              s = @"<%@ Page Language=""C#"" AutoEventWireup=""true"" Inherits=""" + className + @""" MasterPageFile=""~/1_" + language.Symbol + @".master"" Codebehind=""" + fileName + @""" %>
 417:  <asp:Content ContentPlaceHolderID=""contentContentPlaceHolder"" runat=""server"">
 418:   
 419:  <asp:HyperLink NavigateUrl=""~/default.aspx"" Text=""" + home + @""" runat=""server""/> » <asp:HyperLink NavigateUrl=""~/" + language.Symbol + @"/default.aspx"" Text=""" + koran + @""" runat=""server""/> » " + title;
 420:   
 421:              if (intro.Length > 0) s += @"<div id=""intro"">" + intro + @"</div>";
 422:   
 423:              s += @"<div id=""chapter"">";
 424:   
 425:              if (chapter != 1 && chapter != 9)
 426:              {
 427:                  s += @"<span class=""bismilla"">" + bismilla + @"</span>&nbsp;&nbsp;";
 428:              }
 429:   
 430:              // <p><a name=""1"">1</a>. In the name of Allah, Most Gracious, Most Merciful.</p>";
 431:   
 432:              return s;
 433:          }
 434:   
 435:          ////////////////////////////////////////////////////////////////////////////
 436:   
 437:          /// <summary>
 438:          ///
 439:          /// </summary>
 440:          public static string ChapterFileVerse(Ia.Cl.Model.Language language, int verse, string content)
 441:          {
 442:              string s;
 443:   
 444:              // below: I will keep no space between verse and number
 445:              if (language.Symbol == "ja") s = @"<div class=""verse"">" + content + @"<span class=""number""><a id=""" + verse + @""">" + verse + @"</a></span></div>&nbsp;&nbsp;&nbsp;";
 446:              else s = @"<div class=""verse"">" + content + @" <span class=""number""><a id=""" + verse + @""">" + verse + @"</a></span></div>&nbsp;&nbsp;";
 447:   
 448:              return s;
 449:          }
 450:   
 451:          ////////////////////////////////////////////////////////////////////////////
 452:   
 453:          /// <summary>
 454:          ///
 455:          /// </summary>
 456:          public string ChapterFileSpace(Ia.Cl.Model.Language language)
 457:          {
 458:              string s;
 459:   
 460:              s = @"<p><br/></p>";
 461:   
 462:              return s;
 463:          }
 464:   
 465:          ////////////////////////////////////////////////////////////////////////////
 466:   
 467:          /// <summary>
 468:          ///
 469:          /// </summary>
 470:          public static string ChapterFileFooter(Ia.Cl.Model.Language language)
 471:          {
 472:              string s;
 473:   
 474:              s = @"</div>
 475:  </asp:Content>";
 476:   
 477:              return s;
 478:          }
 479:   
 480:          ////////////////////////////////////////////////////////////////////////////
 481:   
 482:          /// <summary>
 483:          ///
 484:          /// </summary>
 485:          public static string ChapterFileCs(Ia.Cl.Model.Language language, string className)
 486:          {
 487:              string s;
 488:   
 489:              s = @"using System;
 490:  using System.Web;
 491:   
 492:  ////////////////////////////////////////////////////////////////////////////
 493:   
 494:  /// <summary>
 495:  ///
 496:  /// </summary>
 497:  public partial class " + className + @" : System.Web.UI.Page
 498:  {
 499:      ////////////////////////////////////////////////////////////////////////////
 500:   
 501:      /// <summary>
 502:      ///
 503:      /// </summary>
 504:      void Page_PreInit(object sender, System.EventArgs e)
 505:      {
 506:          Ia.Islamic.Koran.Wa.Model.Ui.Default.Theme(this, HttpContext.Current.Profile);
 507:      }
 508:   
 509:      ////////////////////////////////////////////////////////////////////////////
 510:   
 511:      /// <summary>
 512:      ///
 513:      /// </summary>
 514:      protected void Page_Load(object sender, EventArgs e)
 515:      {
 516:      }
 517:   
 518:      ////////////////////////////////////////////////////////////////////////////
 519:      ////////////////////////////////////////////////////////////////////////////
 520:  }
 521:  ";
 522:   
 523:              return s;
 524:          }
 525:   
 526:          ////////////////////////////////////////////////////////////////////////////
 527:          ////////////////////////////////////////////////////////////////////////////
 528:   
 529:   
 530:   
 531:   
 532:   
 533:          ////////////////////////////////////////////////////////////////////////////
 534:          ////////////////////////////////////////////////////////////////////////////
 535:   
 536:          /// <summary>
 537:          ///
 538:          /// </summary>
 539:          public static void WriteDefaultAndSearchFiles(Ia.Cl.Model.Language language, out Ia.Cl.Model.Result result)
 540:          {
 541:              bool b;
 542:              string u, fileName;
 543:              StringBuilder sb;
 544:   
 545:              result = new Ia.Cl.Model.Result();
 546:              sb = new StringBuilder(100000);
 547:   
 548:              Ia.Islamic.Cl.Model.Translation translation = new Ia.Islamic.Cl.Model.Translation(language.Id);
 549:   
 550:              u = Ia.Cl.Model.Default.FirstLetterToUpper(language.Symbol);
 551:   
 552:              /*
 553:              - "chapter": (id,chapter,language_id,name,arabicName,revealed_id,introduction)
 554:              */
 555:   
 556:              // below: write default.aspx file in webpage
 557:              sb = new StringBuilder(100000);
 558:              sb.Append(BuildDefaultFile(language, translation, "" + u + "_Default"));
 559:              fileName = websiteFilePath + language.Symbol + @"\default.aspx";
 560:              b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 561:              if (!b) result.AddError("WriteDefaultAndSearchFiles: Can't write file " + fileName);
 562:   
 563:              // below: write default.aspx.cs file in webpage
 564:              sb = new StringBuilder(100000);
 565:              sb.Append(DefaultFileCs(language, translation, "" + u + "_Default"));
 566:              fileName = websiteFilePath + language.Symbol + @"\default.aspx.cs";
 567:              b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 568:              if (!b) result.AddError("WriteDefaultAndSearchFiles: Can't write file " + fileName);
 569:   
 570:              // below: write search.aspx file in webpage
 571:              sb = new StringBuilder(100000);
 572:              sb.Append(SearchFile(language, translation, "" + u + "_Search"));
 573:              fileName = websiteFilePath + language.Symbol + @"\search.aspx";
 574:              b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 575:              if (!b) result.AddError("WriteDefaultAndSearchFiles: Can't write file " + fileName);
 576:   
 577:              // below: write search.aspx.cs file in webpage
 578:              sb = new StringBuilder(100000);
 579:              sb.Append(SearchFileCs(language, translation, "" + u + "_Search"));
 580:              fileName = websiteFilePath + language.Symbol + @"\search.aspx.cs";
 581:              b = Ia.Cl.Model.File.Write(fileName, sb.ToString());
 582:              if (!b) result.AddError("WriteDefaultAndSearchFiles: Can't write file " + fileName);
 583:          }
 584:   
 585:          ////////////////////////////////////////////////////////////////////////////
 586:   
 587:          /// <summary>
 588:          ///
 589:          /// </summary>
 590:          public static string DefaultFileHeader(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
 591:          {
 592:              string s;
 593:   
 594:              s = @"<%@ Page Language=""C#"" AutoEventWireup=""True"" Inherits=""" + className + @""" MasterPageFile=""~/1_" + language.Symbol + @".master"" CodeBehind=""default.aspx.cs"" %>
 595:   
 596:  <asp:Content ContentPlaceHolderID=""contentContentPlaceHolder"" runat=""server"">
 597:   
 598:  <asp:HyperLink NavigateUrl=""~/default.aspx"" Text=""" + translation.MainHome + @""" runat=""server""/> » " + translation.MainTitle + @"
 599:   
 600:  <p id=""enter-words"">" + translation.SearchInstruction + @"</p>
 601:   
 602:  <p id=""text-box""><asp:TextBox id=""tb"" Maxlength=""32"" Columns=""16"" runat=""server""/>&nbsp;<asp:Button Text="" " + translation.SearchButton + @" "" runat=""server"" /></p>
 603:   
 604:  <p id=""hint""><span id=""head"">" + translation.SearchHintName + @"</span>: " + translation.SearchHint + @"</p>
 605:   
 606:  <p id=""search-result""><asp:Label id=""searchResultLabel"" EnableViewState=""false"" runat=""server""/></p>
 607:   
 608:  <ol>
 609:  ";
 610:   
 611:              return s;
 612:          }
 613:   
 614:          ////////////////////////////////////////////////////////////////////////////
 615:   
 616:          /// <summary>
 617:          ///
 618:          /// </summary>
 619:          public static string DefaultAndSearchFileChapterTitle(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, Ia.Islamic.Cl.Model.Chapter chapter)
 620:          {
 621:              string s;
 622:   
 623:              if (language.Id == "ar")
 624:              {
 625:                  s = @"<li><asp:HyperLink NavigateUrl=""~/" + language.Symbol + "/" + chapter.Number + @".aspx"" Text=""" + chapter.Name + @""" runat=""server""/></li>" + "\r\n";
 626:   
 627:                  //if (language.Symbol == "ar" && chapter % 38 == 0) s += @"</td><td style=""vertical-align:top;"">";
 628:                  //else if (language != "ar" && n % 57 == 0) s += @"</td><td style=""vertical-align:top;"">";
 629:              }
 630:              else
 631:              {
 632:                  if (chapter.Name.Length > 0 && chapter.ArabicName.Length > 0) s = @"<li><asp:HyperLink NavigateUrl=""~/" + language.Symbol + "/" + chapter.Number + @".aspx"" Text=""" + chapter.Name + @""" runat=""server""/> (<asp:HyperLink NavigateUrl=""~/" + language.Symbol + "/" + chapter.Number + @".aspx"" Text=""" + chapter.ArabicName + @""" runat=""server""/>)</li>" + "\r\n";
 633:                  else if (chapter.Name.Length > 0) s = @"<li><asp:HyperLink NavigateUrl=""~/" + language.Symbol + "/" + chapter.Number + @".aspx"" Text=""" + chapter.Name + @""" runat=""server""/></li>" + "\r\n";
 634:                  else /*if (arabicName.Length > 0)*/ s = @"<li><asp:HyperLink NavigateUrl=""~/" + language.Symbol + "/" + chapter.Number + @".aspx"" Text=""" + chapter.ArabicName + @""" runat=""server""/></li>" + "\r\n";
 635:              }
 636:   
 637:              return s;
 638:          }
 639:   
 640:          ////////////////////////////////////////////////////////////////////////////
 641:   
 642:          /// <summary>
 643:          ///
 644:          /// </summary>
 645:          public static string DefaultFileFooter(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation)
 646:          {
 647:              string s;
 648:   
 649:              s = @"
 650:  </ol>
 651:  </asp:Content>";
 652:   
 653:              return s;
 654:          }
 655:   
 656:          ////////////////////////////////////////////////////////////////////////////
 657:   
 658:          /// <summary>
 659:          ///
 660:          /// </summary>
 661:          public static string BuildDefaultFile(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
 662:          {
 663:              StringBuilder sb;
 664:              List<Ia.Islamic.Cl.Model.Chapter> chapters;
 665:   
 666:              sb = new StringBuilder(100000);
 667:              sb.Length = 0;
 668:   
 669:              sb.Append(DefaultFileHeader(language, translation, className));
 670:   
 671:              using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
 672:              {
 673:                  chapters = (from q in db.Chapters where q.Koran.LanguageIso == language.Id select q).ToList<Ia.Islamic.Cl.Model.Chapter>();
 674:   
 675:                  foreach (Ia.Islamic.Cl.Model.Chapter chapter in chapters)
 676:                  {
 677:                      sb.Append(DefaultAndSearchFileChapterTitle(language, translation, chapter));
 678:                  }
 679:              }
 680:   
 681:              sb.Append(DefaultFileFooter(language, translation));
 682:   
 683:              return sb.ToString();
 684:          }
 685:   
 686:          ////////////////////////////////////////////////////////////////////////////
 687:   
 688:          /// <summary>
 689:          ///
 690:          /// </summary>
 691:          public static string DefaultFileCs(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
 692:          {
 693:              string s;
 694:   
 695:              s = @"using System;
 696:  using System.Web;
 697:   
 698:  ////////////////////////////////////////////////////////////////////////////
 699:   
 700:  /// <summary>
 701:  ///
 702:  /// </summary>
 703:  public partial class " + className + @" : System.Web.UI.Page
 704:  {
 705:      ////////////////////////////////////////////////////////////////////////////
 706:   
 707:      /// <summary>
 708:      ///
 709:      /// </summary>
 710:      void Page_PreInit(object sender, System.EventArgs e)
 711:      {
 712:          Ia.Islamic.Koran.Wa.Model.Ui.Default.Theme(this, HttpContext.Current.Profile);
 713:      }
 714:   
 715:      ////////////////////////////////////////////////////////////////////////////
 716:   
 717:      /// <summary>
 718:      ///
 719:      /// </summary>
 720:      protected void Page_Load(object sender, EventArgs e)
 721:      {
 722:          if (!IsPostBack)
 723:          {
 724:          }
 725:          else
 726:          {
 727:              Response.Redirect(""search.aspx?tb="" + tb.Text);
 728:          }
 729:      }
 730:   
 731:      ////////////////////////////////////////////////////////////////////////////
 732:      ////////////////////////////////////////////////////////////////////////////
 733:  }
 734:  ";
 735:   
 736:              return s;
 737:          }
 738:   
 739:          ////////////////////////////////////////////////////////////////////////////
 740:   
 741:          /// <summary>
 742:          ///
 743:          /// </summary>
 744:          public static string SearchFile(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
 745:          {
 746:              string s;
 747:   
 748:              s = @"<%@ Page Language=""C#"" AutoEventWireup=""True"" Inherits=""" + className + @""" MasterPageFile=""~/1_" + language.Symbol + @".master"" CodeBehind=""search.aspx.cs"" %>
 749:   
 750:  <asp:Content ContentPlaceHolderID=""contentContentPlaceHolder"" runat=""server"">
 751:   
 752:  <asp:HyperLink NavigateUrl=""~/default.aspx"" Text=""" + translation.MainHome + @""" runat=""server""/> » <asp:HyperLink NavigateUrl=""~/" + language.Symbol + @"/default.aspx"" Text=""" + translation.MainTitle + @""" runat=""server""/> » " + translation.SearchTitle + @"
 753:   
 754:  <p id=""enter-words"">" + translation.SearchInstruction + @"</p>
 755:   
 756:  <p id=""text-box""><asp:TextBox id=""tb"" Maxlength=""32"" Columns=""16"" runat=""server""/>&nbsp;<asp:Button Text="" " + translation.SearchButton + @" "" runat=""server"" /></p>
 757:   
 758:  <p id=""hint""><span id=""head"">" + translation.SearchHintName + @"</span>: " + translation.SearchHint + @"</p>
 759:   
 760:  <p id=""search-result""><asp:Label id=""searchResultLabel"" EnableViewState=""false"" runat=""server""/></p>
 761:   
 762:  <asp:Repeater id=""verseRepeater"" OnItemDataBound=""Repeater_ItemDataBound"" EnableViewState=""false"" Visible=""false"" runat=""server"">
 763:   
 764:  <ItemTemplate>
 765:  <p><asp:HyperLink id=""hyperLink"" runat=""server"" />&nbsp;<asp:Label id=""label"" runat=""server""/></p>
 766:  </ItemTemplate>
 767:   
 768:  <AlternatingItemTemplate>
 769:  <p><asp:HyperLink id=""hyperLink"" runat=""server"" />&nbsp;<asp:Label id=""label"" runat=""server""/></p>
 770:  </AlternatingItemTemplate>
 771:   
 772:  </asp:Repeater>
 773:   
 774:  </asp:Content>
 775:  ";
 776:   
 777:              return s;
 778:          }
 779:   
 780:          ////////////////////////////////////////////////////////////////////////////
 781:   
 782:          /// <summary>
 783:          ///
 784:          /// </summary>
 785:          public static string SearchFileCs(Ia.Cl.Model.Language language, Ia.Islamic.Cl.Model.Translation translation, string className)
 786:          {
 787:              string s;
 788:   
 789:              s = @"using System;
 790:  using System.Web;
 791:  using System.Web.UI.WebControls;
 792:   
 793:  ////////////////////////////////////////////////////////////////////////////
 794:   
 795:  /// <summary>
 796:  ///
 797:  /// </summary>
 798:  public partial class " + className + @" : System.Web.UI.Page
 799:  {
 800:      private string language;
 801:   
 802:      ////////////////////////////////////////////////////////////////////////////
 803:   
 804:      /// <summary>
 805:      ///
 806:      /// </summary>
 807:      void Page_PreInit(object sender, System.EventArgs e)
 808:      {
 809:          Ia.Islamic.Koran.Wa.Model.Ui.Default.Theme(this, HttpContext.Current.Profile);
 810:      }
 811:   
 812:      ////////////////////////////////////////////////////////////////////////////
 813:   
 814:      /// <summary>
 815:      ///
 816:      /// </summary>
 817:      protected void Page_Init(object sender, EventArgs e)
 818:      {
 819:          language = """ + language.Symbol + @""";
 820:      }
 821:   
 822:      ////////////////////////////////////////////////////////////////////////////
 823:   
 824:      /// <summary>
 825:      ///
 826:      /// </summary>
 827:      protected void Page_Load(object sender, EventArgs e)
 828:      {
 829:          if (!IsPostBack)
 830:          {
 831:              if (Request.QueryString[""tb""] != null)
 832:              {
 833:                  tb.Text = Server.HtmlEncode(Request.QueryString[""tb""].ToString());
 834:   
 835:                  Search(sender, e);
 836:              }
 837:              else
 838:              {
 839:                  tb.Text = null;
 840:              }
 841:          }
 842:          else
 843:          {
 844:              Search(sender, e);
 845:          }
 846:      }
 847:   
 848:      ////////////////////////////////////////////////////////////////////////////
 849:   
 850:      /// <summary>
 851:      ///
 852:      /// </summary>
 853:      public void Search(object sender, EventArgs e)
 854:      {
 855:          verseRepeater.Visible = false;
 856:   
 857:          var verseList = Ia.Islamic.Cl.Model.Business.Default.Search(Server.HtmlEncode(tb.Text), language, out Ia.Cl.Model.Result result);
 858:   
 859:          if (result.IsSuccessful)
 860:          {
 861:              verseRepeater.Visible = true;
 862:   
 863:              verseRepeater.DataSource = verseList;
 864:              verseRepeater.DataBind();
 865:   
 866:              if (!result.HasWarning)
 867:              {
 868:                  searchResultLabel.Text = result.MessageWithoutCaption;
 869:                  searchResultLabel.CssClass = ""success"";
 870:              }
 871:              else
 872:              {
 873:                  searchResultLabel.Text = result.MessageWithoutCaption;
 874:                  searchResultLabel.CssClass = ""warning"";
 875:              }
 876:          }
 877:          else
 878:          {
 879:              searchResultLabel.Text = result.MessageWithoutCaption;
 880:              searchResultLabel.CssClass = ""error"";
 881:          }
 882:      }
 883:   
 884:      ////////////////////////////////////////////////////////////////////////////
 885:   
 886:      /// <summary>
 887:      ///
 888:      /// </summary>
 889:      public void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
 890:      {
 891:          ListItemType itemType = e.Item.ItemType;
 892:          Ia.Islamic.Cl.Model.Ui.VerseUi verseUi;
 893:   
 894:          verseUi = (Ia.Islamic.Cl.Model.Ui.VerseUi)e.Item.DataItem;
 895:   
 896:          if (itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem)
 897:          {
 898:              for (int i = 0; i < e.Item.Controls.Count; i++)
 899:              {
 900:                  try
 901:                  {
 902:                      if (e.Item.Controls[i].GetType().ToString() == ""System.Web.UI.WebControls.Label"")
 903:                      {
 904:                          Label label = (Label)e.Item.Controls[i];
 905:   
 906:                          if (label.ID == ""label"") label.Text = verseUi.Content;
 907:                      }
 908:                      else if (e.Item.Controls[i].GetType().ToString() == ""System.Web.UI.WebControls.HyperLink"")
 909:                      {
 910:                          HyperLink hyperLink = (HyperLink)e.Item.Controls[i];
 911:   
 912:                          if (hyperLink.ID == ""hyperLink"")
 913:                          {
 914:                              hyperLink.Text = verseUi.ChapterNumber + "":"" + verseUi.Number;
 915:                              hyperLink.NavigateUrl = verseUi.ChapterNumber + "".aspx#"" + verseUi.Number;
 916:                          }
 917:                      }
 918:                  }
 919:                  catch { }
 920:              }
 921:          }
 922:      }
 923:   
 924:      ////////////////////////////////////////////////////////////////////////////
 925:      ////////////////////////////////////////////////////////////////////////////
 926:  }
 927:  ";
 928:   
 929:              return s;
 930:          }
 931:   
 932:          ////////////////////////////////////////////////////////////////////////////
 933:          ////////////////////////////////////////////////////////////////////////////
 934:      }
 935:   
 936:      ////////////////////////////////////////////////////////////////////////////
 937:      ////////////////////////////////////////////////////////////////////////////
 938:  }