模块化

This commit is contained in:
hsc
2025-12-23 15:07:51 +08:00
parent 4da28d08a8
commit 72f3b855d8
51 changed files with 1356 additions and 302 deletions

View File

@@ -15,6 +15,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LAEPS", "LAEPS\LAEPS.csproj", "{5EC9A233-D154-4B77-6911-063269A883E9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoginModule", "LoginModule\LoginModule.csproj", "{F79AC87E-7A5A-486F-BE6C-51E81CA569E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UIShare", "UIShare\UIShare.csproj", "{F7A7D4FA-974C-470F-9543-0B256640BD81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SettingModule", "SettingModule\SettingModule.csproj", "{2C3C2DBB-F782-416B-8571-07D3F533820B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateInfoModule", "UpdateInfoModule\UpdateInfoModule.csproj", "{B99017CA-BB14-426A-BBF0-C0C05C6510CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MainModule", "MainModule\MainModule.csproj", "{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,10 +57,36 @@ Global
{5EC9A233-D154-4B77-6911-063269A883E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EC9A233-D154-4B77-6911-063269A883E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EC9A233-D154-4B77-6911-063269A883E9}.Release|Any CPU.Build.0 = Release|Any CPU
{F79AC87E-7A5A-486F-BE6C-51E81CA569E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F79AC87E-7A5A-486F-BE6C-51E81CA569E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F79AC87E-7A5A-486F-BE6C-51E81CA569E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F79AC87E-7A5A-486F-BE6C-51E81CA569E4}.Release|Any CPU.Build.0 = Release|Any CPU
{F7A7D4FA-974C-470F-9543-0B256640BD81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7A7D4FA-974C-470F-9543-0B256640BD81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7A7D4FA-974C-470F-9543-0B256640BD81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7A7D4FA-974C-470F-9543-0B256640BD81}.Release|Any CPU.Build.0 = Release|Any CPU
{2C3C2DBB-F782-416B-8571-07D3F533820B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C3C2DBB-F782-416B-8571-07D3F533820B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C3C2DBB-F782-416B-8571-07D3F533820B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C3C2DBB-F782-416B-8571-07D3F533820B}.Release|Any CPU.Build.0 = Release|Any CPU
{B99017CA-BB14-426A-BBF0-C0C05C6510CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B99017CA-BB14-426A-BBF0-C0C05C6510CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B99017CA-BB14-426A-BBF0-C0C05C6510CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B99017CA-BB14-426A-BBF0-C0C05C6510CA}.Release|Any CPU.Build.0 = Release|Any CPU
{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F79AC87E-7A5A-486F-BE6C-51E81CA569E4} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{2C3C2DBB-F782-416B-8571-07D3F533820B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{B99017CA-BB14-426A-BBF0-C0C05C6510CA} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{715852A3-D2DE-4C2E-AEF2-2BC0ADBEAC0A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22BD9235-6581-454D-97D8-F4E932F80888}
EndGlobalSection

View File

@@ -7,23 +7,8 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--MaterialDesign: MahApps Compatibility-->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />
<!--MahApps-->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
<!--MaterialDesign-->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
<!--自定义style-->
<ResourceDictionary Source="Resources\Styles\WindowStyle.xaml"></ResourceDictionary>
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@@ -9,10 +9,11 @@ using System.Data;
using System.Reflection;
using System.Windows;
using static System.Runtime.InteropServices.JavaScript.JSType;
using LAEPS.PubEvent;
using UIShare.PubEvent;
using Notifications.Wpf.Core;
using Logger;
using Common;
using ORM;
namespace LAEPS
{
@@ -33,7 +34,6 @@ namespace LAEPS
}
private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//通常全局异常捕捉的都是致命信息
LoggerHelper.Error(e.Exception.Message,e.Exception.StackTrace);
}
@@ -50,20 +50,44 @@ namespace LAEPS
}
protected override void OnInitialized()
{
var login=Container.Resolve<LoginView>();
//初始化数据库
DatabaseConfig.SetTenant(10001);
DatabaseConfig.InitMySql("127.0.0.1",3306,"LAEPS","root","123456");
DatabaseConfig.CreateDatabaseAndCheckConnection(createDatabase: true, checkConnection: true);
SqlSugarContext.InitDatabase();
//显示登录窗口
var login=Container.Resolve<LoginModuleView>();
var re=Container.Resolve<IRegionManager>();
RegionManager.SetRegionManager(login, re);
RegionManager.SetRegionManager(Application.Current.MainWindow, re);
login.Show();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//注册视图
containerRegistry.RegisterForNavigation<MainView>("MainView");
containerRegistry.RegisterForNavigation<SettingView>("SettingView");
containerRegistry.RegisterForNavigation<UpdateInfoView>("UpdateInfoView");
//注册弹窗
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>("MessageBox");
// 注册通知管理器
INotificationManager NotificationManager = new NotificationManager();
containerRegistry.RegisterInstance<INotificationManager>(NotificationManager);
}
//指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中)
protected override IModuleCatalog CreateModuleCatalog()
{
//指定模块加载方式为从文件夹中以反射发现并加载module(推荐用法)
return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
}
//手动模块加载方式
//protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
//{
// Type moduleAType = typeof(LoginModule.LoginModule);
// moduleCatalog.AddModule(new ModuleInfo()
// {
// ModuleName = moduleAType.Name,
// ModuleType = moduleAType.AssemblyQualifiedName,
// InitializationMode = InitializationMode.OnDemand
// });
// base.ConfigureModuleCatalog(moduleCatalog);
//}
}
}

View File

@@ -34,20 +34,21 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignColors" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Notifications.Wpf.Core" Version="2.0.1" />
<PackageReference Include="Prism.Unity" Version="9.0.537" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Logger\Logger.csproj" />
<ProjectReference Include="..\LoginModule\LoginModule.csproj" />
<ProjectReference Include="..\MainModule\MainModule.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\ORM\ORM.csproj" />
<ProjectReference Include="..\Service\Service.csproj" />
<ProjectReference Include="..\SettingModule\SettingModule.csproj" />
<ProjectReference Include="..\UIShare\UIShare.csproj" />
<ProjectReference Include="..\UpdateInfoModule\UpdateInfoModule.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,8 +1,5 @@
using LAEPS.PubEvent;
using ControlzEx.Standard;
using LAEPS.ViewModels;
using Prism.Commands;
using Prism.Mvvm;
using UIShare.PubEvent;
using UIShare.ViewModelBase;
using System.Windows.Input;
namespace LAEPS.ViewModels.Dialogs

View File

@@ -1,9 +1,9 @@
using LAEPS.PubEvent;
using LAEPS.Views;
using LAEPS.Views;
using MaterialDesignThemes.Wpf;
using Notifications.Wpf.Core;
using Prism.Events;
using Prism.Ioc;
using Prism.Modularity;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,6 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using UIShare.PubEvent;
namespace LAEPS.ViewModels
{

View File

@@ -0,0 +1,21 @@
<mah:MetroWindow xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
x:Class="LAEPS.Views.LoginModuleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
xmlns:local="clr-namespace:LAEPS.Views"
mc:Ignorable="d"
Title="学习交流平台"
WindowStartupLocation="CenterScreen"
Height="315"
Width="420"
ResizeMode="NoResize">
<Grid>
<ContentControl prism:RegionManager.RegionName="LoginRegion" />
</Grid>
</mah:MetroWindow>

View File

@@ -1,4 +1,4 @@
using LAEPS.PubEvent;
using UIShare.PubEvent;
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
@@ -23,9 +23,9 @@ namespace LAEPS.Views
/// <summary>
/// Login.xaml 的交互逻辑
/// </summary>
public partial class LoginView : MetroWindow
public partial class LoginModuleView : MetroWindow
{
public LoginView(IEventAggregator eventAggregator)
public LoginModuleView(IEventAggregator eventAggregator)
{
InitializeComponent();
//订阅登录成功事件

View File

@@ -1,151 +0,0 @@
<mah:MetroWindow xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:helpers="clr-namespace:LAEPS.Helpers"
x:Class="LAEPS.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:local="clr-namespace:LAEPS.Views"
mc:Ignorable="d"
Title="学习交流平台"
WindowStartupLocation="CenterScreen"
Height="315"
Width="420"
ResizeMode="NoResize">
<Window.Resources>
<Style TargetType="TextBox"
BasedOn="{StaticResource MahApps.Styles.TextBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="PasswordBox"
BasedOn="{StaticResource MahApps.Styles.PasswordBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Flat}">
<Setter Property="FontSize"
Value="15" />
<Setter Property="FontWeight"
Value="SemiBold" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Background"
Value="#2196F3" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Margin"
Value="0,20,0,0" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<!-- 表单区域 -->
<Border Grid.Row="0"
Background="White"
Margin="20,20,20,0"
CornerRadius="5"
BorderThickness="1"
BorderBrush="#E0E0E0"
Padding="30,20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="用户登录"
HorizontalAlignment="Center"
FontSize="15"
Padding="3" />
<StackPanel Grid.Row="1">
<!-- 用户名输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="17">
<materialDesign:PackIcon Kind="Account" VerticalAlignment="Center"/>
<TextBox Text="{Binding Account}"
mah:TextBoxHelper.Watermark="请输入账号"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
</StackPanel>
<!-- 密码输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="7">
<materialDesign:PackIcon Kind="Lock"
VerticalAlignment="Center" />
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay}"
mah:TextBoxHelper.Watermark="请输入密码"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
</StackPanel>
</StackPanel>
<!-- 登录按钮 -->
<Button Grid.Row="2"
Command="{Binding LoginCommand}"
Content="登 录"
Width="120"
Height="33"
mah:ControlsHelper.CornerRadius="5">
<Button.Effect>
<DropShadowEffect BlurRadius="8"
ShadowDepth="3"
Opacity="0.5" />
</Button.Effect>
</Button>
</Grid>
</Border>
<!-- 底部版权信息 -->
<TextBlock Grid.Row="2"
Text="© 2025 大学生学习交流平台"
Foreground="#777"
FontSize="12"
HorizontalAlignment="Center"
Margin="0,10" />
</Grid>
</mah:MetroWindow>

View File

@@ -1,4 +1,4 @@
using LAEPS.PubEvent;
using UIShare.PubEvent;
using Prism.Events;
using System;
using System.Collections.Generic;

View File

@@ -0,0 +1,21 @@
using LoginModule.Views;
using Prism.Modularity;
using System.Reflection;
namespace LoginModule
{
public class LoginModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("LoginRegion", typeof(LoginView));
regionManager.RegisterViewWithRegion("LoginRegion", typeof(RegisterView));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<LoginView>("LoginView");
containerRegistry.RegisterForNavigation<RegisterView>("RegisterView");
}
}
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,14 +1,15 @@
using LAEPS.PubEvent;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.PubEvent;
using UIShare.ViewModelBase;
namespace LAEPS.ViewModels
namespace LoginModule.ViewModels
{
public class LoginViewModel:BindableBase
public class LoginViewModel: NavigateViewModelBase
{
#region
private string _Password;
@@ -25,11 +26,18 @@ namespace LAEPS.ViewModels
}
#endregion
public ICommand LoginCommand { get; set; }
public ICommand RegisterCommand { get; set; }
private IEventAggregator _eventAggregator;
public LoginViewModel(IContainerProvider containerProvider)
public LoginViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
LoginCommand = new AsyncDelegateCommand(OnLogin);
RegisterCommand = new AsyncDelegateCommand(OnRegister);
}
private async Task OnRegister()
{
_regionManager.RequestNavigate("LoginRegion", "RegisterView");
}
private async Task OnLogin()

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.ViewModelBase;
namespace LoginModule.ViewModels
{
public class RegisterViewModel : NavigateViewModelBase
{
#region
private string _SecondPassword;
public string SecondPassword
{
get => _SecondPassword;
set => SetProperty(ref _SecondPassword, value);
}
private string _Password;
public string Password
{
get => _Password;
set => SetProperty(ref _Password, value);
}
private string _Account;
public string Account
{
get => _Account;
set => SetProperty(ref _Account, value);
}
#endregion
public ICommand BackCommand { get; set; }
public ICommand RegisterCommand { get; set; }
public RegisterViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
BackCommand = new DelegateCommand(OnBack);
RegisterCommand = new AsyncDelegateCommand(OnRegister);
}
private void OnBack()
{
_regionManager.RequestNavigate("LoginRegion", "LoginView");
}
private async Task OnRegister()
{
_regionManager.RequestNavigate("LoginRegion", "LoginView");
}
}
}

View File

@@ -0,0 +1,163 @@
<UserControl x:Class="LoginModule.Views.LoginView"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:local="clr-namespace:LoginModule.Views"
mc:Ignorable="d"
Height="315"
Width="420">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- 这里是你的额外样式 -->
<Style TargetType="TextBox"
BasedOn="{StaticResource MahApps.Styles.TextBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="PasswordBox"
BasedOn="{StaticResource MahApps.Styles.PasswordBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Flat}">
<Setter Property="FontSize"
Value="15" />
<Setter Property="FontWeight"
Value="SemiBold" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Background"
Value="#2196F3" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Margin"
Value="0,20,0,0" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<!-- 表单区域 -->
<Border Grid.Row="0"
Background="White"
Margin="20,20,20,0"
CornerRadius="5"
BorderThickness="1"
BorderBrush="#E0E0E0"
Padding="30,20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="用户登录"
HorizontalAlignment="Center"
FontSize="15"
Padding="3" />
<StackPanel Grid.Row="1">
<!-- 用户名输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="17">
<materialDesign:PackIcon Kind="Account"
VerticalAlignment="Center" />
<TextBox Text="{Binding Account}"
mah:TextBoxHelper.Watermark="请输入账号"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
</StackPanel>
<!-- 密码输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="7">
<materialDesign:PackIcon Kind="Lock"
VerticalAlignment="Center" />
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay}"
mah:TextBoxHelper.Watermark="请输入密码"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
<Label Content="注册账户"
HorizontalAlignment="Right"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding RegisterCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</StackPanel>
</StackPanel>
<!-- 登录按钮 -->
<Button Grid.Row="2"
Command="{Binding LoginCommand}"
Content="登 录"
Width="120"
Height="33"
mah:ControlsHelper.CornerRadius="5">
<Button.Effect>
<DropShadowEffect BlurRadius="8"
ShadowDepth="3"
Opacity="0.5" />
</Button.Effect>
</Button>
</Grid>
</Border>
<!-- 底部版权信息 -->
<TextBlock Grid.Row="2"
Text="© 2025 大学生学习交流平台"
Foreground="#777"
FontSize="12"
HorizontalAlignment="Center"
Margin="0,10" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LoginModule.Views
{
/// <summary>
/// LoginView.xaml 的交互逻辑
/// </summary>
public partial class LoginView : UserControl
{
public LoginView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,175 @@
<UserControl x:Class="LoginModule.Views.RegisterView"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:local="clr-namespace:LoginModule.Views"
mc:Ignorable="d"
Height="315"
Width="420">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- 这里是你的额外样式 -->
<Style TargetType="TextBox"
BasedOn="{StaticResource MahApps.Styles.TextBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="PasswordBox"
BasedOn="{StaticResource MahApps.Styles.PasswordBox}">
<Setter Property="FontSize"
Value="14" />
<Setter Property="BorderThickness"
Value="0,0,0,2" />
<Setter Property="BorderBrush"
Value="#E0E0E0" />
<Setter Property="Padding"
Value="5,8" />
<Setter Property="Background"
Value="Transparent" />
</Style>
<Style TargetType="Button"
BasedOn="{StaticResource MahApps.Styles.Button.Flat}">
<Setter Property="FontSize"
Value="15" />
<Setter Property="FontWeight"
Value="SemiBold" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Background"
Value="#2196F3" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Margin"
Value="0,20,0,0" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<!-- 表单区域 -->
<Border Grid.Row="0"
Background="White"
Margin="20,20,20,0"
CornerRadius="5"
BorderThickness="1"
BorderBrush="#E0E0E0"
Padding="30,20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="用户注册"
HorizontalAlignment="Center"
FontSize="15"
Padding="3" />
<StackPanel Grid.Row="1">
<!-- 用户名输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="7">
<materialDesign:PackIcon Kind="Account"
VerticalAlignment="Center" />
<TextBox Text="{Binding Account}"
mah:TextBoxHelper.Watermark="请输入账号"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
</StackPanel>
<!-- 密码输入 -->
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"
Margin="7">
<materialDesign:PackIcon Kind="Lock"
VerticalAlignment="Center" />
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay}"
mah:TextBoxHelper.Watermark="请输入密码"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
<StackPanel Orientation="Horizontal"
Margin="7">
<materialDesign:PackIcon Kind="Lock"
VerticalAlignment="Center" />
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding SecondPassword, Mode=TwoWay}"
mah:TextBoxHelper.Watermark="请输入二次密码"
mah:TextBoxHelper.ClearTextButton="True"
VerticalContentAlignment="Center"
Width="180"
Height="30"
Padding="0" />
</StackPanel>
<Label Content="返回"
HorizontalAlignment="Right"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding BackCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</StackPanel>
</StackPanel>
<!-- 登录按钮 -->
<Button Grid.Row="2"
Command="{Binding RegisterCommand}"
Content="注 册"
Width="120"
Height="33"
mah:ControlsHelper.CornerRadius="5">
<Button.Effect>
<DropShadowEffect BlurRadius="8"
ShadowDepth="3"
Opacity="0.5" />
</Button.Effect>
</Button>
</Grid>
</Border>
<!-- 底部版权信息 -->
<TextBlock Grid.Row="2"
Text="© 2025 大学生学习交流平台"
Foreground="#777"
FontSize="12"
HorizontalAlignment="Center"
Margin="0,10" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LoginModule.Views
{
/// <summary>
/// RegisterView.xaml 的交互逻辑
/// </summary>
public partial class RegisterView : UserControl
{
public RegisterView()
{
InitializeComponent();
}
}
}

19
MainModule/MainModule.cs Normal file
View File

@@ -0,0 +1,19 @@
using MainModule.Views;
using System.Reflection;
namespace MainModule
{
public class MainModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("ShellViewManager", typeof(MainView));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<MainView>("MainView");
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\MainView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,18 +1,6 @@
using LAEPS.PubEvent;
using LAEPS.ViewModels;
using Logger;
using NLog;
using Prism.Dialogs;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.ViewModelBase;
namespace LAEPS.ViewModels
namespace MainModule.ViewModels
{
public class MainViewModel : NavigateViewModelBase
{

View File

@@ -1,4 +1,4 @@
<UserControl x:Class="LAEPS.Views.MainView"
<UserControl x:Class="MainModule.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@@ -13,7 +13,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LAEPS.Views
namespace MainModule.Views
{
/// <summary>
/// MainView.xaml 的交互逻辑

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Model.Entity
{
public class BaseEntity
public abstract class BaseEntity
{
/// <summary>
/// 主键Id

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Entity
{
public class UserEntity:BaseEntity
{
public string UserName { get; set; }
public string Password { get; set; }
public string Role { get; set; }
public string Status { get; set; }
}
}

180
Model/Result.cs Normal file
View File

@@ -0,0 +1,180 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Result
{
public Result()
{
}
private int _code;
private readonly string _msg;
/// <summary>
/// 结果是否成功
/// </summary>
public bool IsSuccess => _code == 0;
/// <summary>
/// 结果代码
/// </summary>
public int Code { set => _code = value; get => _code; }
/// <summary>
/// 结果消息
/// </summary>
public string Msg => _msg;
/// <summary>
/// 构造方法
/// </summary>
/// <param name="code"></param>
/// <param name="msg"></param>
/// <param name="exception"></param>
protected Result(int code, string msg, Exception? exception = null)
{
if (exception != null)
{
var listMoreMsg = new List<string>();
if (exception is ResultException resultException)
{
listMoreMsg.AddRange(resultException.MessageList);
}
//else if (exception is DeviceControlException deviceControlException)
//{
// listMoreMsg.Add(deviceControlException.ErrorInfo);
//}
else
{
listMoreMsg.Add(exception.Message);
}
var strMoreMsg = string.Join("、", listMoreMsg.Where(it => !string.IsNullOrWhiteSpace(it)));
if (!string.IsNullOrWhiteSpace(strMoreMsg))
{
msg += $"{strMoreMsg}";
}
}
_code = code;
_msg = msg;
}
/// <summary>
/// 返回成功结果
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static Result Success()
{
return new Result(0, "");
}
/// <summary>
/// 返回错误结果
/// </summary>
/// <param name="msg"></param>
/// <param name="exception"></param>
/// <returns></returns>
public static Result Error(string msg, Exception? exception = null)
{
return new Result(-1, msg, exception);
}
}
public class Result<T> : Result
{
public Result()
{
}
private T? _data;
/// <summary>
/// 结果数据
/// </summary>
public T? Data { set => _data = value; get => _data; }
/// <summary>
/// 构造方法
/// </summary>
/// <param name="code"></param>
/// <param name="msg"></param>
/// <param name="data"></param>
/// <param name="exception"></param>
private Result(int code, string msg, T? data, Exception? exception = null) : base(code, msg, exception)
{
_data = data;
}
/// <summary>
/// 返回成功数据
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static Result<T> Success(T data)
{
return new Result<T>(0, "", data);
}
/// <summary>
/// 返回失败信息
/// </summary>
/// <param name="msg"></param>
/// <param name="exception"></param>
/// <returns></returns>
public new static Result<T> Error(string msg, Exception? exception = null)
{
return new Result<T>(-1, msg, default, exception);
}
/// <summary>
/// 返回失败信息和数据
/// </summary>
/// <param name="msg"></param>
/// <param name="data"></param>
/// <param name="exception"></param>
/// <returns></returns>
public static Result<T> Error(string msg, T data, Exception? exception = null)
{
return new Result<T>(-1, msg, data, exception);
}
}
public class ResultException : Exception
{
private List<string>? _messageList;
public List<string> MessageList
{
get
{
List<string> messages = new();
if (_messageList != null)
{
messages.AddRange(_messageList.Where(it => !string.IsNullOrWhiteSpace(it)));
}
return messages;
}
}
public override string Message => string.Join(", ", MessageList);
public ResultException() : base(null)
{
}
public void AddAdditionMessage(string message)
{
_messageList ??= new();
_messageList.Add(message);
}
}
}

View File

@@ -34,7 +34,7 @@ namespace ORM
public static int SnowFlakeWorkId { get; private set; }
#region
private static void InitSqlite()
public static void InitSqlite()
{
DbConnectionType = DbType.Sqlite;
// 获取程序运行目录
@@ -48,20 +48,20 @@ namespace ORM
string DBPath = Path.Combine(folder, "SQL.db");
DbConnectionString = $"Data Source={DBPath};Version=3;";
}
private static void InitMySql(string Server, int Port, string Database, string Uid,string Pwd)
public static void InitMySql(string Server, int Port, string Database, string Uid,string Pwd)
{
DbConnectionType = DbType.MySql;
DbConnectionString =
$"Server={Server};Port={Port};Database={Database};Uid={Uid};Pwd={Pwd};";
}
private static void InitSqlServer(string server,int port,string database,string user,string password)
public static void InitSqlServer(string server,int port,string database,string user,string password)
{
DbConnectionType = DbType.SqlServer;
DbConnectionString =
$"Data Source={server},{port};Initial Catalog={database};user={user};Password={password};";
}
private static void InitSqlServerLocalDb()
public static void InitSqlServerLocalDb()
{
DbConnectionType = DbType.SqlServer;
string baseDir = AppDomain.CurrentDomain.BaseDirectory;

View File

@@ -3,6 +3,7 @@ using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -79,7 +80,44 @@ namespace ORM
};
}
);
}
/// <summary>
/// 初始化数据库,创建所有后缀为 Entity 的表
/// </summary>
public static void InitDatabase()
{
// 加载 Model.dll 文件
string modelDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Model.dll");
if (!File.Exists(modelDllPath))
{
throw new FileNotFoundException($"未找到 Model.dll 文件: {modelDllPath}");
}
// 加载指定的程序集Model.dll
var modelAssembly = Assembly.LoadFrom(modelDllPath);
// 获取所有的 Model层下的Entity 类(后缀为 Entity
var entityTypes = modelAssembly.GetTypes()
.Where(t => t.Name.EndsWith("Entity") && t.IsClass && !t.IsInterface && !t.IsAbstract)
.ToList();
// 使用 SqlSugar 自动创建表
using (var db = DbContext)
{
foreach (var entityType in entityTypes)
{
// 判断该类型是否为类且符合条件
if (entityType.IsClass)
{
// 自动创建表
db.CodeFirst.InitTables(entityType);
}
}
}
}
}
}

View File

@@ -0,0 +1,132 @@
using Model;
using Model.Entity;
using ORM;
using Service.Interface;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Service.Implement
{
public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : BaseEntity, new()
{
protected readonly SqlSugarRepository<TEntity> _repository;
public BaseService(SqlSugarRepository<TEntity> repository)
{
_repository = repository;
}
/// <summary>
/// 查询全部
/// </summary>
public virtual async Task<Result<List<TEntity>>> GetAllAsync()
{
try
{
var list = await _repository.Entities.ToListAsync();
return Result<List<TEntity>>.Success(list);
}
catch (Exception ex)
{
return Result<List<TEntity>>.Error("查询所有数据失败", ex);
}
}
/// <summary>
/// 根据日期查询全部
/// </summary>
public virtual async Task<Result<List<TEntity>>> GetAllAsyncByDate(DateTime? startDate, DateTime? endDate)
{
try
{
var list = await _repository.Entities.Where(x => x.CreateTime >= startDate && x.CreateTime <= endDate).ToListAsync();
return Result<List<TEntity>>.Success(list);
}
catch (Exception ex)
{
return Result<List<TEntity>>.Error("查询所有数据失败", ex);
}
}
/// <summary>
/// 分页查询
/// </summary>
public virtual async Task<Result<List<TEntity>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total)
{
try
{
var list = await _repository.Entities
.OrderBy(d => d.Id)
.ToPageListAsync(pageIndex, pageSize, total);
total.Value = (int)Math.Ceiling((double)total.Value / pageSize);
return Result<List<TEntity>>.Success(list);
}
catch (Exception ex)
{
return Result<List<TEntity>>.Error("分页查询数据失败", ex);
}
}
/// <summary>
/// 分页查询,并可以根据日期范围进行过滤
/// </summary>
public virtual async Task<Result<List<TEntity>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, DateTime? startDate, DateTime? endDate)
{
try
{
var list = await _repository.Entities
.Where(x=>x.CreateTime>=startDate&&x.CreateTime <= endDate)
.OrderBy(d => d.Id)
.ToPageListAsync(pageIndex, pageSize, total);
total.Value = (int)Math.Ceiling((double)total.Value / pageSize);
return Result<List<TEntity>>.Success(list);
}
catch (Exception ex)
{
return Result<List<TEntity>>.Error("分页查询数据失败", ex);
}
}
/// <summary>
/// 插入单条数据
/// </summary>
public virtual async Task<Result<bool>> InsertAsync(TEntity entity)
{
try
{
var result = await _repository.Context.Insertable(entity).ExecuteCommandAsync();
return Result<bool>.Success(result > 0);
}
catch (Exception ex)
{
return Result<bool>.Error("插入数据失败", ex);
}
}
/// <summary>
/// 删除单条数据(根据 Id
/// </summary>
/// <param name="id">主键 Id</param>
public virtual async Task<Result<bool>> DeleteAsync(long id)
{
if (id <= 0)
return Result<bool>.Error("主键 Id 无效,无法删除");
try
{
// 删除实体
var result = await _repository.Context
.Deleteable<TEntity>()
.Where(x => x.Id == id)
.ExecuteCommandAsync();
return Result<bool>.Success(result > 0);
}
catch (Exception ex)
{
return Result<bool>.Error("删除数据失败", ex);
}
}
}
}

