123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- 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 = "Monkey";
- 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<MyStructZodiac> MSZ, ref List<MyStructGoroskop> MSG)
- {
- using (StreamReader sr = new StreamReader(path))
- {
- while (sr.EndOfStream != true)
- {
- string[] array = sr.ReadLine().Split(';');
- try
- {
- DateTime data1 = new DateTime(1, Convert.ToInt32(array[1]), Convert.ToInt32(array[0]));
- MSZ.Add(new MyStructZodiac()
- {
- data = data1,
- str = ""
- });
- }
- catch (Exception e)
- {
- DateTime data = new DateTime();
- MSZ.Add(new MyStructZodiac()
- {
- data = data,
- str = e.Message
- });
- }
- try
- {
- DateTime data1 = new DateTime(Convert.ToInt32(array[2]), 1, 1);
- MSG.Add(new MyStructGoroskop()
- {
- data = data1,
- str = ""
- });
- }
- catch (Exception e)
- {
- DateTime data = new DateTime();
- MSG.Add(new MyStructGoroskop()
- {
- 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 MyStructZodiac
- {
- public DateTime data;
- public string str;
- }
- struct MyStructGoroskop
- {
- public DateTime data;
- public string str;
- }
- private void WorkFile(object sender, RoutedEventArgs e)
- {
- List<MyStructZodiac> myStructzodiac = new List<MyStructZodiac>();
- List<MyStructGoroskop> myStructgoroskop = new List<MyStructGoroskop>();
- List<string> idonto = new List<string>();
- getData("horoscopeEastern.csv", ref myStructzodiac, ref myStructgoroskop);
- for (int i = 0; i < myStructzodiac.Count; i++)
- {
- if (myStructzodiac[i].data == DateTime.MinValue && myStructgoroskop[i].data == DateTime.MinValue)
- {
- idonto.Add(i + " Error in zodiak: " + myStructzodiac[i].str + "\n"+ i + " Error in goroskop: " + myStructgoroskop[i].str);
- }
- else if (myStructzodiac[i].data == DateTime.MinValue && myStructgoroskop[i].data != DateTime.MinValue)
- {
- idonto.Add(i + " Error in zodiak: " + myStructzodiac[i].str + "\n" + i + " Восточный гороскоп: " + AnimalYear(myStructgoroskop[i].data.Year));
- }
- else if (myStructzodiac[i].data != DateTime.MinValue && myStructgoroskop[i].data == DateTime.MinValue)
- {
- idonto.Add(i + " Знак зодиака: " + Zodiak(myStructzodiac[i].data.Day, myStructzodiac[i].data.Month) + "\n" + i + " Error in goroskop: " + myStructgoroskop[i].str);
- }
- else
- {
- idonto.Add(i + " Знак зодиака: " + Zodiak(myStructzodiac[i].data.Day, myStructzodiac[i].data.Month) + "\n" + i + " Восточный гороскоп: " + AnimalYear(myStructgoroskop[i].data.Year));
- }
- }
- inputData("Input.txt", idonto);
- }
- }
- }
|