|
@@ -0,0 +1,254 @@
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Data;
|
|
|
|
+using System.IO;
|
|
|
|
+using Avalonia.Controls;
|
|
|
|
+using Avalonia.Controls.Shapes;
|
|
|
|
+using Avalonia.Interactivity;
|
|
|
|
+using Avalonia.Markup.Xaml.MarkupExtensions;
|
|
|
|
+using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
+
|
|
|
|
+namespace MyCalendarHome
|
|
|
|
+{
|
|
|
|
+ public partial class MainWindow : Window
|
|
|
|
+ {
|
|
|
|
+ public MainWindow()
|
|
|
|
+ {
|
|
|
|
+ InitializeComponent();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static string Zodiak(int d, int m)
|
|
|
|
+ {
|
|
|
|
+ if ((d >= 21 && m == 3) || (d <= 20 && m == 4)) return "Овен";
|
|
|
|
+ if ((d >= 21 && m == 4) || (d <= 20 && m == 5)) return "Телец";
|
|
|
|
+ if ((d >= 21 && m == 5) || (d <= 21 && m == 6)) return "Близнецы";
|
|
|
|
+ if ((d >= 22 && m == 6) || (d <= 22 && m == 7)) return "рак";
|
|
|
|
+ if ((d >= 23 && m == 7) || (d <= 23 && m == 8)) return "лев";
|
|
|
|
+ if ((d >= 24 && m == 8) || (d <= 23 && m == 9)) return "дева";
|
|
|
|
+ if ((d >= 24 && m == 9) || (d <= 23 && m == 10)) return "весы";
|
|
|
|
+ if ((d >= 24 && m == 10) || (d <= 22 && m == 11)) return "скорпион";
|
|
|
|
+ if ((d >= 23 && m == 11) || (d <= 21 && m == 12)) return "стрелец";
|
|
|
|
+ if ((d >= 22 && m == 12) || (d <= 20 && m == 1)) return "козерог";
|
|
|
|
+ if ((d >= 21 && m == 1) || (d <= 18 && m == 2)) return "водолей";
|
|
|
|
+ else return "рыбы";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static string AnimalYear(int y)
|
|
|
|
+ {
|
|
|
|
+ int f = y % 10;
|
|
|
|
+ string Color;
|
|
|
|
+
|
|
|
|
+ if ((f == 0) || (f == 1)) Color = "White";
|
|
|
|
+ else if((f == 2) || (f == 3)) Color = "Blue";
|
|
|
|
+ else if((f == 4) || (f == 5)) Color = "Green";
|
|
|
|
+ else if((f == 6) || (f == 7)) Color = "Red";
|
|
|
|
+ else Color = "Yellow";
|
|
|
|
+
|
|
|
|
+ f = y % 12;
|
|
|
|
+ string Animal;
|
|
|
|
+
|
|
|
|
+ if (f == 4) Animal = "Rat";
|
|
|
|
+ else if(f == 5) Animal = "Ox";
|
|
|
|
+ else if (f == 6) Animal = "Tiger";
|
|
|
|
+ else if (f == 7) Animal = "Rabbit";
|
|
|
|
+ else if (f == 8) Animal = "Dragon";
|
|
|
|
+ else if (f == 9) Animal = "Snake";
|
|
|
|
+ else if (f == 10) Animal = "Horse";
|
|
|
|
+ else if (f == 11) Animal = "Goat";
|
|
|
|
+ else if (f == 0) Animal = "Monkeq";
|
|
|
|
+ else if (f == 1) Animal = "Rooster";
|
|
|
|
+ else if (f == 2) Animal = "Dog";
|
|
|
|
+ else Animal = "Pig";
|
|
|
|
+
|
|
|
|
+ return Color + " " + Animal;
|
|
|
|
+ }
|
|
|
|
+ public static int DifferenceYear(DateTime one, DateTime two)
|
|
|
|
+ {
|
|
|
|
+ int total = one.Year - two.Year;
|
|
|
|
+ if (two.Month > one.Month || (two.Month == one.Month && two.Day > one.Day))
|
|
|
|
+ return total - 1;
|
|
|
|
+ return total;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int DifferenceMonth(DateTime one, DateTime two)
|
|
|
|
+ {
|
|
|
|
+ int total = (one.Year - two.Year) * 12 + one.Month - two.Month;
|
|
|
|
+ if (two.Day > one.Day || (two.Month == one.Month && two.Day > one.Day))
|
|
|
|
+ return total - 1;
|
|
|
|
+ return total;
|
|
|
|
+ }
|
|
|
|
+ public static int DifferenceDay(DateTime one, DateTime two)
|
|
|
|
+ {
|
|
|
|
+ if (two.Month > one.Month)
|
|
|
|
+ {
|
|
|
|
+ int day = 31 - two.Day + one.Day;
|
|
|
|
+ if (day > 31) day = day - 31;
|
|
|
|
+ return (day);
|
|
|
|
+ }
|
|
|
|
+ else if (two.Month == one.Month)
|
|
|
|
+ {
|
|
|
|
+ return (31 + one.Day - two.Day)%31;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return (31 + one.Day - two.Day) % 31;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public static int GetCountDayWeek(DateTime one)
|
|
|
|
+ {
|
|
|
|
+ DayOfWeek dayofweek = one.DayOfWeek;
|
|
|
|
+ int total = 0;
|
|
|
|
+ while (one.Year < DateTime.Now.Year)
|
|
|
|
+ {
|
|
|
|
+ if (one.DayOfWeek == dayofweek)
|
|
|
|
+ {
|
|
|
|
+ total++;
|
|
|
|
+ }
|
|
|
|
+ DateTime Year = one.AddYears(1);
|
|
|
|
+ one = Year;
|
|
|
|
+ }
|
|
|
|
+ return total;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static string GetLeapYears(DateTime one)
|
|
|
|
+ {
|
|
|
|
+ string str = "";
|
|
|
|
+
|
|
|
|
+ while (one.Year < DateTime.Now.Year)
|
|
|
|
+ {
|
|
|
|
+ if (DateTime.IsLeapYear(one.Year))
|
|
|
|
+ {
|
|
|
|
+ str = str + one.Year.ToString() + " ";
|
|
|
|
+ }
|
|
|
|
+ DateTime Year = one.AddYears(1);
|
|
|
|
+ one = Year;
|
|
|
|
+ }
|
|
|
|
+ return str;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void GetAndShowInform(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (Calendar.SelectedDate == null)
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = true;
|
|
|
|
+ ErrorMassage.Text = "Для продолжения введите дату.";
|
|
|
|
+ }
|
|
|
|
+ else if (Calendar.SelectedDate.Value > DateTime.Now)
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = true;
|
|
|
|
+ ErrorMassage.Text = "Дата не может быть больше сегодняшней.";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ NameZodiak.IsVisible = false;
|
|
|
|
+ EastGoroskop.IsVisible = false;
|
|
|
|
+ ErrorMassage.IsVisible = false;
|
|
|
|
+ string date = Calendar.SelectedDate.ToString();
|
|
|
|
+ DateTime data1 = Convert.ToDateTime(date);
|
|
|
|
+ Year.Text = "Года: " + DifferenceYear(DateTime.Now, data1);
|
|
|
|
+ Month.Text = "Месяца: " + DifferenceMonth(DateTime.Now, data1) % 12;
|
|
|
|
+ Day.Text = "Дни: " + DifferenceDay(DateTime.Now, data1);
|
|
|
|
+ DayWeek.Text = "День недели: " + data1.DayOfWeek.ToString();
|
|
|
|
+ CountDayWeek.Text = "Отпраздновал в этот же день: " + GetCountDayWeek(data1);
|
|
|
|
+ LeapYear.Text = GetLeapYears(data1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ private void GetNameZodiac(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (Calendar.SelectedDate == null)
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = true;
|
|
|
|
+ ErrorMassage.Text = "Для продолжения введите дату.";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = false;
|
|
|
|
+ string date = Calendar.SelectedDate.ToString();
|
|
|
|
+ DateTime data1 = Convert.ToDateTime(date);
|
|
|
|
+ EastGoroskop.IsVisible = false;
|
|
|
|
+ NameZodiak.IsVisible = true;
|
|
|
|
+ NameZodiak.Text = "Знак зодиака: " + Zodiak(data1.Day, data1.Month);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void GetEastGoroskop(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (Calendar.SelectedDate == null)
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = true;
|
|
|
|
+ ErrorMassage.Text = "Для продолжения введите дату.";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ErrorMassage.IsVisible = false;
|
|
|
|
+ string date = Calendar.SelectedDate.ToString();
|
|
|
|
+ DateTime data1 = Convert.ToDateTime(date);
|
|
|
|
+ NameZodiak.IsVisible = false;
|
|
|
|
+ EastGoroskop.IsVisible = true;
|
|
|
|
+ EastGoroskop.Text = "Всточный гороскоп: " + AnimalYear(data1.Year);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static void getData(string path, ref List<MyStruct> MS)
|
|
|
|
+ {
|
|
|
|
+ using (StreamReader sr = new StreamReader(path))
|
|
|
|
+ {
|
|
|
|
+ while (sr.EndOfStream != true)
|
|
|
|
+ {
|
|
|
|
+ string[] array = sr.ReadLine().Split(';');
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ DateTime data1 = new DateTime(Convert.ToInt32(array[2]), Convert.ToInt32(array[1]), Convert.ToInt32(array[0]));
|
|
|
|
+ MS.Add(new MyStruct()
|
|
|
|
+ {
|
|
|
|
+ data = data1,
|
|
|
|
+ str = ""
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ DateTime data = new DateTime();
|
|
|
|
+ MS.Add(new MyStruct()
|
|
|
|
+ {
|
|
|
|
+ data = data,
|
|
|
|
+ str = e.Message
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ static void inputData(string path, List<string> S)
|
|
|
|
+ {
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(path, true))
|
|
|
|
+ {
|
|
|
|
+ foreach (string u in S)
|
|
|
|
+ {
|
|
|
|
+ sw.WriteLine(u);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ struct MyStruct
|
|
|
|
+ {
|
|
|
|
+ public DateTime data;
|
|
|
|
+ public string str;
|
|
|
|
+ }
|
|
|
|
+ private void WorkFile(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ List<MyStruct> myStruct = new List<MyStruct>();
|
|
|
|
+ List<string> idonto = new List<string>();
|
|
|
|
+ getData("C:\\Users\\semen\\Downloads\\horoscopeEastern.csv", ref myStruct);
|
|
|
|
+ foreach (MyStruct item in myStruct)
|
|
|
|
+ {
|
|
|
|
+ if (item.data == DateTime.MinValue)
|
|
|
|
+ {
|
|
|
|
+ idonto.Add(item.str);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ idonto.Add(Zodiak(item.data.Day, item.data.Month) + " " + AnimalYear(item.data.Year));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ inputData("Input.txt", idonto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|