MainWindow.axaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using Avalonia.Controls;
  6. using Avalonia.Controls.Shapes;
  7. using Avalonia.Interactivity;
  8. using Avalonia.Markup.Xaml.MarkupExtensions;
  9. using static System.Runtime.InteropServices.JavaScript.JSType;
  10. namespace MyCalendarHome
  11. {
  12. public partial class MainWindow : Window
  13. {
  14. public MainWindow()
  15. {
  16. InitializeComponent();
  17. }
  18. static string Zodiak(int d, int m)
  19. {
  20. if ((d >= 21 && m == 3) || (d <= 20 && m == 4)) return "Овен";
  21. if ((d >= 21 && m == 4) || (d <= 20 && m == 5)) return "Телец";
  22. if ((d >= 21 && m == 5) || (d <= 21 && m == 6)) return "Близнецы";
  23. if ((d >= 22 && m == 6) || (d <= 22 && m == 7)) return "рак";
  24. if ((d >= 23 && m == 7) || (d <= 23 && m == 8)) return "лев";
  25. if ((d >= 24 && m == 8) || (d <= 23 && m == 9)) return "дева";
  26. if ((d >= 24 && m == 9) || (d <= 23 && m == 10)) return "весы";
  27. if ((d >= 24 && m == 10) || (d <= 22 && m == 11)) return "скорпион";
  28. if ((d >= 23 && m == 11) || (d <= 21 && m == 12)) return "стрелец";
  29. if ((d >= 22 && m == 12) || (d <= 20 && m == 1)) return "козерог";
  30. if ((d >= 21 && m == 1) || (d <= 18 && m == 2)) return "водолей";
  31. else return "рыбы";
  32. }
  33. static string AnimalYear(int y)
  34. {
  35. int f = y % 10;
  36. string Color;
  37. if ((f == 0) || (f == 1)) Color = "White";
  38. else if((f == 2) || (f == 3)) Color = "Blue";
  39. else if((f == 4) || (f == 5)) Color = "Green";
  40. else if((f == 6) || (f == 7)) Color = "Red";
  41. else Color = "Yellow";
  42. f = y % 12;
  43. string Animal;
  44. if (f == 4) Animal = "Rat";
  45. else if(f == 5) Animal = "Ox";
  46. else if (f == 6) Animal = "Tiger";
  47. else if (f == 7) Animal = "Rabbit";
  48. else if (f == 8) Animal = "Dragon";
  49. else if (f == 9) Animal = "Snake";
  50. else if (f == 10) Animal = "Horse";
  51. else if (f == 11) Animal = "Goat";
  52. else if (f == 0) Animal = "Monkey";
  53. else if (f == 1) Animal = "Rooster";
  54. else if (f == 2) Animal = "Dog";
  55. else Animal = "Pig";
  56. return Color + " " + Animal;
  57. }
  58. public static int DifferenceYear(DateTime one, DateTime two)
  59. {
  60. int total = one.Year - two.Year;
  61. if (two.Month > one.Month || (two.Month == one.Month && two.Day > one.Day))
  62. return total - 1;
  63. return total;
  64. }
  65. public static int DifferenceMonth(DateTime one, DateTime two)
  66. {
  67. int total = (one.Year - two.Year) * 12 + one.Month - two.Month;
  68. if (two.Day > one.Day || (two.Month == one.Month && two.Day > one.Day))
  69. return total - 1;
  70. return total;
  71. }
  72. public static int DifferenceDay(DateTime one, DateTime two)
  73. {
  74. if (two.Month > one.Month)
  75. {
  76. int day = 31 - two.Day + one.Day;
  77. if (day > 31) day = day - 31;
  78. return (day);
  79. }
  80. else if (two.Month == one.Month)
  81. {
  82. return (31 + one.Day - two.Day)%31;
  83. }
  84. else
  85. {
  86. return (31 + one.Day - two.Day) % 31;
  87. }
  88. }
  89. public static int GetCountDayWeek(DateTime one)
  90. {
  91. DayOfWeek dayofweek = one.DayOfWeek;
  92. int total = 0;
  93. while (one.Year < DateTime.Now.Year)
  94. {
  95. if (one.DayOfWeek == dayofweek)
  96. {
  97. total++;
  98. }
  99. DateTime Year = one.AddYears(1);
  100. one = Year;
  101. }
  102. return total;
  103. }
  104. public static string GetLeapYears(DateTime one)
  105. {
  106. string str = "";
  107. while (one.Year < DateTime.Now.Year)
  108. {
  109. if (DateTime.IsLeapYear(one.Year))
  110. {
  111. str = str + one.Year.ToString() + " ";
  112. }
  113. DateTime Year = one.AddYears(1);
  114. one = Year;
  115. }
  116. return str;
  117. }
  118. private void GetAndShowInform(object sender, RoutedEventArgs e)
  119. {
  120. if (Calendar.SelectedDate == null)
  121. {
  122. ErrorMassage.IsVisible = true;
  123. ErrorMassage.Text = "Для продолжения введите дату.";
  124. }
  125. else if (Calendar.SelectedDate.Value > DateTime.Now)
  126. {
  127. ErrorMassage.IsVisible = true;
  128. ErrorMassage.Text = "Дата не может быть больше сегодняшней.";
  129. }
  130. else
  131. {
  132. NameZodiak.IsVisible = false;
  133. EastGoroskop.IsVisible = false;
  134. ErrorMassage.IsVisible = false;
  135. string date = Calendar.SelectedDate.ToString();
  136. DateTime data1 = Convert.ToDateTime(date);
  137. Year.Text = "Года: " + DifferenceYear(DateTime.Now, data1);
  138. Month.Text = "Месяца: " + DifferenceMonth(DateTime.Now, data1) % 12;
  139. Day.Text = "Дни: " + DifferenceDay(DateTime.Now, data1);
  140. DayWeek.Text = "День недели: " + data1.DayOfWeek.ToString();
  141. CountDayWeek.Text = "Отпраздновал в этот же день: " + GetCountDayWeek(data1);
  142. LeapYear.Text = GetLeapYears(data1);
  143. }
  144. }
  145. private void GetNameZodiac(object sender, RoutedEventArgs e)
  146. {
  147. if (Calendar.SelectedDate == null)
  148. {
  149. ErrorMassage.IsVisible = true;
  150. ErrorMassage.Text = "Для продолжения введите дату.";
  151. }
  152. else
  153. {
  154. ErrorMassage.IsVisible = false;
  155. string date = Calendar.SelectedDate.ToString();
  156. DateTime data1 = Convert.ToDateTime(date);
  157. EastGoroskop.IsVisible = false;
  158. NameZodiak.IsVisible = true;
  159. NameZodiak.Text = "Знак зодиака: " + Zodiak(data1.Day, data1.Month);
  160. }
  161. }
  162. private void GetEastGoroskop(object sender, RoutedEventArgs e)
  163. {
  164. if (Calendar.SelectedDate == null)
  165. {
  166. ErrorMassage.IsVisible = true;
  167. ErrorMassage.Text = "Для продолжения введите дату.";
  168. }
  169. else
  170. {
  171. ErrorMassage.IsVisible = false;
  172. string date = Calendar.SelectedDate.ToString();
  173. DateTime data1 = Convert.ToDateTime(date);
  174. NameZodiak.IsVisible = false;
  175. EastGoroskop.IsVisible = true;
  176. EastGoroskop.Text = "Всточный гороскоп: " + AnimalYear(data1.Year);
  177. }
  178. }
  179. static void getData(string path, ref List<MyStructZodiac> MSZ, ref List<MyStructGoroskop> MSG)
  180. {
  181. using (StreamReader sr = new StreamReader(path))
  182. {
  183. while (sr.EndOfStream != true)
  184. {
  185. string[] array = sr.ReadLine().Split(';');
  186. try
  187. {
  188. DateTime data1 = new DateTime(1, Convert.ToInt32(array[1]), Convert.ToInt32(array[0]));
  189. MSZ.Add(new MyStructZodiac()
  190. {
  191. data = data1,
  192. str = ""
  193. });
  194. }
  195. catch (Exception e)
  196. {
  197. DateTime data = new DateTime();
  198. MSZ.Add(new MyStructZodiac()
  199. {
  200. data = data,
  201. str = e.Message
  202. });
  203. }
  204. try
  205. {
  206. DateTime data1 = new DateTime(Convert.ToInt32(array[2]), 1, 1);
  207. MSG.Add(new MyStructGoroskop()
  208. {
  209. data = data1,
  210. str = ""
  211. });
  212. }
  213. catch (Exception e)
  214. {
  215. DateTime data = new DateTime();
  216. MSG.Add(new MyStructGoroskop()
  217. {
  218. data = data,
  219. str = e.Message
  220. });
  221. }
  222. }
  223. }
  224. }
  225. static void inputData(string path, List<string> S)
  226. {
  227. using (StreamWriter sw = new StreamWriter(path, true))
  228. {
  229. foreach (string u in S)
  230. {
  231. sw.WriteLine(u);
  232. }
  233. }
  234. }
  235. struct MyStructZodiac
  236. {
  237. public DateTime data;
  238. public string str;
  239. }
  240. struct MyStructGoroskop
  241. {
  242. public DateTime data;
  243. public string str;
  244. }
  245. private void WorkFile(object sender, RoutedEventArgs e)
  246. {
  247. List<MyStructZodiac> myStructzodiac = new List<MyStructZodiac>();
  248. List<MyStructGoroskop> myStructgoroskop = new List<MyStructGoroskop>();
  249. List<string> idonto = new List<string>();
  250. getData("horoscopeEastern.csv", ref myStructzodiac, ref myStructgoroskop);
  251. for (int i = 0; i < myStructzodiac.Count; i++)
  252. {
  253. if (myStructzodiac[i].data == DateTime.MinValue && myStructgoroskop[i].data == DateTime.MinValue)
  254. {
  255. idonto.Add(i + " Error in zodiak: " + myStructzodiac[i].str + "\n"+ i + " Error in goroskop: " + myStructgoroskop[i].str);
  256. }
  257. else if (myStructzodiac[i].data == DateTime.MinValue && myStructgoroskop[i].data != DateTime.MinValue)
  258. {
  259. idonto.Add(i + " Error in zodiak: " + myStructzodiac[i].str + "\n" + i + " Восточный гороскоп: " + AnimalYear(myStructgoroskop[i].data.Year));
  260. }
  261. else if (myStructzodiac[i].data != DateTime.MinValue && myStructgoroskop[i].data == DateTime.MinValue)
  262. {
  263. idonto.Add(i + " Знак зодиака: " + Zodiak(myStructzodiac[i].data.Day, myStructzodiac[i].data.Month) + "\n" + i + " Error in goroskop: " + myStructgoroskop[i].str);
  264. }
  265. else
  266. {
  267. idonto.Add(i + " Знак зодиака: " + Zodiak(myStructzodiac[i].data.Day, myStructzodiac[i].data.Month) + "\n" + i + " Восточный гороскоп: " + AnimalYear(myStructgoroskop[i].data.Year));
  268. }
  269. }
  270. inputData("Input.txt", idonto);
  271. }
  272. }
  273. }