Jelajahi Sumber

add image for users, add annimation

ЧернощековаАР 2 minggu lalu
induk
melakukan
b48d5af2b1

+ 19 - 0
AvaloniaApplication2/App.axaml

@@ -11,5 +11,24 @@
   
     <Application.Styles>
         <FluentTheme />
+		<Style Selector="TextBlock.MyTB">
+			<Setter Property="Background" Value="LightGray"/>
+		</Style>
+		<Style Selector="TextBlock.MyTB:pointerover">
+			<Setter Property="Background" Value="LightGray"/>
+			<Setter Property="FontSize" Value="48"/>
+		</Style>
+		<Style Selector="TextBlock.AnimatedTB">
+			<Style.Animations>
+				<Animation Duration="0:0:3" IterationCount="INFINITE" PlaybackDirection="Alternate" Easing="BounceEaseIn">
+					<KeyFrame Cue="0%">
+						<Setter Property="FontSize" Value="12"/>
+					</KeyFrame>
+					<KeyFrame Cue="100%">
+						<Setter Property="FontSize" Value="48"/>
+					</KeyFrame>
+				</Animation>
+			</Style.Animations>
+		</Style>
     </Application.Styles>
 </Application>

+ 1 - 0
AvaloniaApplication2/AvaloniaApplication2.csproj

@@ -14,6 +14,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="AnimatedImage.Avalonia" Version="1.0.7" />
     <PackageReference Include="Avalonia" Version="11.1.0" />
     <PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
     <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />

+ 9 - 4
AvaloniaApplication2/ChernoshchekovaContext.cs

@@ -82,16 +82,16 @@ public partial class ChernoshchekovaContext : DbContext
 
             entity.ToTable("users");
 
-            entity.Property(e => e.IdUser).HasColumnName("id_user");
+            entity.Property(e => e.IdUser)
+                .ValueGeneratedOnAdd()
+                .HasColumnName("id_user");
             entity.Property(e => e.BirthDate)
                 .HasColumnType("timestamp without time zone")
                 .HasColumnName("birth_date");
             entity.Property(e => e.Gender)
                 .ValueGeneratedOnAdd()
                 .HasColumnName("gender");
-            entity.Property(e => e.LoginedId)
-                .ValueGeneratedOnAdd()
-                .HasColumnName("logined_id");
+            entity.Property(e => e.Image).HasColumnName("image");
             entity.Property(e => e.UserName)
                 .HasColumnType("character varying")
                 .HasColumnName("user_name");
@@ -100,6 +100,11 @@ public partial class ChernoshchekovaContext : DbContext
                 .HasForeignKey(d => d.Gender)
                 .OnDelete(DeleteBehavior.ClientSetNull)
                 .HasConstraintName("users_gender_fk");
+
+            entity.HasOne(d => d.IdUserNavigation).WithOne(p => p.User)
+                .HasForeignKey<User>(d => d.IdUser)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("users_logined_fk");
         });
 
         OnModelCreatingPartial(modelBuilder);

+ 30 - 0
AvaloniaApplication2/Res/DateConverter.cs

@@ -0,0 +1,30 @@
+using Avalonia.Data.Converters;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AvaloniaApplication2.Resources
+{
+    internal class DateConverter : IValueConverter
+    {
+        // from VM to Viev
+        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+        {         
+            if (value is DateTime) return new DateTimeOffset((DateTime)value, TimeSpan.Zero); 
+            return null;
+        }
+
+        //from View to VM
+        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+        {
+            if (value is DateTimeOffset myDateTimeOffset)
+            {
+                return new DateTime(myDateTimeOffset.Year, myDateTimeOffset.Month, myDateTimeOffset.Day);
+            }
+            return null;
+        }
+    }
+}

+ 18 - 0
AvaloniaApplication2/Res/UserLogicalConverter.cs

@@ -0,0 +1,18 @@
+using Avalonia.Data.Converters;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AvaloniaApplication2.Resources
+{
+    internal class UserLogicalConverter : IMultiValueConverter
+    {
+        public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
+        {
+            return !(values[0].Equals(values[1]));
+        }
+    }
+}

+ 1 - 2
AvaloniaApplication2/User.cs

@@ -13,10 +13,9 @@ public partial class User
 
     public long Gender { get; set; }
 
-    public long LoginedId { get; set; }
     public byte[]? Image { get; set; }
 
     public virtual Gender GenderNavigation { get; set; } = null!;
 
-    public virtual Logined Logined { get; set; } = null!;
+    public virtual Logined IdUserNavigation { get; set; } = null!;
 }

+ 1 - 1
AvaloniaApplication2/ViewModels/UserProfileForAdminViewModel.cs

@@ -26,7 +26,7 @@ namespace AvaloniaApplication2.ViewModels
         {
             GendersList = db.Genders.ToList();
             editedUser = db.Users.Include(x => x.GenderNavigation).FirstOrDefault(x => x.IdUser == id);
-            imageUser = EditedUser.Image != null ? new Bitmap(new MemoryStream(editedUser.Image)) : new Bitmap("Assets/профиль.png");
+            imageUser = EditedUser.Image != null ? new Bitmap(new MemoryStream(editedUser.Image)) : new Bitmap("C:/Users/ЧернощековаАР/source/repos/AvaloniaApplication2/AvaloniaApplication2/Assets/профиль.png");
         }
 
         public DateTimeOffset DateTimeOffset

