FrmAddCom.cs
6.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
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 TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;
namespace TSA_V
{
public partial class FrmAddCom : FrmBase
{
public FrmAddCom()
{
InitializeComponent();
}
private void FrmAddCom_Shown(object sender, EventArgs e)
{
SetSkin(this);
LanguageProcess();
}
private string getListMsg(List<string> list)
{
string msg = "";
foreach (string str in list)
{
msg += str + ",";
}
return msg.Substring(0, msg.Length - 1);
}
private List<ComponetInfo> comList = new List<ComponetInfo>();
private void btnBomImport_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;
comList = CSVBomManager.ReadFile(fileName);
if (comList.Count <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectRightFile, "请选择正确的文件(文件格式可以通过下载模板获得)"));
}
Dictionary<string, List<string>> PnPositonMap = new Dictionary<string, List<string>>();
Dictionary<string, List<string>> positionPNMap = new Dictionary<string, List<string>>();
foreach (ComponetInfo com in comList)
{
if (!PnPositonMap.ContainsKey(com.PN))
{
PnPositonMap.Add(com.PN, new List<string>());
}
if (!PnPositonMap[com.PN].Contains(com.PositionNum))
{
PnPositonMap[com.PN].Add(com.PositionNum);
}
if (!positionPNMap.ContainsKey(com.PositionNum))
{
positionPNMap.Add(com.PositionNum, new List<string>());
}
if (!positionPNMap[com.PositionNum].Contains(com.PN))
{
positionPNMap[com.PositionNum].Add(com.PN);
}
}
foreach (string pnKey in PnPositonMap.Keys)
{
List<string> positions = new List<string>(PnPositonMap[pnKey]);
if (positions.Count > 1)
{
result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPosition,
"元器件【{0}】配置多个位置【{1}】,是否确定导入?", pnKey, getListMsg(positions), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
comList = new List<ComponetInfo>();
return;
}
}
}
foreach (string key in positionPNMap.Keys)
{
List<string> pnList = new List<string>(positionPNMap[key]);
if (pnList.Count > 1)
{
result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPn,
"位置【{0}】配置多个元器件【{1}】,是否确定导入?", key, getListMsg(pnList), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
comList = new List<ComponetInfo>();
return;
}
}
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (this.txtBomName.Text.Equals("") || this.txtBomFilePath.Text.Equals(""))
{
}
this.Close();
}
private bool SaveComList()
{
string bomName = txtBomName.Text;
if (bomName.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteCName,"请先输入元器件库名称!"));
txtBomName.Focus();
return false;
}
if (CSVBomManager.allComMap.ContainsKey(bomName))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CNameHasExits,"元器件库【{0}】已存在,请重新输入!",bomName));
txtBomName.Focus();
return false;
}
if (comList.Count <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ImportFile,"请导入元件文件!"));
txtBomName.Focus();
return false;
}
if (CSVBomManager.AddBom(bomName, comList))
{
return true;
} return false;
}
private void btnSave_Click(object sender, EventArgs e)
{
bool result = SaveComList();
if (result)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk,"保存成功!"));
this.Close();
}
}
private void btnBeginIn_Click(object sender, EventArgs e)
{
bool result = SaveComList();
if (result)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk,"保存成功!"));
this.Visible = false;
FrmPutCom frm = new FrmPutCom();
if (frm.SetOperateInfo(txtBomName.Text, comList))
{
frm.ShowDialog();
this.Close();
}
}
}
private void FrmAddCom_Load(object sender, EventArgs e)
{
SetScreen();
}
}
}