From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
Plugin.DODriverControl/DataModal.xaml.cs | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 177 insertions(+), 0 deletions(-)
diff --git a/Plugin.DODriverControl/DataModal.xaml.cs b/Plugin.DODriverControl/DataModal.xaml.cs
new file mode 100644
index 0000000..ba7ac53
--- /dev/null
+++ b/Plugin.DODriverControl/DataModal.xaml.cs
@@ -0,0 +1,177 @@
+锘縰sing HMI.Core.Util;
+using HMI.UI.DpUtil;
+using HMI.UI.Util;
+using Panuon.WPF.UI;
+using Plugin.DODriverControl.Entity;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+
+namespace Plugin.DODriverControl
+{
+ /// <summary>
+ /// ModalWindow.xaml 鐨勪氦浜掗�昏緫
+ /// </summary>
+ public partial class DataModal : WindowX
+ {
+ public DataModal()
+ {
+ this.DataContext = this;
+ InitializeComponent();
+ }
+
+ private string filePath;
+ public DIOData Data { get; set; }
+
+ private ObservableCollection<DIOData> 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;
+ }
+
+ SaveOrUpdateData();
+ }
+ 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)
+ {
+ Data.Name = TbName.Text;
+ Data.Address = TbAddress.Text;
+ Data.Dio = (DIOType)CbDio.SelectedItem;
+ Data.PressDownValue = TbPressDownValue.Text;
+ Data.PressUpValue = TbPressUpValue.Text;
+ Data.PressDownText = TbPressDownText.Text;
+ Data.PressUpText = TbPressUpText.Text;
+
+ Data.ControlType = (ControlType)CbControlType.SelectedItem;
+ if (Data.ControlType == ControlType.BOOL)
+ {
+ Data.PressDownValue = true.ToString();
+ Data.PressUpValue = false.ToString();
+ }
+ }
+ return flag;
+ }
+
+ public bool? Open(DIOData data, ObservableCollection<DIOData> datasource, string filePath)
+ {
+ this.filePath = filePath;
+ Datasource = datasource;
+ Data = data;
+
+ TbName.Text = Data.Name;
+ TbAddress.Text = Data.Address;
+ CbDio.SelectedItem = Data.Dio;
+ TbPressDownValue.Text = Data.PressDownValue;
+ TbPressUpValue.Text = Data.PressUpValue;
+ TbPressDownText.Text = Data.PressDownText;
+ TbPressUpText.Text = Data.PressUpText;
+
+ CbControlType.SelectedItem = Data.ControlType;
+ return this.ShowDialog();
+ }
+
+ private void SaveOrUpdateData()
+ {
+ int index = -1;
+ if (Datasource != null)
+ {
+ index = Datasource.IndexOf(Data);
+ }
+ if (index < 0)
+ {
+ InsertData(Data);
+ }
+ else
+ {
+ UpdateData(index, Data);
+ }
+ }
+
+ public void InsertData(DIOData data)
+ {
+ Datasource.Add(data);
+ XmlHelper.SerializeToXml(filePath, Datasource);
+ }
+
+ public void UpdateData(int index, DIOData data)
+ {
+ var temp = XmlHelper.DeepClone(Datasource);
+ temp[index] = data;
+ XmlHelper.SerializeToXml(filePath, temp);
+ }
+
+ private void CbControlType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
+ {
+ if ((ControlType)e.AddedItems[0] == ControlType.BOOL)
+ {
+ FgPressDownValue.Visibility = System.Windows.Visibility.Collapsed;
+ FgPressUpValue.Visibility = System.Windows.Visibility.Collapsed;
+ }
+ else
+ {
+ FgPressDownValue.Visibility = System.Windows.Visibility.Visible;
+ FgPressUpValue.Visibility = System.Windows.Visibility.Visible;
+ }
+ }
+ }
+}
--
Gitblit v1.9.1