StockerMonitor.xaml.cs
10.8 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
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>
/// StockerMonitor.xaml 的交互逻辑
/// </summary>
public partial class StockerMonitor : UserControl
{
public string ControlName { get; set; }
/// <summary>
/// 画堆垛机,rows代表排数,比如2代表两排货架,4代表双伸位,1代表单排
/// </summary>
/// <param name="columns"></param>
/// <param name="rows"></param>
/// <param name="direction"></param>
/// <param name="maxWidth"></param>
/// <param name="maxHeight"></param>
public StockerMonitor(int columns, int rows, bool direction, int maxWidth, int maxHeight)
{
InitializeComponent();
this.MaxWidth = maxWidth;
this.MaxHeight = maxHeight;
//grid.ma = MaxWidth;
//grid.Height = MaxHeight;
Render(columns, rows, direction);
}
private void Render(int columns, int rows, bool direction)
{
if (columns <= 0)
{
return;
}
for (int i = 0; i < columns; i++)
{
var a = new ColumnDefinition
{
Width = new GridLength(100 / columns, GridUnitType.Star)
};
grid.ColumnDefinitions.Add(a);
}
if (rows == 1)
{
var a = new RowDefinition();
var b = new RowDefinition();
a.Height = new GridLength(50, GridUnitType.Star);
b.Height = new GridLength(50, GridUnitType.Star);
grid.RowDefinitions.Add(a);
grid.RowDefinitions.Add(b);
if (direction)
{
//先画堆垛机
RenderStocker(0, 0);
RenderLocation(columns, 1);
}
else
{
RenderStocker(0, 1);
RenderLocation(columns, 0);
}
}
else if (rows == 2)
{
var a = new RowDefinition();
var b = new RowDefinition();
var c = new RowDefinition();
a.Height = new GridLength(33, GridUnitType.Star);
b.Height = new GridLength(33, GridUnitType.Star);
c.Height = new GridLength(33, GridUnitType.Star);
grid.RowDefinitions.Add(a);
grid.RowDefinitions.Add(b);
grid.RowDefinitions.Add(c);
RenderStocker(0, 1);
RenderLocation(columns, 0);
RenderLocation(columns, 2);
}
else if (rows == 4)
{
var a = new RowDefinition();
var b = new RowDefinition();
var c = new RowDefinition();
var d = new RowDefinition();
var e = new RowDefinition();
a.Height = new GridLength(33, GridUnitType.Star);
b.Height = new GridLength(33, GridUnitType.Star);
c.Height = new GridLength(33, GridUnitType.Star);
d.Height = new GridLength(33, GridUnitType.Star);
e.Height = new GridLength(33, GridUnitType.Star);
grid.RowDefinitions.Add(a);
grid.RowDefinitions.Add(b);
grid.RowDefinitions.Add(c);
grid.RowDefinitions.Add(d);
grid.RowDefinitions.Add(e);
RenderStocker(0, 2);
RenderLocation(columns, 0);
RenderLocation(columns, 1);
RenderLocation(columns, 3);
RenderLocation(columns, 4);
}
else
{
}
}
private void RenderStocker(int columnIndex, int rowIndex)
{
Border border = new Border
{
BorderThickness = new Thickness(0, 0, 1, 1),
BorderBrush = Brushes.Blue,
Name = "stocker",
Background = Brushes.White
};
Image image = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri("/Content/Image/Tractor.ico", UriKind.Relative);
bi3.EndInit();
image.Source = bi3;
image.Stretch = Stretch.Fill;
border.Child = image;
border.SetValue(Grid.RowProperty, rowIndex);
border.SetValue(Grid.ColumnProperty, columnIndex);
grid.Children.Add(border);
}
private void RenderLocation(int columns, int rowIndex)
{
//再画货架
for (int i = 0; i < columns; i++)
{
Border border = new Border
{
BorderThickness = new Thickness(1, 1, 1, 1),
BorderBrush = Brushes.Blue,
Name = "location" + rowIndex.ToString() + i.ToString(),
Background = Brushes.White,
CornerRadius = new CornerRadius(5)
};
Image image = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri("pack://application:,,,/Content/Image/List.JPG", UriKind.RelativeOrAbsolute);
bi3.EndInit();
image.Source = bi3;
image.Stretch = Stretch.Fill;
//border.Background =new ImageBrush(bi3);
TextBlock textBlock = new TextBlock();
textBlock.Text = (i + 1).ToString();
textBlock.TextAlignment = TextAlignment.Center;
textBlock.FontSize = 16;
textBlock.Foreground = new SolidColorBrush(Colors.Blue);
textBlock.FontWeight = FontWeight.FromOpenTypeWeight(20);
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(textBlock);
stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
stackPanel.VerticalAlignment = VerticalAlignment.Center;
border.Child = stackPanel;
border.SetValue(Grid.RowProperty, rowIndex);
border.SetValue(Grid.ColumnProperty, i);
grid.Children.Add(border);
}
}
/// <summary>
/// 设置位置以及背景色,1白色,2,3蓝色,4红色
/// </summary>
/// <param name="flag"></param>
/// <param name="columnIndex"></param>
public void SetStocker(int flag, int columnIndex)
{
Border border = GetUIElement(0, 0, "stocker");
if (border == null) return;
if (columnIndex > grid.ColumnDefinitions.Count || columnIndex < 0)
{
return;
}
switch (flag)
{
case 1:
border.Background = Brushes.White;
break;
case 2:
border.Background = Brushes.Blue;
break;
case 3:
border.Background = Brushes.Green;
break;
case 4:
border.Background = Brushes.Red;
break;
default:
border.Background = Brushes.White;
break;
}
if ((columnIndex - 1) < 0)
return;
border.SetValue(Grid.ColumnProperty, columnIndex - 1);
}
/// <summary>
/// 设置货架监控 1,
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="rowIndex"></param>
/// <param name="flag"></param>
public void SetLocation(int columnIndex, int rowIndex, int flag)
{
Border border = GetUIElement(columnIndex, rowIndex, null);
if (border == null) return;
Image image = (Image)border.Child;
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
switch (flag)
{
case 0:
bi3.UriSource = new Uri("/Content/Image/List.JPG", UriKind.Relative);
break;
case 1:
bi3.UriSource = new Uri("/Content/Image/取货架.png", UriKind.Relative);
break;
case 2:
bi3.UriSource = new Uri("/Content/Image/送货架.png", UriKind.Relative);
break;
default:
bi3.UriSource = new Uri("/Content/Image/List.JPG", UriKind.Relative);
break;
}
bi3.EndInit();
image.Source = bi3;
image.Stretch = Stretch.Fill;
border.Child = image;
}
private Border GetUIElement(int columnIndex, int rowIndex, String name)
{
String uiName = "";
if (String.IsNullOrEmpty(name))
{
uiName = "location" + rowIndex + columnIndex;
}
else
{
uiName = name;
}
foreach (var item in grid.Children)
{
Border border = (Border)item;
if (border.Name == uiName)
{
return border;
}
}
return null;
}
/// <summary>
/// 设置监控属性
/// </summary>
/// <param name="props"></param>
public void SetProp(List<EquipmentProp> props)
{
//获取工作状态
var taskExcute = props.Find(t => t.EquipmentTypePropTemplateCode == "TaskExcuteStatus").Value;
//获取位置 currentColumn
var currentColumn = props.Find(t => t.EquipmentTypePropTemplateCode == "CurrentColumn").Value;
int flag = 0;
switch (taskExcute)
{
case "1":
flag = 1;
break;
case "2":
flag = 2;
break;
case "3":
flag = 3;
break;
case "4":
flag = 4;
break;
default:
flag = 1;
break;
}
SetStocker(flag, Convert.ToInt32(currentColumn));
}
}
}