FrmComponentList.cs
9.0 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
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 OnlineStore.LoadCSVLibrary;
using OnlineStore.Common;
namespace OnlineStore.AutoCountClient
{
internal partial class FrmComponentList : FrmBase
{
public static FrmComponentList instance = new FrmComponentList();
private FrmComponentList()
{
InitializeComponent();
}
private void FrmPointType_Load(object sender, EventArgs e)
{
}
private DataGridViewRow SetRowInfo(DataGridViewRow view, ComponetInfo com)
{
if (view == null)
{
view = new DataGridViewRow();
view.CreateCells(dgvList);
}
view.Cells[Column_PN.Index].Value = com.PartNum.ToString();
view.Cells[this.Column_Name.Index].Value = com.ProductName.ToString();
view.Cells[Column_F.Index].Value = com.Encapsulations.ToString();
view.Cells[this.Column_Des.Index].Value = com.Describe.ToString();
return view;
}
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_PN.Name].Value == null)
{
return null;
}
point.PartNum = row.Cells[this.Column_PN.Name].Value.ToString();
point.Encapsulations = row.Cells[this.Column_F.Name].Value.ToString();
point.ProductName = row.Cells[this.Column_Name.Name].Value.ToString();
point.Describe = row.Cells[this.Column_Des.Name].Value.ToString();
}
catch (Exception ex)
{
LogUtil.error( "保存数据出错:" + ex.ToString());
return null;
}
return point;
}
private void showDetail(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (obj == null)
{
MessageBox.Show( "请选择元器件!" );
return;
}
txtPartNum.Tag = obj;
txtName.Text = obj.ProductName;
txtDes.Text = obj.Describe;
txtFengzhuang.Text = obj.Encapsulations.ToString();
txtPartNum.Text = obj.PartNum;
int index = -1;
groupInfo.Text = "元器件【"+ obj.PartNum + "】的基本信息";
}
private void DeleteCom(int rowIndex)
{
DataGridViewRow row = dgvList.Rows[rowIndex];
ComponetInfo obj = getRowPointInfo(row);
if (MessageBox.Show(
"确认要删除元器件【" + obj.PartNum + "】吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
CSVBomManager.RemoveCom(obj);
this.dgvList.Rows.RemoveAt(rowIndex);
MessageBox.Show("元器件【" + obj.PartNum + "】删除成功!", "提示");
}
}
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 FrmComponentList_FormClosing(object sender, FormClosingEventArgs e)
{
this.Visible = false;
//FrmMenu.frmMain.Visible = true;
e.Cancel = true;
}
private void FrmComponentList_Shown(object sender, EventArgs e)
{
}
}
}