多程序实现
This commit is contained in:
parent
b37d1c1056
commit
e007188418
12
BOB.sln
12
BOB.sln
@ -17,6 +17,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Command", "Command\Command.
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceCommand", "DeviceCommand\DeviceCommand.csproj", "{94177FB3-45E4-466E-BB9F-761295736D35}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessManager", "ProcessManager\ProcessManager.csproj", "{269FEC4B-B5AD-4BE8-853F-56C37A3557A6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{E2897246-96B3-48BE-AA08-4E774BE2BCFB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -51,6 +55,14 @@ Global
|
||||
{94177FB3-45E4-466E-BB9F-761295736D35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{94177FB3-45E4-466E-BB9F-761295736D35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{94177FB3-45E4-466E-BB9F-761295736D35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{269FEC4B-B5AD-4BE8-853F-56C37A3557A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{269FEC4B-B5AD-4BE8-853F-56C37A3557A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{269FEC4B-B5AD-4BE8-853F-56C37A3557A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{269FEC4B-B5AD-4BE8-853F-56C37A3557A6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
|
||||
<ProjectReference Include="..\Logger\Logger.csproj" />
|
||||
<ProjectReference Include="..\Model\Model.csproj" />
|
||||
<ProjectReference Include="..\ORM\ORM.csproj" />
|
||||
<ProjectReference Include="..\Service\Service.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using BOB.Models;
|
||||
using Logger;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Model;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BOB.Models
|
||||
namespace Model
|
||||
{
|
||||
public class DeviceConfigModel
|
||||
{
|
||||
@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
29
ProcessManager/App.xaml
Normal file
29
ProcessManager/App.xaml
Normal file
@ -0,0 +1,29 @@
|
||||
<prism:PrismApplication x:Class="ProcessManager.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ProcessManager"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
>
|
||||
<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" />
|
||||
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</prism:PrismApplication>
|
||||
37
ProcessManager/App.xaml.cs
Normal file
37
ProcessManager/App.xaml.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using BOB;
|
||||
using BOB.ViewModels;
|
||||
using BOB.ViewModels.Dialogs;
|
||||
using BOB.Views;
|
||||
using BOB.Views.Dialogs;
|
||||
using Prism.Ioc;
|
||||
using ProcessManager.ViewModels;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace ProcessManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : PrismApplication
|
||||
{
|
||||
protected override Window CreateShell()
|
||||
{
|
||||
return Container.Resolve<MainWindow>();
|
||||
}
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
|
||||
}
|
||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterForNavigation<MainWindow, PMainViewModel>();
|
||||
containerRegistry.RegisterDialog<Setting, SettingViewModel>("Setting");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
10
ProcessManager/AssemblyInfo.cs
Normal file
10
ProcessManager/AssemblyInfo.cs
Normal 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)
|
||||
)]
|
||||
64
ProcessManager/JsonHelper.cs
Normal file
64
ProcessManager/JsonHelper.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using BOB;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace ProcessManager
|
||||
{
|
||||
public class JsonHelper
|
||||
{
|
||||
private static readonly object _lock = new();
|
||||
public static string SystemPath { get; set; } =
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BOB");
|
||||
|
||||
private static string ConfigFile => Path.Combine(SystemPath, "system.json");
|
||||
|
||||
private static readonly JsonSerializerSettings jsonSettings = new()
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All, // 必须开启
|
||||
Formatting = Formatting.Indented,
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead,
|
||||
};
|
||||
|
||||
#region 配置保存
|
||||
public static void SaveToFile(SystemConfig config)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!Directory.Exists(SystemPath))
|
||||
Directory.CreateDirectory(SystemPath);
|
||||
|
||||
string json = JsonConvert.SerializeObject(config, jsonSettings);
|
||||
File.WriteAllText(ConfigFile, json);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 配置加载
|
||||
public static SystemConfig LoadFromFile()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!File.Exists(ConfigFile))
|
||||
{
|
||||
// 如果不存在自动创建一个默认的 SystemConfig
|
||||
var defaultConfig = new SystemConfig();
|
||||
SaveToFile(defaultConfig);
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(ConfigFile);
|
||||
return JsonConvert.DeserializeObject<SystemConfig>(json, jsonSettings);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 如果反序列化失败,避免程序崩溃
|
||||
throw new Exception("系统配置加载失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
188
ProcessManager/MainWindow.xaml
Normal file
188
ProcessManager/MainWindow.xaml
Normal file
@ -0,0 +1,188 @@
|
||||
<mah:MetroWindow x:Class="ProcessManager.MainWindow"
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
xmlns:local="clr-namespace:ProcessManager"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="600" Width="1000">
|
||||
<materialDesign:DialogHost x:Name="MainDialogHost">
|
||||
<UniformGrid Columns="3"
|
||||
Margin="16"
|
||||
HorizontalAlignment="Center"
|
||||
Cursor="">
|
||||
<materialDesign:Card Width="220"
|
||||
Margin="5"
|
||||
Padding="8"
|
||||
Height="230"
|
||||
Background="DarkSlateGray"
|
||||
Foreground="white"
|
||||
Cursor="">
|
||||
<StackPanel>
|
||||
<TextBlock Margin="16,16,12,8"
|
||||
FontSize="16"
|
||||
Text="设备1" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流负载WS-68030-380T"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流电源SQ0030G1D"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="高压电流双向源PSB11000"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源IT6724C"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源IT6724C"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流负载EAEL9080"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<RadioButton Margin="16,4,16,0"
|
||||
Content="自动启动"
|
||||
Style="{StaticResource MaterialDesignUserForegroundRadioButton}" />
|
||||
<Separator Style="{StaticResource MaterialDesignLightSeparator}" />
|
||||
|
||||
</StackPanel>
|
||||
<materialDesign:Card.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="编辑"
|
||||
Command="{Binding EditCommand}"
|
||||
CommandParameter="设备1" />
|
||||
<MenuItem Header="启动"
|
||||
Command="{Binding StartCommand}"
|
||||
CommandParameter="设备1" />
|
||||
</ContextMenu>
|
||||
</materialDesign:Card.ContextMenu>
|
||||
</materialDesign:Card>
|
||||
<materialDesign:Card Width="220"
|
||||
Margin="5"
|
||||
Height="230"
|
||||
Padding="8"
|
||||
Background="#1976D2"
|
||||
Foreground="white">
|
||||
<StackPanel>
|
||||
<TextBlock Margin="16,16,12,8"
|
||||
FontSize="16"
|
||||
Text="设备2" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流负载WS-68030-380T"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流电源SQ0030G1D"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="高压电流双向源PSB11000"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源IT6724C"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源IT6724C"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流负载EAEL9080"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<RadioButton Margin="16,4,16,0"
|
||||
Content="自动启动"
|
||||
Style="{StaticResource MaterialDesignUserForegroundRadioButton}" />
|
||||
<Separator Style="{StaticResource MaterialDesignLightSeparator}" />
|
||||
|
||||
</StackPanel>
|
||||
<materialDesign:Card.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="编辑"
|
||||
Command="{Binding EditCommand}"
|
||||
CommandParameter="设备2" />
|
||||
<MenuItem Header="启动"
|
||||
Command="{Binding StartCommand}"
|
||||
CommandParameter="设备2" />
|
||||
</ContextMenu>
|
||||
</materialDesign:Card.ContextMenu>
|
||||
</materialDesign:Card>
|
||||
<materialDesign:Card Margin="5"
|
||||
Width="220"
|
||||
Height="230"
|
||||
Padding="8"
|
||||
Background="#FF9800"
|
||||
Foreground="White">
|
||||
<StackPanel Cursor="">
|
||||
<TextBlock Margin="16,16,12,8"
|
||||
FontSize="16"
|
||||
Text="设备3" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流负载WS-68030-380T"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="交流电源SQ0030G1D"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="高压电流双向源PSB11000"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源E36233A"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流电源E36233A"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="低压直流负载EAEL9080"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<RadioButton Margin="16,4,16,0"
|
||||
Content="自动启动"
|
||||
Style="{StaticResource MaterialDesignUserForegroundRadioButton}" />
|
||||
<Separator Style="{StaticResource MaterialDesignLightSeparator}" />
|
||||
|
||||
</StackPanel>
|
||||
<materialDesign:Card.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="编辑"
|
||||
Command="{Binding EditCommand}"
|
||||
CommandParameter="设备3" />
|
||||
<MenuItem Header="启动"
|
||||
Command="{Binding StartCommand}"
|
||||
CommandParameter="设备3" />
|
||||
</ContextMenu>
|
||||
</materialDesign:Card.ContextMenu>
|
||||
</materialDesign:Card>
|
||||
<materialDesign:Card Margin="5" Width="220"
|
||||
Padding="8"
|
||||
Height="140"
|
||||
Background="#00BCD4"
|
||||
Foreground="White">
|
||||
<StackPanel Cursor="">
|
||||
<TextBlock Margin="16,16,12,8"
|
||||
FontSize="16"
|
||||
Text="水冷机和环境箱" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="水冷机LQ7500-D"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<CheckBox Margin="16,4,16,0"
|
||||
Content="环境箱ZXKS"
|
||||
Style="{StaticResource MaterialDesignUserForegroundCheckBox}" />
|
||||
<RadioButton Margin="16,4,16,0"
|
||||
Content="自动启动"
|
||||
Style="{StaticResource MaterialDesignUserForegroundRadioButton}" />
|
||||
<Separator Style="{StaticResource MaterialDesignLightSeparator}" />
|
||||
|
||||
</StackPanel>
|
||||
<materialDesign:Card.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="编辑"
|
||||
Command="{Binding EditCommand}"
|
||||
CommandParameter="水冷机和环境箱" />
|
||||
<MenuItem Header="启动"
|
||||
Command="{Binding StartCommand}"
|
||||
CommandParameter="水冷机和环境箱" />
|
||||
</ContextMenu>
|
||||
</materialDesign:Card.ContextMenu>
|
||||
</materialDesign:Card>
|
||||
|
||||
</UniformGrid>
|
||||
</materialDesign:DialogHost>
|
||||
</mah:MetroWindow>
|
||||
25
ProcessManager/MainWindow.xaml.cs
Normal file
25
ProcessManager/MainWindow.xaml.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using MahApps.Metro.Controls;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
||||
namespace ProcessManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : MetroWindow
|
||||
{
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
15
ProcessManager/ProcessManager.csproj
Normal file
15
ProcessManager/ProcessManager.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<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>
|
||||
<ProjectReference Include="..\BOB\BOB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
160
ProcessManager/Setting.xaml
Normal file
160
ProcessManager/Setting.xaml
Normal file
@ -0,0 +1,160 @@
|
||||
<UserControl x:Class="ProcessManager.Setting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:ProcessManager"
|
||||
Height="500"
|
||||
Width="800">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Margin="16"
|
||||
Orientation="Vertical">
|
||||
|
||||
<!-- 子程序路径 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0 5">
|
||||
<TextBlock Margin="0 5"
|
||||
Text="子程序路径:"
|
||||
materialDesign:HintAssist.Hint="子程序路径" />
|
||||
<TextBox Text="{Binding Config.SubProgramFilePath,Mode=TwoWay}"
|
||||
materialDesign:HintAssist.Hint="子程序路径"
|
||||
Margin="0,0,0,8" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<!-- 默认程序 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0 5">
|
||||
<TextBlock Margin="0 5"
|
||||
Text="子程序路径:"
|
||||
materialDesign:HintAssist.Hint="子程序路径" />
|
||||
<TextBox Text="{Binding Config.DefaultSubProgramFilePath,Mode=TwoWay}"
|
||||
materialDesign:HintAssist.Hint="默认程序"
|
||||
Margin="0,0,0,16" />
|
||||
</StackPanel>
|
||||
<!-- 设备列表 -->
|
||||
<ListBox ItemsSource="{Binding Devices}"
|
||||
SelectedItem="{Binding SelectedDevice, Mode=TwoWay}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="4">
|
||||
<TextBlock Text="{Binding DeviceName}"
|
||||
FontSize="14"
|
||||
materialDesign:HintAssist.Hint="设备名称" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<StackPanel Grid.Column="1"
|
||||
DataContext="{Binding SelectedDevice}">
|
||||
<!-- 设备名称 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="设备名称:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding DeviceName, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- IPAddress -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="IP地址:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.IPAddress, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Port -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="端口:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.Port, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
<!-- IPAddress -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="串口:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.COMPort, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Port -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="波特率:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.BaudRate, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
<!-- IPAddress -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="数据位:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.DataBit, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Port -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="停止位:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.StopBit, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- ReadTimeout -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="读取超时:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.ReadTimeout, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- WriteTimeout -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
<TextBlock Text="写入超时:"
|
||||
Width="120"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding CommunicationConfig.WriteTimeout, Mode=TwoWay}"
|
||||
Width="200" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Grid.ColumnSpan="2"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="20 5">
|
||||
<Button Command="{Binding SaveCommand}"
|
||||
Margin="10 0"
|
||||
Content="保存" />
|
||||
<Button Command="{Binding CancelCommand}"
|
||||
Content="取消" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
19
ProcessManager/Setting.xaml.cs
Normal file
19
ProcessManager/Setting.xaml.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using BOB;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
||||
namespace ProcessManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Setting.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class Setting : UserControl
|
||||
{
|
||||
public Setting()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
83
ProcessManager/ViewModels/PMainViewModel.cs
Normal file
83
ProcessManager/ViewModels/PMainViewModel.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ProcessManager.ViewModels
|
||||
{
|
||||
public class PMainViewModel:BindableBase
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private Dictionary<string, Process> ProcessDic { get; set; } = new Dictionary<string, Process>();
|
||||
public ICommand StartCommand { get; set; }
|
||||
public ICommand EditCommand { get; set; }
|
||||
public PMainViewModel(IDialogService dialogService)
|
||||
{
|
||||
_dialogService = dialogService;
|
||||
EditCommand=new DelegateCommand<string>(OnEdit);
|
||||
StartCommand = new DelegateCommand<string>(OnStart);
|
||||
}
|
||||
|
||||
private void OnStart(string deviceName)
|
||||
{
|
||||
if (ProcessDic.ContainsKey(deviceName))
|
||||
{
|
||||
MessageBox.Show("进程已启动");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
string currentDir = Environment.CurrentDirectory;
|
||||
string exePath = Path.Combine(currentDir, "BOB.exe");
|
||||
if (!File.Exists(exePath))
|
||||
{
|
||||
MessageBox.Show($"未找到文件: {exePath}");
|
||||
return;
|
||||
}
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = exePath,
|
||||
UseShellExecute = true
|
||||
};
|
||||
var process = Process.Start(startInfo);
|
||||
process.EnableRaisingEvents = true;
|
||||
process.Exited += (s, args) =>
|
||||
{
|
||||
ProcessDic.Remove(deviceName);
|
||||
};
|
||||
ProcessDic.Add(deviceName, process);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"启动失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEdit(string deviceName)
|
||||
{
|
||||
if (ProcessDic.ContainsKey(deviceName))
|
||||
{
|
||||
MessageBox.Show("请先关闭进程再进行编辑");
|
||||
return;
|
||||
}
|
||||
var ConfigSystem = JsonHelper.LoadFromFile();
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ "SystemConfig", ConfigSystem },
|
||||
{ "Title", deviceName }
|
||||
};
|
||||
|
||||
_dialogService.ShowDialog("Setting", parameters, r =>
|
||||
{
|
||||
if (r.Result == ButtonResult.OK)
|
||||
{
|
||||
// 用户点击 OK
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
75
ProcessManager/ViewModels/SettingViewModel.cs
Normal file
75
ProcessManager/ViewModels/SettingViewModel.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using BOB;
|
||||
using BOB.Models;
|
||||
using Model;
|
||||
using Prism.Mvvm;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ProcessManager.ViewModels
|
||||
{
|
||||
public class SettingViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
private string _Title;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _Title;
|
||||
set => SetProperty(ref _Title, value);
|
||||
}
|
||||
private DeviceConfigModel _SelectedDevice;
|
||||
|
||||
public DeviceConfigModel SelectedDevice
|
||||
{
|
||||
get => _SelectedDevice;
|
||||
set => SetProperty(ref _SelectedDevice, value);
|
||||
}
|
||||
|
||||
private SystemConfig _config;
|
||||
public SystemConfig Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<DeviceConfigModel> Devices { get; set; } = new ObservableCollection<DeviceConfigModel>();
|
||||
|
||||
public DialogCloseListener RequestClose { get; set; }
|
||||
public ICommand SaveCommand { get; set; }
|
||||
public ICommand CancelCommand { get; set; }
|
||||
public SettingViewModel()
|
||||
{
|
||||
CancelCommand = new DelegateCommand(Cancel);
|
||||
SaveCommand = new DelegateCommand(Save);
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
RequestClose.Invoke();
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
RequestClose.Invoke();
|
||||
}
|
||||
|
||||
public bool CanCloseDialog() => true;
|
||||
|
||||
public void OnDialogClosed() { }
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
// 从参数获取 SystemConfig
|
||||
if (parameters.ContainsKey("SystemConfig"))
|
||||
{
|
||||
Config = parameters.GetValue<SystemConfig>("SystemConfig");
|
||||
Devices.Clear();
|
||||
foreach (var d in Config.DeviceList)
|
||||
Devices.Add(d);
|
||||
}
|
||||
if (parameters.ContainsKey("Title"))
|
||||
{
|
||||
Title= parameters.GetValue<string>("Title");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user