实现了Mqtt服务器详情页的简单功能
This commit is contained in:
@@ -89,6 +89,7 @@ public partial class App : Application
|
|||||||
services.AddScoped<DeviceDetailView>();
|
services.AddScoped<DeviceDetailView>();
|
||||||
services.AddScoped<MqttsViewModel>();
|
services.AddScoped<MqttsViewModel>();
|
||||||
services.AddScoped<MqttsView>();
|
services.AddScoped<MqttsView>();
|
||||||
|
services.AddScoped<MqttServerDetailViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigureLogging(ILoggingBuilder loggingBuilder)
|
private void ConfigureLogging(ILoggingBuilder loggingBuilder)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class MqttRepository
|
|||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
using (var _db = DbContext.GetInstance())
|
using (var _db = DbContext.GetInstance())
|
||||||
{
|
{
|
||||||
var result = await _db.Queryable<DbMqtt>()
|
var result = await _db.Queryable<DbMqtt>().Includes(m=>m.VariableDatas)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Logger.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
Logger.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public class VarDataRepository
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Logger.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
|
Logger.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result.Select(d=>d.CopyTo<VariableData>()).ToList();
|
return result.Select(d => d.CopyTo<VariableData>())
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +140,8 @@ public class VarDataRepository
|
|||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
Stopwatch stopwatch2 = new Stopwatch();
|
Stopwatch stopwatch2 = new Stopwatch();
|
||||||
stopwatch2.Start();
|
stopwatch2.Start();
|
||||||
var dbList = variableDatas.Select(vb => vb.CopyTo<DbVariableData>()).ToList();
|
var dbList = variableDatas.Select(vb => vb.CopyTo<DbVariableData>())
|
||||||
|
.ToList();
|
||||||
stopwatch2.Stop();
|
stopwatch2.Stop();
|
||||||
Logger.Info($"复制 VariableData'{variableDatas.Count()}'个, 耗时:{stopwatch2.ElapsedMilliseconds}ms");
|
Logger.Info($"复制 VariableData'{variableDatas.Count()}'个, 耗时:{stopwatch2.ElapsedMilliseconds}ms");
|
||||||
|
|
||||||
@@ -157,13 +159,14 @@ public class VarDataRepository
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="variableData">VariableData实体</param>
|
/// <param name="variableData">VariableData实体</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> UpdateAsync(VariableData variableData)
|
public async Task<bool> UpdateAsync(VariableData variableData)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
using (var _db = DbContext.GetInstance())
|
using (var _db = DbContext.GetInstance())
|
||||||
{
|
{
|
||||||
var result = await _db.Updateable(variableData.CopyTo<DbVariableData>())
|
var result = await _db.UpdateNav(variableData.CopyTo<DbVariableData>())
|
||||||
|
.Include(d => d.Mqtts)
|
||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Logger.Info($"更新VariableData '{variableData.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
Logger.Info($"更新VariableData '{variableData.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
@@ -176,7 +179,7 @@ public class VarDataRepository
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="variableData">VariableData实体</param>
|
/// <param name="variableData">VariableData实体</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> UpdateAsync(List<VariableData> variableDatas)
|
public async Task<bool> UpdateAsync(List<VariableData> variableDatas)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
@@ -195,13 +198,14 @@ public class VarDataRepository
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="variableData">VariableData实体</param>
|
/// <param name="variableData">VariableData实体</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> UpdateAsync(List<VariableData> variableDatas, SqlSugarClient db)
|
public async Task<bool> UpdateAsync(List<VariableData> variableDatas, SqlSugarClient db)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
var dbVarDatas = variableDatas.Select(vd => vd.CopyTo<DbVariableData>());
|
var dbVarDatas = variableDatas.Select(vd => vd.CopyTo<DbVariableData>());
|
||||||
var result = await db.Updateable(dbVarDatas.ToList())
|
var result = await db.UpdateNav(dbVarDatas.ToList())
|
||||||
|
.Include(d => d.Mqtts)
|
||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
@@ -273,7 +277,8 @@ public class VarDataRepository
|
|||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
using var _db = DbContext.GetInstance();
|
using var _db = DbContext.GetInstance();
|
||||||
|
|
||||||
var dbList = variableDatas.Select(vd => vd.CopyTo<DbVariableData>()).ToList();
|
var dbList = variableDatas.Select(vd => vd.CopyTo<DbVariableData>())
|
||||||
|
.ToList();
|
||||||
var result = await _db.Deleteable<DbVariableData>(dbList)
|
var result = await _db.Deleteable<DbVariableData>(dbList)
|
||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|||||||
@@ -76,4 +76,9 @@ public class Mqtt
|
|||||||
/// MQTT客户端登录用户名。
|
/// MQTT客户端登录用户名。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关联的变量数据列表。
|
||||||
|
/// </summary>
|
||||||
|
public List<VariableData>? VariableDatas { get; set; }
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@ public class EnumDescriptionConverter : IValueConverter
|
|||||||
|
|
||||||
private string GetEnumDescription(object enumObj)
|
private string GetEnumDescription(object enumObj)
|
||||||
{
|
{
|
||||||
|
if (enumObj == null) return null; // Add null check here
|
||||||
|
|
||||||
var fi = enumObj.GetType().GetField(enumObj.ToString());
|
var fi = enumObj.GetType().GetField(enumObj.ToString());
|
||||||
|
|
||||||
var attributes =
|
var attributes =
|
||||||
|
|||||||
@@ -175,6 +175,12 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
await AddVariableTable(menu);
|
await AddVariableTable(menu);
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
// 导航到Mqtt服务器
|
||||||
|
case MenuType.MqttMenu:
|
||||||
|
var mqttVM = App.Current.Services.GetRequiredService<MqttServerDetailViewModel>();
|
||||||
|
mqttVM.CurrentMqtt=_dataServices.Mqtts.FirstOrDefault(d=>d.Id == menu.DataId);
|
||||||
|
menu.ViewModel = mqttVM;
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
152
ViewModels/MqttServerDetailViewModel.cs
Normal file
152
ViewModels/MqttServerDetailViewModel.cs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PMSWPF.Models;
|
||||||
|
using PMSWPF.Services;
|
||||||
|
using PMSWPF.Helper;
|
||||||
|
using PMSWPF.Enums;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PMSWPF.ViewModels
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT服务器详情视图模型。
|
||||||
|
/// 负责管理单个MQTT服务器的配置及其关联的变量数据。
|
||||||
|
/// </summary>
|
||||||
|
public partial class MqttServerDetailViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<MqttServerDetailViewModel> _logger;
|
||||||
|
private readonly DataServices _dataServices;
|
||||||
|
private readonly IDialogService _dialogService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前正在编辑的MQTT服务器对象。
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private Mqtt _currentMqtt;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 与当前MQTT服务器关联的变量数据集合。
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private ObservableCollection<VariableData> _associatedVariables;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">日志服务。</param>
|
||||||
|
/// <param name="dataServices">数据服务。</param>
|
||||||
|
/// <param name="dialogService">对话框服务。</param>
|
||||||
|
public MqttServerDetailViewModel(ILogger<MqttServerDetailViewModel> logger, DataServices dataServices,
|
||||||
|
IDialogService dialogService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_dataServices = dataServices;
|
||||||
|
_dialogService = dialogService;
|
||||||
|
AssociatedVariables = new ObservableCollection<VariableData>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnLoaded()
|
||||||
|
{
|
||||||
|
if (CurrentMqtt.VariableDatas != null)
|
||||||
|
{
|
||||||
|
AssociatedVariables = new ObservableCollection<VariableData>(CurrentMqtt.VariableDatas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存MQTT服务器及其关联变量的更改。
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task SaveChanges()
|
||||||
|
{
|
||||||
|
if (CurrentMqtt == null) return;
|
||||||
|
|
||||||
|
// TODO: 实现保存逻辑。这可能涉及到更新Mqtt对象和更新VariableData对象。
|
||||||
|
// 由于Mqtt和VariableData之间的关联可能在数据库中通过中间表维护,
|
||||||
|
// 这里需要根据实际的数据库操作来调整。
|
||||||
|
// 例如,如果Mqtt对象本身包含关联的VariableData列表,则直接保存Mqtt对象即可。
|
||||||
|
// 如果是多对多关系,可能需要更新中间表。
|
||||||
|
|
||||||
|
// 示例:假设Mqtt对象需要更新
|
||||||
|
// await _dataServices.UpdateMqttAsync(CurrentMqtt);
|
||||||
|
|
||||||
|
// 示例:假设变量数据也需要保存
|
||||||
|
// foreach (var variable in AssociatedVariables.Where(v => v.IsModified))
|
||||||
|
// {
|
||||||
|
// await _dataServices.UpdateVariableDataAsync(variable);
|
||||||
|
// }
|
||||||
|
|
||||||
|
NotificationHelper.ShowMessage("MQTT服务器详情保存功能待实现。", NotificationType.Info);
|
||||||
|
_logger.LogInformation("Save changes for MQTT server detail initiated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从当前MQTT服务器中移除选定的变量。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="variablesToRemove">要移除的变量列表。</param>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task RemoveVariables(System.Collections.IList variablesToRemove)
|
||||||
|
{
|
||||||
|
if (CurrentMqtt == null || variablesToRemove == null || variablesToRemove.Count == 0)
|
||||||
|
{
|
||||||
|
NotificationHelper.ShowMessage("请选择要移除的变量。", NotificationType.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var variablesList = variablesToRemove.Cast<VariableData>()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var result = await _dialogService.ShowConfrimeDialog(
|
||||||
|
"确认移除", $"确定要从MQTT服务器 '{CurrentMqtt.Name}' 中移除选定的 {variablesList.Count} 个变量吗?");
|
||||||
|
if (result != true) return;
|
||||||
|
|
||||||
|
foreach (var variable in variablesList) // 使用ToList()避免在迭代时修改集合
|
||||||
|
{
|
||||||
|
// 移除变量与当前MQTT服务器的关联
|
||||||
|
variable.Mqtts?.Remove(CurrentMqtt);
|
||||||
|
// 标记变量为已修改,以便保存时更新数据库
|
||||||
|
variable.IsModified = true;
|
||||||
|
AssociatedVariables.Remove(variable);
|
||||||
|
_logger.LogInformation($"Removed variable {variable.Name} from MQTT server {CurrentMqtt.Name}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 这里需要调用DataServices来更新数据库中VariableData的Mqtt关联
|
||||||
|
// 例如:await _dataServices.UpdateVariableDataAssociationsAsync(variablesToRemove);
|
||||||
|
NotificationHelper.ShowMessage("变量移除成功,请记得保存更改。", NotificationType.Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加变量到当前MQTT服务器。
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task AddVariables()
|
||||||
|
{
|
||||||
|
if (CurrentMqtt == null) return;
|
||||||
|
|
||||||
|
// TODO: 实现选择变量的对话框,让用户选择要添加的变量
|
||||||
|
// 例如:var selectedVariables = await _dialogService.ShowVariableSelectionDialogAsync();
|
||||||
|
// 这里只是一个占位符,实际需要一个UI来选择变量
|
||||||
|
NotificationHelper.ShowMessage("添加变量功能待实现,需要一个变量选择对话框。", NotificationType.Info);
|
||||||
|
_logger.LogInformation("Add variables to MQTT server initiated.");
|
||||||
|
|
||||||
|
// 假设我们已经通过对话框获取到了一些要添加的变量
|
||||||
|
// List<VariableData> newVariables = ...;
|
||||||
|
// foreach (var variable in newVariables)
|
||||||
|
// {
|
||||||
|
// if (variable.Mqtts == null) variable.Mqtts = new List<Mqtt>();
|
||||||
|
// if (!variable.Mqtts.Any(m => m.Id == CurrentMqtt.Id))
|
||||||
|
// {
|
||||||
|
// variable.Mqtts.Add(CurrentMqtt);
|
||||||
|
// variable.IsModified = true; // 标记为已修改
|
||||||
|
// AssociatedVariables.Add(variable);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// NotificationHelper.ShowMessage("变量添加成功,请记得保存更改。", NotificationType.Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ using PMSWPF.Enums;
|
|||||||
using PMSWPF.Helper;
|
using PMSWPF.Helper;
|
||||||
using PMSWPF.Models;
|
using PMSWPF.Models;
|
||||||
using PMSWPF.Services;
|
using PMSWPF.Services;
|
||||||
|
using PMSWPF.Views;
|
||||||
|
|
||||||
namespace PMSWPF.ViewModels;
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ public partial class MqttsViewModel : ViewModelBase
|
|||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
private readonly MqttRepository _mqttRepository;
|
private readonly MqttRepository _mqttRepository;
|
||||||
private readonly ILogger<MqttsViewModel> _logger;
|
private readonly ILogger<MqttsViewModel> _logger;
|
||||||
|
private readonly NavgatorServices _navgatorServices;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<Mqtt> _mqtts;
|
private ObservableCollection<Mqtt> _mqtts;
|
||||||
@@ -25,13 +27,14 @@ public partial class MqttsViewModel : ViewModelBase
|
|||||||
private Mqtt _selectedMqtt;
|
private Mqtt _selectedMqtt;
|
||||||
|
|
||||||
public MqttsViewModel(
|
public MqttsViewModel(
|
||||||
ILogger<MqttsViewModel> logger, IDialogService dialogService, DataServices dataServices
|
ILogger<MqttsViewModel> logger, IDialogService dialogService, DataServices dataServices, NavgatorServices navgatorServices
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_mqttRepository = new MqttRepository();
|
_mqttRepository = new MqttRepository();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
_dataServices = dataServices;
|
_dataServices = dataServices;
|
||||||
|
_navgatorServices = navgatorServices;
|
||||||
|
|
||||||
if (dataServices.Mqtts == null || dataServices.Mqtts.Count == 0)
|
if (dataServices.Mqtts == null || dataServices.Mqtts.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -124,4 +127,18 @@ public partial class MqttsViewModel : ViewModelBase
|
|||||||
_logger.LogError($"编辑MQTT的过程中发生错误:{e}");
|
_logger.LogError($"编辑MQTT的过程中发生错误:{e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导航到MQTT服务器详情页面。
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void NavigateToMqttDetail()
|
||||||
|
{
|
||||||
|
// if (SelectedMqtt == null)
|
||||||
|
// {
|
||||||
|
// NotificationHelper.ShowMessage("请选择一个MQTT服务器以查看详情。", NotificationType.Warning);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// _navgatorServices.NavigateTo<MqttServerDetailView>(SelectedMqtt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ partial class VariableTableViewModel : ViewModelBase
|
|||||||
if (!variable.Mqtts.Any(m => m.Id == selectedMqtt.Id))
|
if (!variable.Mqtts.Any(m => m.Id == selectedMqtt.Id))
|
||||||
{
|
{
|
||||||
variable.Mqtts.Add(selectedMqtt);
|
variable.Mqtts.Add(selectedMqtt);
|
||||||
variable.IsModified = true; // 标记为已修改
|
// variable.IsModified = true; // 标记为已修改
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,10 @@
|
|||||||
<DataTemplate DataType="{x:Type vm:VariableTableViewModel}">
|
<DataTemplate DataType="{x:Type vm:VariableTableViewModel}">
|
||||||
<local:VariableTableView DataContext="{Binding }"/>
|
<local:VariableTableView DataContext="{Binding }"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
<!-- Mqtt服务器详情页 -->
|
||||||
|
<DataTemplate DataType="{x:Type vm:MqttServerDetailViewModel}">
|
||||||
|
<local:MqttServerDetailView DataContext="{Binding }"/>
|
||||||
|
</DataTemplate>
|
||||||
</ContentControl.Resources>
|
</ContentControl.Resources>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
|
||||||
|
|||||||
109
Views/MqttServerDetailView.xaml
Normal file
109
Views/MqttServerDetailView.xaml
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<UserControl x:Class="PMSWPF.Views.MqttServerDetailView"
|
||||||
|
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"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:PMSWPF.Views"
|
||||||
|
xmlns:viewmodels="clr-namespace:PMSWPF.ViewModels"
|
||||||
|
xmlns:models="clr-namespace:PMSWPF.Models"
|
||||||
|
xmlns:iNKORE="clr-namespace:iNKORE.UI.WPF.Modern.Controls;assembly=iNKORE.UI.WPF.Modern"
|
||||||
|
xmlns:converters="clr-namespace:PMSWPF.ValueConverts"
|
||||||
|
xmlns:extensions="clr-namespace:PMSWPF.Extensions"
|
||||||
|
xmlns:enums="clr-namespace:PMSWPF.Enums"
|
||||||
|
d:DataContext="{d:DesignInstance Type=viewmodels:MqttServerDetailViewModel}"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<converters:EnumDescriptionConverter x:Key="EnumDescriptionConverter"/>
|
||||||
|
</UserControl.Resources>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- MQTT Server Details -->
|
||||||
|
<StackPanel Grid.Row="0" Margin="10">
|
||||||
|
<TextBlock Text="MQTT 服务器详情" Style="{StaticResource SubtitleTextBlockStyle}" Margin="0,0,0,10"/>
|
||||||
|
<Grid Margin="0,0,0,10">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="0" Grid.Column="0" Text="名称:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding CurrentMqtt.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,10,0"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="0" Grid.Column="2" Text="主机:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="0" Grid.Column="3" Text="{Binding CurrentMqtt.Host, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="端口:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding CurrentMqtt.Port, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,10,0"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="2" Text="客户端ID:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="3" Text="{Binding CurrentMqtt.ClientID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="2" Grid.Column="0" Text="用户名:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding CurrentMqtt.UserName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,10,0"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="2" Grid.Column="2" Text="密码:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="2" Grid.Column="3" Text="{Binding CurrentMqtt.PassWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="3" Grid.Column="0" Text="发布主题:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding CurrentMqtt.PublishTopic, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,10,0"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="3" Grid.Column="2" Text="订阅主题:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Row="3" Grid.Column="3" Text="{Binding CurrentMqtt.SubscribeTopic, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="4" Grid.Column="0" Text="平台:" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
||||||
|
<!-- <ComboBox Grid.Row="4" Grid.Column="1" SelectedValue="{Binding CurrentMqtt.MqttPlatform, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" -->
|
||||||
|
<!-- Margin="0,0,10,0" -->
|
||||||
|
<!-- ItemsSource="{Binding Source={extensions:EnumBindingSourceExtension {x:Type enums:MqttPlatform}}}" -->
|
||||||
|
<!-- DisplayMemberPath="Description" -->
|
||||||
|
<!-- SelectedValuePath="Value"/> -->
|
||||||
|
</Grid>
|
||||||
|
<Button Content="保存更改" Command="{Binding SaveChangesCommand}" HorizontalAlignment="Right" Margin="0,10,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Associated Variables -->
|
||||||
|
<Grid Grid.Row="1" Margin="10,0,10,10">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Grid.Row="0" Text="关联变量" Style="{StaticResource SubtitleTextBlockStyle}" Margin="0,0,0,10"/>
|
||||||
|
<DataGrid Grid.Row="1" x:Name="AssociatedVariablesDataGrid"
|
||||||
|
ItemsSource="{Binding AssociatedVariables}"
|
||||||
|
AutoGenerateColumns="False"
|
||||||
|
CanUserAddRows="False"
|
||||||
|
CanUserDeleteRows="False"
|
||||||
|
IsReadOnly="True"
|
||||||
|
SelectionMode="Extended">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="名称" Binding="{Binding Name}"/>
|
||||||
|
<DataGridTextColumn Header="地址" Binding="{Binding S7Address}"/>
|
||||||
|
<DataGridTextColumn Header="数据类型" Binding="{Binding DataType}"/>
|
||||||
|
<DataGridTextColumn Header="当前值" Binding="{Binding DataValue}"/>
|
||||||
|
<DataGridTextColumn Header="显示值" Binding="{Binding DisplayValue}"/>
|
||||||
|
<DataGridTextColumn Header="更新时间" Binding="{Binding UpdateTime, StringFormat='yyyy-MM-dd HH:mm:ss'}"/>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Actions for Associated Variables -->
|
||||||
|
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
|
||||||
|
<Button Content="添加变量" Command="{Binding AddVariablesCommand}" Margin="0,0,10,0"/>
|
||||||
|
<Button Content="移除选中变量" Command="{Binding RemoveVariablesCommand}" CommandParameter="{Binding ElementName=AssociatedVariablesDataGrid, Path=SelectedItems}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
@@ -166,6 +166,13 @@
|
|||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Delete}" />
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Delete}" />
|
||||||
</ui:AppBarButton.Icon>
|
</ui:AppBarButton.Icon>
|
||||||
</ui:AppBarButton>
|
</ui:AppBarButton>
|
||||||
|
<!-- 查看详情 -->
|
||||||
|
<ui:AppBarButton Command="{Binding NavigateToMqttDetailCommand}"
|
||||||
|
Label="查看详情">
|
||||||
|
<ui:AppBarButton.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Document}" />
|
||||||
|
</ui:AppBarButton.Icon>
|
||||||
|
</ui:AppBarButton>
|
||||||
<ui:AppBarButton x:Name="ShareButton"
|
<ui:AppBarButton x:Name="ShareButton"
|
||||||
Label="Share">
|
Label="Share">
|
||||||
<ui:AppBarButton.Icon>
|
<ui:AppBarButton.Icon>
|
||||||
|
|||||||
Reference in New Issue
Block a user