using HMI.UI.DpUtil; using HMI.UI.Util; using Panuon.WPF.UI; using Plugin.DODriverControl.Entity; using System.ComponentModel; namespace Plugin.DODriverControl { /// /// ModalWindow.xaml 的交互逻辑 /// public partial class ConfigModal : WindowX { public ConfigModal() { this.DataContext = this; InitializeComponent(); } public ConfigData config { get; private 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; } } 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 err) { err = null; //string group = TbGroup.Text; //var temp = Datasource.FirstOrDefault(d => d.Group == group && d.Name == value.ToString()); //if (temp != null && temp != Data) //{ // err = this.lang("App.MustBeUnique", $"{this.lang("doc.group")},{this.lang("doc.name")}"); // return false; //} return true; } private bool ValidateAddress(object value, out string err) { err = null; //string group = TbGroup.Text; //var temp = Datasource.FirstOrDefault(d => d.Address == value.ToString()); //if (temp != null && temp != Data) //{ // err = this.lang("App.MustBeUnique", this.lang("doc.Address")); // return false; //} return true; } private bool ValidateForm() { bool flag = FormGroupHelper.ValidateForm(formPanel); if (flag) { config.Type = (ConfigType)CbType.SelectedItem; config.IP = TbIP.Text; config.Port = TbPort.Text; } return flag; } public bool? Open(ConfigData config) { this.config = config; CbType.SelectedItem = config.Type; TbIP.Text = config.IP; TbPort.Text = config.Port; return this.ShowDialog(); } } }