FrmComponentList.cs
33.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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
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;
using TSA_V.DeviceLibrary.manager;
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_PN.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";
}
internal void LoadComList()
{
List<string> keyList = new List<string>(LoadCSVLibrary.CSVBomManager.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 = CSVBomManager.GetComList(key);
//foreach (ComponetInfo com in list)
//{
// if (com != null)
// {
// dgvList.Rows.Add(SetRowInfo(null, com));
// }
//}
UpdateGridList(list);
}
}
private void UpdateGridList(List<ComponetInfo> list)
{
this.dgvList.Rows.Clear();
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_PN.Index].Value = com.PN.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.TagNo.ToString();
view.Cells[this.Column_Position.Index].Value = com.PositionNum.ToString();
view.Cells[this.Column_Count.Index].Value = com.ComCount.ToString();
view.Cells[this.Column_ID.Index].Value = com.Id.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 (IsNew)
{
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);
string oldPosition = obj.PositionNum;
string oldTagNo = obj.TagNo;
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.PN = FormUtil.getValue(txtName);
obj.ComponentDes = FormUtil.getValue(txtDes);
obj.ComCount = FormUtil.GetIntValue(txtCount).ToString();
obj.Notes = FormUtil.getValue(txtNotes);
obj.TagNo = FormUtil.getValue(txtPartNum);
obj.Id = FormUtil.GetIntValue(txtId);
obj.PositionNum = position.PositionNum;
if (obj.PN.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComName, "请输入元器件名称!"));
txtName.Focus();
return;
}
if (int.Parse(obj.ComCount) <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComNum, "请输入元器件数量!"));
txtCount.Focus();
return;
}
if (obj.PositionNum.Equals(oldPosition).Equals(false) && (!String.IsNullOrEmpty(obj.TagNo)))
{
List<ComponetInfo> list = CSVBomManager.GetComList(cmbList.Text);
List<ComponetInfo> objs = (from m in list where m.Id.Equals(obj.Id).Equals(false) && m.PN.Equals(obj.PN) && m.PositionNum.Equals(obj.PositionNum) select m).ToList();
if (objs.Count > 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ComExists, "元器件已存在"));
}
}
if (obj.TagNo.Equals(oldTagNo).Equals(false) && (!String.IsNullOrEmpty(obj.TagNo)))
{
List<ComponetInfo> list = CSVBomManager.GetComList(cmbList.Text);
List<ComponetInfo> objs = (from m in list where (!String.IsNullOrEmpty(m.TagNo)) && m.TagNo.Equals(obj.TagNo) select m).ToList();
if (objs.Count > 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PartNAExist, "元器件编号[{0}]已存在", obj.TagNo));
txtPartNum.Focus();
return;
}
}
bool result = CSVBomManager.UpdateComponet(cmbList.Text, obj);
if (result)
{
//ComponentManager.Update(obj);
SetRowInfo(dgvList.Rows[rowIndex], obj);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ComSaveOk, "元器件【{0}】保存成功!", obj.TagNo + "-" + obj.PN));
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.ComInfo, "元器件【{0}】的基本信息", obj.TagNo + "-" + obj.PN);
}
}
}
}
private void AddCom()
{
ComponetInfo obj = new ComponetInfo();
if (cmbPositionNumList.SelectedIndex < 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectCPosition, "请选择元器件位置!"));
cmbPositionNumList.Focus();
return;
}
TSAVPosition position = (TSAVPosition)cmbPositionNumList.SelectedItem;
obj.TagNo = FormUtil.getValue(txtPartNum);
obj.PN = FormUtil.getValue(txtName);
obj.ComponentDes = FormUtil.getValue(txtDes);
obj.ComCount = FormUtil.GetIntValue(txtCount).ToString();
obj.Notes = FormUtil.getValue(txtNotes);
obj.PositionNum = position.PositionNum;
//if (obj.TagNo.Equals(""))
//{
// MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePartName, "请输入元器件编号!"));
// txtPartNum.Focus();
// return;
//}
//判断编号是否存在
List<ComponetInfo> allList = CSVBomManager.GetComList(cmbList.Text);
List<ComponetInfo> objs = (from m in allList where (!String.IsNullOrEmpty(m.TagNo)) && m.TagNo.Equals(obj.TagNo) select m).ToList();
if (objs.Count > 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PartNAExist, "元器件编号[{0}]已存在", obj.TagNo));
txtPartNum.Focus();
return;
}
objs = (from m in allList where m.PN.Equals(obj.PN) && m.PositionNum.Equals(m.PositionNum) select m).ToList();
if (objs.Count > 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PartNAExist, "元器件编号[{0}]已存在", obj.PN + "-" + obj.PositionNum));
txtPartNum.Focus();
return;
}
if (obj.PN.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComName, "请输入元器件名称!"));
txtName.Focus();
return;
}
if (int.Parse(obj.ComCount) <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteComNum, "请输入元器件数量!"));
txtCount.Focus();
return;
}
if (String.IsNullOrEmpty(obj.TagNo))
{
List<ComponetInfo> lists = CSVBomManager.GetComList(cmbList.Text);
List<ComponetInfo> hasList = (from m in lists where m.Id.Equals(obj.Id).Equals(false) && m.PN.Equals(obj.PN) && m.PositionNum.Equals(obj.PositionNum) select m).ToList();
if (objs.Count > 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ComExists, "元器件已存在"));
}
}
List<ComponetInfo> list = CSVBomManager.AddCom(cmbList.Text, obj);
if (list == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveError, "保存失败!"));
return;
}
//ComponentManager.Update(obj);
//dgvList.Rows.Add(SetRowInfo(null, obj));
UpdateGridList(list);
dgvList.Rows[dgvList.Rows.Count - 1].Selected = true;
btnNewCom.Visible = true;
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ComSaveOk, "元器件【{0}】保存成功!", obj.TagNo + "-" + obj.PN));
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.ComInfo, "元器件【{0}】的基本信息", obj.TagNo + "-" + obj.PN);
}
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_PN.Name].Value == null)
{
return null;
}
point.TagNo = row.Cells[this.Column_partNumber.Name].Value.ToString();
point.PN = row.Cells[this.Column_PN.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 = row.Cells[this.Column_Count.Name].Value.ToString();
point.Id = Convert.ToInt32(row.Cells[this.Column_ID.Name].Value.ToString());
}
catch (Exception ex)
{
LogUtil.error("保存数据出错:" + ex.ToString());
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CheckComNum, "请检查元器件数据是否正确!"));
return null;
}
return point;
}
private bool IsNew = false;
private void btnNewCom_Click(object sender, EventArgs e)
{
IsNew = true;
txtPartNum.Text = "";
txtName.Text = "";
txtDes.Text = "";
txtCount.Text = "";
txtPartNum.Text = "";
txtNotes.Text = "";
txtPartNum.Enabled = true;
this.cmbPositionNumList.SelectedIndex = 0;
btnNewCom.Visible = false;
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.NewCom, "新增元器件");
}
private ComponetInfo selCom = null;
private void showDetail(int rowIndex)
{
try
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceCom, "请选择元器件!"));
return;
}
selCom = obj;
IsNew = false;
txtPartNum.Tag = obj;
txtName.Text = obj.PN;
txtDes.Text = obj.ComponentDes;
txtCount.Text = obj.ComCount.ToString();
txtPartNum.Text = obj.TagNo;
txtNotes.Text = obj.Notes;
if (txtPartNum.Text == "")
{
txtPartNum.Enabled = true;
}
else
{
txtPartNum.Enabled = false;
}
btnNewCom.Visible = true;
txtId.Text = obj.Id.ToString();
//txtPosition.Text = obj.PositionNum;
int selPosIndex = -1;
int index = -1;
string[] posNum = CSVBomManager.GetPositionNum(obj.PositionNum);
foreach (TSAVPosition p in allPosition)
{
index++;
if (p.PositionNum.Equals(posNum[0]))
{
selPosIndex = index;
break;
}
}
if (selPosIndex >= 0 && this.cmbPositionNumList.Items.Count > 0)
{
this.cmbPositionNumList.SelectedIndex = selPosIndex;
}
groupInfo.Text = ResourceCulture.GetString(ResourceCulture.ComInfo, "元器件【{ 0}】的基本信息", obj.TagNo + " " + obj.PN);
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
private void DeleteCom(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (cmbList.SelectedIndex >= 0)
{
string bomName = this.cmbList.Text;
if (!CSVBomManager.canRemoveCom(bomName, obj))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CanotDelCom, "元器件已使用,不能删除!"));
return;
}
if (MessageBox.Show(
ResourceCulture.GetString(ResourceCulture.SureDelCom, "确认要删除元器件【{0}】吗?", obj.TagNo + " " + obj.PN),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
List<ComponetInfo> newlist = CSVBomManager.RemoveCom(cmbList.Text, obj);
if (newlist == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveError, "保存失败!"));
return;
}
//this.dgvList.Rows.RemoveAt(rowIndex);
UpdateGridList(newlist);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DelComOk, "元器件【{0}】删除成功!", obj.TagNo + " " + obj.PN)
, ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示"));
}
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectC, "请先选择一个元器件库"));
}
}
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 = CSVBomManager.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
{
CSVBomManager.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();
}
}
private void cmbPositionNumList_SelectedIndexChanged(object sender, EventArgs e)
{
string pNum = cmbPositionNumList.Text;
if (pNum.Equals(""))
{
return;
}
TSAVPosition position = CSVPositionReader<TSAVPosition>.GetPositonByNum(pNum);
if (position != null && position.PositionType.Equals(2))
{
LinkVisible(true );
}
else
{
LinkVisible(false);
}
}
private void LinkVisible(bool show)
{
linkLabel1.Visible = show;
linkLabel2.Visible = show;
linkCloseAll.Visible = show;
linkOpenAll.Visible = show;
linkUpdate.Visible = show;
}
private LabelInfo PreLabel = null;
private void CloseLed(string pPnum)
{
if (PreLabel != null)
{
if ( pPnum!=""&& PreLabel.pos != pPnum)
{
LedLabelController.CloseLed(PreLabel.ip, PreLabel.mac);
PreLabel = null;
}
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string pNum = cmbPositionNumList.Text;
CloseLed(pNum);
TSAVPosition position = CSVPositionReader<TSAVPosition>.GetPositonByNum(pNum);
if (position != null && position.PositionType.Equals(2))
{
PreLabel = LedLabelController.GetLabel(position, selCom, true);
LedLabelController.OpenLed(position.DeviceIP, position.Leds);
//LedLabelController.UpdateScreen(PreLabel);
}
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
CloseLed("");
string pNum = cmbPositionNumList.Text;
TSAVPosition position = CSVPositionReader<TSAVPosition>.GetPositonByNum(pNum);
if (position != null && position.PositionType.Equals(2))
{
PreLabel = LedLabelController.GetLabel(position, selCom, true);
LedLabelController.CloseLed(PreLabel.ip, PreLabel.mac);
}
}
private void btnExport_Click(object sender, EventArgs e)
{
if (cmbList.Text != "" && cmbList.SelectedIndex >= 0)
{
try
{
string key = cmbList.Text;
List<ComponetInfo> list = CSVBomManager.GetComList(key);
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = key + "-" + DateTime.Now.ToString("MM:dd:HH:mm").Replace(":", "");
sfd.Filter = @"csv|*.csv";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
string[] line = getLine(list);
File.WriteAllLines(filePath, line.ToArray(), Encoding.GetEncoding("gbk"));
MessageBox.Show(ResourceCulture.GetString("成功导出程序到文件:") + "\r\n" + filePath, ResourceCulture.GetString("提示"));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private string[] getLine(List<ComponetInfo> list)
{
List<string> titleList = new List<string>();
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Num, "位号"));
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编码"));
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置"));
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Count, "数量"));
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Notes, "注意事项"));
titleList.Add(ResourceCulture.GetString(ResourceCulture.Col_Del, "描述"));
string spilt = ",";
List<string> line = new List<string>();
line.Add(string.Join(spilt, titleList));
line.Add(spilt);
foreach (ComponetInfo comp in list)
{
List<string> valueList = new List<string>();
valueList.Add(comp.TagNo);
valueList.Add(comp.PN);
valueList.Add(comp.PositionNum);
valueList.Add(comp.ComCount);
valueList.Add(comp.Notes);
valueList.Add(comp.ComponentDes);
line.Add(string.Join(spilt, valueList));
}
return line.ToArray();
}
private Dictionary<string,string> getTitleMap()
{
Dictionary<string, string> titleMap = new Dictionary<string, string>();
titleMap.Add("TagNo",ResourceCulture.GetString(ResourceCulture.Col_Num, "位号"));
titleMap.Add("PN",ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编码"));
titleMap.Add("PositionNum",ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置"));
titleMap.Add("ComCount",ResourceCulture.GetString(ResourceCulture.Col_Count, "数量"));
titleMap.Add("Notes",ResourceCulture.GetString(ResourceCulture.Col_Notes, "注意事项"));
titleMap.Add("ComponentDes",ResourceCulture.GetString(ResourceCulture.Col_Del, "描述"));
return titleMap;
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string pNum = cmbPositionNumList.Text;
CloseLed(pNum);
TSAVPosition position = CSVPositionReader<TSAVPosition>.GetPositonByNum(pNum);
if (position != null && position.PositionType.Equals(2))
{
PreLabel = LedLabelController.GetLabel(position, selCom, true);
LedLabelController.UpdateScreen(PreLabel);
}
}
private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LedLabelController.OpenAll();
}
private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LedLabelController.CloseAll();
}
private void btnImport_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
DialogResult result = this.openFileDialog1.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string fileName = this.openFileDialog1.FileName;
List<ComponetInfo> comList = CSVBomManager.ReadFile(fileName, getTitleMap());
if (comList.Count <= 0)
{
}
List<ComponetUploadInfo> uploadList = new List<ComponetUploadInfo>();
string bomName = cmbList.Text;
List<ComponetInfo> list = CSVBomManager.GetComList(bomName);
foreach (ComponetInfo obj in comList)
{
foreach (ComponetInfo currObj in list)
{
if (currObj.IsSameCom(obj.PN,obj.PositionNum,obj.TagNo))
{
ComponetUploadInfo upload = new ComponetUploadInfo();
upload.Id = currObj.Id;
upload.PN = currObj.PN;
upload.TagNo=currObj.TagNo;
upload.ComCount = currObj.ComCount;
upload.NewCount = obj.ComCount;
upload.PositionNum = currObj.PositionNum;
uploadList.Add(upload);
break;
}
}
}
if(uploadList.Count <= 0)
{
}
FrmListViewer<ComponetUploadInfo> frmListViewer = new FrmListViewer<ComponetUploadInfo>(uploadList, 1);
List<ComponetInfo> newList = new List<ComponetInfo>();
DialogResult showRes = frmListViewer.ShowDialog();
if (showRes.Equals(DialogResult.OK))
{
uploadList = frmListViewer.dataList;
foreach (ComponetInfo currObj in list)
{
foreach (ComponetUploadInfo upload in uploadList)
{
if (currObj.IsSameCom(upload.PN, upload.PositionNum, upload.TagNo))
{
LogUtil.info($"修改元器件库{bomName} PN:{currObj.ComCount} TagNo:{currObj.TagNo} 的数量:{currObj.ComCount}->{upload.NewCount}");
currObj.ComCount = upload.NewCount;
break;
}
}
newList.Add(currObj);
}
//
CSVBomManager.AddBom(bomName, newList);
UpdateGridList(list);
MessageBox.Show(ResourceCulture.GetString("SaveOk", "保存成功!" ));
}
}
}
}
}