实现了添加设备的弹出对话框,未完成对话框的内容
This commit is contained in:
@@ -21,6 +21,7 @@ namespace PMSWPF
|
||||
{
|
||||
var container = new ServiceCollection();
|
||||
container.AddSingleton<NavgatorServices>();
|
||||
container.AddSingleton<IDeviceDialogService, DeviceDialogService>();
|
||||
container.AddSingleton<MainViewModel>();
|
||||
container.AddSingleton<HomeViewModel>();
|
||||
container.AddSingleton<DevicesViewModel>();
|
||||
|
||||
@@ -9,21 +9,21 @@ public class DevicesRepositories:BaseRepositories
|
||||
|
||||
}
|
||||
|
||||
public async Task<int> Add(DbPLC dbPLC)
|
||||
public async Task<int> Add(DbDevice dbDevice)
|
||||
{
|
||||
return await _db.Insertable<DbPLC>(dbPLC).ExecuteCommandAsync();
|
||||
return await _db.Insertable<DbDevice>(dbDevice).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task<List<DbPLC>> GetAll()
|
||||
public async Task<List<DbDevice>> GetAll()
|
||||
{
|
||||
return await _db.Queryable<DbPLC>().ToListAsync();
|
||||
return await _db.Queryable<DbDevice>().ToListAsync();
|
||||
}
|
||||
public async Task<DbPLC> GetById(int id)
|
||||
public async Task<DbDevice> GetById(int id)
|
||||
{
|
||||
return await _db.Queryable<DbPLC>().FirstAsync(p=>p.id == id);
|
||||
return await _db.Queryable<DbDevice>().FirstAsync(p=>p.Id == id);
|
||||
}
|
||||
public async Task<int> DeleteById(int id)
|
||||
{
|
||||
return await _db.Deleteable<DbPLC>(new DbPLC() { id = id }).ExecuteCommandAsync();
|
||||
return await _db.Deleteable<DbDevice>(new DbDevice() { Id = id }).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
20
Services/DeviceDialogService.cs
Normal file
20
Services/DeviceDialogService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using PMSWPF.Models;
|
||||
using PMSWPF.ViewModels.Dialogs;
|
||||
using PMSWPF.Views.Dialogs;
|
||||
|
||||
namespace PMSWPF.Services;
|
||||
|
||||
public class DeviceDialogService : IDeviceDialogService
|
||||
{
|
||||
public async Task<Device> ShowAddDeviceDialog(Device device)
|
||||
{
|
||||
DeviceDialogViewModel ddvm = new DeviceDialogViewModel()
|
||||
{
|
||||
Title = "添加设备"
|
||||
};
|
||||
|
||||
DeviceDialog dialog = new DeviceDialog(ddvm);
|
||||
await dialog.ShowAsync();
|
||||
return device;
|
||||
}
|
||||
}
|
||||
8
Services/IDeviceDialogService.cs
Normal file
8
Services/IDeviceDialogService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using PMSWPF.Models;
|
||||
|
||||
namespace PMSWPF.Services;
|
||||
|
||||
public interface IDeviceDialogService
|
||||
{
|
||||
Task<Device> ShowAddDeviceDialog(Device device);
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
namespace PMSWPF.ViewModels;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using PMSWPF.Models;
|
||||
using PMSWPF.Services;
|
||||
using PMSWPF.ViewModels.Dialogs;
|
||||
using PMSWPF.Views.Dialogs;
|
||||
|
||||
public class DevicesViewModel:ViewModelBase
|
||||
namespace PMSWPF.ViewModels;
|
||||
|
||||
public partial class DevicesViewModel : ViewModelBase
|
||||
{
|
||||
public DevicesViewModel()
|
||||
private readonly IDeviceDialogService _deviceDialogService;
|
||||
|
||||
public DevicesViewModel(IDeviceDialogService deviceDialogService)
|
||||
{
|
||||
|
||||
_deviceDialogService = deviceDialogService;
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public async void AddDevice()
|
||||
{
|
||||
Device device = new Device();
|
||||
await _deviceDialogService.ShowAddDeviceDialog(device);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
13
ViewModels/Dialogs/DeviceDialogViewModel.cs
Normal file
13
ViewModels/Dialogs/DeviceDialogViewModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace PMSWPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class DeviceDialogViewModel:ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string title="添加设备";
|
||||
public DeviceDialogViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
namespace PMSWPF.ViewModels;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
public class ViewModelBase
|
||||
namespace PMSWPF.ViewModels;
|
||||
|
||||
public partial class ViewModelBase:ObservableObject
|
||||
{
|
||||
|
||||
public ViewModelBase()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,16 @@
|
||||
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:dl="clr-namespace:PMSWPF.Views.Dialogs"
|
||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||
d:DataContext="{d:DesignInstance vm:DevicesViewModel}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Content="添加"/>
|
||||
<StackPanel Margin="10 5" Orientation="Horizontal">
|
||||
<Button Margin="5" Command="{Binding AddDeviceCommand}" Content="添加"/>
|
||||
</StackPanel>
|
||||
<TextBlock Text="DevicesView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
</UserControl>
|
||||
|
||||
50
Views/Dialogs/DeviceDialog.xaml
Normal file
50
Views/Dialogs/DeviceDialog.xaml
Normal file
@@ -0,0 +1,50 @@
|
||||
<ui:ContentDialog
|
||||
x:Class="PMSWPF.Views.Dialogs.DeviceDialog"
|
||||
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:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:vmd="clr-namespace:PMSWPF.ViewModels.Dialogs"
|
||||
x:Name="dialog"
|
||||
Title="{Binding Title}"
|
||||
d:DesignHeight="756"
|
||||
d:DesignWidth="700"
|
||||
CloseButtonClick="OnCloseButtonClick"
|
||||
CloseButtonText="取消"
|
||||
Closed="OnClosed"
|
||||
DefaultButton="Primary"
|
||||
PrimaryButtonClick="OnPrimaryButtonClick"
|
||||
PrimaryButtonText="添加"
|
||||
FullSizeDesired="False"
|
||||
IsShadowEnabled="True"
|
||||
d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}"
|
||||
mc:Ignorable="d">
|
||||
<ikw:SimpleStackPanel Spacing="12">
|
||||
<TextBox
|
||||
ui:ControlHelper.Header="设备IP地址:"
|
||||
AcceptsReturn="True"
|
||||
Text="{Binding ElementName=dialog, Path=Title, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<TextBox ui:ControlHelper.Header="PrimaryButtonText"
|
||||
Text="{Binding ElementName=dialog, Path=PrimaryButtonText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<TextBox ui:ControlHelper.Header="SecondaryButtonText"
|
||||
Text="{Binding ElementName=dialog, Path=SecondaryButtonText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<TextBox ui:ControlHelper.Header="CloseButtonText"
|
||||
Text="{Binding ElementName=dialog, Path=CloseButtonText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<ComboBox
|
||||
ui:ControlHelper.Header="DefaultButton"
|
||||
ItemsSource="{Binding Source={x:Type ui:ContentDialogButton}}"
|
||||
SelectedItem="{Binding ElementName=dialog, Path=DefaultButton}" />
|
||||
<CheckBox Content="FullSizeDesired" IsChecked="{Binding ElementName=dialog, Path=FullSizeDesired}" />
|
||||
<CheckBox Content="IsShadowEnabled" IsChecked="{Binding ElementName=dialog, Path=IsShadowEnabled}" />
|
||||
<StackPanel>
|
||||
<Button Click="TryOpenAnother" Content="Try to open another ContentDialog" />
|
||||
<TextBlock
|
||||
x:Name="ErrorText"
|
||||
Margin="0,8,0,0"
|
||||
Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}"
|
||||
Visibility="Collapsed" />
|
||||
</StackPanel>
|
||||
</ikw:SimpleStackPanel>
|
||||
</ui:ContentDialog>
|
||||
48
Views/Dialogs/DeviceDialog.xaml.cs
Normal file
48
Views/Dialogs/DeviceDialog.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using PMSWPF.Models;
|
||||
using PMSWPF.ViewModels.Dialogs;
|
||||
|
||||
namespace PMSWPF.Views.Dialogs;
|
||||
|
||||
public partial class DeviceDialog
|
||||
{
|
||||
|
||||
public DeviceDialog(DeviceDialogViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private void OnCloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
var deferral = args.GetDeferral();
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
private async void TryOpenAnother(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// await new TestContentDialog { Owner = Owner }.ShowAsync();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// ErrorText.Text = ex.Message;
|
||||
// ErrorText.Visibility = Visibility.Visible;
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnClosed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
||||
{
|
||||
ErrorText.Text = string.Empty;
|
||||
ErrorText.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user