浏览代码

Первое задание без стилей

Blueris 2 月之前
父节点
当前提交
c72110c418
共有 2 个文件被更改,包括 112 次插入9 次删除
  1. 15 7
      AvaloniaApplication1/MainWindow.axaml
  2. 97 2
      AvaloniaApplication1/MainWindow.axaml.cs

+ 15 - 7
AvaloniaApplication1/MainWindow.axaml

@@ -6,13 +6,21 @@
         x:Class="AvaloniaApplication1.MainWindow"
         Title="AvaloniaApplication1">
 	<Grid HorizontalAlignment="Center">
-		<StackPanel VerticalAlignment="Center">
-
-			<TextBlock Name="text"></TextBlock>
-			<DatePicker Name="dateT"></DatePicker>
-			<Button Click="Button_Click" Width="100" Height="30" HorizontalAlignment="Center">
-				</Button>
-			
+		<StackPanel Margin="50 100 50 50">
+			<TextBlock Name="yearT"></TextBlock>
+			<TextBlock Name="mounthT"></TextBlock>
+			<TextBlock Name="daysT"></TextBlock>
+			<TextBlock Name="dayOfWeek"></TextBlock>
+			<TextBlock Name="DBW"></TextBlock>
+			<TextBlock Name="Viss"></TextBlock>
+			<TextBlock Name="VisY"></TextBlock>
+		</StackPanel>
+		<StackPanel Margin="100 250 100 100">
+		
+			<DatePicker Width="400" Height="30" VerticalAlignment="Center" Name="dateT"></DatePicker>
+			<Button  VerticalAlignment="Center" Click="Button_Click" Width="160" Height="30" HorizontalAlignment="Center">
+			Подтвердить выбор	
+			</Button>			
 		</StackPanel>
 
 	</Grid>

+ 97 - 2
AvaloniaApplication1/MainWindow.axaml.cs

@@ -19,8 +19,103 @@ namespace AvaloniaApplication1
         {
             string date = dateT.SelectedDate.ToString();
 
-            int day = int.Parse(date.Substring(0, 2));
-            int mounth = int.Parse(date.Substring(3, 2));
+            if (date == "")
+            {
+                mounthT.Text = "Âû ââåëè íåñóùåñòâóþùóþ äàòó";
+            }
+            else
+            {
+                int day = int.Parse(date.Substring(0, 2));
+                int mounth = int.Parse(date.Substring(3, 2));
+                int year = int.Parse(date.Substring(6, 4));
+
+                DateTime BD = new DateTime(year, mounth, day);
+                DateTime ToDay = DateTime.Now;
+
+
+                if (BD > ToDay)
+                {
+                    mounthT.Text = "Âû ââåëè áóäóùóþ äàòó";
+                }
+                else
+                {
+                    int Vis = 0;
+                    int DbWeek = 0;
+                    DateTime dayW;
+                    int age = ToDay.Year - BD.Year;
+                    int months = ToDay.Month - BD.Month;
+                    int days = ToDay.Day - BD.Day;
+
+                    if (ToDay.Month < BD.Month || (ToDay.Month == BD.Month && ToDay.Day < BD.Day))
+                    {
+                        age--;
+                    }
+
+                    if (days < 0)
+                    {
+                        months--;
+                        days += DateTime.DaysInMonth(ToDay.Year, ToDay.Month - 1);
+                    }
+
+                    if (months < 0)
+                    {
+                        months += 12;
+                    }
+                    VisY.Text = "Âèñîêîñíûå ãîäû: ";
+                    string DayOfWeek = BD.DayOfWeek.ToString();
+                    for (int i = year; i <= ToDay.Year; i++)
+                    {
+                        if (i % 4 == 0)
+                        {
+
+                            VisY.Text = VisY.Text + i + " ";
+                            Vis++;
+                        }
+                        dayW = new DateTime(i, mounth, day);
+
+                        if (dayW.DayOfWeek.ToString() == DayOfWeek && dayW != BD && dayW != ToDay)
+                        {
+                            DbWeek++;
+                        }
+                    }
+
+                    if (DayOfWeek == "Monday")
+                    {
+                        DayOfWeek = "Ïîíåäåëüíèê";
+                    }
+                    if (DayOfWeek == "Tuesday")
+                    {
+                        DayOfWeek = "Âòîðíèê";
+                    }
+                    if (DayOfWeek == "Wednesday")
+                    {
+                        DayOfWeek = "Ñðåäà";
+                    }
+                    if (DayOfWeek == "Thursday")
+                    {
+                        DayOfWeek = "×åòâåðã";
+                    }
+                    if (DayOfWeek == "Friday")
+                    {
+                        DayOfWeek = "Ïÿòíèöà";
+                    }
+                    if (DayOfWeek == "Saturday")
+                    {
+                        DayOfWeek = "Ñóááîòà";
+                    }
+                    if (DayOfWeek == "Sunday")
+                    {
+                        DayOfWeek = "Âîñêðåñåíüå";
+                    }
+
+                    dayOfWeek.Text = "Äåíü íåäåëè: " + DayOfWeek;
+                    yearT.Text = "Êîëè÷åñòâî ëåò: " + age.ToString();
+                    mounthT.Text = "Êîëè÷åñòâî ìåñÿöåâ: " + months.ToString();
+                    daysT.Text = "Êîëè÷åñòâî äíåé: " + days.ToString();
+                    DBW.Text = "Êîëè÷åñòâî îòïðàçäíîâàííûõ äíåé ðîæäåíèé â " + DayOfWeek + ": " + DbWeek;
+                    Viss.Text = "Êîëè÷åñòâî âèñîêîñíûõ ãîäîâ: " + Vis;
+                }
+            }
         }
     }
 }