View File

@@ -0,0 +1,90 @@
using Model;
using Model.Entity;
using ORM;
using Service.Implement;
public class UserService: BaseService<UserEntity>
{
public UserService(SqlSugarRepository<UserEntity> repository) : base(repository)
{
}
public async Task<Result<UserEntity>> GetUserByUserNameAsync(string username)
{
if (string.IsNullOrWhiteSpace(username))
return Result<UserEntity>.Error("用户名不能为空");
try
{
var user = await _repository.Entities
.Where(x => x.UserName == username)
.FirstAsync();
if (user == null)
return Result<UserEntity>.Error("用户不存在");
return Result<UserEntity>.Success(user);
}
catch (Exception ex)
{
return Result<UserEntity>.Error("获取用户失败", ex);
}
}
public override async Task<Result<bool>> InsertAsync(UserEntity entity)
{
if (entity == null)
return Result<bool>.Error("用户数据不能为空");
try
{
// 唯一性校验
bool exists = await _repository.Entities
.AnyAsync(x => x.UserName == entity.UserName);
if (exists)
return Result<bool>.Error("用户名已存在");
var result = await _repository.InsertAsync(entity);
return Result<bool>.Success(result);
}
catch (Exception ex)
{
return Result<bool>.Error("插入数据失败", ex);
}
}
/// <summary>
/// 更新单条用户记录
/// </summary>
/// <param name="entity">要更新的用户实体Id 必须有值</param>
public async Task<Result<bool>> UpdateAsync(UserEntity entity)
{
if (entity == null)
return Result<bool>.Error("用户数据不能为空");
if (entity.Id <= 0)
return Result<bool>.Error("主键 Id 无效,无法更新");
try
{
// 唯一性校验(可选,如果允许改用户名就检查)
bool exists = await _repository.Entities
.Where(x => x.UserName == entity.UserName && x.Id != entity.Id)
.AnyAsync();
if (exists)
return Result<bool>.Error("用户名已存在");
// 更新整个实体
var result = await _repository.UpdateAsync(entity);
return Result<bool>.Success(result);
}
catch (Exception ex)
{
return Result<bool>.Error("更新用户失败", ex);
}
}
}

