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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using FLY.OBJComponents.Client;
using FLY.Thick.Base.Common;
using FLY.UI.Module;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
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 System.Windows.Threading;
using ThickTcpUiInWindow;
namespace FLY.Thick.BlowingScan.UI.Client.UIModule
{
/// <summary>
/// DynAreaIO.xaml 的交互逻辑
/// </summary>
public partial class DynAreaIO : UserControl
{
DynAreaIOViewModel viewModel;
TDGage gage;
public DynAreaIO()
{
InitializeComponent();
}
public void Init(int id)
{
//获取设备
gage = Application.Current.Properties["ThickGage"] as TDGage;
viewModel = new DynAreaIOViewModel();
viewModel.Init(gage.mDynArea, gage.mWarningReasonWindow);
this.DataContext = viewModel;
}
protected virtual void Border_IO_Click(object sender, RoutedEventArgs e)
{
PgErrorTable p = new PgErrorTable();
p.Init(gage.mWarningService,
gage.mWarningReasonWindow,
gage.mFlyAdServiceClient,
typeof(WdIOTip));
(Application.Current.Properties["NavigationService"] as NavigationService).Navigate(p);
}
}
public class DynAreaIOViewModel : INotifyPropertyChanged
{
#region 延时推送 MARKNO
const int MARKNO_UPDATEERROR = 1;
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public UInt16 IStatus { get; set; } = 0xffff;
public UInt16 OStatus { get; set; } = 0x000f;
public int Hrs { get; set; } = 3;
/// <summary>
/// 是永久使用
/// </summary>
public bool IsForever { get; set; } = false;
public bool IsError { get; set; }
/// <summary>
/// 异常消息
/// </summary>
public string ErrMsg { get; set; }
DynArea mDynArea;
BufferWindow<OBJComponents.Common.FlyData_WarningHistory> mWindow;
DispatcherTimer timer_error;
private int reason_list_index = -1;
public void Init(DynArea dynArea, OBJComponents.Client.BufferWindow<OBJComponents.Common.FlyData_WarningHistory> mWarningReasonWindow)
{
//创建窗口观察 报警原因列表
mWindow = mWarningReasonWindow;
mDynArea = dynArea;
Misc.BindingOperations.SetBinding(mDynArea, "IStatus", this, "IStatus");
Misc.BindingOperations.SetBinding(mDynArea, "OStatus", this, "OStatus");
Misc.BindingOperations.SetBinding(mDynArea, "Hrs", this, "Hrs");
UpdateIsForever();
//报警原因轮流显示
timer_error = new DispatcherTimer();
timer_error.Interval = TimeSpan.FromSeconds(3);
timer_error.Tick += (s, e) =>
{
reason_list_index--;
if (reason_list_index < 0)
reason_list_index = mWindow.Record.Count();
UpdateError();
};
mWindow.Record.CollectionChanged += Record_CollectionChanged;
mDynArea.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "ServerIsConnected")
{
UpdateError();
}
else if (e.PropertyName == "Hrs")
{
UpdateIsForever();
}
};
UpdateError();
}
void UpdateIsForever()
{
if (mDynArea.Hrs > 50000)
IsForever = true;
else
IsForever = false;
}
private void Record_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
FObjBase.PollModule.Current.Poll_JustOnce(
new FObjBase.PollModule.PollHandler(delegate ()
{
reason_list_index = mWindow.Record.Count() - 1;
UpdateError();
}), this, MARKNO_UPDATEERROR);
}
void UpdateError()
{
if (!mDynArea.ServerIsConnected)
{
ErrMsg = "服务器连接断开";
IsError = true;
reason_list_index = -1;
timer_error.Stop();
}
else if (mWindow.Record.Count > 0)
{
if (reason_list_index >= mWindow.Record.Count)
reason_list_index = mWindow.Record.Count - 1;
else if (reason_list_index < 0)
reason_list_index = 0;
ErrMsg = mWindow.Record[reason_list_index].Description;
IsError = true;
timer_error.Start();
}
else
{
IsError = false;
ErrMsg = "";
reason_list_index = -1;
timer_error.Stop();
}
}
}
public class DynAreaIOViewModel_UnitTest : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public UInt16 IStatus { get; set; } = 0xff7f;
public UInt16 OStatus { get; set; } = 0x0005;
public int Hrs { get; set; } = 2000;
/// <summary>
/// 是永久使用
/// </summary>
public bool IsForever { get; set; } = false;
public bool IsError { get; set; }
/// <summary>
/// 异常消息
/// </summary>
public string ErrMsg { get; set; }
}
public class UIModule_DynAreaIO : IUIModule
{
/// <summary>
/// 控件标题
/// 它的值取决于culture
/// </summary>
public string Title
{
get
{
return Application.Current.FindResource("strDynAreaIO") as string;
}
}
/// <summary>
/// 控件
/// 创建时,需要给它唯一ID,让加载自己的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FrameworkElement GetComponent(int id)
{
DynAreaIO graph = new DynAreaIO();
graph.Init(id);
return graph;
}
/// <summary>
/// 控件缩略图,用于编辑界面时,大致看看
/// 创建时,需要给它唯一ID,让加载自己的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FrameworkElement GetThumbnail(int id)
{
return new System.Windows.Controls.Grid();
}
/// <summary>
/// 给出全部控件ID, 控件自行删除没有的参数
/// </summary>
/// <param name="IDs"></param>
public void MatchParam(int[] IDs)
{
}
}
}