StockerMonitor.xaml.cs
7.28 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
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>
/// StockerMonitor.xaml 的交互逻辑
/// </summary>
public partial class StockerMonitor : UserControl
{
public string ControlName { get; set; }
public StockerMonitor(int columns,bool two,bool direction,int maxWidth,int maxHeight)
{
InitializeComponent();
this.MaxWidth = maxWidth;
this.MaxHeight = maxHeight;
//grid.ma = MaxWidth;
//grid.Height = MaxHeight;
Render(columns,two,direction);
}
private void Render(int columns,bool two,bool direction)
{
if (columns <= 0)
{
return;
}
for (int i = 0; i < columns; i++)
{
var a = new ColumnDefinition();
a.Width = new GridLength(100/columns,GridUnitType.Star);
grid.ColumnDefinitions.Add(a);
}
if (two)
{
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
{
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);
}
}
private void RenderStocker(int columnIndex,int rowIndex)
{
Border border = new Border();
border.BorderThickness = new Thickness(0, 0, 1, 1);
border.BorderBrush = Brushes.Blue;
border.Name = "stocker";
border.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();
border.BorderThickness = new Thickness(0, 0, 1, 1);
border.BorderBrush = Brushes.Blue;
border.Name = "location"+rowIndex.ToString()+i.ToString();
border.Background = Brushes.White;
Image image = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri("/Content/image/List.JPG", UriKind.Relative);
bi3.EndInit();
image.Source = bi3;
image.Stretch = Stretch.Fill;
border.Child = image;
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;
switch (flag)
{
case 1:
border.Background = Brushes.White;
break;
case 2:
border.Background = Brushes.Blue;
break;
case 3:
border.Background = Brushes.Blue;
break;
case 4:
border.Background = Brushes.Red;
break;
default:
border.Background = Brushes.White;
break;
}
border.SetValue(Grid.ColumnProperty, columnIndex);
}
/// <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;
}
}
}