alielie
2025-11-24 9211ec11c112e18cd99e77f889a01110a70031ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using HMI.UI.DpUtil;
using HMI.UI.Util;
using HMI.Util;
using Microsoft.Win32;
using Panuon.WPF.UI;
using Plugin.CurrentSensorControl.Entity;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
 
namespace Plugin.CurrentSensorControl
{
    /// <summary>
    /// ModalWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BurnInSettingModal : WindowX
    {
        public BurnInSettingModal()
        {
            this.DataContext = this;
            InitializeComponent();
        }
 
        private ObservableCollection<PLCTagData> datasource;
 
        public ObservableCollection<PLCTagData> Datasource
        {
            get => datasource;
            set
            {
                Set(ref datasource, value);
            }
        }
 
        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);
                    
                }
                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;
        }
 
        public bool? Open( ObservableCollection<PLCTagData> datasource)
        {
            this.Datasource = datasource;
            return this.ShowDialog();
        }
 
        private void DoExport()
        {
            SaveFileDialog sfd = new SaveFileDialog();
            if (sfd.ShowDialog() == true)
            {
                ExcelHelper.ExportExcel(sfd.FileName, Datasource);
            }
        }
 
        private void DoImport()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == true)
            {
                try
                {
                    Datasource = new ObservableCollection<PLCTagData>(ExcelHelper.ReadFromExcel<PLCTagData>(ofd.FileName));
                }
                catch (Exception ex)
                {
                    ControlPage.Logger.Error("Import Error.", ex);
                    ToastHelper.Error(ex.Message);
                }
            }
        }
 
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var btn = sender as Button;
            switch (btn.Name) {
                case "exportBtn":
                    DoExport();
                    break;
                case "importBtn":
                    DoImport();
                    break;
                default:
                    break;
            }
 
        }
    }
}