Quellcode durchsuchen

添加用户信息显示

宝臣 王 vor 3 Monaten
Ursprung
Commit
d90f55ed09

+ 5 - 4
UniformMaterialManagementSystem/ViewModels/LoginPageViewModel.cs

@@ -87,10 +87,11 @@ namespace UniformMaterialManagementSystem.ViewModels
             // 验证密码
             var instance = (LoginPageViewModel)context.ObjectInstance;
             _user = instance._service?.Query(x => x.IsEnabled)
-                 .Include(x => x.SupervisionUnit)
-                 .Include(x => x.Roles)
-                 .ThenInclude(x => x.Menus)
-                 .FirstOrDefault(x => x.LoginName == userName);
+                .Include(x => x.Company)
+                .Include(x => x.SupervisionUnit)
+                .Include(x => x.Roles)
+                .ThenInclude(x => x.Menus)
+                .FirstOrDefault(x => x.LoginName == userName);
 
             return _user == null ? new ValidationResult("用户名不存在") : ValidationResult.Success;
         }

+ 98 - 7
UniformMaterialManagementSystem/Views/MainWindow.xaml

@@ -22,7 +22,6 @@
 
     <Window.Resources>
         <converters:TabIndexToVisibilityConverter x:Key="IsSelectedAndIndexConverter" />
-        <converters:UnicodeToIconConverter x:Key="UnicodeToIconConverter" />
 
         <Style x:Key="ButtonStateStyle" TargetType="{x:Type Button}">
             <Setter Property="Background" Value="Transparent" />
@@ -150,12 +149,104 @@
                     Style="{StaticResource ButtonCloseStyle}" />
             </StackPanel>
 
-            <ToolBarPanel Grid.Row="1" Background="GhostWhite">
-                <Menu
-                    x:Name="MenuMain"
-                    Margin="15,0,0,0"
-                    Background="GhostWhite" />
-            </ToolBarPanel>
+            <Grid Grid.Row="1">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="*" />
+                    <ColumnDefinition Width="Auto" />
+                </Grid.ColumnDefinitions>
+
+                <ToolBarPanel Grid.Column="0" Background="GhostWhite">
+                    <Menu
+                        x:Name="MenuMain"
+                        Margin="15,0,0,0"
+                        Background="GhostWhite" />
+                </ToolBarPanel>
+
+                <Button
+                    x:Name="HoverButton"
+                    Grid.Column="1"
+                    Width="30"
+                    Height="30"
+                    Margin="0,0,10,0"
+                    MouseEnter="HoverButton_OnMouseEnter"
+                    MouseLeave="HoverButton_OnMouseLeave">
+                    <Button.Resources>
+                        <Style TargetType="Border">
+                            <Setter Property="CornerRadius" Value="30" />
+                        </Style>
+                    </Button.Resources>
+                </Button>
+
+                <Popup
+                    x:Name="InfoPopup"
+                    Grid.Column="1"
+                    AllowsTransparency="True"
+                    Placement="Bottom"
+                    PlacementTarget="{Binding ElementName=HoverButton}"
+                    PopupAnimation="Fade">
+                    <Border
+                        Padding="10"
+                        Background="LightBlue"
+                        CornerRadius="5">
+                        <GroupBox x:Name="InfoPopupGroupBox" Header="用户信息">
+                            <Grid>
+                                <Grid.RowDefinitions>
+                                    <RowDefinition />
+                                    <RowDefinition />
+                                    <RowDefinition />
+                                    <RowDefinition />
+                                </Grid.RowDefinitions>
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="Auto" />
+                                    <ColumnDefinition Width="*" />
+                                </Grid.ColumnDefinitions>
+
+                                <Label
+                                    x:Name="WorkYearLabel"
+                                    Grid.Row="0"
+                                    Grid.Column="0"
+                                    Content="工作年度:" />
+                                <Label
+                                    x:Name="WorkYear"
+                                    Grid.Row="0"
+                                    Grid.Column="1"
+                                    HorizontalContentAlignment="Left" />
+
+                                <Label
+                                    Grid.Row="1"
+                                    Grid.Column="0"
+                                    Content="登录账号:" />
+                                <Label
+                                    x:Name="LoginAccount"
+                                    Grid.Row="1"
+                                    Grid.Column="1"
+                                    HorizontalContentAlignment="Left" />
+
+                                <Label
+                                    Grid.Row="2"
+                                    Grid.Column="0"
+                                    Content="所属企业:" />
+                                <Label
+                                    x:Name="Company"
+                                    Grid.Row="2"
+                                    Grid.Column="1"
+                                    HorizontalContentAlignment="Left" />
+
+                                <Label
+                                    Grid.Row="3"
+                                    Grid.Column="0"
+                                    Content="监管单位:" />
+                                <Label
+                                    x:Name="SupervisionUnit"
+                                    Grid.Row="3"
+                                    Grid.Column="1"
+                                    HorizontalContentAlignment="Left" />
+                            </Grid>
+                        </GroupBox>
+                    </Border>
+                </Popup>
+
+            </Grid>
 
             <Grid Grid.Row="2">
                 <Grid.ColumnDefinitions>

+ 27 - 4
UniformMaterialManagementSystem/Views/MainWindow.xaml.cs

@@ -20,6 +20,19 @@ namespace UniformMaterialManagementSystem.Views
             InitializeComponent();
 
             this.DataContext = App.Current.Services.GetService(typeof(MainWindowViewModel));
+
+            HoverButton.Content = App.CurrentUser?.UserName[0];
+
+            WorkYear.Content = App.CurrentUser?.WorkYear;
+            LoginAccount.Content = App.CurrentUser?.UserName;
+            Company.Content = App.CurrentUser?.Company?.Name;
+            SupervisionUnit.Content = App.CurrentUser?.SupervisionUnit.Name;
+
+            Company.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+            SupervisionUnit.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+            WorkYearLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+
+            InfoPopupGroupBox.Width = Math.Max(Math.Ceiling(Company.DesiredSize.Width), Math.Ceiling(SupervisionUnit.DesiredSize.Width)) + Math.Ceiling(WorkYearLabel.DesiredSize.Width) + 20;
         }
 
         private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
@@ -110,9 +123,9 @@ namespace UniformMaterialManagementSystem.Views
         protected override void OnSourceInitialized(EventArgs e)
         {
             base.OnSourceInitialized(e);
-            
+
             var presentationSource = PresentationSource.FromVisual(this);
-            if (presentationSource==null) return;
+            if (presentationSource == null) return;
 
             var source = (HwndSource)presentationSource;
             source.AddHook(HookProc);
@@ -121,9 +134,9 @@ namespace UniformMaterialManagementSystem.Views
         public static IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
         {
             if (msg != WmGetMinMaxInfo) return IntPtr.Zero;
-            
+
             var structure = Marshal.PtrToStructure(lParam, typeof(MinMaxInfo));
-            if(structure == null) return IntPtr.Zero;
+            if (structure == null) return IntPtr.Zero;
 
             var mmi = (MinMaxInfo)structure;
             var monitor = MonitorFromWindow(hWnd, MonitorDefaultTonNearest);
@@ -192,5 +205,15 @@ namespace UniformMaterialManagementSystem.Views
             public Point ptMinTrackSize;
             public Point ptMaxTrackSize;
         }
+
+        private void HoverButton_OnMouseEnter(object sender, MouseEventArgs e)
+        {
+            InfoPopup.IsOpen = true;
+        }
+
+        private void HoverButton_OnMouseLeave(object sender, MouseEventArgs e)
+        {
+            InfoPopup.IsOpen = false;
+        }
     }
 }