using HMI.Core.Util;
|
using HMI.ParameterManage.Entity;
|
using HMI.ParameterManage.Model;
|
using HMI.UI.DpUtil;
|
using Panuon.WPF.UI;
|
using System;
|
using System.ComponentModel;
|
using System.Windows.Interop;
|
|
namespace HMI.ParameterManage
|
{
|
/// <summary>
|
/// ModalWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class ParameterModal : WindowX
|
{
|
private XmlModel DataModel;
|
public ParameterModal(XmlModel model)
|
{
|
DataModel = model;
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
public ParameterData Data { 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;
|
}
|
|
DataModel.SaveOrUpdateParameter(Data);
|
}
|
catch (Exception ex)
|
{
|
Panuon.WPF.UI.Toast.Show(this, "Error!", ToastPosition.Top);
|
e.Cancel = true;
|
return;
|
}
|
finally
|
{
|
_isProcessing = false;
|
ButtonHelper.SetIsPending(okButton, false);
|
}
|
}
|
base.OnClosing(e);
|
}
|
|
public bool ValidateName(object value, out string err)
|
{
|
return DataModel.ValidateParameterName(value, out err);
|
}
|
|
private bool ValidateForm()
|
{
|
bool flag = FormGroupHelper.ValidateForm(formPanel);
|
if (flag)
|
{
|
Data.Name = TbName.Text;
|
Data.Value = TbValue.Text;
|
Data.Unit = TbUnit.Text;
|
Data.Description = TbDescription.Text;
|
Data.ProductName = TbProductName.Text;
|
Data.PGroup = TbPGroup.Text;
|
}
|
return flag;
|
}
|
|
public bool? Open(ParameterData data)
|
{
|
Data = data;
|
TbName.Text = Data.Name;
|
TbValue.Text = Data.Value;
|
TbUnit.Text = Data.Unit;
|
TbProductName.Text = Data.ProductName;
|
TbDescription.Text = Data.Description;
|
TbPGroup.Text = Data.PGroup;
|
return this.ShowDialog();
|
}
|
}
|
}
|