using HMI.Core.Entity;
|
using HMI.ParameterManage.Model;
|
using HMI.UI.DpUtil;
|
using HMI.UI.Util;
|
using Panuon.WPF.UI;
|
using System;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Windows;
|
using System.Windows.Controls;
|
|
namespace HMI.ParameterManage
|
{
|
/// <summary>
|
/// ModalWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class ProductModal : WindowX
|
{
|
|
private XmlModel DataModel;
|
|
public ProductModal(XmlModel dataModel)
|
{
|
DataModel = dataModel;
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
public ProductData 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.SaveOrUpdateData(Data);
|
}
|
catch (Exception ex)
|
{
|
ToastHelper.Error(this, $"Error: {ex.Message}");
|
e.Cancel = true;
|
return;
|
}
|
finally
|
{
|
_isProcessing = false;
|
ButtonHelper.SetIsPending(okButton, false);
|
}
|
}
|
base.OnClosing(e);
|
}
|
|
private bool ValidateName(object value, out string msg)
|
{
|
return DataModel.ValidateProductName(value, out msg);
|
}
|
|
private bool ValidateForm()
|
{
|
bool flag = FormGroupHelper.ValidateForm(formPanel);
|
if (flag)
|
{
|
Data.Name = TbName.Text;
|
Data.IsMaster = TbIsMaster.IsChecked == true;
|
Data.ParentId = CbParent.Text;
|
}
|
return flag;
|
}
|
|
public bool? Open(ProductData data, bool isEdit)
|
{
|
Data = data;
|
TbName.Text = Data.Name;
|
TbIsMaster.IsChecked = Data.IsMaster;
|
FgParentId.Visibility = isEdit ? Visibility.Collapsed : Visibility.Visible;
|
|
CbParent.ItemsSource = DataModel.Products.Select(e => e.Name).ToList();
|
//TbParentId.Text = Data.ParentId;
|
|
return this.ShowDialog();
|
}
|
}
|
}
|