FrmBoardList.cs
15.4 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
using log4net;
using MetroFramework.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using System;
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.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.LoadCSVLibrary;
namespace TSA_V
{
public partial class FrmBoardList : FrmBase
{
public static FrmBoardList instance = new FrmBoardList();
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool LoadOk = false;
private FrmBoardList( )
{
InitializeComponent();
}
PointDisplay display = new PointDisplay();
private void FrmBoard_Load(object sender, EventArgs e)
{
display.SetPic(picBoard, panBoard);
LanguageProcess();
LoadCom();
}
public void LoadCom()
{
LoadOk = false;
cmbBoardList.DataSource = null;
cmbBoardList.DataSource = BoardManager.boardList;
cmbBoardList.DisplayMember = "boardName";
cmbBoardList.ValueMember = "boardId";
if (BoardManager.boardList.Count > 0)
{
cmbBoardList.SelectedIndex = 0;
}
this.listPoint.Columns.Clear();
ColumnHeader preSendwire = new ColumnHeader();
preSendwire.Text =ResourceCulture.GetString(ResourceCulture.Col_Num, "位号"); //设置列标题
preSendwire.Width = 120; //设置列宽度
preSendwire.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(preSendwire); //将列头添加到ListView控件。
ColumnHeader chName = new ColumnHeader();
chName.Text = ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编码"); //设置列标题
chName.Width = 100; //设置列宽度
chName.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(chName); //将列头添加到ListView控件。
ColumnHeader position = new ColumnHeader();
position.Text = ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置"); //设置列标题
position.Width = 80; //设置列宽度
position.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(position); //将列头添加到ListView控件。
ColumnHeader leftCount = new ColumnHeader();
leftCount.Text = ResourceCulture.GetString(ResourceCulture.Col_KuCun, "库存"); //设置列标题
leftCount.Width = 100; //设置列宽度
leftCount.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(leftCount); //将列头添加到ListView控件。
LoadOk = true;
LoadBoard();
}
private void UpdateCol()
{
if (this.listPoint.Columns.Count >= 4)
{
this.listPoint.Columns[0].Text = ResourceCulture.GetString(ResourceCulture.Col_Num, "编号");
this.listPoint.Columns[1].Text = ResourceCulture.GetString(ResourceCulture.Col_Name, "名称");
this.listPoint.Columns[2].Text = ResourceCulture.GetString(ResourceCulture.Col_Position, "位置");
this.listPoint.Columns[3].Text = ResourceCulture.GetString(ResourceCulture.Col_KuCun, "库存");
}
}
//FrmBoardInfo frm = null;
private void btnSave_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
this.Visible = false;
FrmBoardInfo.instance.Show();
FrmBoardInfo.instance.SetBoard(board);
FrmBoardInfo.instance.LoadForm();
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectP,"请选择程序!"));
}
}
private int pointHight = 14;
//private void btnLook_Click(object sender, EventArgs e)
//{
// LoadBoard();
// this.panel1.Refresh();
//}
private void LoadBoard()
{
if (!LoadOk)
{
return;
}
try
{
LoadOk = false;
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
groupBox2.Text = "【" + board.boardName + "】";
txtBomName.Text = board.bomName;
txtLength.Text = board.boardLength.ToString();
txtWidth.Text = board.boardWidth.ToString();
txtPointCount.Text = board.smtList.Count.ToString();
txtMianji.Text = (board.boardLength * board.boardWidth).ToString();
LoadPoint(board);
loadPictureBoxSize(board);
FrmProjectorScreen.instance.ShowPoint(false, board.smtList.ToArray());
}
}
catch (Exception ex)
{
}
finally
{
LoadOk = true;
}
}
int preId = -1;
private void LoadPoint(BoardInfo board)
{
if (preId >= 0 && preId.Equals(board.boardId))
{
return;
}
preId = board.boardId;
this.listPoint.Items.Clear();
int i = 0;
foreach (SMTPointInfo point in board.smtList)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
lvi.Text = point.PartNum.ToString();
lvi.SubItems.Add(point.pointName);
ComponetInfo com = CSVBomManager.GetCom(board.bomName, point.PartNum);
if (com != null)
{
lvi.SubItems.Add(com.PositionNum);
lvi.SubItems.Add(com.ComCount.ToString());
}
else
{
lvi.SubItems.Add(point.PositionNum);
lvi.SubItems.Add(0.ToString());
}
//lvi.SubItems.Add(point.NodePositionX.ToString());
//lvi.SubItems.Add(point.NodePositionY.ToString());
this.listPoint.Items.Add(lvi);
i++;
}
}
private void btnNew_Click(object sender, EventArgs e)
{
//FrmBoardInfo info = new FrmBoardInfo(null);
FrmAddBoard info = new FrmAddBoard();
this.Visible = false;
info.ShowDialog();
if (FrmBoardInfo.instance.Visible.Equals(false))
{
this.Visible = true;
LoadCom();
cmbBoardList_SelectedIndexChanged(null, null);
preId = -1;
}
}
private void cmbBoardList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadBoard();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
////如果是当前默认程序,不能删除
//if (BoardManager.CurrBoard != null && board.boardId.Equals(BoardManager.CurrBoardId))
//{
// MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CanotDel,"【{0}】是默认工作程序,不能删除!",board.boardName));
// return;
//}
if (MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureDeleteP,"确认要删除程序【{0}】吗?",board.boardName),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示"),
//if (MessageBox.Show("确认要删除程序【" + board.boardName + "】吗?", "删除确认",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question).Equals(DialogResult.OK))
{
BoardManager.Delete(board);
cmbBoardList.DataSource = BoardManager.boardList;
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DeletePOk, "删除程序【{0}】成功!", board.boardName));
this.listPoint.Clear();
this.txtBomName.Text = "";
this.txtLength.Text = "";
this.txtMianji.Text = "";
this.txtPointCount.Text = "";
this.txtWidth.Text = "";
this.picBoard.Image = null;
LoadCom();
cmbBoardList_SelectedIndexChanged(null, null);
preId = -1;
}
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectP,"请选择程序!"));
}
}
private BoardInfo preBoard = null;
private void loadPictureBoxSize(BoardInfo board = null)
{
if (board == null)
{
board = preBoard;
}
if (board == null)
{
return;
}
preBoard = board;
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
List<SMTPointInfo> pointList = board.smtList;
int width = board.boardWidth;
int height = board.boardLength;
display.SetImage(board.GetImage());
display.ShowName = false ;
display.ImageNormal = true ;
display.LoadPoint(width, height, pointList);
}
private void FrmBoardList_Shown(object sender, EventArgs e)
{
//SetSkin(this);
//LoadBoard();
if ((BoardManager.boardList.Count <= 0) && (LoadCSVLibrary.CSVBomManager.allComMap.Count <= 0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ImportComList, "请先导入元器件库!"));
this.Close();
}
display.SetPic(picBoard, panBoard);
}
private void btnBack_Click(object sender, EventArgs e)
{
Close();
}
private void FrmBoardList_FormClosing(object sender, FormClosingEventArgs e)
{
Close();
e.Cancel = true;
}
private void Close()
{
FrmProjectorScreen.instance.ClearPoint();
this.Visible = false;
FrmMenu.frmMain.Visible = true;
}
private void picBoard_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
UpdateCol();
}
}
private void btnImport_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
openFileDialog1.Filter = @"data|*.data";
DialogResult result = this.openFileDialog1.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string fileName = this.openFileDialog1.FileName;
string[] lines = File.ReadAllLines(fileName, Encoding.GetEncoding("gbk"));
if (lines.Length <= 0)
{
MessageBox.Show(ResourceCulture.GetString("解析程序失败,请选择正确文件"), ResourceCulture.GetString("提示"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool isNeedUpdate = false;
BoardInfo board = BoardManager.StringToBoard(lines[0], out isNeedUpdate);
if (board == null)
{
MessageBox.Show(ResourceCulture.GetString("解析程序失败,请选择正确文件"), ResourceCulture.GetString("提示"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (BoardManager.getBoardByName(board.boardName) != null)
{
MessageBox.Show(ResourceCulture.GetString("导入失败:程序名已存在"), ResourceCulture.GetString("提示"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string oldName = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_DEFAULT);
string newName = board.boardName + Path.GetExtension(oldName);
string configPath = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_PATH);
string oldPath = Application.StartupPath + @"\" + configPath +@"\" + oldName;
string newPath = Application.StartupPath + @"\" + configPath + @"\" + newName;
if (File.Exists(oldPath))
{
File.Copy(oldPath, newPath, true);
}
board.imgName = newName;
board.boardId = BoardManager.GetNextId();
BoardManager.Add(board);
MessageBox.Show(ResourceCulture.GetString("导入成功"), ResourceCulture.GetString("提示"));
LoadCom();
preId = -1;
}
}
private void btnExport_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = "PROGRAM-" + board.boardName + "-" + DateTime.Now.ToString("yyyy:MM:dd:HH:mm").Replace(":", "");
sfd.Filter = @"data|*.data";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
File.WriteAllText(filePath, JsonHelper.SerializeObject(board), Encoding.GetEncoding("gbk"));
MessageBox.Show(ResourceCulture.GetString("成功导出程序到文件:")+"\r\n" + filePath, ResourceCulture.GetString("提示"));
}
}
}
}
private void listPoint_SelectedIndexChanged(object sender, EventArgs e)
{
if (LoadOk)
{
if (listPoint.SelectedItems != null && listPoint.SelectedItems.Count > 0)
{
int index = listPoint.SelectedItems[0].Index;
display.selectIndex = index;
loadPictureBoxSize(null);
}
}
}
}
}