MainWindow.axaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using System;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Runtime.Intrinsics.Arm;
  7. namespace AvaloniaApplication1
  8. {
  9. public partial class MainWindow : Window
  10. {
  11. public MainWindow()
  12. {
  13. InitializeComponent();
  14. }
  15. public void Button_Click(object source, RoutedEventArgs args)
  16. {
  17. string date = dateT.SelectedDate.ToString();
  18. if (date == "")
  19. {
  20. mounthT.Text = "Âû ââåëè íåñóùåñòâóþùóþ äàòó";
  21. }
  22. else
  23. {
  24. int day = int.Parse(date.Substring(0, 2));
  25. int mounth = int.Parse(date.Substring(3, 2));
  26. int year = int.Parse(date.Substring(6, 4));
  27. DateTime BD = new DateTime(year, mounth, day);
  28. DateTime ToDay = DateTime.Now;
  29. if (BD > ToDay)
  30. {
  31. mounthT.Text = "Âû ââåëè áóäóùóþ äàòó";
  32. }
  33. else
  34. {
  35. int Vis = 0;
  36. int DbWeek = 0;
  37. DateTime dayW;
  38. int age = ToDay.Year - BD.Year;
  39. int months = ToDay.Month - BD.Month;
  40. int days = ToDay.Day - BD.Day;
  41. if (ToDay.Month < BD.Month || (ToDay.Month == BD.Month && ToDay.Day < BD.Day))
  42. {
  43. age--;
  44. }
  45. if (days < 0)
  46. {
  47. months--;
  48. days += DateTime.DaysInMonth(ToDay.Year, ToDay.Month - 1);
  49. }
  50. if (months < 0)
  51. {
  52. months += 12;
  53. }
  54. VisY.Text = "Âèñîêîñíûå ãîäû: ";
  55. string DayOfWeek = BD.DayOfWeek.ToString();
  56. for (int i = year; i <= ToDay.Year; i++)
  57. {
  58. if (i % 4 == 0)
  59. {
  60. VisY.Text = VisY.Text + i + " ";
  61. Vis++;
  62. }
  63. dayW = new DateTime(i, mounth, day);
  64. if (dayW.DayOfWeek.ToString() == DayOfWeek && dayW != BD && dayW != ToDay)
  65. {
  66. DbWeek++;
  67. }
  68. }
  69. if (DayOfWeek == "Monday")
  70. {
  71. DayOfWeek = "Ïîíåäåëüíèê";
  72. }
  73. if (DayOfWeek == "Tuesday")
  74. {
  75. DayOfWeek = "Âòîðíèê";
  76. }
  77. if (DayOfWeek == "Wednesday")
  78. {
  79. DayOfWeek = "Ñðåäà";
  80. }
  81. if (DayOfWeek == "Thursday")
  82. {
  83. DayOfWeek = "×åòâåðã";
  84. }
  85. if (DayOfWeek == "Friday")
  86. {
  87. DayOfWeek = "Ïÿòíèöà";
  88. }
  89. if (DayOfWeek == "Saturday")
  90. {
  91. DayOfWeek = "Ñóááîòà";
  92. }
  93. if (DayOfWeek == "Sunday")
  94. {
  95. DayOfWeek = "Âîñêðåñåíüå";
  96. }
  97. dayOfWeek.Text = "Äåíü íåäåëè: " + DayOfWeek;
  98. yearT.Text = "Êîëè÷åñòâî ëåò: " + age.ToString();
  99. mounthT.Text = "Êîëè÷åñòâî ìåñÿöåâ: " + months.ToString();
  100. daysT.Text = "Êîëè÷åñòâî äíåé: " + days.ToString();
  101. DBW.Text = "Êîëè÷åñòâî îòïðàçäíîâàííûõ äíåé ðîæäåíèé â " + DayOfWeek + ": " + DbWeek;
  102. Viss.Text = "Êîëè÷åñòâî âèñîêîñíûõ ãîäîâ: " + Vis;
  103. }
  104. }
  105. }
  106. }
  107. }