2 Komitmen 21c3c0bc03 ... 98757179b3

Pembuat SHA1 Pesan Tanggal
  宝臣 王 98757179b3 Merge branch 'master' of https://git.xxb.lttc.cn/wangbc/UniformMaterialManagementSystem 3 bulan lalu
  宝臣 王 8750ca2ae2 添加单位类型过滤不同的单位名称功能 3 bulan lalu

+ 29 - 4
UniformMaterialManagementSystem/ViewModels/RegisterPageViewModel.cs

@@ -1,4 +1,5 @@
-using CommunityToolkit.Mvvm.ComponentModel;
+using System.Collections.ObjectModel;
+using CommunityToolkit.Mvvm.ComponentModel;
 using CommunityToolkit.Mvvm.Input;
 
 using System.ComponentModel.DataAnnotations;
@@ -30,6 +31,29 @@ namespace UniformMaterialManagementSystem.ViewModels
         [Required(ErrorMessage = "单位类型不能为空")]
         private string _selectedUnitType = string.Empty;
 
+        partial void OnSelectedUnitTypeChanged(string value)
+        {
+            List<Company> list;
+            if (value.StartsWith("Material"))
+            {
+                list = _companies.Where(x => x is { Category: "material", IsEnabled: true }).ToList();
+            }
+            else if (value.StartsWith("Product"))
+            {
+                list = _companies.Where(x => x is { Category: "product", IsEnabled: true }).ToList();
+            }
+            else
+            {
+                list = _companies.ToList();
+            }
+
+            CompanyList.Clear();
+            foreach (var company in list)
+            {
+                CompanyList.Add(company);
+            }
+        }
+
         [ObservableProperty]
         private ICollection<SupervisionUnit> _units = [];
 
@@ -37,11 +61,12 @@ namespace UniformMaterialManagementSystem.ViewModels
         [Required(ErrorMessage = "单位不能为空")]
         private SupervisionUnit _selectedUnit = null!;
 
+        private readonly ICollection<Company> _companies;
+
         [ObservableProperty]
-        private ICollection<Company> _companyList = [];
+        private ObservableCollection<Company> _companyList = [];
 
         [ObservableProperty]
-        [Required(ErrorMessage = "公司不能为空")]
         private Company? _selectedCompany;
 
         [ObservableProperty]
@@ -75,7 +100,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                 _roles[unitType.Key] = roles.First(r => r.Name == unitType.Key);
             }
 
-            CompanyList = context.Companies.ToList();
+            _companies = context.Companies.ToList();
 
             Units = context.SupervisionUnits.ToList();
         }

+ 1 - 1
UniformMaterialManagementSystem/Views/LoginAndRegister/RegisterPage.xaml

@@ -190,7 +190,7 @@
                         Padding="5,0,0,0"
                         BorderBrush="#019b9b"
                         DisplayMemberPath="Name"
-                        ItemsSource="{Binding CompanyList}"
+                        ItemsSource="{Binding CompanyList, Mode=OneWay}"
                         SelectedItem="{Binding SelectedCompany}"
                         Style="{StaticResource WpfComboBoxStyle}"
                         Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}" />