Browse Source

Полная работа

ПроваленкоЛН 2 tuần trước cách đây
mục cha
commit
877fdbb749

+ 1 - 0
AvaloniaApplication2/App.axaml

@@ -11,5 +11,6 @@
   
     <Application.Styles>
         <FluentTheme />
+		<StyleInclude Source="/Styles1.axaml"></StyleInclude>
     </Application.Styles>
 </Application>

BIN
AvaloniaApplication2/Assets/picture.jpg


BIN
AvaloniaApplication2/Assets/picture.png


+ 1 - 1
AvaloniaApplication2/AvaloniaApplication2.csproj

@@ -14,7 +14,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <None Remove="Assets\picture.png" />
+    <None Remove="Assets\picture.jpg" />
   </ItemGroup>
 
   <ItemGroup>

+ 1 - 1
AvaloniaApplication2/Converters/ImageConverter.cs

@@ -16,7 +16,7 @@ namespace AvaloniaApplication2.Converters
     {
         public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
         {
-            return value == null ? new Bitmap(AssetLoader.Open(new Uri("avares://AvaloniaApplication2/Assets/picture.png"))) : new Bitmap(new MemoryStream((byte[])value));
+            return value == null ? new Bitmap(AssetLoader.Open(new Uri("avares://AvaloniaApplication2/Assets/picture.jpg"))) : new Bitmap(new MemoryStream((byte[])value));
         }
 
         public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)

+ 38 - 0
AvaloniaApplication2/Styles1.axaml

@@ -0,0 +1,38 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+
+	<Style Selector="TextBlock.PurpleTextBlock">
+		<Setter Property="Foreground" Value="#800080"/>
+		<Setter Property="FontSize" Value="16" />
+	</Style>
+	
+	<Style Selector="TextBlock">
+		<Setter Property="Foreground" Value="#FFFFFF"/>
+		<Setter Property="FontSize" Value="16" />
+	</Style>
+
+	<Style Selector="TextBox">
+		<Setter Property="Background" Value="#800080" />
+		<Setter Property="Foreground" Value="#FFFFFF" />
+		<Setter Property="BorderBrush" Value="#DA70D6" />
+		<Setter Property="BorderThickness" Value="2" />
+		<Setter Property="Padding" Value="5" />
+		<Setter Property="FontSize" Value="14" />
+	</Style>
+
+	<Style Selector="Button">
+		<Setter Property="Background" Value="#800080" />
+		<Setter Property="Foreground" Value="#FFFFFF" />
+		<Setter Property="BorderBrush" Value="#DA70D6" />
+		<Setter Property="BorderThickness" Value="2" />
+		<Setter Property="Padding" Value="10" />
+		<Setter Property="FontSize" Value="16" />
+		<Setter Property="CornerRadius" Value="5" />
+	</Style>
+
+	<Style Selector="Button:hover">
+		<Setter Property="Background" Value="#DA70D6" />
+
+	</Style>
+
+</Styles>

+ 7 - 0
AvaloniaApplication2/ViewModels/AuthVM.cs

@@ -1,5 +1,6 @@
 using AvaloniaApplication2.Models;
 using Microsoft.EntityFrameworkCore;
+using ReactiveUI;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -13,9 +14,11 @@ namespace AvaloniaApplication2.ViewModels
     {
         string _login = "";
         string _password = "";
+        string _message = "";
 
         public string Login { get => _login; set => _login = value; }
         public string Password { get => _password; set => _password = value; }
+        public string Message { get => _message; set => this.RaiseAndSetIfChanged(ref _message, value); }
 
         public void AutoUser()
         {
@@ -25,6 +28,10 @@ namespace AvaloniaApplication2.ViewModels
             {
                 MainWindowViewModel.Instance.Page = new Personal(user);
             }
+            else
+            {
+                Message = "Неверные данные входа";
+            }
 
         }
     }

+ 33 - 1
AvaloniaApplication2/ViewModels/PersonalVM.cs

@@ -1,4 +1,7 @@
-using AvaloniaApplication2.Models;
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Platform.Storage;
+using AvaloniaApplication2.Models;
 using ReactiveUI;
 using System;
 using System.Collections.Generic;
@@ -16,5 +19,34 @@ namespace AvaloniaApplication2.ViewModels
         {
             User = user;
         }
+
+        public void Vixod()
+        {
+            MainWindowViewModel.Instance.Page = new AuthAndReg();
+        }
+
+        public async Task Image()
+        {
+            if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desctop || desctop.MainWindow?.StorageProvider is not { } provider) throw new NullReferenceException("провайдер отсутствует");
+
+            var file = await provider.OpenFilePickerAsync(
+                new FilePickerOpenOptions()
+                {
+                    Title = "Выберите изображение",
+                    AllowMultiple = false,
+                    FileTypeFilter = [FilePickerFileTypes.All, FilePickerFileTypes.ImageAll]
+                }
+                );
+            if (file != null)
+            {
+                await using var readStream = await file[0].OpenReadAsync();
+                byte[] buffer = new byte[readStream.Length];
+                readStream.ReadAtLeast(buffer, 1);
+                User.Image = buffer;
+                MainWindowViewModel.myconnection.Users.Update(User);
+                MainWindowViewModel.myconnection.SaveChanges();
+                MainWindowViewModel.Instance.Page = new Personal(User);
+            }
+        }
     }
 }

