using HMI.Core.Entity; using HMI.Core.Util; 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 { /// /// ModalWindow.xaml 的交互逻辑 /// public partial class TestItemModal : WindowX { public TestItemModal() { this.DataContext = this; InitializeComponent(); } public TestItemData Data { get; set; } public ObservableCollection 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 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(); } } }