123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- using Avalonia.Controls;
- using Avalonia.Controls.Primitives;
- using Avalonia.Interactivity;
- using Avalonia.Media.Imaging;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Runtime.Intrinsics.Arm;
- using System.Text;
- using Tmds.DBus.Protocol;
- using static System.Runtime.InteropServices.JavaScript.JSType;
- namespace AvaloniaApplication2
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- public void Button_Click1(object sender, RoutedEventArgs e)
- {
- if (dateT.SelectedDate == null)
- {
- message10.Text = "Âûáåðèòå äàòó!";
- return;
- }
- string date1 = dateT.SelectedDate.ToString();
- DateTime birthdate = DateTime.Parse(date1);
- DateTime today = DateTime.Today;
- if (birthdate > today)
- {
- message10.Text = "Äàòà åùå íå íàñòóïèëà!";
- return;
- }
- int age_y = today.Year - birthdate.Year;
- int age_m = today.Month - birthdate.Month;
- int age_d = today.Day - birthdate.Day;
- if (age_d < 0)
- {
- age_m--;
- age_d += DateTime.DaysInMonth(today.Year, today.Month);
- }
- if (age_m < 0)
- {
- age_y--;
- age_m += 12;
- }
- message1.Text = $"Ëåò - {age_y}. ";
- message2.Text = $"Ìåñÿöåâ - {age_m}";
- message3.Text = $"Äíåé - { age_d}.";
- message4.Text = "Äåíü íåäåëè: " + birthdate.DayOfWeek;
- int count = 0;
- for (DateTime date = birthdate; date <= today; date = date.AddYears(1))
- {
- if (date.DayOfWeek == birthdate.DayOfWeek)
- {
- count++;
- }
- }
- message5.Text = "Òàêèõ äíåé: " + (age_m < today.Month ? count - 1 : count) + ".";
- int startYear = birthdate.Year;
- int endYear = today.Year;
- string vsk = "Âèñîêîñíûå ãîäû: " + string.Join(" ", Enumerable.Range(startYear, endYear - startYear + 1).Where(VSK));
- message7.Text = vsk;
- }
- static bool VSK(int year) => (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
- public void Radio1(object sender, RoutedEventArgs e)
- {
- string date1 = dateT.SelectedDate.ToString();
- DateTime birthdate = DateTime.Parse(date1);
- DateTime today = DateTime.Today;
- int age_yy = birthdate.Year;
- int age_mm = birthdate.Month;
- int age_dd = birthdate.Day;
- string path13 = "zodiak.png";
- if (age_dd >= 21 && age_mm == 3 || age_dd <= 20 && age_mm == 4)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Îâåí.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 21 && age_mm == 4 || age_dd <= 21 && age_mm == 5)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Òåëåö.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 22 && age_mm == 5 || age_dd <= 21 && age_mm == 6)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Áëèçíåöû.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 22 && age_mm == 6 || age_dd <= 23 && age_mm == 7)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Ðàê.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 24 && age_mm == 7 || age_dd <= 23 && age_mm == 8)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Ëåâ.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 24 && age_mm == 8 || age_dd <= 23 && age_mm == 9)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Äåâà.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 24 && age_mm == 9 || age_dd <= 23 && age_mm == 10)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Âåñû.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 24 && age_mm == 10 || age_dd <= 22 && age_mm == 11)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Ñêîðïèîí.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 23 && age_mm == 11 || age_dd <= 21 && age_mm == 12)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Ñòðåëåö.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 22 && age_mm == 12 || age_dd <= 20 && age_mm == 1)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Êîçåðîã.";
- pic.Source = new Bitmap(path13);
- }
- else if (age_dd >= 21 && age_mm == 1 || age_dd <= 19 && age_mm == 2)
- {
- message6.Text = "Âàø çíàê çîäèàêà - Âîäîëåé.";
- pic.Source = new Bitmap(path13);
- }
- else
- {
- message6.Text = "Âàø çíàê çîäèàêà - Ðûáû.";
- pic.Source = new Bitmap(path13);
- }
- }
- public void Radio2(object sender, RoutedEventArgs e)
- {
- string path1 = "pig.webp";
- string path2 = "dog.jpg";
- string path3 = "drakon.webp";
- string path4 = "koza.webp";
- string path5 = "loshadka.webp";
- string path6 = "petux.webp";
- string path7 = "monkey.jpg";
- string path8 = "rabbit.jpg";
- string path9 = "mouse.jpg";
- string path10 = "zmeya.jpg";
- string path11 = "tiger.jpg";
- string path12 = "buk.png";
- string date1 = dateT.SelectedDate.ToString();
- DateTime birthdate = DateTime.Parse(date1);
- DateTime today = DateTime.Today;
- int age_yy = birthdate.Year;
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Ñâèíüè.";
- pic.Source = new Bitmap(path1);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Êðûñû.";
- pic.Source = new Bitmap(path9);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Áûêà.";
- pic.Source = new Bitmap(path12);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Òèãðà.";
- pic.Source = new Bitmap(path11);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Êðîëèêà.";
- pic.Source = new Bitmap(path8);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Äðàêîíà.";
- pic.Source = new Bitmap(path3);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Çìåè.";
- pic.Source = new Bitmap(path10);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Ëîøàäè.";
- pic.Source = new Bitmap(path5);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Êîçû.";
- pic.Source = new Bitmap(path4);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Îáåçüÿíû.";
- pic.Source = new Bitmap(path7);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Ïåòóõà.";
- pic.Source = new Bitmap(path6);
- }
- 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)
- {
- message6.Text = "Âû ðîäèëèñü â ãîä Ñîáàêè.";
- pic.Source = new Bitmap(path2);
- }
- }
- public void Button_Click2(object sender, RoutedEventArgs e)
- {
- string inputPath = "data.csv";
- string outputPath = "data2.csv";
- var lines = new List<string>();
- try
- {
- using (StreamReader reader = new StreamReader(inputPath, Encoding.UTF8))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- lines.Add(line);
- }
- }
- }
- catch (Exception ex)
- {
- message10.Text = $"Îøèáêà ïðè ÷òåíèè ôàéëà: {ex.Message}";
- return;
- }
- var outputLines = new List<string>();
- if (lines.Count > 0)
- {
- var headers = lines[0] + " Çíàê çîäèàêà Âîñòî÷íûé ãîðîñêîï Îøèáêè ";
- outputLines.Add(headers);
- }
- for (int i = 1; i < lines.Count; i++)
- {
- var line = lines[i];
- var columns = line.Split(';');
- if (columns.Length < 3) continue;
- var day = columns[0].Trim();
- var month = columns[1].Trim();
- var year = columns[2].Trim();
- string zodiacSign = "Íåîïðåäåëåíî";
- string chineseZodiac = "Íåîïðåäåëåíî";
- string error = "";
- if (ParseDate(day, month, year, out DateTime birthdate, out error))
- {
- zodiacSign = Zodiac(birthdate);
- chineseZodiac = Goroscop(birthdate.Year);
- }
- else
- {
- error = "Îøèáêà: " + error;
- }
- outputLines.Add($"{day};{month};{year};{zodiacSign};{chineseZodiac};{error}");
- }
- try
- {
- using (StreamWriter writer = new StreamWriter(outputPath, false, Encoding.UTF8))
- {
- foreach (var outputLine in outputLines)
- {
- writer.WriteLine(outputLine);
- }
- }
- message10.Text = "Îáðàáîòêà çàâåðøåíà. Ðåçóëüòàòû çàïèñàíû â òåêñòîâûé ôàéë.";
- }
- catch (Exception ex)
- {
- message10.Text = $"Îøèáêà: {ex.Message}";
- }
- }
- public bool ParseDate(string day, string month, string year, out DateTime birthdate, out string error)
- {
- birthdate = default;
- error = "";
- int dayNum = 0, monthNum = 0, yearNum = 0;
- if (ConvertToInt(day, out dayNum) && dayNum >= 1 && dayNum <= 31)
- {
-
- }
- else if (ConvertToDecimal(day, out decimal decimalDay))
- {
- dayNum = (int)(decimalDay > 0.5m ? Math.Ceiling(decimalDay) : Math.Floor(decimalDay));
- if (dayNum < 1 || dayNum > 31) error += "Íåêîððåêòíûé äåíü; ";
- }
- else
- {
- error += "Íåêîððåêòíûé äåíü; ";
- }
- if (ConvertMonth(month, out monthNum) || (ConvertToInt(month, out monthNum) && monthNum >= 1 && monthNum <= 12))
- {
-
- }
- else
- {
- error += "Íåêîððåêòíûé ìåñÿö; ";
- }
-
- if (ConvertToInt(year, out yearNum) && yearNum >= 1900 && yearNum <= DateTime.Now.Year)
- {
-
- }
- else
- {
- error += "Íåêîððåêòíûé ãîä; ";
- }
- if (yearNum > 0)
- {
- int validDay = dayNum > 0 ? dayNum : 1;
- int validMonth = monthNum > 0 ? monthNum : 1;
- try
- {
- birthdate = new DateTime(yearNum, validMonth, validDay);
- return true;
- }
- catch
- {
- error += "Îøèáêà ñîçäàíèÿ äàòû; ";
- }
- }
- return false;
- }
- private bool ConvertToDecimal(string input, out decimal result)
- {
- return decimal.TryParse(input, out result);
- }
- private bool ConvertMonth(string month, out int monthNum)
- {
- monthNum = 0;
- month = month.Trim().ToLower();
- var months = new Dictionary<string, int>
- {
- { "ÿíâàðü", 1 },
- { "ôåâðàëü", 2 },
- { "ìàðò", 3 },
- { "àïðåëü", 4 },
- { "ìàé", 5 },
- { "èþíü", 6 },
- { "èþëü", 7 },
- { "àâãóñò", 8 },
- { "ñåíòÿáðü", 9 },
- { "îêòÿáðü", 10 },
- { "íîÿáðü", 11 },
- { "äåêàáðü", 12 }
- };
- return months.TryGetValue(month, out monthNum);
- }
- private bool ConvertToInt(string value, out int result)
- {
- result = 0;
- value = value.Trim();
- if (int.TryParse(value, out result))
- {
- return true;
- }
- var wordsToNumbers = new Dictionary<string, int>
- {
- { "ïåðâîå", 1 },
- { "âòîðîå", 2 },
- { "òðåòüå", 3 },
- { "÷åòâåðòîå", 4 },
- { "ïÿòîå", 5 },
- { "øåñòîå", 6 },
- { "ñåäüìîå", 7 },
- { "âîñüìîå", 8 },
- { "äåâÿòîå", 9 },
- { "äåñÿòîå", 10 },
- { "îäèííàäöàòîå", 11 },
- { "äâåíàäöàòîå", 12 }
- };
- if (wordsToNumbers.TryGetValue(value.ToLower(), out result))
- {
- return true;
- }
- if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out double doubleValue))
- {
- result = (int)Math.Round(doubleValue);
- return true;
- }
- return false;
- }
- public string Zodiac(DateTime birthdate)
- {
- int day = birthdate.Day;
- int month = birthdate.Month;
- if (month == 3 && day >= 21 || month == 4 && day <= 20) return "Îâåí";
- if (month == 4 && day >= 21 || month == 5 && day <= 21) return "Òåëåö";
- if (month == 5 && day >= 22 || month == 6 && day <= 21) return "Áëèçíåöû";
- if (month == 6 && day >= 22 || month == 7 && day <= 23) return "Ðàê";
- if (month == 7 && day >= 24 || month == 8 && day <= 23) return "Ëåâ";
- if (month == 8 && day >= 24 || month == 9 && day <= 23) return "Äåâà";
- if (month == 9 && day >= 24 || month == 10 && day <= 23) return "Âåñû";
- if (month == 10 && day >= 24 || month == 11 && day <= 22) return "Ñêîðïèîí";
- if (month == 11 && day >= 23 || month == 12 && day <= 21) return "Ñòðåëåö";
- if (month == 12 && day >= 22 || month == 1 && day <= 20) return "Êîçåðîã";
- if (month == 1 && day >= 21 || month == 2 && day <= 19) return "Âîäîëåé";
- if (month == 2 && day >= 20 || month == 3 && day <= 20) return "Ðûáû";
- return "Íåèçâåñòíî";
- }
- public string Goroscop(int year)
- {
- string[] animals = { "Êðûñà", "Áûê", "Òèãð", "Êðîëèê", "Äðàêîí", "Çìåÿ", "Ëîøàäü", "Êîçà", "Îáåçüÿíà", "Ïåòóõ", "Ñîáàêà", "Ñâèíüÿ" };
- return animals[year % 12];
- }
- }
- }
|