FrmComponentList.cs
15.9 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
390
391
392
393
394
395
396
397
398
399
400
401
402
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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using TSA_V.LoadCSVLibrary;
namespace TSA_V
{
public partial class FrmComponentList : FrmBase
{
public static FrmComponentList instance = new FrmComponentList();
private FrmComponentList()
{
InitializeComponent();
}
private void FrmPointType_Load(object sender, EventArgs e)
{
// SetSkin(this);
loadPositionList();
LoadComList();
LanguageProcess();
LanguagePro();
}
private void LanguagePro()
{
this.Column_partNumber.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Num, "编号");
this.Column_Name.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Name, "名称");
this.Column_Count.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Count, "数量");
this.Column_Position.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Position, "位置");
this.Column_Notes.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Notes, "注意事项");
this.Column_description.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Del, "描述");
this.Column_Del.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
this.Column_Del.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
this.Column_Del.ToolTipText = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
}
private List<TSAVPosition> allPosition = new List<TSAVPosition>(CSVPositionReader<TSAVPosition>.allPositionMap.Values);
private void loadPositionList()
{
cmbPositionNumList.DataSource = null;
cmbPositionNumList.DataSource = allPosition;
cmbPositionNumList.DisplayMember = "PositionNum";
cmbPositionNumList.ValueMember = "PositionNum";
}
private void LoadComList()
{
List<string> keyList =new List<string> ( LoadCSVLibrary.CSVReaderBomManager.allComMap.Keys);
this.cmbList.Items.Clear();
foreach (string key in keyList)
{
this.cmbList.Items.Add(key);
}
if (keyList.Count > 0)
{
this.cmbList.SelectedIndex = 0;
}
}
private void cmbList_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbList.SelectedIndex >= 0)
{
this.dgvList.Rows.Clear();
string key = cmbList.Text;
List<ComponetInfo> list = CSVReaderBomManager.GetComList(key);
foreach (ComponetInfo com in list)
{
if (com != null)
{
dgvList.Rows.Add(SetRowInfo(null, com));
}
}
}
}
private DataGridViewRow SetRowInfo(DataGridViewRow view, ComponetInfo com)
{
if (view == null)
{
view = new DataGridViewRow();
view.CreateCells(dgvList);
}
view.Cells[Column_Name.Index].Value = com.ComponentName.ToString();
view.Cells[this.Column_X.Index].Value = com.PositionX.ToString();
view.Cells[Column_Y.Index].Value = com.PositionY.ToString();
view.Cells[this.Column_description.Index].Value = com.ComponentDes.ToString();
view.Cells[this.Column_Notes.Index].Value = com.Notes.ToString();
view.Cells[this.Column_partNumber.Index].Value = com.PartNum.ToString();
view.Cells[this.Column_Position.Index].Value = com.PositionNum.ToString();
view.Cells[this.Column_Count.Index].Value = com.ComCount.ToString();
return view;
}
private void btnNew_Click(object sender, EventArgs e)
{
FrmAddCom frm = new FrmAddCom();
this.Visible = false;
frm.ShowDialog();
LoadComList();
this.Visible = true;
}
private void btnSave_Click(object sender, EventArgs e)
{
//if (groupInfo.Text.StartsWith("新增"))
//{
// //AddCom();
//}
//else
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectC,"请选择元器件!"));
return;
}
if (cmbPositionNumList.SelectedIndex < 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectCPosition,"请选择元器件位置!"));
cmbPositionNumList.Focus();
return;
}
TSAVPosition position = (TSAVPosition)cmbPositionNumList.SelectedItem;
obj.ComponentName = FormUtil.getValue(txtName);
obj.ComponentDes = FormUtil.getValue(txtDes);
obj.ComCount = FormUtil.GetIntValue(txtCount);
obj.Notes = FormUtil.getValue(txtNotes);
obj.PartNum = FormUtil.getValue(txtPartNum);
obj.PositionNum = position.PositionNum;
if (obj.ComponentName.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComName,"请输入元器件名称!"));
txtName.Focus();
return;
}
//if (obj.PositionNum.Equals(""))
//{
// MessageBox.Show("请输入元器件所在位置!");
// this.txtPosition.Focus();
// return;
//}
if (obj.ComCount<=0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComNum,"请输入元器件数量!"));
txtCount.Focus();
return;
}
CSVReaderBomManager.SaveComponet(cmbList.Text, obj);
//ComponentManager.Update(obj);
SetRowInfo(dgvList.Rows[rowIndex], obj);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ComSaveOk,"元器件【{0}】保存成功!", obj.PartNum + "-" + obj.ComponentName ));
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.ComInfo,"元器件【{0}】的基本信息",obj.PartNum + "-" + obj.ComponentName);
}
}
}
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 ComponetInfo getRowPointInfo(DataGridViewRow row)
{
ComponetInfo point = new ComponetInfo();
try
{
if (row.Cells[Column_Name.Name].Value == null)
{
return null;
}
point.PartNum = row.Cells[this.Column_partNumber.Name].Value.ToString();
point.ComponentName = row.Cells[this.Column_Name.Name].Value.ToString();
point.PositionX =Convert.ToDouble( row.Cells[this.Column_X.Name].Value.ToString());
point.PositionY =Convert.ToDouble( row.Cells[this.Column_Y.Name].Value.ToString());
point.ComponentDes = row.Cells[this.Column_description.Name].Value.ToString();
point.Notes = row.Cells[this.Column_Notes.Name].Value.ToString();
point.PositionNum = row.Cells[this.Column_Position.Name].Value.ToString();
point.ComCount = Convert.ToInt32(row.Cells[this.Column_Count.Name].Value.ToString());
}
catch (Exception ex)
{
LogUtil.error( "保存数据出错:" + ex.ToString());
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CheckComNum,"请检查元器件数据是否正确!"));
return null;
}
return point;
}
private void showDetail(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceCom,"请选择元器件!"));
return;
}
txtPartNum.Tag = obj;
txtName.Text = obj.ComponentName;
txtDes.Text = obj.ComponentDes;
txtCount.Text = obj.ComCount.ToString();
txtPartNum.Text = obj.PartNum;
txtNotes.Text = obj.Notes;
//txtPosition.Text = obj.PositionNum;
int index = -1;
foreach (TSAVPosition p in allPosition)
{
index++;
if (p.PositionNum.Equals(obj.PositionNum))
{
break;
}
}
if (index >= 0)
{
this.cmbPositionNumList.SelectedIndex = index;
}
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.ChoiceLibrary, "元器件【{0}】的基本信息",obj.PartNum+"-"+obj.ComponentName);
}
private void DeleteCom(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (MessageBox.Show(
ResourceCulture.GetString(ResourceCulture.SureDelCom, "确认要删除元器件【{0}】吗?", obj.PartNum + "-" + obj.ComponentName),
ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
CSVReaderBomManager.RemoveCom(cmbList.Text, obj);
this.dgvList.Rows.RemoveAt(rowIndex);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DelComOk,"元器件【{0}】删除成功!",obj.PartNum + "-" + obj.ComponentName)
,ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"));
}
}
private void btnBack_Click(object sender, EventArgs e)
{
//this.Close();
this.Visible = false;
FrmMenu.frmMain.Visible = true;
}
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 btnDownLoad_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = ResourceCulture.GetString( "元器件库模板");
sfd.Filter = @"csv|*.csv";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
//if (Directory.Exists(filePath))
{
string sourcePath = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.Componet_Template);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
//复制文件
File.Copy(sourcePath, filePath);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DemoSave,"模板已保存在:" )+ filePath);
}
}
}
private void BtnBeiLiao_Click(object sender, EventArgs e)
{
if (cmbList.SelectedIndex >= 0)
{
string key = cmbList.Text;
List<ComponetInfo> list = CSVReaderBomManager.GetComList(key);
FrmPutCom frm = new FrmPutCom();
if (frm.SetOperateInfo(key, list))
{
this.Visible = false;
frm.ShowDialog();
this.Visible = true;
cmbList_SelectedIndexChanged(null, null);
}
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceLibrary,"请先选择一个元器件库"));
}
}
private void btnDel_Click_1(object sender, EventArgs e)
{
if (cmbList.SelectedIndex >= 0)
{
string bomName = this.cmbList.Text;
//如果在程序中存在,不能删除
foreach (BoardInfo board in BoardManager.boardList)
{
if (board.bomName.Equals(bomName))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CanotDelC,"元器件库【{0}】在程序【{1}】中使用,不能删除!",bomName,board.boardName));
return;
}
}
if (MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureDeleteC,"确认要删除元器件库【{0}】吗?",bomName),
ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
CSVReaderBomManager.RemoveBom(bomName);
dgvList.Rows.Clear();
this.txtCount.Text = "";
this.txtDes.Text = "";
this.txtName.Text = "";
this.txtNotes.Text = "";
this.txtPartNum.Text = "";
LoadComList();
}
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectC,"请先选择一个元器件库"));
}
}
private void FrmComponentList_FormClosing(object sender, FormClosingEventArgs e)
{
this.Visible = false;
FrmMenu.frmMain.Visible = true;
e.Cancel = true;
}
private void FrmComponentList_Shown(object sender, EventArgs e)
{
}
private void FrmComponentList_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
LanguagePro();
}
}
}
}