FrmProgramList.cs
13.5 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
using LineSoldering.Common;
using LineSoldering.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using LineSoldering.LoadCSVLibrary;
namespace LineSoldering.Client
{
public partial class FrmProgramList : FrmBase
{
public FrmProgramList()
{
InitializeComponent();
}
private void FrmPointType_Load(object sender, EventArgs e)
{
LoadCom();
LoadList();
loadFixtureType();
}
List<string> FileList = new List<string>();
private void LoadCom()
{
try
{
cmbAoiFile.Items.Clear();
FileList = new List<string>();
string appPath = Application.StartupPath;
string pathName = ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string filePath = appPath + pathName;
string path = Path.GetDirectoryName(filePath);
string suffix = Path.GetExtension(filePath);
string[] files = Directory.GetFiles(path);
foreach (string f in files)
{
if (Path.GetExtension(f).Equals(suffix))
{
string fileName = Path.GetFileName(f);
FileList.Add(fileName);
cmbAoiFile.Items.Add(fileName);
}
}
if (FileList.Count > 0)
{
cmbAoiFile.SelectedIndex = 0;
}
}
catch (Exception ex)
{
LogUtil.error("加载出错:" + ex.ToString());
}
}
private void LoadList()
{
cmbFixtureType.SelectedIndex = 0;
dgvList.Rows.Clear();
foreach (SProgramInfo obj in SProgramManager.programList)
{
dgvList.Rows.Add(SetRowInfo(null, obj));
}
}
private void loadFixtureType()
{
List<SProgramInfo> point = new List<SProgramInfo>();
point.Add(new SProgramInfo(1));
point.Add(new SProgramInfo(2));
point.Add(new SProgramInfo(3));
this.Column_FixtureType.DataSource = point;
this.Column_FixtureType.ValueMember = "FixtureType";
this.Column_FixtureType.DisplayMember = "FixtureName";
}
private DataGridViewRow SetRowInfo(DataGridViewRow view, SProgramInfo com)
{
if (view == null)
{
view = new DataGridViewRow();
view.CreateCells(dgvList);
}
view.Cells[Column_Name.Index].Value = com.PartNumber.ToString();
view.Cells[Column_boardCode.Index].Value = com.Code.ToString();
view.Cells[Column_FixtureType.Index].Value = com.FixtureType;
view.Cells[this.Column_Id.Index].Value = com.Id;
view.Cells[Column_Width.Index].Value = com.Width;
view.Cells[Column_Length.Index].Value = com.Length;
view.Cells[Column_CoverPlate.Index].Value = com.IsCoverPlate;
view.Cells[Column_Check1.Index].Value = com.IsMaterialCheck1;
view.Cells[Column_Check2.Index].Value = com.IsMaterialCheck2;
view.Cells[Column_Station2Check1.Index].Value = com.IsStation2Check1;
view.Cells[Column_Station2Check2.Index].Value = com.IsStation2Check2;
view.Cells[Column_AoiFile.Index].Value = com.AoiFile;
return view;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (groupInfo.Text.StartsWith("新增"))
{
AddProgram();
LoadList();
}
else
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
DataGridViewRow row = dgvList.Rows[rowIndex];
SProgramInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show( "请选择程序!");
return;
}
obj.PartNumber = FormUtil.getValue(txtPartNumber);
//obj.ProgramDetial = FormUtil.getValue(txtDes);
obj.Length = FormUtil.GetIntValue(txtLength);
obj.Width = FormUtil.GetIntValue(txtWidth);
obj.FixtureType = cmbFixtureType.SelectedIndex + 1;
obj.Code = FormUtil.getValue(txtWareCode);
obj.ProgramDetial = FormUtil.getValue(txtDetial);
obj.IsCoverPlate = chbCoverPlate.Checked;
obj.IsMaterialCheck1 = chbMaterialCheck1.Checked;
obj.IsMaterialCheck2 = chbMaterialCheck2.Checked;
obj.IsStation2Check1 = chbStation2Check1.Checked;
obj.IsStation2Check2 = chbStation2Check2.Checked;
obj.AoiFile = cmbAoiFile.Text;
if (obj.PartNumber.Equals(""))
{
MessageBox.Show("请输入程序名称!");
txtPartNumber.Focus();
return;
}
if (obj.Length <= 0)
{
MessageBox.Show("请输入程序长度!");
txtLength.Focus();
return;
}
if (obj.Width <= 0)
{
MessageBox.Show("请输入程序宽度!");
txtWidth.Focus();
return;
}
if (obj.AoiFile.Equals(""))
{
MessageBox.Show("请选择AOI程序!");
txtWidth.Focus();
return;
}
SProgramInfo o = SProgramManager.getByPartNum(obj.PartNumber);
if (o != null&&(!obj.Id.Equals(o.Id)))
{
MessageBox.Show("程序名称【" + obj.PartNumber + "】已存在!");
txtPartNumber.Focus();
return;
}
SProgramManager.Update(obj);
SetRowInfo(dgvList.Rows[rowIndex], obj);
MessageBox.Show("程序【"+obj.PartNumber+"】保存成功!");
groupInfo.Text = "程序【" + obj.PartNumber + "】的基本信息";
LoadList();
}
}
}
private void AddProgram()
{
SProgramInfo obj = new SProgramInfo();
obj.PartNumber = FormUtil.getValue(txtPartNumber);
//obj.ProgramDetial = FormUtil.getValue(txtDes);
obj.Length = FormUtil.GetIntValue(txtLength);
obj.Width = FormUtil.GetIntValue(txtWidth);
obj.Id = SProgramManager.GetNextId();
obj.FixtureType = cmbFixtureType.SelectedIndex + 1;
obj.Code = FormUtil.getValue(txtWareCode);
obj.ProgramDetial = FormUtil.getValue(txtDetial);
obj.IsCoverPlate = chbCoverPlate.Checked;
obj.IsMaterialCheck1 = chbMaterialCheck1.Checked;
obj.IsMaterialCheck2 = chbMaterialCheck2.Checked;
obj.IsStation2Check1 = chbStation2Check1.Checked;
obj.IsStation2Check2 = chbStation2Check2.Checked;
obj.AoiFile = cmbAoiFile.Text;
if (obj.PartNumber.Equals(""))
{
MessageBox.Show("请输入程序名称!");
txtPartNumber.Focus();
return;
}
if (obj.Length <= 0)
{
MessageBox.Show("请输入程序长度!");
txtLength.Focus();
return;
}
if (obj.Width <= 0)
{
MessageBox.Show("请输入程序宽度!");
txtWidth.Focus();
return;
}
if (obj.AoiFile.Equals(""))
{
MessageBox.Show("请选择AOI程序!");
txtWidth.Focus();
return;
}
if (SProgramManager.getByPartNum(obj.PartNumber) != null)
{
MessageBox.Show("程序名称【"+obj.PartNumber+"】已存在!");
txtPartNumber.Focus();
return;
}
SProgramManager.Add(obj);
MessageBox.Show("程序【" + obj.PartNumber + "】保存成功!");
groupInfo.Text = "程序【" + obj.PartNumber + "】的基本信息";
}
private void btnDel_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
DeleteCom(rowIndex);
}
}
private SProgramInfo getRowPointInfo(DataGridViewRow row)
{
SProgramInfo point = new SProgramInfo();
try
{
if (row.Cells[Column_Name.Name].Value == null)
{
return null;
}
int id = Convert.ToInt32( row.Cells[this.Column_Id.Name].Value.ToString());
point = SProgramManager.getById(id);
}
catch (Exception ex)
{
LogUtil.error( "保存数据出错:" + ex.ToString());
MessageBox.Show("请检查程序数据是否正确!");
return null;
}
return point;
}
private void showDetail(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
SProgramInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show("请选择程序!");
return;
}
txtId.Tag = obj;
txtPartNumber.Text = obj.PartNumber;
txtWareCode.Text = obj.Code;
txtLength.Text = obj.Length.ToString();
txtWidth.Text = obj.Width.ToString();
chbCoverPlate.Checked = obj.IsCoverPlate;
chbMaterialCheck1.Checked = obj.IsMaterialCheck1;
chbMaterialCheck2.Checked = obj.IsMaterialCheck2;
chbStation2Check1.Checked = obj.IsStation2Check1;
chbStation2Check2.Checked = obj.IsStation2Check2;
cmbFixtureType.SelectedIndex = obj.FixtureType - 1;
txtId.Text = obj.Id.ToString();
//判断索引
int index = FileList.IndexOf(obj.AoiFile);
if (index >= 0)
{
cmbAoiFile.SelectedIndex = index;
}
groupInfo.Text = "程序【" + obj.PartNumber + "】的基本信息";
}
private void DeleteCom(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
SProgramInfo obj = getRowPointInfo(row);
if (obj.GetBoardMap().Count > 0)
{
MessageBox.Show("程序【"+obj.PartNumber+"】已经配置了产品,无法删除");
return;
}
if (MessageBox.Show(
"确认要删除程序【" + obj.PartNumber + "】吗?","提示",MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
SProgramManager.Delete(obj);
this.dgvList.Rows.RemoveAt(rowIndex);
MessageBox.Show("程序【" + obj.PartNumber + "】删除成功!");
LoadList();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex >= 0)
{
string name = this.dgvList.Columns[e.ColumnIndex].Name;
if (name.Equals(this.Column_Del.Name))
{
DeleteCom(e.RowIndex);
}
}
}
private void dgvList_SelectionChanged(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
showDetail(rowIndex);
}
}
private void FrmComponentList_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
groupInfo.Text = "新增";
txtId.Text = "";
txtPartNumber.Text = "";
txtLength.Text = "";
txtWidth.Text = "";
txtDetial.Text = "";
txtWareCode.Text = "";
chbCoverPlate.Checked = false;
chbMaterialCheck1.Checked = false;
chbMaterialCheck2.Checked = false;
chbStation2Check1.Checked = false;
chbStation2Check2.Checked = false;
}
}
}