MainWindow.axaml.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Primitives;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Media.Imaging;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net.NetworkInformation;
  11. using System.Runtime.Intrinsics.Arm;
  12. using System.Text;
  13. using Tmds.DBus.Protocol;
  14. using static System.Runtime.InteropServices.JavaScript.JSType;
  15. namespace AvaloniaApplication2
  16. {
  17. public partial class MainWindow : Window
  18. {
  19. public MainWindow()
  20. {
  21. InitializeComponent();
  22. }
  23. public void Button_Click1(object sender, RoutedEventArgs e)
  24. {
  25. if (dateT.SelectedDate == null)
  26. {
  27. message10.Text = "Âûáåðèòå äàòó!";
  28. return;
  29. }
  30. string date1 = dateT.SelectedDate.ToString();
  31. DateTime birthdate = DateTime.Parse(date1);
  32. DateTime today = DateTime.Today;
  33. if (birthdate > today)
  34. {
  35. message10.Text = "Äàòà åùå íå íàñòóïèëà!";
  36. return;
  37. }
  38. int age_y = today.Year - birthdate.Year;
  39. int age_m = today.Month - birthdate.Month;
  40. int age_d = today.Day - birthdate.Day;
  41. if (age_d < 0)
  42. {
  43. age_m--;
  44. age_d += DateTime.DaysInMonth(today.Year, today.Month);
  45. }
  46. if (age_m < 0)
  47. {
  48. age_y--;
  49. age_m += 12;
  50. }
  51. message1.Text = $"Ëåò - {age_y}. ";
  52. message2.Text = $"Ìåñÿöåâ - {age_m}";
  53. message3.Text = $"Äíåé - { age_d}.";
  54. message4.Text = "Äåíü íåäåëè: " + birthdate.DayOfWeek;
  55. int count = 0;
  56. for (DateTime date = birthdate; date <= today; date = date.AddYears(1))
  57. {
  58. if (date.DayOfWeek == birthdate.DayOfWeek)
  59. {
  60. count++;
  61. }
  62. }
  63. message5.Text = "Òàêèõ äíåé: " + (age_m < today.Month ? count - 1 : count) + ".";
  64. int startYear = birthdate.Year;
  65. int endYear = today.Year;
  66. string vsk = "Âèñîêîñíûå ãîäû: " + string.Join(" ", Enumerable.Range(startYear, endYear - startYear + 1).Where(VSK));
  67. message7.Text = vsk;
  68. }
  69. static bool VSK(int year) => (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  70. public void Radio1(object sender, RoutedEventArgs e)
  71. {
  72. string date1 = dateT.SelectedDate.ToString();
  73. DateTime birthdate = DateTime.Parse(date1);
  74. DateTime today = DateTime.Today;
  75. int age_yy = birthdate.Year;
  76. int age_mm = birthdate.Month;
  77. int age_dd = birthdate.Day;
  78. string path13 = "zodiak.png";
  79. if (age_dd >= 21 && age_mm == 3 || age_dd <= 20 && age_mm == 4)
  80. {
  81. message6.Text = "Âàø çíàê çîäèàêà - Îâåí.";
  82. pic.Source = new Bitmap(path13);
  83. }
  84. else if (age_dd >= 21 && age_mm == 4 || age_dd <= 21 && age_mm == 5)
  85. {
  86. message6.Text = "Âàø çíàê çîäèàêà - Òåëåö.";
  87. pic.Source = new Bitmap(path13);
  88. }
  89. else if (age_dd >= 22 && age_mm == 5 || age_dd <= 21 && age_mm == 6)
  90. {
  91. message6.Text = "Âàø çíàê çîäèàêà - Áëèçíåöû.";
  92. pic.Source = new Bitmap(path13);
  93. }
  94. else if (age_dd >= 22 && age_mm == 6 || age_dd <= 23 && age_mm == 7)
  95. {
  96. message6.Text = "Âàø çíàê çîäèàêà - Ðàê.";
  97. pic.Source = new Bitmap(path13);
  98. }
  99. else if (age_dd >= 24 && age_mm == 7 || age_dd <= 23 && age_mm == 8)
  100. {
  101. message6.Text = "Âàø çíàê çîäèàêà - Ëåâ.";
  102. pic.Source = new Bitmap(path13);
  103. }
  104. else if (age_dd >= 24 && age_mm == 8 || age_dd <= 23 && age_mm == 9)
  105. {
  106. message6.Text = "Âàø çíàê çîäèàêà - Äåâà.";
  107. pic.Source = new Bitmap(path13);
  108. }
  109. else if (age_dd >= 24 && age_mm == 9 || age_dd <= 23 && age_mm == 10)
  110. {
  111. message6.Text = "Âàø çíàê çîäèàêà - Âåñû.";
  112. pic.Source = new Bitmap(path13);
  113. }
  114. else if (age_dd >= 24 && age_mm == 10 || age_dd <= 22 && age_mm == 11)
  115. {
  116. message6.Text = "Âàø çíàê çîäèàêà - Ñêîðïèîí.";
  117. pic.Source = new Bitmap(path13);
  118. }
  119. else if (age_dd >= 23 && age_mm == 11 || age_dd <= 21 && age_mm == 12)
  120. {
  121. message6.Text = "Âàø çíàê çîäèàêà - Ñòðåëåö.";
  122. pic.Source = new Bitmap(path13);
  123. }
  124. else if (age_dd >= 22 && age_mm == 12 || age_dd <= 20 && age_mm == 1)
  125. {
  126. message6.Text = "Âàø çíàê çîäèàêà - Êîçåðîã.";
  127. pic.Source = new Bitmap(path13);
  128. }
  129. else if (age_dd >= 21 && age_mm == 1 || age_dd <= 19 && age_mm == 2)
  130. {
  131. message6.Text = "Âàø çíàê çîäèàêà - Âîäîëåé.";
  132. pic.Source = new Bitmap(path13);
  133. }
  134. else
  135. {
  136. message6.Text = "Âàø çíàê çîäèàêà - Ðûáû.";
  137. pic.Source = new Bitmap(path13);
  138. }
  139. }
  140. public void Radio2(object sender, RoutedEventArgs e)
  141. {
  142. string path1 = "pig.webp";
  143. string path2 = "dog.jpg";
  144. string path3 = "drakon.webp";
  145. string path4 = "koza.webp";
  146. string path5 = "loshadka.webp";
  147. string path6 = "petux.webp";
  148. string path7 = "monkey.jpg";
  149. string path8 = "rabbit.jpg";
  150. string path9 = "mouse.jpg";
  151. string path10 = "zmeya.jpg";
  152. string path11 = "tiger.jpg";
  153. string path12 = "buk.png";
  154. string date1 = dateT.SelectedDate.ToString();
  155. DateTime birthdate = DateTime.Parse(date1);
  156. DateTime today = DateTime.Today;
  157. int age_yy = birthdate.Year;
  158. if (age_yy == 1899 || age_yy == 1911 || age_yy == 1923 || age_yy == 1935 || age_yy == 1947 || age_yy == 1959 || age_yy == 1971 || age_yy == 1983 || age_yy == 1995 || age_yy == 2007 || age_yy == 2019 || age_yy == 2031)
  159. {
  160. message6.Text = "Âû ðîäèëèñü â ãîä Ñâèíüè.";
  161. pic.Source = new Bitmap(path1);
  162. }
  163. if (age_yy == 1900 || age_yy == 1912 || age_yy == 1924 || age_yy == 1936 || age_yy == 1948 || age_yy == 1960 || age_yy == 1972 || age_yy == 1984 || age_yy == 1996 || age_yy == 2008 || age_yy == 2020 || age_yy == 2032)
  164. {
  165. message6.Text = "Âû ðîäèëèñü â ãîä Êðûñû.";
  166. pic.Source = new Bitmap(path9);
  167. }
  168. if (age_yy == 1901 || age_yy == 1913 || age_yy == 1925 || age_yy == 1937 || age_yy == 1949 || age_yy == 1961 || age_yy == 1973 || age_yy == 1985 || age_yy == 1997 || age_yy == 2009 || age_yy == 2021 || age_yy == 2033)
  169. {
  170. message6.Text = "Âû ðîäèëèñü â ãîä Áûêà.";
  171. pic.Source = new Bitmap(path12);
  172. }
  173. if (age_yy == 1902 || age_yy == 1914 || age_yy == 1926 || age_yy == 1938 || age_yy == 1950 || age_yy == 1962 || age_yy == 1974 || age_yy == 1986 || age_yy == 1998 || age_yy == 2010 || age_yy == 2022 || age_yy == 2034)
  174. {
  175. message6.Text = "Âû ðîäèëèñü â ãîä Òèãðà.";
  176. pic.Source = new Bitmap(path11);
  177. }
  178. if (age_yy == 1903 || age_yy == 1915 || age_yy == 1927 || age_yy == 1939 || age_yy == 1951 || age_yy == 1963 || age_yy == 1975 || age_yy == 1987 || age_yy == 1999 || age_yy == 2011 || age_yy == 2023 || age_yy == 2035)
  179. {
  180. message6.Text = "Âû ðîäèëèñü â ãîä Êðîëèêà.";
  181. pic.Source = new Bitmap(path8);
  182. }
  183. if (age_yy == 1904 || age_yy == 1916 || age_yy == 1928 || age_yy == 1940 || age_yy == 1952 || age_yy == 1964 || age_yy == 1976 || age_yy == 1988 || age_yy == 2000 || age_yy == 2012 || age_yy == 2024 || age_yy == 2036)
  184. {
  185. message6.Text = "Âû ðîäèëèñü â ãîä Äðàêîíà.";
  186. pic.Source = new Bitmap(path3);
  187. }
  188. if (age_yy == 1905 || age_yy == 1917 || age_yy == 1929 || age_yy == 1941 || age_yy == 1953 || age_yy == 1965 || age_yy == 1977 || age_yy == 1989 || age_yy == 2001 || age_yy == 2013 || age_yy == 2025 || age_yy == 2037)
  189. {
  190. message6.Text = "Âû ðîäèëèñü â ãîä Çìåè.";
  191. pic.Source = new Bitmap(path10);
  192. }
  193. if (age_yy == 1906 || age_yy == 1918 || age_yy == 1930 || age_yy == 1942 || age_yy == 1954 || age_yy == 1966 || age_yy == 1978 || age_yy == 1990 || age_yy == 2002 || age_yy == 2014 || age_yy == 2026 || age_yy == 2038)
  194. {
  195. message6.Text = "Âû ðîäèëèñü â ãîä Ëîøàäè.";
  196. pic.Source = new Bitmap(path5);
  197. }
  198. if (age_yy == 1907 || age_yy == 1919 || age_yy == 1931 || age_yy == 1943 || age_yy == 1955 || age_yy == 1967 || age_yy == 1979 || age_yy == 1991 || age_yy == 2003 || age_yy == 2015 || age_yy == 2027 || age_yy == 2039)
  199. {
  200. message6.Text = "Âû ðîäèëèñü â ãîä Êîçû.";
  201. pic.Source = new Bitmap(path4);
  202. }
  203. if (age_yy == 1908 || age_yy == 1920 || age_yy == 1932 || age_yy == 1944 || age_yy == 1956 || age_yy == 1968 || age_yy == 1980 || age_yy == 1992 || age_yy == 2004 || age_yy == 2016 || age_yy == 2028 || age_yy == 2040)
  204. {
  205. message6.Text = "Âû ðîäèëèñü â ãîä Îáåçüÿíû.";
  206. pic.Source = new Bitmap(path7);
  207. }
  208. if (age_yy == 1909 || age_yy == 1921 || age_yy == 1933 || age_yy == 1945 || age_yy == 1957 || age_yy == 1969 || age_yy == 1981 || age_yy == 1993 || age_yy == 2005 || age_yy == 2017 || age_yy == 2029 || age_yy == 2041)
  209. {
  210. message6.Text = "Âû ðîäèëèñü â ãîä Ïåòóõà.";
  211. pic.Source = new Bitmap(path6);
  212. }
  213. if (age_yy == 1910 || age_yy == 1922 || age_yy == 1934 || age_yy == 1946 || age_yy == 1958 || age_yy == 1970 || age_yy == 1982 || age_yy == 1994 || age_yy == 2006 || age_yy == 2018 || age_yy == 2030 || age_yy == 2042)
  214. {
  215. message6.Text = "Âû ðîäèëèñü â ãîä Ñîáàêè.";
  216. pic.Source = new Bitmap(path2);
  217. }
  218. }
  219. public void Button_Click2(object sender, RoutedEventArgs e)
  220. {
  221. string inputPath = "data.csv";
  222. string outputPath = "data2.csv";
  223. var lines = new List<string>();
  224. try
  225. {
  226. using (StreamReader reader = new StreamReader(inputPath, Encoding.UTF8))
  227. {
  228. string line;
  229. while ((line = reader.ReadLine()) != null)
  230. {
  231. lines.Add(line);
  232. }
  233. }
  234. }
  235. catch (Exception ex)
  236. {
  237. message10.Text = $"Îøèáêà ïðè ÷òåíèè ôàéëà: {ex.Message}";
  238. return;
  239. }
  240. var outputLines = new List<string>();
  241. if (lines.Count > 0)
  242. {
  243. var headers = lines[0] + " Çíàê çîäèàêà Âîñòî÷íûé ãîðîñêîï Îøèáêè ";
  244. outputLines.Add(headers);
  245. }
  246. for (int i = 1; i < lines.Count; i++)
  247. {
  248. var line = lines[i];
  249. var columns = line.Split(';');
  250. if (columns.Length < 3) continue;
  251. var day = columns[0].Trim();
  252. var month = columns[1].Trim();
  253. var year = columns[2].Trim();
  254. string zodiacSign = "Íåîïðåäåëåíî";
  255. string chineseZodiac = "Íåîïðåäåëåíî";
  256. string error = "";
  257. if (ParseDate(day, month, year, out DateTime birthdate, out error))
  258. {
  259. zodiacSign = Zodiac(birthdate);
  260. chineseZodiac = Goroscop(birthdate.Year);
  261. }
  262. else
  263. {
  264. error = "Îøèáêà: " + error;
  265. }
  266. outputLines.Add($"{day};{month};{year};{zodiacSign};{chineseZodiac};{error}");
  267. }
  268. try
  269. {
  270. using (StreamWriter writer = new StreamWriter(outputPath, false, Encoding.UTF8))
  271. {
  272. foreach (var outputLine in outputLines)
  273. {
  274. writer.WriteLine(outputLine);
  275. }
  276. }
  277. message10.Text = "Îáðàáîòêà çàâåðøåíà. Ðåçóëüòàòû çàïèñàíû â òåêñòîâûé ôàéë.";
  278. }
  279. catch (Exception ex)
  280. {
  281. message10.Text = $"Îøèáêà: {ex.Message}";
  282. }
  283. }
  284. public bool ParseDate(string day, string month, string year, out DateTime birthdate, out string error)
  285. {
  286. birthdate = default;
  287. error = "";
  288. int dayNum = 0, monthNum = 0, yearNum = 0;
  289. if (ConvertToInt(day, out dayNum) && dayNum >= 1 && dayNum <= 31)
  290. {
  291. }
  292. else if (ConvertToDecimal(day, out decimal decimalDay))
  293. {
  294. dayNum = (int)(decimalDay > 0.5m ? Math.Ceiling(decimalDay) : Math.Floor(decimalDay));
  295. if (dayNum < 1 || dayNum > 31) error += "Íåêîððåêòíûé äåíü; ";
  296. }
  297. else
  298. {
  299. error += "Íåêîððåêòíûé äåíü; ";
  300. }
  301. if (ConvertMonth(month, out monthNum) || (ConvertToInt(month, out monthNum) && monthNum >= 1 && monthNum <= 12))
  302. {
  303. }
  304. else
  305. {
  306. error += "Íåêîððåêòíûé ìåñÿö; ";
  307. }
  308. if (ConvertToInt(year, out yearNum) && yearNum >= 1900 && yearNum <= DateTime.Now.Year)
  309. {
  310. }
  311. else
  312. {
  313. error += "Íåêîððåêòíûé ãîä; ";
  314. }
  315. if (yearNum > 0)
  316. {
  317. int validDay = dayNum > 0 ? dayNum : 1;
  318. int validMonth = monthNum > 0 ? monthNum : 1;
  319. try
  320. {
  321. birthdate = new DateTime(yearNum, validMonth, validDay);
  322. return true;
  323. }
  324. catch
  325. {
  326. error += "Îøèáêà ñîçäàíèÿ äàòû; ";
  327. }
  328. }
  329. return false;
  330. }
  331. private bool ConvertToDecimal(string input, out decimal result)
  332. {
  333. return decimal.TryParse(input, out result);
  334. }
  335. private bool ConvertMonth(string month, out int monthNum)
  336. {
  337. monthNum = 0;
  338. month = month.Trim().ToLower();
  339. var months = new Dictionary<string, int>
  340. {
  341. { "ÿíâàðü", 1 },
  342. { "ôåâðàëü", 2 },
  343. { "ìàðò", 3 },
  344. { "àïðåëü", 4 },
  345. { "ìàé", 5 },
  346. { "èþíü", 6 },
  347. { "èþëü", 7 },
  348. { "àâãóñò", 8 },
  349. { "ñåíòÿáðü", 9 },
  350. { "îêòÿáðü", 10 },
  351. { "íîÿáðü", 11 },
  352. { "äåêàáðü", 12 }
  353. };
  354. return months.TryGetValue(month, out monthNum);
  355. }
  356. private bool ConvertToInt(string value, out int result)
  357. {
  358. result = 0;
  359. value = value.Trim();
  360. if (int.TryParse(value, out result))
  361. {
  362. return true;
  363. }
  364. var wordsToNumbers = new Dictionary<string, int>
  365. {
  366. { "ïåðâîå", 1 },
  367. { "âòîðîå", 2 },
  368. { "òðåòüå", 3 },
  369. { "÷åòâåðòîå", 4 },
  370. { "ïÿòîå", 5 },
  371. { "øåñòîå", 6 },
  372. { "ñåäüìîå", 7 },
  373. { "âîñüìîå", 8 },
  374. { "äåâÿòîå", 9 },
  375. { "äåñÿòîå", 10 },
  376. { "îäèííàäöàòîå", 11 },
  377. { "äâåíàäöàòîå", 12 }
  378. };
  379. if (wordsToNumbers.TryGetValue(value.ToLower(), out result))
  380. {
  381. return true;
  382. }
  383. if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out double doubleValue))
  384. {
  385. result = (int)Math.Round(doubleValue);
  386. return true;
  387. }
  388. return false;
  389. }
  390. public string Zodiac(DateTime birthdate)
  391. {
  392. int day = birthdate.Day;
  393. int month = birthdate.Month;
  394. if (month == 3 && day >= 21 || month == 4 && day <= 20) return "Îâåí";
  395. if (month == 4 && day >= 21 || month == 5 && day <= 21) return "Òåëåö";
  396. if (month == 5 && day >= 22 || month == 6 && day <= 21) return "Áëèçíåöû";
  397. if (month == 6 && day >= 22 || month == 7 && day <= 23) return "Ðàê";
  398. if (month == 7 && day >= 24 || month == 8 && day <= 23) return "Ëåâ";
  399. if (month == 8 && day >= 24 || month == 9 && day <= 23) return "Äåâà";
  400. if (month == 9 && day >= 24 || month == 10 && day <= 23) return "Âåñû";
  401. if (month == 10 && day >= 24 || month == 11 && day <= 22) return "Ñêîðïèîí";
  402. if (month == 11 && day >= 23 || month == 12 && day <= 21) return "Ñòðåëåö";
  403. if (month == 12 && day >= 22 || month == 1 && day <= 20) return "Êîçåðîã";
  404. if (month == 1 && day >= 21 || month == 2 && day <= 19) return "Âîäîëåé";
  405. if (month == 2 && day >= 20 || month == 3 && day <= 20) return "Ðûáû";
  406. return "Íåèçâåñòíî";
  407. }
  408. public string Goroscop(int year)
  409. {
  410. string[] animals = { "Êðûñà", "Áûê", "Òèãð", "Êðîëèê", "Äðàêîí", "Çìåÿ", "Ëîøàäü", "Êîçà", "Îáåçüÿíà", "Ïåòóõ", "Ñîáàêà", "Ñâèíüÿ" };
  411. return animals[year % 12];
  412. }
  413. }
  414. }