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

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