Prechádzať zdrojové kódy

почти сделали добавление и сделали сортировку с костылями

мухинна 11 mesiacov pred
rodič
commit
ae52282245

+ 32 - 4
AvaloniaApplication5/ViewModels/MainWindowViewModel.cs

@@ -25,20 +25,48 @@ namespace AvaloniaApplication5.ViewModels
         public PageUserCabinetViewModel PageUCabinetVM { get => pageUCabinetVM; set => pageUCabinetVM = value; }
 
         private PageUserCabinetViewModel pageUCabinetVM;
-
-         UserControl ucAdmin;
+        #region VMadmin
+        
+        UserControl ucAdmin;
         public UserControl UCAdmin
         {
             get => ucAdmin;
             set => this.RaiseAndSetIfChanged(ref ucAdmin, value);
         }
-        public List<Logintable> UserList => DBConnect.Logintables.Include(x => x.IdRoleNavigation).Include(x => x.User.IdGenderNavigation).ToList();
+        
+        public MainWindowViewModel()
+        {
+            userList = DBConnect.Logintables.Include(x => x.IdRoleNavigation).Include(x => x.User.IdGenderNavigation).ToList();
+        }
+        List<Logintable> userList;
+        public List<Logintable> UserList { get => userList; set =>this.RaiseAndSetIfChanged(ref userList,value); }
         public void EditUser(int id)
         {
-            PageUCabinetVM = new PageUserCabinetViewModel(DBConnect, id);
+            PageUCabinetVM = id==0?  new PageUserCabinetViewModel(DBConnect):new PageUserCabinetViewModel(DBConnect, id);
             UCAdmin = new PageUserCabinet();
         }
+        public List<string> OrdersName => new List<string>() { "По возрастанию", "По убыванию" };
+        string orderByName = "По возрастанию";
+        public string OrderByName { 
+            get => orderByName; 
+        set
+            {
+                orderByName = value;
+                switch (value)
+                {
+                    case "По возрастанию":                        
+                        UserList = UserList.OrderBy(x => x.User.Name).ToList();
+                        break;
+                    case "По убыванию":
+                        UserList = UserList.OrderByDescending(x => x.User.Name).ToList();
+                        break;
+                }                
+            }
+        }
+
+        
 
+        #endregion
 
         public void LoadPageList()
         {

+ 8 - 1
AvaloniaApplication5/ViewModels/PageUserCabinetViewModel.cs

@@ -19,6 +19,12 @@ namespace AvaloniaApplication5.ViewModels
             CurrentUser = dBConnect.Logintables.Include(x=>x.IdRoleNavigation).Include(x=>x.User.IdGenderNavigation).FirstOrDefault(x => x.Id == idUser);
             oldPass = currentUser.Password;
         }
+        public PageUserCabinetViewModel(_1234Context dBConnect)
+        {
+            this.dBConnect = dBConnect;
+            int maxid = dBConnect.Logintables.Select(x => x.Id).Max();
+            currentUser = new Logintable() { User = new User() { IdLogin = ++maxid }, IdRole =2 };
+        }
 
         public Logintable? CurrentUser { get => currentUser; set => currentUser = value; }
 
@@ -38,7 +44,8 @@ namespace AvaloniaApplication5.ViewModels
         {
            if (CurrentUser.Password == null || CurrentUser.Password =="") CurrentUser.Password = oldPass; 
            if (changePass==(currentUser.Password == PasswordMatch))
-            {               
+            {
+                if (currentUser.Id == 0) dBConnect.Add(currentUser);
                 dBConnect.SaveChanges();
                 Message = "Ñîõðàíåíî óñïåøíî";
             }

+ 1 - 1
AvaloniaApplication5/Views/PageUserCabinet.axaml

@@ -11,7 +11,7 @@
 		<TextBox Text="{Binding PageUCabinetVM.CurrentUser.User.Name}"/>
 		<TextBlock Text="Логин"/>
 		<TextBox Text="{Binding PageUCabinetVM.CurrentUser.Login}"/>
-		<CheckBox Content="Изменить парль" IsChecked="{Binding PageUCabinetVM.ChangePass}"/>
+		<CheckBox Content="Изменить пароль" IsChecked="{Binding PageUCabinetVM.ChangePass}"/>
 		<StackPanel IsVisible="{Binding PageUCabinetVM.ChangePass}">
 			<TextBlock Text="Введите новый пароль"/>
 			<TextBox Text="{Binding PageUCabinetVM.CurrentUser.Password,Mode=OneWayToSource}" PasswordChar="•"/>

+ 11 - 3
AvaloniaApplication5/Views/PageUserList.axaml

@@ -6,8 +6,16 @@
               xmlns:vm="using:AvaloniaApplication5.ViewModels"
              x:DataType="vm:MainWindowViewModel"
 			 x:Class="AvaloniaApplication5.Views.PageUserList">
-	<Grid ColumnDefinitions="*,*">
-		<ListBox Grid.Column="0" ItemsSource="{Binding UserList}">
+	<Grid ColumnDefinitions="*,*" RowDefinitions="50,*">
+		<StackPanel Orientation="Horizontal" Grid.Row="0">
+			<Button Content="Добавить пользователя" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).EditUser}" CommandParameter="0"/>
+			<ComboBox ItemsSource="{Binding OrdersName}" SelectedValue="{Binding OrderByName}">
+			
+			</ComboBox>
+				
+			
+		</StackPanel>
+		<ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{Binding UserList}">
 			<ListBox.ItemTemplate>
 				<DataTemplate>
 					<StackPanel>
@@ -26,7 +34,7 @@
 				</DataTemplate>
 			</ListBox.ItemTemplate>
 		</ListBox>
-		<ContentControl Grid.Column="1" Content="{Binding UCAdmin}"/>
+		<ContentControl Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Content="{Binding UCAdmin}"/>
 	</Grid>
 	
 </UserControl>