Files
DMS/Services/DialogService.cs

190 lines
5.7 KiB
C#
Raw Normal View History

2025-07-04 14:15:44 +08:00
using HandyControl.Tools.Extension;
using iNKORE.UI.WPF.Modern.Controls;
2025-07-03 12:55:00 +08:00
using NPOI.SS.Formula.Functions;
2025-07-05 16:13:46 +08:00
using PMSWPF.Enums;
2025-06-12 18:56:25 +08:00
using PMSWPF.Models;
using PMSWPF.ViewModels.Dialogs;
using PMSWPF.Views.Dialogs;
namespace PMSWPF.Services;
public class DialogService :IDialogService
{
public DialogService()
{
}
2025-06-12 18:56:25 +08:00
public async Task<Device> ShowAddDeviceDialog()
{
var device = new Device();
2025-07-01 21:34:20 +08:00
DeviceDialogViewModel vm = new DeviceDialogViewModel(device);
vm.Title = "添加设备";
vm.PrimaryButContent = "添加设备";
return await ShowConentDialog(vm,device);
}
private static async Task<Device> ShowConentDialog(DeviceDialogViewModel viewModel,Device device)
{
var dialog = new DeviceDialog(viewModel);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return device;
}
return null;
}
2025-07-01 21:34:20 +08:00
public async Task<Device> ShowEditDeviceDialog(Device device)
{
DeviceDialogViewModel vm = new DeviceDialogViewModel(device);
vm.Title = "编辑设备";
vm.PrimaryButContent = "编辑设备";
return await ShowConentDialog(vm,device);
}
public async Task<Mqtt> ShowAddMqttDialog()
{
var mqtt = new Mqtt();
MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
vm.Title = "添加MQTT";
vm.PrimaryButContent = "添加MQTT";
return await ShowConentDialog(vm, mqtt);
}
public async Task<Mqtt> ShowEditMqttDialog(Mqtt mqtt)
{
MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
vm.Title = "编辑MQTT";
vm.PrimaryButContent = "编辑MQTT";
return await ShowConentDialog(vm, mqtt);
}
private static async Task<Mqtt> ShowConentDialog(MqttDialogViewModel viewModel, Mqtt mqtt)
{
var dialog = new MqttDialog(viewModel);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return mqtt;
}
return null;
}
2025-07-01 21:34:20 +08:00
public async Task<bool> ShowConfrimeDialog(string title, string message,string buttonText="确认")
{
ConfrimDialogViewModel vm = new ConfrimDialogViewModel();
vm.Title = title;
vm.Message = message;
vm.PrimaryButtonText = buttonText;
var dialog = new ConfirmDialog(vm);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return true;
}
return false;
}
2025-07-03 12:55:00 +08:00
public async Task<VariableTable> ShowAddVarTableDialog()
{
VarTableDialogViewModel vm = new();
vm.Title = "添加变量表";
vm.PrimaryButtonText = "添加变量表";
vm.VariableTable = new VariableTable();
var dialog = new VarTableDialog(vm);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return vm.VariableTable;
}
return null;
}
2025-07-03 12:55:00 +08:00
public async Task<VariableData> ShowAddVarDataDialog()
{
VarDataDialogViewModel vm = new();
vm.Title = "添加变量";
vm.PrimaryButtonText = "添加变量";
vm.VariableData = new VariableData();
var dialog = new VarDataDialog(vm);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return vm.VariableData;
}
return null;
}
2025-07-01 21:34:20 +08:00
public void ShowMessageDialog(string title, string message)
{
MessageBox.Show(message);
}
2025-07-03 15:29:07 +08:00
public async Task<VariableData> ShowEditVarDataDialog(VariableData variableData)
{
VarDataDialogViewModel vm = new();
vm.Title = "编辑变量";
vm.PrimaryButtonText = "编辑变量";
vm.VariableData = variableData;
var dialog = new VarDataDialog(vm);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return vm.VariableData;
}
return null;
}
2025-07-04 13:40:14 +08:00
public async Task<string> ShowImportExcelDialog()
{
var vm = new ImportExcelDialogViewModel();
var dialog = new ImportExcelDialog(vm);
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
return vm.FilePath;
}
return null;
}
2025-07-04 14:15:44 +08:00
public ContentDialog ShowProcessingDialog(string title, string message)
{
ProcessingDialogViewModel vm = new ProcessingDialogViewModel();
vm.Title = title;
vm.Message = message;
var dialog = new ProcessingDialog(vm);
_ = dialog.ShowAsync(); // 不await让它在后台显示
return dialog;
}
2025-07-05 16:13:46 +08:00
public async Task<PollLevelType?> ShowPollLevelDialog(PollLevelType pollLevelType)
{
var vm = new PollLevelDialogViewModel(pollLevelType);
var dialog = new PollLevelDialog(vm);
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
return vm.SelectedPollLevelType;
}
return null;
}
2025-07-05 18:15:21 +08:00
public async Task<Mqtt?> ShowMqttSelectionDialog()
{
var vm = new MqttSelectionDialogViewModel();
var dialog = new MqttSelectionDialog(vm);
var result = await dialog.ShowAsync();
return result == ContentDialogResult.Primary ? vm.SelectedMqtt : null;
}
public async Task<List<VariableData>> ShowOpcUaImportDialog()
{
var vm= new OpcUaImportDialogViewModel();
var dialog = new OpcUaImportDialog(vm);
var result = await dialog.ShowAsync();
return result == ContentDialogResult.Primary ? vm.GetSelectedVariables().ToList() : null;
2025-07-05 18:15:21 +08:00
}
}