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 SettingModal : WindowX
|
{
|
public SettingModal()
|
{
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
public ParameterData Data { get; set; }
|
private ObservableCollection<ParameterData> Datasource;
|
|
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(ParameterData data)
|
{
|
}
|
|
private bool ValidateForm()
|
{
|
bool flag = FormGroupHelper.ValidateForm(formPanel);
|
if (flag)
|
{
|
Data.Name = TbName.Text;
|
Data.Type = CbType.Text;
|
Data.Value = TbValue.Text;
|
Data.Unit = TbUnit.Text;
|
Data.Description = TbDescription.Text;
|
Data.PGroup = CbGroup.Text;
|
Data.Source = CbSource.Text;
|
}
|
return flag;
|
}
|
|
public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource)
|
{
|
Datasource = datasource;
|
Data = data;
|
TbName.Text = Data.Name;
|
CbType.SelectedValue = Data.Type;
|
TbValue.Text = Data.Value;
|
TbUnit.Text = Data.Unit;
|
TbDescription.Text = Data.Description;
|
CbGroup.SelectedValue = Data.PGroup;
|
CbSource.SelectedValue = Data.Source;
|
return this.ShowDialog();
|
}
|
}
|
}
|