Ver Fonte

Добавьте файлы проекта.

semen há 4 dias atrás
pai
commit
fb0efa8d80

+ 25 - 0
MyCalendarHome.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34723.18
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCalendarHome", "MyCalendarHome\MyCalendarHome.csproj", "{6A11726E-D7A0-4EAB-9ACE-C0CFEF421D08}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6A11726E-D7A0-4EAB-9ACE-C0CFEF421D08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6A11726E-D7A0-4EAB-9ACE-C0CFEF421D08}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6A11726E-D7A0-4EAB-9ACE-C0CFEF421D08}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6A11726E-D7A0-4EAB-9ACE-C0CFEF421D08}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {3C2F662B-2254-4522-AB5A-F09E96AF3979}
+	EndGlobalSection
+EndGlobal

+ 11 - 0
MyCalendarHome/App.axaml

@@ -0,0 +1,11 @@
+<Application xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             x:Class="MyCalendarHome.App"
+             RequestedThemeVariant="Default">
+             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+	<Application.Styles>
+		<FluentTheme />
+		<StyleInclude Source="/StyleCalendar.axaml"></StyleInclude>
+	</Application.Styles>
+</Application>

+ 24 - 0
MyCalendarHome/App.axaml.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+
+namespace MyCalendarHome
+{
+    public partial class App : Application
+    {
+        public override void Initialize()
+        {
+            AvaloniaXamlLoader.Load(this);
+        }
+
+        public override void OnFrameworkInitializationCompleted()
+        {
+            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            {
+                desktop.MainWindow = new MainWindow();
+            }
+
+            base.OnFrameworkInitializationCompleted();
+        }
+    }
+}

+ 60 - 0
MyCalendarHome/MainWindow.axaml

@@ -0,0 +1,60 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        x:Class="MyCalendarHome.MainWindow"
+        Title="MyCalendarHome">
+	<ScrollViewer>
+		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
+			<StackPanel Name="Choose">
+				<Border Padding="30" Margin="0,0,0,0">
+					<StackPanel>
+						<TextBlock Classes="Error" Name="ErrorMassage" HorizontalAlignment="Center" Margin="0,0,0,10" >
+
+						</TextBlock>
+						<TextBlock FontWeight="Bold" Margin="0,0,0,10">
+							Введите дату:
+						</TextBlock>
+						<DatePicker Name ="Calendar"></DatePicker>
+						<Button Click="GetAndShowInform" HorizontalAlignment="Center" Margin="0,10,0,0" Content="Узнать все"/>
+						<StackPanel Name="GG" Orientation="Horizontal" VerticalAlignment="Center">
+							<TextBlock Name="Year" Margin="0,10,0,10">Года:</TextBlock>
+						</StackPanel>
+						<TextBlock Name="Month" Margin="0,0,0,10">
+							Месяца:
+						</TextBlock>
+						<TextBlock Name="Day" Margin="0,0,0,10">
+							Дни:
+						</TextBlock>
+						<TextBlock Name="DayWeek" Margin="0,0,0,10">
+							День недели:
+						</TextBlock>
+						<TextBlock Name="CountDayWeek" Margin="0,0,0,10">
+							Отпраздновал в этот же день:
+						</TextBlock>
+						<TextBlock Margin="0,0,0,10">
+							Номера висакосных годов:
+						</TextBlock>
+						<TextBlock Name="LeapYear" Margin="0,0,0,10">
+							
+						</TextBlock>
+						<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" >
+						<Button Click="GetNameZodiac" Margin="0,10,20,0" Content="Знак зодиака"/>
+						<Button Click="GetEastGoroskop" Margin="0,10,0,0" Content="Восточный гороскоп"/>
+						</StackPanel>
+						<TextBlock Name="NameZodiak" HorizontalAlignment="Center" Margin="0,10,0,0">
+
+						</TextBlock>
+						<TextBlock Name="EastGoroskop" HorizontalAlignment="Center" Margin="0,10,0,0">
+
+						</TextBlock>
+						<Button Click="WorkFile" HorizontalAlignment="Center" Margin="0,10,0,0" Content="Поработать с файлом"/>
+
+					</StackPanel>
+				</Border>
+				
+			</StackPanel>
+		</StackPanel>
+	</ScrollViewer>
+</Window>

+ 254 - 0
MyCalendarHome/MainWindow.axaml.cs

@@ -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);
+        }
+    }
+}

+ 19 - 0
MyCalendarHome/MyCalendarHome.csproj

@@ -0,0 +1,19 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
+    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
+  </ItemGroup>
+</Project>

+ 22 - 0
MyCalendarHome/Program.cs

@@ -0,0 +1,22 @@
+using System;
+using Avalonia;
+
+namespace MyCalendarHome
+{
+    internal class Program
+    {
+        // Initialization code. Don't use any Avalonia, third-party APIs or any
+        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
+        // yet and stuff might break.
+        [STAThread]
+        public static void Main(string[] args) => BuildAvaloniaApp()
+            .StartWithClassicDesktopLifetime(args);
+
+        // Avalonia configuration, don't remove; also used by visual designer.
+        public static AppBuilder BuildAvaloniaApp()
+            => AppBuilder.Configure<App>()
+                .UsePlatformDetect()
+                .WithInterFont()
+                .LogToTrace();
+    }
+}

+ 36 - 0
MyCalendarHome/StyleCalendar.axaml

@@ -0,0 +1,36 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+  <Design.PreviewWith>
+    <Border Padding="20">
+      <!-- Add Controls for Previewer Here -->
+    </Border>
+  </Design.PreviewWith>
+
+  <!-- Add Styles Here -->
+	<Style Selector="Button">
+		<Setter Property="Background" Value="DarkGreen"/>
+		<Setter Property="Foreground" Value="WhiteSmoke"/>
+	</Style>
+	<Style Selector="TextBlock">
+		<Setter Property="FontSize" Value="16"/>
+		<Setter Property="Foreground" Value="DarkGreen"/>
+		<Setter Property="FontWeight" Value="Bold"/>
+	</Style>
+	<Style Selector="TextBlock.Error">
+		<Setter Property="FontSize" Value="16"/>
+		<Setter Property="Foreground" Value="Red"/>
+		<Setter Property="FontWeight" Value="Bold"/>
+	</Style>
+	<Style Selector="Border">
+		<Setter Property="Background" Value="White"/>
+		<Setter Property="BorderBrush" Value="LightGray"/>
+		<Setter Property="BorderThickness" Value="2"/>
+		<Setter Property="CornerRadius" Value="16"/>
+	</Style>
+	<Style Selector="Label">
+		<Setter Property="FontSize" Value="16"/>
+		<Setter Property="Foreground" Value="DarkGreen"/>
+		<Setter Property="FontWeight" Value="Bold"/>
+	</Style>
+
+</Styles>

+ 18 - 0
MyCalendarHome/app.manifest

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <!-- This manifest is used on Windows only.
+       Don't remove it as it might cause problems with window transparency and embedded controls.
+       For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+  <assemblyIdentity version="1.0.0.0" name="MyCalendarHome.Desktop"/>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- A list of the Windows versions that this application has been tested on
+           and is designed to work with. Uncomment the appropriate elements
+           and Windows will automatically select the most compatible environment. -->
+
+      <!-- Windows 10 -->
+      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+    </application>
+  </compatibility>
+</assembly>