Бобарикке 1 miesiąc temu
rodzic
commit
96dbe589b2

+ 26 - 0
AvaloniaApplication1/Resources/ImageConverter.cs

@@ -0,0 +1,26 @@
+using Avalonia.Data.Converters;
+using Avalonia.Media.Imaging;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AvaloniaApplication1.Resources
+{
+    internal class ImageConverter : IValueConverter
+    {
+        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+        {
+            if (value is byte[]) return new Bitmap(new MemoryStream((byte[])value));
+            return null;
+        }
+
+        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 0 - 9
AvaloniaApplication1/ViewModels/MainPageViewModel.cs

@@ -24,7 +24,6 @@ namespace AvaloniaApplication1.ViewModels
         public MainPageViewModel()
         {
             this.smesharikiMain = myConnection.Smesharikis.Include(x => x.GenderNavigation).ToList();
-            ImageSmesh();
             this.smeshariki = this.smesharikiMain;
             genders =
             [
@@ -80,14 +79,6 @@ namespace AvaloniaApplication1.ViewModels
             if(!string.IsNullOrEmpty(Search)) Smeshariki = Smeshariki.Where(x => x.Name.ToLower().Contains(Search.ToLower())).ToList();
             if (selectedGender != null && selectedGender.Id != 0) { Smeshariki = Smeshariki.Where(x => x.GenderNavigation == selectedGender).ToList(); }
         }
-        public void ImageSmesh()
-        {
-            foreach (var item in SmesharikiMain)
-            {
-                Images.Add(new Bitmap(new MemoryStream(item.Image)));
-            }
-
-        }
 
 
 

+ 4 - 2
AvaloniaApplication1/ViewModels/MainWindowViewModel.cs

@@ -40,13 +40,15 @@ namespace AvaloniaApplication1.ViewModels
             {
                 if(user.IdRole == 2)
                 {
-                    Uc = new MainPage();
                     Id = user.Id;
+                    Uc = new UserPage();
+                    
                 }
                 else
                 {
-                    Uc = new UsersMainPage();
                     Id = user.Id;
+                    Uc = new UserPage();
+                    
                 }
             }
             else

+ 2 - 1
AvaloniaApplication1/ViewModels/UserMainViewModel.cs

@@ -12,6 +12,7 @@ namespace AvaloniaApplication1.ViewModels
     {
         User user;
         List<Gender> genders;
+        
 
         public User User { get => user; set => this.RaiseAndSetIfChanged(ref user, value); }
         public List<Gender> Genders { get => genders; set => this.RaiseAndSetIfChanged(ref genders, value); }
@@ -20,11 +21,11 @@ namespace AvaloniaApplication1.ViewModels
 
         public UserMainViewModel(int id)
         {
+
             user = myConnection.Users.Include(x => x.GenderNavigation).FirstOrDefault(x => x.Id == id);
             Genders = myConnection.Genders.ToList();
         }
 
-        public void Smeshariki() => MainWindowViewModel.Self.Uc = new UsersMainPage();
 
         public DateTimeOffset DateTimeOffset
         {

+ 24 - 0
AvaloniaApplication1/ViewModels/UserViewModel.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using Avalonia.Controls;
+using AvaloniaApplication1.Models;
+using ReactiveUI;
+
+namespace AvaloniaApplication1.ViewModels
+{
+	public class UserViewModel : ViewModelBase
+	{
+        UserControl page = new UsersMainPage();
+        public UserControl Page { get => page; set => this.RaiseAndSetIfChanged(ref page, value); }
+
+     
+        public void toProfile()
+        {
+            Page = new ProfileUser(MainWindowViewModel.Self.Id);
+        }
+        public void toSmesh() 
+        {
+            Page = new UsersMainPage();
+        }
+    }
+}

+ 15 - 24
AvaloniaApplication1/Views/ProfileUser.axaml

@@ -6,30 +6,21 @@
              x:Class="AvaloniaApplication1.ProfileUser"
 			 xmlns:vm="using:AvaloniaApplication1.ViewModels"
 			 x:DataType="vm:UserMainViewModel">
-	
-	<Grid RowDefinitions="50,*,50" ColumnDefinitions="200,*" >
-		<TextBlock Text="Шарарам" Grid.ColumnSpan="2" HorizontalAlignment="Center"	VerticalAlignment="Center" Foreground="Yellow" FontSize="30" FontWeight="Black"></TextBlock>
-		<TextBlock Text="Персонажи"  HorizontalAlignment="Center"  FontSize="30"> </TextBlock>
-		<StackPanel  Grid.Row="1">
-			<Button Content="Профиль"/>
-			<Button Content="Смешарики" Command="{Binding Smeshariki}"/>
-		</StackPanel>
-		<StackPanel Grid.Column="1" Grid.Row="1">
-			<TextBlock Text="{Binding User.LastName}" Margin="0 5"/>
-			<TextBlock Text="{Binding User.FirstName}" Margin="0 5"/>
-			<TextBlock Text="{Binding User.Patronymic}" Margin="0 5"/>
-			<ComboBox ItemsSource="{Binding Genders}" SelectedItem="{Binding User.GenderNavigation}">
-				<ComboBox.ItemTemplate>
-					<DataTemplate>
-						<TextBlock Text="{Binding Title}"/>
-					</DataTemplate>
-				</ComboBox.ItemTemplate>
-			</ComboBox>
+	<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
+		<!--<Image Source="{Binding, Converter= {StaticResource myImageConverter}}" Width="100" Height="100"/>-->
+		<TextBlock Text="{Binding User.LastName}" Margin="0 5"/>
+		<TextBlock Text="{Binding User.FirstName}" Margin="0 5"/>
+		<TextBlock Text="{Binding User.Patronymic}" Margin="0 5"/>
+		<ComboBox ItemsSource="{Binding Genders}" SelectedItem="{Binding User.GenderNavigation}">
+			<ComboBox.ItemTemplate>
+				<DataTemplate>
+					<TextBlock Text="{Binding Title}"/>
+				</DataTemplate>
+			</ComboBox.ItemTemplate>
+		</ComboBox>
 
-			<DatePicker SelectedDate="{Binding DateTimeOffset}"/>
-			<Button Content="Сохранить" Command="{Binding Save}"/>
+		<DatePicker SelectedDate="{Binding DateTimeOffset}"/>
+		<Button Content="Сохранить" Command="{Binding Save}"/>
 
-
-		</StackPanel>
-	</Grid>
+	</StackPanel>
 </UserControl>

+ 19 - 0
AvaloniaApplication1/Views/UserPage.axaml

@@ -0,0 +1,19 @@
+<UserControl 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="AvaloniaApplication1.UserPage"
+			 xmlns:vm="using:AvaloniaApplication1.ViewModels"
+			 x:DataType="vm:UserViewModel">
+	<Grid RowDefinitions="50,*,50" ColumnDefinitions="200,*" >
+		<StackPanel Grid.Column="0" Grid.Row="1">
+			<Button Content="Профиль" Command="{Binding toProfile}"/>
+			<Button Content="Смешарики"/>
+		</StackPanel>
+		<TextBlock Text="Шарарам" Grid.ColumnSpan="2" HorizontalAlignment="Center"	VerticalAlignment="Center" Foreground="Yellow" FontSize="30" FontWeight="Black"></TextBlock>
+		<TextBlock Text="Персонажи"  HorizontalAlignment="Center"  FontSize="30"> </TextBlock>
+		<ContentControl Content="{Binding Page}" Grid.Column="1" Grid.Row="1"/>
+	</Grid>
+
+</UserControl>

+ 15 - 0
AvaloniaApplication1/Views/UserPage.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using AvaloniaApplication1.ViewModels;
+
+namespace AvaloniaApplication1;
+
+public partial class UserPage : UserControl
+{
+    public UserPage()
+    {
+        InitializeComponent();
+        DataContext = new UserViewModel();
+    }
+}

+ 33 - 36
AvaloniaApplication1/Views/UsersMainPage.axaml

@@ -5,46 +5,43 @@
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="AvaloniaApplication1.UsersMainPage"
 			 xmlns:vm="using:AvaloniaApplication1.ViewModels"
-			 x:DataType="vm:MainPageViewModel">
-	<Grid RowDefinitions="50,*,50" ColumnDefinitions="200,*" >
-		<TextBlock Text="Шарарам" Grid.ColumnSpan="2" HorizontalAlignment="Center"	VerticalAlignment="Center" Foreground="Yellow" FontSize="30" FontWeight="Black"></TextBlock>
-		<TextBlock Text="Персонажи"  HorizontalAlignment="Center"  FontSize="30"> </TextBlock>
-		<StackPanel  Grid.Row="1">
-			<Button Content="Профиль" Command="{Binding ProfileUser}"/>
-			<Button Content="Смешарики"/>
-		</StackPanel>
-		<Grid RowDefinitions="50,*" Grid.Column="1" Grid.Row="1">
+			 x:DataType="vm:MainPageViewModel"
+			 xmlns:conv="using:AvaloniaApplication1.Resources">
+
+	<UserControl.Resources>
+		<conv:ImageConverter x:Key="myImageConverter"/>
+	</UserControl.Resources>
+	<Grid RowDefinitions="50,*" Grid.Column="1" Grid.Row="1">
+		<StackPanel Orientation="Horizontal">
+			<TextBox Text="{Binding Search}" Width="200" Watermark="Введите имя: "></TextBox>
+			<ComboBox ItemsSource="{Binding Genders}" SelectedItem="{Binding SelectedGender}">
+				<ComboBox.ItemTemplate>
+					<DataTemplate>
+						<TextBlock Text="{Binding Title}"/>
+					</DataTemplate>
+				</ComboBox.ItemTemplate>
+			</ComboBox>
 			<StackPanel Orientation="Horizontal">
-				<TextBox Text="{Binding Search}" Width="200" Watermark="Введите имя: "></TextBox>
-				<ComboBox ItemsSource="{Binding Genders}" SelectedItem="{Binding SelectedGender}">
-					<ComboBox.ItemTemplate>
-						<DataTemplate>
-							<TextBlock Text="{Binding Title}"/>
-						</DataTemplate>
-					</ComboBox.ItemTemplate>
-				</ComboBox>
-				<StackPanel Orientation="Horizontal">
-					<RadioButton Content="По возрастанию" Command="{Binding OrderByAge}" CommandParameter="1"></RadioButton>
-					<RadioButton Content="По убыванию" Command="{Binding OrderByAge}" CommandParameter="2"></RadioButton>
-				</StackPanel>
+				<RadioButton Content="По возрастанию" Command="{Binding OrderByAge}" CommandParameter="1"></RadioButton>
+				<RadioButton Content="По убыванию" Command="{Binding OrderByAge}" CommandParameter="2"></RadioButton>
 			</StackPanel>
-			<ListBox ItemsSource="{Binding Smeshariki}" Grid.Row="1">
-				<ListBox.ItemTemplate>
-					<DataTemplate>
-						<StackPanel Orientation="Horizontal">
-							<Image Source="{Binding Image}" Width="100" Height="100"/>
-							<StackPanel>
-								<TextBlock Text="{Binding Name, StringFormat= Имя: {0}}"></TextBlock>
-								<TextBlock Text="{Binding Animal, StringFormat= Животное: {0}}"></TextBlock>
-								<TextBlock Text="{Binding Age, StringFormat= Возраст: {0}}"></TextBlock>
-								<TextBlock Text="{Binding GenderNavigation.Title, StringFormat= Пол: {0}}"></TextBlock>
+		</StackPanel>
+		<ListBox ItemsSource="{Binding Smeshariki}" Grid.Row="1">
+			<ListBox.ItemTemplate>
+				<DataTemplate>
+					<StackPanel Orientation="Horizontal">
+						<Image Source="{Binding Image, Converter= {StaticResource myImageConverter}}" Width="100" Height="100"/>
+						<StackPanel>
+							<TextBlock Text="{Binding Name, StringFormat= Имя: {0}}"></TextBlock>
+							<TextBlock Text="{Binding Animal, StringFormat= Животное: {0}}"></TextBlock>
+							<TextBlock Text="{Binding Age, StringFormat= Возраст: {0}}"></TextBlock>
+							<TextBlock Text="{Binding GenderNavigation.Title, StringFormat= Пол: {0}}"></TextBlock>
 
-							</StackPanel>
 						</StackPanel>
-					</DataTemplate>
-				</ListBox.ItemTemplate>
-			</ListBox>
-		</Grid>
+					</StackPanel>
+				</DataTemplate>
+			</ListBox.ItemTemplate>
+		</ListBox>
 	</Grid>
 
 

+ 2 - 0
AvaloniaApplication1/Views/UsersMainPage.axaml.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
+using AvaloniaApplication1.ViewModels;
 
 namespace AvaloniaApplication1;
 
@@ -9,5 +10,6 @@ public partial class UsersMainPage : UserControl
     public UsersMainPage()
     {
         InitializeComponent();
+        DataContext = new MainPageViewModel();
     }
 }