+ 1 - 1
AvaloniaApplication2/ViewModels/UserProfileViewModel.cs

@@ -26,7 +26,7 @@ namespace AvaloniaApplication2.ViewModels
         {
             GendersList = db.Genders.ToList();
             editedUser = db.Users.Include(x => x.GenderNavigation).FirstOrDefault(x => x.IdUser == id);
-            imageUser = EditedUser.Image != null ? new Bitmap(new MemoryStream(editedUser.Image)) : new Bitmap("");
+            imageUser = EditedUser.Image != null ? new Bitmap(new MemoryStream(editedUser.Image)) : new Bitmap("C:/Users/ЧернощековаАР/source/repos/AvaloniaApplication2/AvaloniaApplication2/Assets/профиль.png");
         }
 
         public DateTimeOffset DateTimeOffset

+ 1 - 1
AvaloniaApplication2/Views/PageForAdmin.axaml

@@ -34,7 +34,7 @@
 							<TextBlock Text="{Binding UserName, StringFormat=Имя: {0}}"/>
 							<TextBlock Text="{Binding BirthDate, StringFormat=Дата рождения: {0:dd/MM/yyyy}}"/>
 							<TextBlock Text="{Binding GenderNavigation.NameGender, StringFormat=Пол: {0}}"/>
-							<TextBlock Text="{Binding Logined.IdRoleNavigation.IdRole, StringFormat=Роль в системе: {0}}"/>
+							<TextBlock Text="{Binding IdUserNavigation.IdRoleNavigation.IdRole, StringFormat=Роль в системе: {0}}"/>
 							<Button Content="Изменить персональные данные пользователя" Command="{Binding $parent[UserControl].((vm:PageForAdminViewModel)DataContext).Press}" CommandParameter="{Binding IdUser}"/>
 						</StackPanel>
 					</DataTemplate>

+ 2 - 0
AvaloniaApplication2/Views/UserProfile.axaml

@@ -24,6 +24,8 @@
 			</ComboBox.ItemTemplate>
 		</ComboBox>
 		<Button Command="{Binding UserProfileVM.Save}" Content="СОХРАНИТЬ ИЗМЕНЕНИЯ" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Content="Выбрать изображение пользователя" Command="{Binding UserProfileVM.Image}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<Button Command="{Binding UserProfileVM.GoBack}" Content="ВЫХОД" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<TextBlock Text="Развлекаловка" HorizontalAlignment="Center" VerticalAlignment="Bottom" Classes="AnimatedTB"/>
 	</StackPanel>
 </UserControl>

+ 7 - 5
AvaloniaApplication2/Views/UserProfileForAdmin.axaml

@@ -8,11 +8,11 @@
 			 x:DataType="vm:MainWindowViewModel"
 			 Background="LightGray">
 	<StackPanel>
-		<TextBlock Text="ПРОФИЛЬ ПОЛЬЗОВАТЕЛЯ" VerticalAlignment="Top" HorizontalAlignment="Center" FontStyle="Normal" FontWeight="Bold" FontSize="18" Padding="5"/>
+		<TextBlock Text="ПРОФИЛЬ ПОЛЬЗОВАТЕЛЯ" VerticalAlignment="Top" HorizontalAlignment="Center" FontStyle="Normal" FontWeight="Bold" FontSize="18" Padding="5" Classes="MyTB"/>
 		<TextBlock Text="Имя пользователя" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="0,0,70,0"/>
-		<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-			<TextBox Text="{Binding UserProfileForAdminVM.EditedUser.UserName}" Width="200" Height="" Padding="5" Margin="5"/>
-		
+		<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top">
+			<TextBox Text="{Binding UserProfileForAdminVM.EditedUser.UserName}" Width="200" Height="30" Padding="5" Margin="5"/>
+			<Image Source="{Binding UserProfileForAdminVM.ImageUser}" Width="100" Height="100"/>
 		</StackPanel>
 		<TextBlock Text="Дата рождения" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="0,0,90,0"/>
 		<DatePicker SelectedDate="{ Binding UserProfileForAdminVM.DateTimeOffset}" HorizontalAlignment="Center" Width="300" Height="" Padding="5" Margin="5"/>
@@ -23,7 +23,9 @@
 				</DataTemplate>
 			</ComboBox.ItemTemplate>
 		</ComboBox>
-		<Button Command="{Binding UserProfileForAdminVM.Save}" Content="СОХРАНИТЬ ИЗМЕНЕНИЯ" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Command="{Binding UserProfileForAdminVM.Save}" Content="Сохранить изменения" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Content="Выбрать изображение пользователя" Command="{Binding UserProfileForAdminVM.Image}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<Button Command="{Binding UserProfileForAdminVM.GoBack}" Content="ВЫХОД" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<TextBlock Text="Развлекаловка" HorizontalAlignment="Center" VerticalAlignment="Bottom" Classes="AnimatedTB"/>
 	</StackPanel>
 </UserControl>