Бобарикке 5 дней назад
Родитель
Сommit
3ca8fb8e4d

+ 1 - 0
AvaloniaApplication1/AvaloniaApplication1.csproj

@@ -21,6 +21,7 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Xaml.Interactions" Version="0.10.22" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.18">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 23 - 11
AvaloniaApplication1/ViewModels/AdminViewModel.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using Avalonia.Controls;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using ReactiveUI;
 
 namespace AvaloniaApplication1.ViewModels
@@ -8,20 +9,31 @@ namespace AvaloniaApplication1.ViewModels
 	public class AdminViewModel : ViewModelBase
 	{
         UserControl page = new MainPage();
+        bool flag = false;
+        List<string> pages = ["Ñìåøàðèêè","Ïðîôèëü","Äîáàâèòü ñìåøàðèêà"];
+        string selectedItem;
         public UserControl Page { get => page; set => this.RaiseAndSetIfChanged(ref page, value); }
-
-
-        public void toProfile()
-        {
-            Page = new AdminUsers();
-        }
-        public void toSmesh()
+        public List<string> Pages { get => pages; set => this.RaiseAndSetIfChanged(ref pages, value); }
+        public string SelectedItem { get => selectedItem; set { selectedItem = value; navigation(); } }
+        public bool Flag { get => flag; set => this.RaiseAndSetIfChanged(ref flag, value); }
+        public void navigation()
         {
-            Page = new MainPage();
+            if(selectedItem == "Ñìåøàðèêè")
+            {
+                Page = new MainPage();
+            }else if(selectedItem == "Ïðîôèëü")
+            {
+                Page = new AdminUsers();
+            }else if(selectedItem == "Äîáàâèòü ñìåøàðèêà")
+            {
+                Page = new AddSmesh();
+            }
         }
-        public void AddSmesh()
+
+        public void Press()
         {
-            Page = new AddSmesh();
-        }
+            flag = !flag;
+        } 
+            
     }
 }

+ 30 - 3
AvaloniaApplication1/ViewModels/UpdateSmesharikViewModel.cs

@@ -23,23 +23,34 @@ namespace AvaloniaApplication1.ViewModels
 		Smeshariki smesh;
 		List<Gender> genders;
         Bitmap imageSmesh;
+        List<Property> property;
+        List<Property> property2;
+        Property selectedProperty;
         public ICommand DeleteItemCommand { get; }
-        public ObservableCollection<Property> Properties { get; } = new ObservableCollection<Property>();
+        public ObservableCollection<Property> Properties { get; }
         public Smeshariki Smesh { get => smesh; set => this.RaiseAndSetIfChanged(ref smesh, value); }
         public List<Gender> Genders { get => genders; set => this.RaiseAndSetIfChanged(ref genders, value); }
         public Gender selectedGender;
         public Gender SelectedGender { get => selectedGender; set => this.RaiseAndSetIfChanged(ref selectedGender, value); }
         public Bitmap ImageSmesh { get => imageSmesh; set => this.RaiseAndSetIfChanged(ref imageSmesh, value); }
+        public List<Property> Property { get => property; set => this.RaiseAndSetIfChanged(ref property, value); }
+        public List<Property> Property2 { get => property2; set => this.RaiseAndSetIfChanged(ref property2, value); }
+        public Property SelectedProperty { get => selectedProperty; set { selectedProperty = value; AddNewItem(); } }
         public UpdateSmesharikViewModel(int id)
 		{
             Genders = myConnection.Genders.ToList();
             smesh = myConnection.Smesharikis.Include(x => x.GenderNavigation).Include(x=> x.IdProperties).FirstOrDefault(x=> x.Id ==id);
 			imageSmesh = Smesh.Image != null ? new Bitmap(new MemoryStream(smesh.Image)) : new Bitmap("çàãëóøêà.png");
-
+            Properties = new ObservableCollection<Property>(smesh.IdProperties);
+            property2 = myConnection.Properties.ToList();
+            property = property2.Except(Properties).ToList();
         }
 
 		public void Save() 
 		{
+
+            smesh.IdProperties = Properties.ToList();
+
 			myConnection.SaveChanges();
 			MainWindowViewModel.Self.Uc = new AdminPage();
 		} 