View File

@@ -0,0 +1,55 @@
using Model;
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Service.Interface
{
/// <summary>
/// 泛型基础服务接口(返回 Result 封装)
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
public interface IBaseService<TEntity> where TEntity : class, new()
{
/// <summary>
/// 查询全部
/// </summary>
/// <returns>返回包含数据的 Result</returns>
Task<Result<List<TEntity>>> GetAllAsync();
/// <summary>
/// 根据日期查询全部
/// </summary>
/// <param name="startDate">开始日期</param>
/// <param name="endDate">结束日期</param>
/// <returns>返回包含日期范内的数据的 Result</returns>
Task<Result<List<TEntity>>> GetAllAsyncByDate(DateTime? startDate, DateTime? endDate);
/// <summary>
/// 插入单条数据
/// </summary>
/// <param name="entity"></param>
/// <returns>返回操作是否成功的 Result</returns>
Task<Result<bool>> InsertAsync(TEntity entity);
/// <summary>
/// 分页查询
/// </summary>
/// <param name="pageIndex">页码从1开始</param>
/// <param name="pageSize">每页数量</param>
/// <param name="total">总条数(输出参数)</param>
/// <returns>返回包含分页数据的 Result</returns>
Task<Result<List<TEntity>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total);
/// <summary>
/// 分页查询,并根据日期范围进行过滤
/// </summary>
/// <param name="pageIndex">页码从1开始</param>
/// <param name="pageSize">每页数量</param>
/// <param name="total">总条数(输出参数)</param>
/// <param name="startDate">开始日期</param>
/// <param name="endDate">结束日期</param>
/// <returns>返回包含分页数据的 Result</returns>
Task<Result<List<TEntity>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, DateTime? startDate, DateTime? endDate);
}
}

