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