schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XImagingXhandler.XDAL;
using XCommon.Log;
using System.Collections.ObjectModel;
 
namespace XHandler.View.MethodProperty
{
    /// <summary>
    /// WaitforProperty.xaml 的交互逻辑
    /// </summary>
    public partial class WaitforProperty : UserControl,ITimerObserver
    {
        public MethodWaitFor methodWaitFor { get; set; }
        public MethodWaitFor currmethodWaitFor = null;
        public MethodEx method = null;
 
        #region 全局属性变量
        string isrun = "";
        string status = "";
        string name = "";
        string label = "";
        string duringTimeText = "";
        string duringTimeStrIndex = "";
        bool endTimer = false;
        int mark = 0;
        #endregion
 
        public WaitforProperty()
        {
            InitializeComponent();
        }
 
        #region timer变更后,更新节点内的Timer绑定
        /// <summary>
        /// timer变更后,更新节点内的Timer绑定
        /// </summary>
        /// <param name="duringTimerList">节点内的Timer管理对象</param>
        public void ReceiveAndUpdate(List<DropdownName> duringTimerList)
        {
            cbTimerList.ItemsSource = duringTimerList;
            if (methodWaitFor.duringTimeTextStrIndex == "")
            {
                if (duringTimerList.Count > 0)
                {
                    cbTimerList.SelectedIndex = 0;
                }
            }
            else
            {
                if (duringTimerList.Count > 0)
                {
                    var containsValue = (cbTimerList.ItemsSource as List<DropdownName>).FirstOrDefault(x=>x.dropdown_id.Equals(methodWaitFor.duringTimeTextStrIndex));
                    if (containsValue != null)
                    {
                        cbTimerList.SelectedValue = methodWaitFor.duringTimeTextStrIndex;
                    }
                }
            }
        }
        #endregion
 
        public WaitforProperty(MethodEx method, List<DropdownName> duringTimerList)
        {
            InitializeComponent();
            mark = 0;
            methodWaitFor = new MethodWaitFor();
            methodWaitFor.name = method.method_name;
            methodWaitFor.label = method.method_name;
            methodWaitFor.status = (method.isEnabled == true ? "enable" : "disable");
            methodWaitFor.isrun = "disable";
            methodWaitFor.strIndex = method.strIndex;
            cbTimerList.ItemsSource = duringTimerList;
 
            this.method = method;
            if (method.tag != null)
            {
                methodWaitFor = (MethodWaitFor)method.tag;
 
                currmethodWaitFor = methodWaitFor;
                isrun = methodWaitFor.isrun;
                status = methodWaitFor.status;
                name = methodWaitFor.name;
                label = methodWaitFor.label;
                duringTimeText = methodWaitFor.duringTimeText;
                duringTimeStrIndex = methodWaitFor.duringTimeTextStrIndex;
                endTimer = methodWaitFor.enableEndWaitfor = true;
            }
            this.DataContext = methodWaitFor;
        }
 
        private void cbTimerList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (methodWaitFor != null)
                {
                    var currentItem = cbTimerList.SelectedItem as DropdownName;
                    if(currentItem == null)
                    {
                        return;
                    }
                    methodWaitFor.duringTimeText = (currentItem).dropdown_name;
                    methodWaitFor.duringTimeTextStrIndex = cbTimerList.SelectedValue.ToString();
                    if (this.method != null)
                    {
                        this.method.method_Tipcontent = string.Format("{0}", methodWaitFor.duringTimeText.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void cbxEndTimer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (methodWaitFor != null)
                {
                    methodWaitFor.enableEndWaitfor = (bool)cbxEndTimer.IsChecked;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (methodWaitFor != null)
                {
                    methodWaitFor.name = tbxCommandName.Text;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mark += 1;
            try
            {
                if (mark > 1)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(duringTimeText))
                {
                    tbxCommandName.Text = name;
 
 
                    cbTimerList.Text = duringTimeText;
                    cbxEndTimer.IsChecked = endTimer;
 
                    if (currmethodWaitFor != null)
                    {
                        methodWaitFor = currmethodWaitFor;
                    }
                }
                else
                {
                    cbTimerList.SelectedIndex = -1;
 
                    if (currmethodWaitFor != null)
                    {
                        methodWaitFor = currmethodWaitFor;
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
    }
}