+ 1 - 1
AvaloniaApplication2/Views/AdminReg.axaml

@@ -9,7 +9,7 @@
  
 	<Grid>
 		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
-			<TextBlock Text="{Binding ErrorMessage}"></TextBlock>
+			<TextBlock Classes="PurpleTextBlock" Text="{Binding ErrorMessage}"></TextBlock>
 			<TextBox Text="{Binding NewUser.Fio}" IsVisible="{Binding Visible}" Watermark="ФИО"></TextBox>
 			<TextBox Text="{Binding NewUser.Login}" IsVisible="{Binding Visible}" Watermark="Логин"></TextBox>
 			<TextBox Text="{Binding Pass}" IsVisible="{Binding Visible}" Watermark="Пароль"></TextBox>

+ 1 - 0
AvaloniaApplication2/Views/Auth.axaml

@@ -9,6 +9,7 @@
   
 	<Grid>
 		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+			<TextBlock Classes="PurpleTextBlock" Text="{Binding Message}"></TextBlock>
 			<TextBox Text="{Binding Login}" Watermark="Логин"></TextBox>
 			<TextBox Text="{Binding Password}" Watermark="Пароль"></TextBox>
 			<Button Command="{Binding AutoUser}">

+ 34 - 15
AvaloniaApplication2/Views/Personal.axaml

@@ -11,21 +11,40 @@
 		<conv:ImageConverter x:Key="myImageConverter"/>
 	</UserControl.Resources>
 
-	<Grid>
-		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
-			<TextBlock>
-				<TextBlock.Text>
-					<MultiBinding StringFormat="{} Добро пожаловать, {0} - Вы {1}">
-						<Binding Path="User.Fio"></Binding>
-						<Binding Path="User.RoleNavigation.Role1"></Binding>
-						</MultiBinding>
-				</TextBlock.Text>
-			</TextBlock>
-			<StackPanel Orientation="Horizontal">
-			<TextBlock Text="Ваш логин:"></TextBlock>
-			<TextBlock Text="{Binding User.Login}"></TextBlock>			
-			</StackPanel>
-			<Image Height="100" Width="100" Source="{Binding User.Image,Converter={StaticResource myImageConverter}}"></Image>
+	<Grid Margin="20" HorizontalAlignment="Center" VerticalAlignment="Center">
+		<Grid.RowDefinitions>
+			<RowDefinition Height="Auto"/>
+			<RowDefinition Height="Auto"/>
+			<RowDefinition Height="Auto"/>
+			<RowDefinition Height="Auto"/>
+			<RowDefinition Height="Auto"/>
+		</Grid.RowDefinitions>
+		<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
+		<TextBlock Classes="PurpleTextBlock" Grid.Row="0" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center">
+			<TextBlock.Text>
+				<MultiBinding StringFormat="Добро пожаловать, {0} - Вы {1}">
+					<Binding Path="User.Fio" />
+					<Binding Path="User.RoleNavigation.Role1" />
+				</MultiBinding>
+			</TextBlock.Text>
+		</TextBlock>
+
+		<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center" Margin="0,10,0,10">
+			<TextBlock Classes="PurpleTextBlock" Text="Ваш логин:" FontWeight="SemiBold" Margin="0,0,5,0"/>
+			<TextBlock Classes="PurpleTextBlock" Text="{Binding User.Login}" />
+		</StackPanel>
+
+		<Button Command="{Binding Image}" Grid.Row="2" HorizontalAlignment="Center" Margin="0,5">
+			<TextBlock Text="Изменить изображение" />
+		</Button>
+
+		<Border  Grid.Row="3" Margin="0,10" Padding="5">
+			<Image Height="100" Width="100" Source="{Binding User.Image, Converter={StaticResource myImageConverter}}" />
+		</Border>
+
+		<Button Command="{Binding Vixod}" Grid.Row="4" HorizontalAlignment="Center" Margin="0,5">
+			<TextBlock Text="Выйти" />
+		</Button>
 		</StackPanel>
 	</Grid>
 </UserControl>

+ 1 - 1
AvaloniaApplication2/Views/RegUser.axaml

@@ -9,7 +9,7 @@
 	
 	<Grid>
 		<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
-			<TextBlock Text="{Binding ErrorMessage}"></TextBlock>
+			<TextBlock Classes="PurpleTextBlock" Text="{Binding ErrorMessage}"></TextBlock>
 			<TextBox Text="{Binding NewUser.Fio}" Watermark="ФИО"></TextBox>
 			<TextBox Text="{Binding NewUser.Login}" Watermark="Логин"></TextBox>
 			<TextBox Text="{Binding Pass}" Watermark="Пароль"></TextBox>