View File

@@ -0,0 +1,19 @@
using SettingModule.Views;
using System.Reflection;
namespace SettingModule
{
public class SettingModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("ShellViewManager", typeof(SettingView));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<SettingView>("SettingView");
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\LoginView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\SettingView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIShare.ViewModelBase;
namespace LAEPS.ViewModels
namespace SettingModule.ViewModels
{
public class SettingViewModel : NavigateViewModelBase
{

View File

@@ -1,4 +1,4 @@
<UserControl x:Class="LAEPS.Views.SettingView"
<UserControl x:Class="SettingModule.Views.SettingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@@ -13,7 +13,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LAEPS.Views
namespace SettingModule.Views
{
/// <summary>
/// SettingView.xaml 的交互逻辑

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace LAEPS.Converters
namespace UIShare.Converters
{
public class BooleanToVisibilityConverter : IValueConverter
{

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace LAEPS.Helpers
namespace UIShare.Helpers
{
public static class PasswordBoxHelper
{

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAEPS.PubEvent
namespace UIShare.PubEvent
{
public class LoginSuccessEvent:PubSubEvent
{

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAEPS.PubEvent
namespace UIShare.PubEvent
{
public class OverlayEvent : PubSubEvent<bool>
{

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAEPS.PubEvent
namespace UIShare.PubEvent
{
public class WaitingEvent : PubSubEvent<bool>
{

View File

@@ -0,0 +1,21 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- 引用MaterialDesign和MahApps的资源 -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />
<!-- MahApps资源 -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
<!-- Material Design资源 -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
<!--自定义style-->
<ResourceDictionary Source="/UIShare;component/Styles/WindowStyle.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

20
UIShare/UIShare.csproj Normal file
View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Unity" Version="9.0.537" />
<PackageReference Include="MaterialDesignColors" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
<PackageReference Include="Notifications.Wpf.Core" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Behaviors\" />
</ItemGroup>
</Project>

View File

@@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAEPS.ViewModels
namespace UIShare.ViewModelBase
{
public abstract class DialogViewModelBase : BindableBase,IDialogAware
{

View File

@@ -5,18 +5,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LAEPS.ViewModels
namespace UIShare.ViewModelBase
{
public abstract class NavigateViewModelBase : BindableBase, INavigationAware
{
public DialogCloseListener RequestClose { get; set; }
public IEventAggregator _eventAggregator;
public IDialogService _dialogService;
public IRegionManager _regionManager;
private INotificationManager _notificationManager;
public NavigateViewModelBase(IContainerProvider containerProvider)
{
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
_dialogService = containerProvider.Resolve<IDialogService>();
_regionManager = containerProvider.Resolve<IRegionManager>();
_notificationManager = containerProvider.Resolve<INotificationManager>();
}

View File

@@ -0,0 +1,19 @@
using System.Reflection;
using UpdateInfoModule.Views;
namespace UpdateInfoModule
{
public class UpdateInfoModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("ShellViewManager", typeof(UpdateInfoView));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<UpdateInfoView>("UpdateInfoView");
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\UpdateInfoView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,12 +1,6 @@
using Prism.Dialogs;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIShare.ViewModelBase;
namespace LAEPS.ViewModels
namespace UpdateInfoModule.ViewModels
{
public class UpdateInfoViewModel : NavigateViewModelBase
{

View File

@@ -1,4 +1,4 @@
<UserControl x:Class="LAEPS.Views.UpdateInfoView"
<UserControl x:Class="UpdateInfoModule.Views.UpdateInfoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@@ -13,7 +13,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LAEPS.Views
namespace UpdateInfoModule.Views
{
/// <summary>
/// UpdateInfoView.xaml 的交互逻辑