添加项目文件。

This commit is contained in:
2025-05-29 08:58:58 +08:00
parent 9a83d517f0
commit 88ef76bd4d
12 changed files with 278 additions and 0 deletions

7
App.xaml Normal file
View File

@@ -0,0 +1,7 @@
<Application
x:Class="PMSWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PMSWPF">
<Application.Resources />
</Application>

42
App.xaml.cs Normal file
View File

@@ -0,0 +1,42 @@
using System.Configuration;
using System.Data;
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using PMSWPF.Services;
using PMSWPF.ViewModels;
using PMSWPF.Views;
namespace PMSWPF
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
[STAThread]
static void Main(string[] args)
{
using IHost host = CreateHostBuilder(args).Build();
host.Start();
App app = new App();
app.InitializeComponent();
app.MainWindow = host.Services.GetRequiredService<MainView>();
app.MainWindow.Visibility = Visibility.Visible;
app.Run();
}
private static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args).ConfigureServices(services =>
{
services.AddHostedService<DemoBackgroundService>();
services.AddSingleton<MainView>();
services.AddSingleton<MainViewModel>();
});
}
}
}

10
AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

25
Data/DbContext.cs Normal file
View File

@@ -0,0 +1,25 @@
using SqlSugar;
namespace PMSWPF.Data
{
internal class DbContext
{
private static SqlSugarClient _db;
public static SqlSugarClient GetInstance()
{
if (_db == null)
{
string connectionString = "server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=PMS;";
_db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = connectionString,
DbType = DbType.MySql, // 根据实际数据库类型修改如DbType.MySql等
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
}
return _db;
}
}
}

20
Message/MyMessage.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace PMSWPF.Message
{
public class MyMessage : ValueChangedMessage<int>
{
private int count;
public MyMessage(int value) : base(value)
{
}
public int Count { get => count; set => count = value; }
}
}

13
Message/ReqMessage.cs Normal file
View File

@@ -0,0 +1,13 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace PMSWPF.Message
{
public class ReqMessage : RequestMessage<int>
{
public int Count { get; set; }
public ReqMessage(int count)
{
Count = count;
}
}
}

31
PMSWPF.csproj Normal file
View File

@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Remove="App.xaml" />
<Page Include="App.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="HandyControl" Version="3.5.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
<PackageReference Include="SqlSugarCore.MySql" Version="5.1.4.178" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.193" />
</ItemGroup>
<ItemGroup>
<Folder Include="Data\Entities\" />
<Folder Include="Data\Repositories\" />
<Folder Include="Models\" />
<Folder Include="Resources\" />
</ItemGroup>
</Project>

22
PMSWPF.sln Normal file
View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35728.132 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PMSWPF", "PMSWPF.csproj", "{CD3529C9-218C-41EE-B64B-A884DC56E21E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CD3529C9-218C-41EE-B64B-A884DC56E21E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD3529C9-218C-41EE-B64B-A884DC56E21E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD3529C9-218C-41EE-B64B-A884DC56E21E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD3529C9-218C-41EE-B64B-A884DC56E21E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.Hosting;
using PMSWPF.Message;
namespace PMSWPF.Services
{
internal class DemoBackgroundService : BackgroundService
{
int count = 0;
public DemoBackgroundService()
{
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(1000);
count += 1;
var msg = new MyMessage(35) { Count = count };
WeakReferenceMessenger.Default.Send<MyMessage>(msg);
Console.WriteLine("Hello");
}
}
}
}

View File

@@ -0,0 +1,24 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using PMSWPF.Message;
namespace PMSWPF.ViewModels
{
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
{
public MainViewModel()
{
IsActive = true;
}
string text = "Hello Count:";
[ObservableProperty]
string message;
public void Receive(MyMessage message)
{
Message = text + message.Count;
}
}
}

30
Views/MainView.xaml Normal file
View File

@@ -0,0 +1,30 @@
<Window
x:Class="PMSWPF.Views.MainView"
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:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:PMSWPF.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
Title="MainView"
Width="800"
Height="450"
d:DataContext="{d:DesignInstance vm:MainViewModel}"
mc:Ignorable="d">
<StackPanel>
<TextBlock
HorizontalAlignment="Center"
FontSize="36"
Text="{Binding Message}" />
<Border
Width="100"
Height="100"
Background="Orange">
<i:Interaction.Behaviors>
<i:MouseDragElementBehavior />
</i:Interaction.Behaviors>
</Border>
</StackPanel>
</Window>

17
Views/MainView.xaml.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.Windows;
using PMSWPF.ViewModels;
namespace PMSWPF.Views
{
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
public partial class MainView : Window
{
public MainView()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
}
}