瀏覽代碼

添加显示顺序列,优化人员排序规则

宝臣 王 3 月之前
父節點
當前提交
3d6d8675da

+ 6 - 6
DutyApp/DutyApp.csproj

@@ -44,16 +44,16 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.0" />
-		<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
-		<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
+		<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.3" />
+		<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
+		<PackageReference Include="Avalonia.Labs.Controls" Version="11.1.0" />
 		<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0" />
-		<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
+		<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.3" />
 		<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
-		<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.11" />
+		<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
 		<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
 		<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
-		<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.6" />
+		<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />
 		<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.20" />
 		<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.20">
 			<PrivateAssets>all</PrivateAssets>

+ 7 - 2
DutyApp/Models/DailyDutyRecord.cs

@@ -10,8 +10,9 @@ namespace DutyApp.Models
         private string _dutyOfficer = null!;
         private string _title = null!;
         private string _status = null!;
+        private int _index;
 
-        [Key] 
+        [Key]
         public Guid RecordId { get; set; } = new();
 
         public Guid DutyOfficerId { get; set; }
@@ -45,6 +46,10 @@ namespace DutyApp.Models
             set => SetProperty(ref _status, value);
         }
 
-        public int Index { get; set; }
+        public int Index
+        {
+            get => _index;
+            set => SetProperty(ref _index, value);
+        }
     }
 }

+ 6 - 0
DutyApp/Views/DailyDutyRecordPage.axaml

@@ -224,6 +224,12 @@
                                 </DataTemplate>
                             </DataGridTemplateColumn.CellEditingTemplate>
                         </DataGridTemplateColumn>
+                        <DataGridTextColumn
+                            Width="200"
+                            Binding="{Binding Index}"
+                            Header="顺序"
+                            IsReadOnly="True"
+                            IsVisible="True" />
                     </DataGrid.Columns>
                 </DataGrid>
             </Border>

+ 1 - 2
DutyApp/Views/DutyPreviewWindow.axaml

@@ -47,8 +47,7 @@
                         <Grid
                             x:Name="FirstGrid"
                             Grid.Row="0"
-                            Margin="0,30,0,0"
-                            ColumnDefinitions="*,*,*,*,*,*,*,*" />
+                            Margin="0,30,0,0" />
 
                         <StackPanel
                             x:Name="SecondGrid"

+ 19 - 8
DutyApp/Views/DutyPreviewWindow.axaml.cs

@@ -21,23 +21,29 @@ public partial class DutyPreviewWindow : Window
     {
         if (Records.Count == 0) { return; }
 
-        // 获取前10位人员
-        var top8 = Records.Take(8).ToArray();
-        for (var index = 0; index < top8.Length; index++)
+        // 获取前一半位人员
+        var odd = Records.Count % 2;
+        var middle = Records.Count / 2;
+        var media = odd == 0 ? middle : middle + 1;
+        var top = Records.Take(media).ToArray();
+
+        for (var index = 0; index < top.Length; index++)
         {
-            var record = top8[index];
+            var record = top[index];
             var dailDuty = new DailyDuty()
             {
                 Record = record
             };
 
+            FirstGrid.ColumnDefinitions.Add(new ColumnDefinition());
             FirstGrid.Children.Add(dailDuty);
             Grid.SetColumn(dailDuty, index);
         }
 
-        // 获取后10位人员
-        var top7 = Records.Skip(8).Take(7).ToArray();
-        foreach (var record in top7)
+        // 获取剩余人员
+        var rest = Records.Count - media;
+        var next = Records.Skip(media).Take(rest).ToArray();
+        foreach (var record in next)
         {
             var dailDuty = new DailyDuty()
             {
@@ -69,6 +75,11 @@ public partial class DutyPreviewWindow : Window
             child.Width = firstOrDefault.ActualWidth;
         }
 
-        panel.Spacing = firstOrDefault.ActualWidth / 6;
+        var firstGridChildren = FirstGrid.Children.Count;
+        var secondGridChildren = SecondGrid.Children.Count;
+        if (secondGridChildren < firstGridChildren)
+        {
+            panel.Spacing = firstOrDefault.ActualWidth / (secondGridChildren - 1);
+        }
     }
 }