@@ -67,6 +78,20 @@ namespace AvaloniaApplication1.ViewModels
 
         public void Back() => MainWindowViewModel.Self.Uc = new AdminPage();
 
+        public async void AddNewItem()
+        {
+            var newItem = SelectedProperty;
+            await Dispatcher.UIThread.InvokeAsync(() =>
+            {
+                if (newItem != null)
+                {
+                    Properties.Add(newItem);
+                    Property = Property.Except(Properties).ToList();
+                }
+            });
+        }
+
+
         public async void DeleteProperty(int id)
         {
             var newItem = await myConnection.Properties.FirstOrDefaultAsync(x=> x.Id == id);
@@ -74,7 +99,9 @@ namespace AvaloniaApplication1.ViewModels
             {
                 if (newItem != null)
                 {
-                    Smesh.IdProperties.Remove(newItem);
+                    Properties.Remove(newItem);
+                    Property = Property2;
+                    Property = Property.Except(Properties).ToList();
                 }
             });
         }

+ 23 - 9
AvaloniaApplication1/Views/AdminPage.axaml

@@ -6,14 +6,28 @@
              x:Class="AvaloniaApplication1.AdminPage"
 			 xmlns:vm="using:AvaloniaApplication1.ViewModels"
 			 x:DataType="vm:AdminViewModel">
-	<Grid RowDefinitions="50,*,50" ColumnDefinitions="200,*" >
-		<StackPanel Grid.Column="0" Grid.Row="1">
-			<Button Content="Пользователи" Command="{Binding toProfile}"/>
-			<Button Content="Смешарики" Command="{Binding toSmesh}"/>
-			<Button Content="Добавить персонажа" Command="{Binding AddSmesh}"/>
+	<SplitView IsPaneOpen="{Binding Flag}"
+           DisplayMode="CompactInline"
+			   CompactPaneLength="100"
+           OpenPaneLength="300"
+			  >
+		<SplitView.Pane>
+			<StackPanel Orientation="Vertical" HorizontalAlignment="Center" Height="300" VerticalAlignment="Stretch">
+				
+				<Button Content=">" Command="{Binding Press}"/>
+				<ListBox ItemsSource="{Binding Pages}" Width="200" Height="300"	SelectionMode="Single" SelectedItem="{Binding SelectedItem}" IsVisible="{Binding Flag}">
+					<ListBox.ItemTemplate>
+						<DataTemplate>
+							<StackPanel Orientation="Horizontal">
+								<TextBlock Text="{Binding }"/>
+							</StackPanel>
+						</DataTemplate>
+					</ListBox.ItemTemplate>
+				</ListBox>
+			</StackPanel>
+		</SplitView.Pane>
+		<StackPanel>
+			<ContentControl Content="{Binding Page}" Grid.Column="1" Grid.Row="1"/>
 		</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>
+	</SplitView>
 </UserControl>

+ 9 - 1
AvaloniaApplication1/Views/UpdateSmesharik.axaml

@@ -27,12 +27,20 @@
 				</ComboBox>
 				<TextBlock Text="Животное:" Margin="0 5"/>
 				<TextBox Text="{Binding Smesh.Animal}" />
+				<TextBlock Text="Качества:" Margin="0 5"/>
+				<ComboBox ItemsSource="{Binding Property}" SelectedItem="{Binding SelectedProperty}" Width="150">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding Title}"/>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
 
 				<Button Content="Изменить фото смешарика" Command="{Binding Image}"/>
 				<Button Content="Сохранить" Command="{Binding Save}"/>
 
 			</StackPanel>
-			<ListBox ItemsSource="{Binding Smesh.IdProperties}" Width="150" Height="300">
+			<ListBox ItemsSource="{Binding Properties}" Width="150" Height="300">
 				<ListBox.ItemTemplate>
 					<DataTemplate>
 						<StackPanel Orientation="Horizontal">