Program.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. using System;
  5. using System.Linq;
  6. using System.IO;
  7. namespace QuranCalc
  8. {
  9. class MainClass
  10. {
  11. public static string[] SurahNames = new string[] { "Al-Fatihah", "Al-Baqarah", "Aal Imran", "An-Nisa'", "Al-Ma'idah", "Al-An'am", "Al-A'raf", "Al-Anfal", "At-Tawbah", "Yunus", "Hud", "Yusuf", "Ar-Ra'd", "Ibraheem", "Al-Hijr", "An-Nahl", "Al-Isra", "Al-Kahf", "Maryam", "Ta-Ha", "Al-Anbiya'", "Al-Hajj", "Al-Mu'minoon", "An-Nur", "Al-Furqan", "Ash-Shu`ara'", "An-Naml", "Al-Qasas", "Al-`Ankabut", "Ar-Rum", "Luqman", "As-Sajdah", "Al-Ahzab", "Saba'", "Fatir", "Ya Sin", "As-Saffat", "Sad", "Az-Zumar", "Ghafir", "Fussilat", "Ash-Shura", "Az-Zukhruf", "Ad-Dukhan", "Al-Jathiyah", "Al-Ahqaf", "Muhammad", "Al-Fath", "Al-Hujurat", "Qaf", "Ad-Dhariyat", "At-Tur", "An-Najm", "Al-Qamar", "Ar-Rahman", "Al-Waqi'ah", "Al-Hadeed", "Al-Mujadilah", "Al-Hashr", "Al-Mumtahanah", "As-Saff", "Al-Jumu'ah", "Al-Munafiqun", "At-Taghabun", "At-Talaq", "At-Tahreem", "Al-Mulk", "Al-Qalam", "Al-Haqqah", "Al-Ma'aarij", "Nuh", "Al-Jinn", "Al-Muzzammil", "Al-Muddathir", "Al-Qiyamah", "Al-Insan", "Al-Mursalat", "An-Naba'", "An-Nazi'at", "`Abasa", "At-Takweer", "Al-Infitar", "Al-Mutaffifeen", "Al-Inshiqaq", "Al-Burooj", "At-Tariq", "Al-A'la", "Al-Ghashiyah", "Al-Fajr", "Al-Balad", "Ash-Shams", "Al-Lail", "Ad-Duha", "Al-Inshirah", "At-Teen", "Al-`Alaq", "Al-Qadr", "Al-Bayyinah", "Az-Zalzala", "Al-Adiyat", "Al-Qari`ah", "At-Takathur", "Al-Asr", "Al-Humazah", "Al-Feel", "Al-Quraish", "Al-Maa'oun", "Al-Kawthar", "Al-Kafiroun", "An-Nasr", "Al-Masad", "Al-Ikhlas", "Al-Falaq", "Al-Nas" };
  12. public static int Main (string[] args)
  13. {
  14. try
  15. {
  16. if(AyahIncrementer.Finished)
  17. AyahIncrementer.Finished = false;
  18. else
  19. {
  20. Console.Error.WriteLine("QuranCalc");
  21. Console.Error.WriteLine("Copyright (c) 2016 Muhammad Moaz Imtiaz");
  22. Console.Error.WriteLine(".......................................");
  23. }
  24. Console.Write("In how many days would you like to finish the Qur'an? ");
  25. double days = double.Parse(Console.ReadLine());
  26. Console.Write("Sittings per day: ");
  27. double sittings_per_day = double.Parse(Console.ReadLine());
  28. AyahIncrementer ai = new AyahIncrementer();
  29. Console.Write("Custom starting point (y/N)? ");
  30. int startingPoint = 0;
  31. if(Console.ReadLine().ToLower() == "y")
  32. {
  33. Console.Write("Surah number: ");
  34. int sn = int.Parse(Console.ReadLine());
  35. for(int i = 1;i < sn;i++)
  36. ai.Increment(AyahIncrementer.AyahCounts[i-1]);
  37. Console.Write("Ayah number: ");
  38. if((startingPoint += int.Parse(Console.ReadLine())) > AyahIncrementer.AyahCounts[sn - 1])
  39. throw new IndexOutOfRangeException();
  40. ai.Increment(startingPoint);
  41. ai.Increment(-1);
  42. }
  43. // We do not have support for numbers of pages or ruku' at this time, so we will just calculate based on ayaat.
  44. int ayaat_per_sitting = (int)Math.Ceiling((6236-startingPoint)/(days*sittings_per_day)); // 6236 is the number of ayaat in the Qur'an.
  45. string output = string.Empty;
  46. for(int i = 1; i <= days; i++)
  47. {
  48. if(AyahIncrementer.Finished)
  49. break;
  50. for(int j = 1;j <= sittings_per_day;j++)
  51. {
  52. if(sittings_per_day != 1)
  53. {
  54. output += "Day " + i + ",Sitting " + j + "," + ai.NextAyah + " to ";
  55. Console.Write("Day " + i + ", Sitting " + j + ":\t" + ai.NextAyah + " to ");
  56. }
  57. else
  58. {
  59. output += "Day " + i + "," + ai.NextAyah + " to ";
  60. Console.Write("Day " + i + ":\t" + ai.NextAyah + " to ");
  61. }
  62. ai.Increment(ayaat_per_sitting);
  63. output += ai.LastAyah;
  64. Console.Write(ai.LastAyah);
  65. if(j == sittings_per_day && sittings_per_day != 1)
  66. {
  67. output += " *";
  68. Console.Write(" *");
  69. }
  70. output += Environment.NewLine;
  71. Console.WriteLine();
  72. }
  73. }
  74. output += "Ayaat per sitting: " + ayaat_per_sitting + Environment.NewLine;
  75. output += "Ayaat per day: " + ayaat_per_sitting*sittings_per_day + Environment.NewLine;
  76. Console.Write("Ayaat per sitting: " + ayaat_per_sitting + Environment.NewLine);
  77. Console.Write("Ayaat per day: " + ayaat_per_sitting*sittings_per_day + Environment.NewLine);
  78. Console.Write("Output to CSV? (y/N)? ");
  79. if(Console.ReadLine().ToLower() == "y") {
  80. string name = string.Empty;
  81. using(Stream stream = File.OpenWrite(name = DateTime.Now.ToString("s").Replace("-", "").Replace(":", "").Replace('T', '_') + ".csv"))
  82. using(StreamWriter sw = new StreamWriter(stream)) {
  83. sw.Write(output.TrimEnd(Environment.NewLine.ToArray()));
  84. }
  85. Console.WriteLine("Done! File written to " + name + ".");
  86. }
  87. Console.Write("Calculate again (y/N)? ");
  88. if(Console.ReadLine().ToLower() == "y")
  89. Main(args);
  90. return 0;
  91. }
  92. catch(Exception e) {
  93. Console.Error.WriteLine ("Traceback (most recent call last):");
  94. Console.Error.Write (Traceback.Read ());
  95. Console.Error.WriteLine ("At int Main(string[]) (class MainClass):");
  96. Console.Error.WriteLine ("Error: " + e.GetType ().ToString () + " occurred.");
  97. Console.Error.WriteLine ("Description: " + e.Message);
  98. return -1;
  99. }
  100. }
  101. }
  102. }