LineControl.cs
12 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyControlLib
{
public partial class LineControl : UserControl
{
public LineControl()
{
InitializeComponent();
}
public LineControl(string strName,int col, int row)
{
InitializeComponent();
this.Name = strName;
}
/// <summary>
/// 方向排布
/// </summary>
public enum LayDirection
{
Left=0,
Right=2,
Up=3,
Down=1,
}
/// <summary>
/// 元件排布 函数
/// </summary>
/// <param name="Name">元件的名称</param>
/// <param name="start">命名的基数 从0开始</param>
/// <param name="col">列(共29,从0开始)</param>
/// <param name="row">行(共13,从0开始)</param>
/// <param name="count">此次添加的元素个数</param>
/// <param name="direction">以该(col,row)开始以何方向添加元素</param>
public void AddControlToTableLayout(string sName,int start,int col,int row,int count,LayDirection direction,bool Remark)
{
if (col < 0 || col > 20) { throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0} [0,19]", col)); }
if (row < 0 || row > 7) { throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0} [0,6]", row)); }
#region 方向判断
int t = (int)direction;
switch (t)
{
case 0://left
{
if (col - count < -1)
{
throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0}:{1}-{2}<-1", direction.ToString(), col, count));
}
#region
string strName = sName;
for (int i = 0; i < count; i++)
{
LeftStation uc = new LeftStation();
string str=string.Format(strName + "{0:D4}", i+start);
if (tableLayoutPanel1.Controls.Find(str, false).ToArray().Length < 1)
{
uc.Name = str;
Control ct = tableLayoutPanel1.GetControlFromPosition(col - i, row);
tableLayoutPanel1.Controls.Remove(ct);
tableLayoutPanel1.Controls.Add(uc, col - i, row);
uc.Dock = DockStyle.Fill;
if(Remark==true)
{
if (i == count - 1 || i == 0) { continue; }
//left 的工位名称为其下一个
if (i == 0 || i == count - 1) { continue; }
Label lb = new Label();
lb.Font = new Font("宋体", 12);
lb.Text = str;
Control ct1 = tableLayoutPanel1.GetControlFromPosition(col - i, row + 1);
if (ct1 == null)
{
tableLayoutPanel1.Controls.Add(lb, col - i, row + 1);
lb.Dock = DockStyle.Fill;
}
}
}
else
{
throw new ArgumentOutOfRangeException(string.Format("重名名错误{1}",str));
}
}
#endregion
break;
}
case 1://down
{
if (row + count > 7)
{
throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0}:{1}+{2}>6", direction.ToString(), row, count));
}
#region
string strName = sName;
for (int i = 0; i < count; i++)
{
DownStation uc = new DownStation();
string str = string.Format(strName + "{0:D4}", i+start);
if (tableLayoutPanel1.Controls.Find(str, false).ToArray().Length < 1)
{
uc.Name = str;
Control ct = tableLayoutPanel1.GetControlFromPosition(col, row + i);
tableLayoutPanel1.Controls.Remove(ct);
tableLayoutPanel1.Controls.Add(uc, col , row+i);
uc.Dock = DockStyle.Fill;
if (Remark == true)
{
if (i == 0 || i == count - 1) { continue; }
Label lb = new Label();
lb.Font = new Font("宋体", 12);
lb.Text = str;
Control ct1 = tableLayoutPanel1.GetControlFromPosition(col + 1, row + i);
if (ct1 == null)
{
tableLayoutPanel1.Controls.Add(lb, col + 1, row + i);
lb.Dock = DockStyle.Fill;
}
}
}
else
{
throw new ArgumentOutOfRangeException(string.Format("重名名错误{1}", str));
}
}
#endregion
break;
}
case 2://right
{
if (col + count > 20)
{
throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0}:{1}+{2}>15", direction.ToString(), col, count));
}
#region
string strName = sName;
for (int i = 0; i < count; i++)
{
RightStation uc = new RightStation();
string str = string.Format(strName + "{0:D4}", i+start);
if (tableLayoutPanel1.Controls.Find(str, false).ToArray().Length < 1)
{
uc.Name = str;
Control ct = tableLayoutPanel1.GetControlFromPosition(col + i, row);
tableLayoutPanel1.Controls.Remove(ct);
tableLayoutPanel1.Controls.Add(uc, col + i, row);
uc.Dock = DockStyle.Fill;
if (Remark == true)
{
if (i == 0 || i == count - 1) { continue; }
Label lb = new Label();
lb.Font = new Font("宋体",12);
lb.Text = str;
Control ct1 = tableLayoutPanel1.GetControlFromPosition(col + i, row - 1);
if (ct1 == null)
{
tableLayoutPanel1.Controls.Add(lb, col + i, row - 1);
lb.Dock = DockStyle.Fill;
}
}
}
else
{
throw new ArgumentOutOfRangeException(string.Format("重名名错误{1}", str));
}
}
#endregion
break;
}
case 3://Up
{
if (row - count < -1)
{
throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0}:{1}-{2}<-1", direction.ToString(), row, count));
}
#region
string strName = sName;
for (int i = 0; i < count; i++)
{
UpStation uc = new UpStation();
string str = string.Format(strName + "{0:D4}", i+start);
if (tableLayoutPanel1.Controls.Find(str, false).ToArray().Length < 1)
{
uc.Name = str;
Control ct = tableLayoutPanel1.GetControlFromPosition(col, row - i);
tableLayoutPanel1.Controls.Remove(ct);
tableLayoutPanel1.Controls.Add(uc, col , row-i);
uc.Dock = DockStyle.Fill;
if(Remark==true)
{
if (i == 0 || i == count - 1) { continue; }
Label lb = new Label();
lb.Font = new Font("宋体", 12);
lb.Text = str;
Control ct1 = tableLayoutPanel1.GetControlFromPosition(col - 1, row - i);
if (ct1 == null)
{
tableLayoutPanel1.Controls.Add(lb, col - 1, row - i);
lb.Dock = DockStyle.Fill;
}
}
}
else
{
throw new ArgumentOutOfRangeException(string.Format("重名名错误{1}", str));
}
}
#endregion
break;
}
default:
{
throw new ArgumentOutOfRangeException("未定义此方向");
}
}
#endregion
}
/// <summary>
/// 增加设备到监控位置
/// </summary>
/// <param name="Code"></param>
/// <param name="Name"></param>
/// <param name="col"></param>
/// <param name="row"></param>
public void AddEquipmentToTableLayout(string Code, string Name, int col, int row)
{
if (col < 0 || col > 20) { throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0} [0,19]", col)); }
if (row < 0 || row > 7) { throw new ArgumentOutOfRangeException(string.Format("超出了定义范围{0} [0,6]", row)); }
Equipment uc = new Equipment();
uc.Name = Code;
uc.DisplayText = Name;
if (tableLayoutPanel1.Controls.Find(Name, false).ToArray().Length < 1)
{
Control ct = tableLayoutPanel1.GetControlFromPosition(col , row);
tableLayoutPanel1.Controls.Remove(ct);
tableLayoutPanel1.Controls.Add(uc, col , row);
uc.Dock = DockStyle.Fill;
}
else
{
throw new ArgumentOutOfRangeException(string.Format("重名名错误{1}", Name));
}
}
}
}