StockerInfo.xaml.cs
14.7 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
using HHWCS.Bll;
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
{
private List<DeviceAddressEntity> innerAddresses;
public event Func<LocationEntity,DeviceEntity, BllResult> DoubleInEvent;
public event Func<DeviceEntity, BllResult> EmptyOutEvent;
public DeviceEntity Self { get; set; }
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)
{
innerAddresses = address;
Self = deviceEntity;
#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;
case "3":
lab_OperationModel.Content = "机载操作";
break;
case "4":
lab_OperationModel.Content = "单机自动";
break;
case "5":
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)
{
for (int i = list_Alarm.Items.Count-1; i >= 0; i--)
{
var a = (TextBlock)list_Alarm.Items[i];
if (a.Text.Contains(v))
{
list_Alarm.Items.Remove(list_Alarm.Items[i]);
}
}
}
/// <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);
}
private void Btn_DIn_Click(object sender, RoutedEventArgs e)
{
if(innerAddresses != null)
{
var doubleIn = innerAddresses.Find(t => t.DevicePropCode == "DoubleIn");
if(doubleIn != null)
{
if (doubleIn.value == "True")
{
Frm_LocationInput frm_LocationInput = new Frm_LocationInput
{
DeviceEntity = Self
};
if (frm_LocationInput.ShowDialog() == true)
{
LocationEntity locationEntity = frm_LocationInput.NewLocation;
BllResult a = DoubleInEvent?.Invoke(locationEntity,Self);
if (a == null)
{
MessageBox.Show("未处理重入事件");
}
else
{
if (a.Success)
{
MessageBox.Show("重入处理成功");
}
else
{
MessageBox.Show("重入处理失败:" + a.Msg);
}
}
}
}
else
{
MessageBox.Show("当前没有重入报警,无需处理");
}
}
else
{
MessageBox.Show("未找到堆垛机的重入属性");
}
}
else
{
MessageBox.Show("无重入需要处理");
}
}
/// <summary>
/// 空出处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_EOut_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否要进行空出处理?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
if (innerAddresses != null)
{
var emptyOut = innerAddresses.Find(t => t.DevicePropCode == "EmptyOut");
if (emptyOut != null)
{
if (emptyOut.value == "True")
{
BllResult temp = EmptyOutEvent?.Invoke(Self);
if (temp == null)
{
MessageBox.Show("未处理空出事件");
}
else
{
if (temp.Success)
{
MessageBox.Show("空出处理成功");
}
else
{
MessageBox.Show("空出处理失败:" + temp.Msg);
}
}
}
else
{
MessageBox.Show("当前没有空出报警,无需处理");
}
}
else
{
MessageBox.Show("未找到堆垛机的空出属性");
}
}
else
{
MessageBox.Show("无需空出处理");
}
}
}
}
}