uc_boxdebug.cs
8.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
using DeviceLibrary;
using log4net;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
public partial class uc_boxdebug : UserControl
{
private Robot_Config _Config;
public Robot_Config Config
{
get { return _Config; }
set
{
if (value == null)
return;
_Config = value;
robotPosControl1.Config = _Config;
}
}
//如果总配置文件存在,保存到总的配置文件
static string appPath = Application.StartupPath;
class PosState
{
public int InStoreCheck = 0;
public int OutStoreCheck = 0;
}
public uc_boxdebug()
{
InitializeComponent();
}
Dictionary<string, RobotPosition> data;
public void Init(Dictionary<string, RobotPosition> _data)
{
data = _data;
FillBoxPos();
//timer1.Enabled = true;
}
DataGridViewCellStyle GetStyle(string posid) {
return dgv_none;
}
class PosPos {
public string Posid;
public int index;
public int row;
public int col;
}
int PosCompare(string a, string b) {
if (a.StartsWith("fix"))
return -1;
if (b.StartsWith("fix"))
return 1;
string[] pa = a.Split('_');
string[] pb = b.Split('_');
if (int.TryParse(pa[1], out _))
pa[1] += "A";
if (int.TryParse(pb[1], out _))
pb[1] += "A";
var pa1 = pa[1][0] + (pa[1][1].Equals('A') ? "1" : "2");
var pb1 = pb[1][0] + (pb[1][1].Equals('A') ? "1" : "2");
var pa2 = pa[2];
var pb2 = pb[2];
if (pa[2].Length == 2)
{
if (pa[2][1].Equals('A') || pa[2][1].Equals('B'))
{
pa2 = (pa[2][1].Equals('A') ? "1" : "2") + pa[2][0];
}
else if (pa[2][1].Equals('1') || pa[2][1].Equals('2'))
{
pa2 = (pa[2][1].Equals('1') ? "1" : "2") + pa[2][0];
}
}
if (pb[2].Length == 2)
{
if ((pb[2][1].Equals('A') || pb[2][1].Equals('B')))
{
pb2 = (pb[2][1].Equals('A') ? "1" : "2") + pb[2][0];
}
else if ((pb[2][1].Equals('1') || pb[2][1].Equals('2')))
{
pb2 = (pb[2][1].Equals('1') ? "1" : "2") + pb[2][0];
}
}
var isa = Regex.Replace(pa[1], @"[^\d]*", "") + pa1 + pa2 + pa[3].PadLeft(2, '0');
var isb = Regex.Replace(pb[1], @"[^\d]*", "") + pb1 + pb2 + pb[3].PadLeft(2, '0');
if (int.Parse(isa) == int.Parse(isb))
return 0;
else if (int.Parse(isa) > int.Parse(isb))
return 1;
else
return -1;
}
static Font font = new Font("宋体",10);
DataGridViewCellStyle dgv_ok = new DataGridViewCellStyle() { BackColor = Color.LightGreen, Font = font };
DataGridViewCellStyle dgv_oin = new DataGridViewCellStyle() { BackColor = Color.LightGray, Font = font };
DataGridViewCellStyle dgv_oout = new DataGridViewCellStyle() { BackColor = Color.LightSeaGreen, Font = font };
DataGridViewCellStyle dgv_none = new DataGridViewCellStyle() { BackColor = Color.White,Font= font };
void FillBoxPos()
{
dataGridView1.Columns.Clear();
dataGridView1.Rows.Clear();
int colcount = 9;
for (int i = 0; i < colcount; i++)
{
dataGridView1.Columns.Add("Col" + i, "Col" + i);
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
dataGridView1.Rows.Add();
int currentRowIndex = 0;
int currentColIndex = -1;
string lastAB = "";
List<string> datakeys = data.Keys.ToList();
for (int i = 0; i < data.Count; i++)
{
string posname = datakeys[i];
string memo = "";
if (data.ContainsKey(posname))
{
memo = data[posname].Memo;
}
string ab = memo.Substring(0, 2);
if (posname.StartsWith("LabelP") || posname.StartsWith("RFIDP"))
{
ab = "aa";
}
var showname = posname;
if (ab != lastAB)
{
currentRowIndex = 0;
currentColIndex++;
lastAB = ab;
//if (posname.StartsWith("L"))
//{
// dataGridView1.Columns[currentColIndex].HeaderText = "(" + posname.Substring(0, 2) + "";
//}
//else
{
dataGridView1.Columns[currentColIndex].HeaderText = crc.GetString("Res0031","取放料点");
}
}
//if (!posname.StartsWith("L"))
{
if (memo.IndexOf("_") >= 0)
{
var id = memo.IndexOf("_");
var m = memo.Substring(0,id);
var m2 = memo.Substring(id, memo.Length-id);
showname = posname + "(" + crc.GetString(m, m)+ m2 + ")";
}
else
showname = posname + "(" + crc.GetString(memo, memo) + ")";
}
var currentRow = dataGridView1.Rows[currentRowIndex];
currentRow.Cells[currentColIndex].Value = showname;
currentRow.Cells[currentColIndex].Tag = posname;
currentRow.Cells[currentColIndex].Style = GetStyle(posname);
currentRowIndex++;
if (currentRowIndex >= dataGridView1.Rows.Count)
dataGridView1.Rows.Add();
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
if (dataGridView1.Rows[0].Cells[i].Value == null)
{
dataGridView1.Columns[i].Width = 0;
}
}
if (dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 1].Value != null)
{
dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 1].Selected = true;
}
else if (dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 2].Value != null)
{
dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 2].Selected = true;
}
dataGridView1.Rows.RemoveAt(dataGridView1.Rows.Count - 1);
if (dataGridView1.SelectedCells.Count > 0)
setData(dataGridView1.SelectedCells[0].Tag.ToString());
else
setData(data.Keys.ToList().Last());
}
void setData(string posid)
{
RobotPosition ktkPosition = null;
cmbPosition.Text = posid;
if (data.ContainsKey(posid))
{
ktkPosition = data[posid];
robotPosControl1.LoadPos(ktkPosition);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!Visible)
return;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex<0 || dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag == null)
return;
var posid = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString();
setData(posid);
}
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex < 0 || dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag == null)
return;
var posid = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString();
setData(posid);
}
}
}