FrmAddCom.cs
5.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
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 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 = CSVReaderBomManager.ReadFile(fileName);
if (comList.Count > 0)
{
Dictionary<string, string> namePositonMap = new Dictionary<string, string>();
foreach (ComponetInfo com in comList)
{
if (!namePositonMap.ContainsKey(com.ComponentName))
{
//验证库位是否存在过
List<string> positinList = new List<string>();
if (positinList.Contains(com.ComponentName))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CheckFile,"两个不同的元器件中都配置在库位【{0}】中,请检查文件",com.PositionNum));
comList = new List<ComponetInfo>();
return ;
}
namePositonMap.Add(com.ComponentName, com.PositionNum);
}
else
{
string prePosition = namePositonMap[com.ComponentName];
if (!prePosition.Equals(com.PositionNum))
{
result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImport,
"元器件【{0}】配置了两个位置【{1}】和【{2}】,是否确定导入?",com.ComponentName,prePosition,com.PositionNum), "",
MessageBoxButtons.YesNoCancel); ;
if (!result.Equals(DialogResult.Yes))
{
comList = new List<ComponetInfo>();
return ;
}
}
}
}
this.txtBomFilePath.Text = fileName;
}
else
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectRightFile,"请选择正确的文件(文件格式可以通过下载模板获得)"));
}
}
}
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 (CSVReaderBomManager.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 (CSVReaderBomManager.AddBomList(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();
}
}
}