StockerInfo.xaml.cs
19.2 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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
using HHECS.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 HHECS.Controls
{
/// <summary>
/// 标准单叉堆垛机详情监控
/// </summary>
public partial class StockerInfo : UserControl
{
public event Func<Equipment, BllResult> DeleteTask; //删除任务
public event Func<Location, Equipment, BllResult> DoubleInEvent;
public event Func<Equipment, BllResult> EmptyOutEvent;
public event Func<Equipment, BllResult> ForkErrorEvent;
public event Func<Equipment, BllResult> OverrideTask; //重新下发任务
public Equipment 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 });
}
public StockerInfo(int maxW)
{
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(Equipment stocker)
{
Self = stocker;
#region 固定属性赋值
var Fork1ForkHasPallet = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1ForkHasPallet");
if (Fork1ForkHasPallet != null)
{
lab_Fork1ForkHasPallet.Foreground = Brushes.Blue;
switch (Fork1ForkHasPallet.Value)
{
case "True":
lab_Fork1ForkHasPallet.Content = "有货";
break;
case "False":
lab_Fork1ForkHasPallet.Content = "无货";
break;
default:
lab_Fork1ForkHasPallet.Content = "未获取或不识别";
lab_Fork1ForkHasPallet.Foreground = Brushes.Red;
break;
}
}
var Fork1TaskExcuteStatus = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskExcuteStatus");
if (Fork1TaskExcuteStatus != null)
{
lab_Fork1TaskExcuteStatus.Foreground = Brushes.Blue;
TaskExcuteStatus temp = (TaskExcuteStatus)(Convert.ToInt32(Fork1TaskExcuteStatus.Value));
switch (temp)
{
case TaskExcuteStatus.待机:
case TaskExcuteStatus.任务执行中:
case TaskExcuteStatus.任务完成:
lab_Fork1TaskExcuteStatus.Content = temp.ToString();
break;
case TaskExcuteStatus.任务中断_出错:
case TaskExcuteStatus.下发任务错误:
lab_Fork1TaskExcuteStatus.Content = temp.ToString();
lab_Fork1TaskExcuteStatus.Foreground = Brushes.Red;
break;
default:
lab_Fork1TaskExcuteStatus.Content = "未获取或不识别";
lab_Fork1TaskExcuteStatus.Foreground = Brushes.Red;
break;
}
}
var operationModel = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "OperationModel");
if (operationModel != null)
{
lab_OperationModel.Foreground = Brushes.Blue;
OperationModel temp = (OperationModel)(Convert.ToInt32(operationModel.Value));
switch (temp)
{
case OperationModel.维修:
case OperationModel.手动:
case OperationModel.机载操作:
case OperationModel.单机自动:
case OperationModel.联机:
lab_OperationModel.Content = temp.ToString();
break;
default:
lab_OperationModel.Content = "未获取或不识别";
lab_OperationModel.Foreground = Brushes.Red;
break;
}
}
var taskLimit = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "TaskLimit");
if (taskLimit != null)
{
lab_TaskLimit.Foreground = Brushes.Blue;
TaskLimit temp = (TaskLimit)Convert.ToInt32(taskLimit.Value);
switch (temp)
{
case TaskLimit.无限制:
case TaskLimit.限制入库:
case TaskLimit.限制出库:
case TaskLimit.拣选:
lab_TaskLimit.Content = temp.ToString();
break;
default:
lab_TaskLimit.Content = "未获取或不识别";
lab_TaskLimit.Foreground = Brushes.Red;
break;
}
}
var Fork1TaskType = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskType");
if (Fork1TaskType != null)
{
lab_Fork1TaskType.Foreground = Brushes.Blue;
ForkTaskFlag temp = (ForkTaskFlag)Convert.ToInt32(Fork1TaskType.Value);
switch (temp)
{
case ForkTaskFlag.无任务:
case ForkTaskFlag.库内取货:
case ForkTaskFlag.库内放货:
case ForkTaskFlag.库外入库:
case ForkTaskFlag.库外出库:
case ForkTaskFlag.重新分配入库地址:
case ForkTaskFlag.删除任务:
case ForkTaskFlag.任务完成:
lab_Fork1TaskType.Content = temp.ToString();
break;
default:
lab_Fork1TaskType.Content = "未获取或不识别";
lab_Fork1TaskType.Foreground = Brushes.Red;
break;
}
}
var Fork1TaskNo = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskNo");
if (Fork1TaskNo != null)
{
lab_Fork1TaskNo.Content = Fork1TaskNo.Value;
}
var CurrentStation = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "CurrentStation");
if (CurrentStation != null)
{
lab_CurrentStation.Content = CurrentStation.Value;
}
var currentColumn = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "CurrentColumn");
if (currentColumn != null)
{
lab_CurrentColumn.Content = currentColumn.Value;
}
var currentLayer = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "CurrentLayer");
if (currentLayer != null)
{
lab_CurrentLayer.Content = currentLayer.Value;
}
var horizontalDistance = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "HorizontalDistance");
if (horizontalDistance != null)
{
lab_HorizontalDistance.Content = horizontalDistance.Value;
}
var verticalDistance = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "VerticalDistance");
if (verticalDistance != null)
{
lab_VerticalDistance.Content = verticalDistance.Value;
}
var ForkDistance = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ForkDistance");
if (ForkDistance != null)
{
lab_ForkDistance.Content = ForkDistance.Value;
}
#endregion
//监控属性赋值
var tempProps = stocker.EquipmentProps.FindAll(t => t.EquipmentTypePropTemplate.IsMonitor == true);
foreach (var item in tempProps)
{
if (item.Value != item.EquipmentTypePropTemplate.MonitorCompareValue)
{
AddAlarm("报警:" + item.EquipmentTypePropTemplate.Name + " 信息:" + item.EquipmentTypePropTemplate.MonitorFailure, 2);
}
else
{
RemoveAlarm("报警:" + item.EquipmentTypePropTemplate.Name + " 信息:" + item.EquipmentTypePropTemplate.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);
}
/// <summary>
/// 处理重入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_DIn_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否要进行重入处理?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
if (Self != null)
{
var doubleIn = Self.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1DoubleIn");
if (doubleIn != null)
{
if (doubleIn.Value == "True")
{
WinLocationInput frm_LocationInput = new WinLocationInput
{
DeviceEntity = Self
};
if (frm_LocationInput.ShowDialog() == true)
{
Location 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 (Self != null)
{
var emptyOut = Self.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1EmptyOut");
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("无需空出处理");
}
}
}
/// <summary>
/// 重新写入任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_Override_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否要进行任务重新下发处理?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
if (Self != null)
{
var temp = OverrideTask?.Invoke(Self);
if (temp == null)
{
MessageBox.Show("未处理重写事件");
}
else if (temp.Success)
{
MessageBox.Show("重新下发成功");
}
else
{
MessageBox.Show($"重新下发失败:{temp.Msg}");
}
}
else
{
MessageBox.Show("堆垛机未赋值");
}
}
}
/// <summary>
/// 取货错误
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_ForkError_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否要进行取货错误处理?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
if (Self != null)
{
var forkError = Self.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1PickupTaskError");
if (forkError != null)
{
if (forkError.Value == "True")
{
var temp = ForkErrorEvent?.Invoke(Self);
if (temp == null)
{
MessageBox.Show("未处理取货错误事件");
}
if (temp.Success)
{
MessageBox.Show("取货错误处理成功");
}
else
{
MessageBox.Show($"取货错误处理失败:{temp.Msg}");
}
}
else
{
MessageBox.Show("当前没有取货错误报警,无需处理");
}
}
else
{
MessageBox.Show("未找到堆垛机的取货错误属性");
}
}
else
{
MessageBox.Show("堆垛机未赋值");
}
}
}
/// <summary>
/// 删除任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_Delete_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否要进行任务删除处理?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
var temp = DeleteTask?.Invoke(Self);
if (temp == null)
{
MessageBox.Show("未处理任务删除事件");
}
if (temp.Success)
{
MessageBox.Show("任务删除处理成功");
}
else
{
MessageBox.Show($"任务删除失败:{temp.Msg}");
}
}
}
}
}