StockerInfo.xaml.cs
10.1 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using HHWCS.Model;
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;
namespace HHWCSHost.Controls
{
/// <summary>
/// StockerInfo.xaml 的交互逻辑
/// </summary>
public partial class StockerInfo : UserControl
{
public string ControlName
{
get { return (string)GetValue(ControlNameProperty); }
set { SetValue(ControlNameProperty, value); }
}
// Using a DependencyProperty as the backing store for ControlName. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ControlNameProperty =
DependencyProperty.Register("ControlName", typeof(string), typeof(StockerInfo), new PropertyMetadata(""));
public StockerInfo(int maxW, int maxH)
{
InitializeComponent();
this.Width = maxW;
this.Height = maxH;
lab_Name.SetBinding(Label.ContentProperty, new Binding("ControlName") { Source = this });
}
/// <summary>
/// 赋值属性
/// </summary>
/// <param name="deviceEntity"></param>
/// <param name="props"></param>
/// <param name="address"></param>
public void SetProps(DeviceEntity deviceEntity, List<DevicePropEntity> props, List<DeviceAddressEntity> address)
{
#region 固定属性赋值
var taskValidate = address.Find(t => t.DevicePropCode == "TaskValidate");
if (taskValidate != null)
{
lab_TaskValidate.Foreground = Brushes.Blue;
switch (taskValidate.value)
{
case "1":
lab_TaskValidate.Content = "正确";
break;
case "2":
lab_TaskValidate.Content = "错误";
lab_TaskValidate.Foreground = Brushes.Red;
break;
default:
lab_TaskValidate.Content = "未获取或不识别";
lab_TaskValidate.Foreground = Brushes.Red;
break;
}
}
var workModel = address.Find(t => t.DevicePropCode == "WorkModel");
if (workModel != null)
{
lab_WorkModel.Foreground = Brushes.Blue;
switch (workModel.value)
{
case "1":
lab_WorkModel.Content = "脱机";
break;
case "2":
lab_WorkModel.Content = "联机";
break;
default:
lab_WorkModel.Content = "未获取或不识别";
lab_WorkModel.Foreground = Brushes.Red;
break;
}
}
var operationModel = address.Find(t => t.DevicePropCode == "OperationModel");
if (operationModel != null)
{
lab_OperationModel.Foreground = Brushes.Blue;
switch (operationModel.value)
{
case "1":
lab_OperationModel.Content = "脱机";
break;
case "2":
lab_OperationModel.Content = "联机";
break;
default:
lab_OperationModel.Content = "未获取或不识别";
lab_OperationModel.Foreground = Brushes.Red;
break;
}
}
var workStatus = address.Find(t => t.DevicePropCode == "WorkStatus");
if (workStatus != null)
{
lab_WorkStatus.Foreground = Brushes.Blue;
switch (workStatus.value)
{
case "0":
lab_WorkStatus.Content = "待机";
break;
case "1":
lab_WorkStatus.Content = "入库";
break;
case "2":
lab_WorkStatus.Content = "出库";
break;
case "3":
lab_WorkStatus.Content = "拣选";
break;
case "4":
lab_WorkStatus.Content = "转库";
break;
case "5":
lab_WorkStatus.Content = "双重入库";
break;
case "6":
lab_WorkStatus.Content = "回库台位(入库准备)";
break;
case "7":
lab_WorkStatus.Content = "召回";
break;
case "8":
lab_WorkStatus.Content = "急停";
lab_WorkStatus.Foreground = Brushes.Red;
break;
default:
lab_WorkStatus.Content = "未获取或不识别";
lab_WorkStatus.Foreground = Brushes.Red;
break;
}
}
var taskExcuteStatus = address.Find(t => t.DevicePropCode == "TaskExcuteStatus");
if (taskExcuteStatus != null)
{
lab_TaskExcuteStatus.Foreground = Brushes.Blue;
switch (taskExcuteStatus.value)
{
case "1":
lab_TaskExcuteStatus.Content = "待机";
break;
case "2":
lab_TaskExcuteStatus.Content = "任务执行中";
break;
case "3":
lab_TaskExcuteStatus.Content = "任务完成";
break;
case "4":
lab_TaskExcuteStatus.Content = "任务中断(出错)";
lab_TaskExcuteStatus.Foreground = Brushes.Red;
break;
default:
lab_TaskExcuteStatus.Content = "未获取或不识别";
lab_TaskExcuteStatus.Foreground = Brushes.Red;
break;
}
}
var taskNo1 = address.Find(t => t.DevicePropCode == "TaskNo1");
if (taskNo1 != null)
{
lab_TaskNo1.Content = taskNo1.value;
}
var taskNo2 = address.Find(t => t.DevicePropCode == "TaskNo2");
if (taskNo2 != null)
{
lab_TaskNo2.Content = taskNo2.value;
}
var currentColumn = address.Find(t => t.DevicePropCode == "CurrentColumn");
if (currentColumn != null)
{
lab_CurrentColumn.Content = currentColumn.value;
}
var currentLayer = address.Find(t => t.DevicePropCode == "CurrentLayer");
if (currentLayer != null)
{
lab_CurrentLayer.Content = currentLayer.value;
}
var horizontalDistance = address.Find(t => t.DevicePropCode == "HorizontalDistance");
if (horizontalDistance != null)
{
lab_HorizontalDistance.Content = horizontalDistance.value;
}
var verticalDistance = address.Find(t => t.DevicePropCode == "VerticalDistance");
if (verticalDistance != null)
{
lab_VerticalDistance.Content = verticalDistance.value;
}
#endregion
//监控属性赋值
var tempProps = props.FindAll(t => t.DeviceTypeId == deviceEntity.DeviceTypeId && t.IsMonitor == 1);
foreach (var item in tempProps)
{
var temp = address.Find(t => t.DevicePropCode == item.Code);
if (temp.value != item.MonitorCompareValue)
{
AddAlarm("报警:" + item.Name + " 信息:" + item.MonitorFailure, 2);
}
else
{
RemoveAlarm("报警:" + item.Name + " 信息:" + item.MonitorFailure);
}
}
}
private void RemoveAlarm(string v)
{
foreach (var item in list_Alarm.Items)
{
var a = (TextBlock)item;
if (a.Text.Contains(v))
{
list_Alarm.Items.Remove(item);
}
}
}
/// <summary>
/// 添加报警
/// </summary>
/// <param name="log"></param>
/// <param name="level">1显示绿色,2显示红色</param>
public void AddAlarm(string log, int level)
{
//先找存不存在
foreach (var item in list_Alarm.Items)
{
var a = (TextBlock)item;
if (a.Text.Contains(log))
{
//存在就不再次添加
return;
}
}
TextBlock textBlock = new TextBlock
{
Text = DateTime.Now.ToLongTimeString()+":" + log
};
switch (level)
{
case 1:
textBlock.Background = Brushes.Green;
break;
case 2:
textBlock.Background = Brushes.Red;
break;
}
textBlock.MaxWidth = this.Width;
textBlock.TextWrapping = TextWrapping.Wrap;
this.list_Alarm.Items.Add(textBlock);
this.list_Alarm.SelectedIndex = this.list_Alarm.Items.Count - 1;
this.list_Alarm.ScrollIntoView(this.list_Alarm.SelectedItem);
}
}
}