修复了添加设备的一些问题
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using PMSWPF.Models;
|
using iNKORE.UI.WPF.Modern.Controls;
|
||||||
|
using PMSWPF.Models;
|
||||||
using PMSWPF.ViewModels.Dialogs;
|
using PMSWPF.ViewModels.Dialogs;
|
||||||
using PMSWPF.Views.Dialogs;
|
using PMSWPF.Views.Dialogs;
|
||||||
|
|
||||||
@@ -6,15 +7,24 @@ namespace PMSWPF.Services;
|
|||||||
|
|
||||||
public class DeviceDialogService : IDeviceDialogService
|
public class DeviceDialogService : IDeviceDialogService
|
||||||
{
|
{
|
||||||
public async Task<Device> ShowAddDeviceDialog(Device device)
|
public async Task<Device> ShowAddDeviceDialog()
|
||||||
{
|
{
|
||||||
|
Device device = new Device();
|
||||||
DeviceDialogViewModel ddvm = new DeviceDialogViewModel(device)
|
DeviceDialogViewModel ddvm = new DeviceDialogViewModel(device)
|
||||||
{
|
{
|
||||||
Title = "添加设备"
|
Title = "添加设备"
|
||||||
};
|
};
|
||||||
|
|
||||||
DeviceDialog dialog = new DeviceDialog(ddvm);
|
DeviceDialog dialog = new DeviceDialog(ddvm);
|
||||||
await dialog.ShowAsync();
|
var res=await dialog.ShowAsync();
|
||||||
|
if (res == ContentDialogResult.Primary)
|
||||||
|
{
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,5 +4,5 @@ namespace PMSWPF.Services;
|
|||||||
|
|
||||||
public interface IDeviceDialogService
|
public interface IDeviceDialogService
|
||||||
{
|
{
|
||||||
Task<Device> ShowAddDeviceDialog(Device device);
|
Task<Device> ShowAddDeviceDialog();
|
||||||
}
|
}
|
||||||
@@ -29,12 +29,16 @@ public partial class DevicesViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Device device = new Device();
|
|
||||||
await _deviceDialogService.ShowAddDeviceDialog(device);
|
Device device= await _deviceDialogService.ShowAddDeviceDialog();
|
||||||
|
if (device != null)
|
||||||
|
{
|
||||||
DbDevice dbDevice = new DbDevice();
|
DbDevice dbDevice = new DbDevice();
|
||||||
device.CopyTo<DbDevice>(dbDevice);
|
device.CopyTo<DbDevice>(dbDevice);
|
||||||
await _devicesRepositories.Add(dbDevice);
|
await _devicesRepositories.Add(dbDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
catch (DbExistException e)
|
catch (DbExistException e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user