using HMI.Core.Util;
|
using HMI.ParameterManage.Entity;
|
using HMI.UI.DpUtil;
|
using HMI.UI.Util;
|
using Panuon.WPF.UI;
|
using System;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.Linq;
|
|
namespace HMI.ParameterManage
|
{
|
/// <summary>
|
/// ModalWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class TestItemModal : WindowX
|
{
|
public TestItemModal()
|
{
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
public TestItemData Data { get; set; }
|
public ObservableCollection<TestItemData> Datasource { get; set; }
|
|
private bool _isProcessing;
|
|
protected override void OnClosing(CancelEventArgs e)
|
{
|
//Press Continue Button
|
if (DialogResult == true)
|
{
|
if (_isProcessing)
|
{
|
e.Cancel = true;
|
return;
|
}
|
var okButton = WindowXModalDialog.GetOKButton(this);
|
try
|
{
|
_isProcessing = true;
|
ButtonHelper.SetIsPending(okButton, true);
|
if (!ValidateForm())
|
{
|
e.Cancel = true;
|
return;
|
}
|
|
SaveOrUpdateParameter(Data);
|
}
|
catch (Exception ex)
|
{
|
ToastHelper.Error(this, $"Error: {ex.Message}");
|
e.Cancel = true;
|
return;
|
}
|
finally
|
{
|
_isProcessing = false;
|
ButtonHelper.SetIsPending(okButton, false);
|
}
|
}
|
base.OnClosing(e);
|
}
|
|
public bool ValidateName(object value, out string err)
|
{
|
err = null;
|
if (Datasource?.FirstOrDefault(e => e.Name == value.ToString()) != null)
|
{
|
err = this.lang("App.MustBeUnique", this.lang("Pm.Parameter.Name"));
|
return false;
|
}
|
return true;
|
}
|
|
private void SaveOrUpdateParameter(TestItemData data)
|
{
|
}
|
|
private bool ValidateForm()
|
{
|
bool flag = FormGroupHelper.ValidateForm(formPanel);
|
if (flag)
|
{
|
Data.Name = TbName.Text;
|
Data.Type = CbType.Text;
|
Data.Enable = CoEnable.IsChecked == true;
|
Data.LimitDown = NiLimitDown.Value ?? 0;
|
Data.LimitUp = NiLimitUp.Value ?? 0;
|
Data.StrValue = TbStrValue.Text;
|
Data.Offset = NiOffset.Value ?? 0;
|
Data.Source = CbSource.Text;
|
}
|
return flag;
|
}
|
|
public bool? Open(TestItemData data, ObservableCollection<TestItemData> datasource)
|
{
|
Datasource = datasource;
|
Data = data;
|
TbName.Text = Data.Name;
|
CbType.Text = Data.Type;
|
CoEnable.IsChecked = Data.Enable;
|
NiLimitDown.Value = Data.LimitDown;
|
NiLimitUp.Value = Data.LimitUp;
|
TbStrValue.Text = Data.StrValue;
|
NiOffset.Value = Data.Offset;
|
CbSource.Text = Data.Source;
|
return this.ShowDialog();
|
}
|
}
|
}
|