FrmBomViewer.cs
10.3 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
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;
namespace TSA_V
{
public partial class FrmBomViewer : FrmBase
{
public List<ComponetInfo> dataList = new List<ComponetInfo>();
private int viewType = 0;
public FrmBomViewer(List<ComponetInfo> dataList,int viewType=0)
{
InitializeComponent();
this.dataList = dataList;
this.viewType = viewType;
}
private void FrmImageViewer_Load(object sender, EventArgs e)
{
LoadData();
this.WindowState = FormWindowState.Maximized;
}
private void addData (ComponetInfo obj)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgvData);
row.Cells[0].Value = obj.Id;
row.Cells[Column_TagNo.Index].Value = obj.TagNo;
row.Cells[Column_PN.Index].Value = obj.PN;
row.Cells[Column_PositionNum.Index].Value = obj.PositionNum;
row.Cells[Column_ComCount.Index].Value = obj.ComCount;
row.Cells[Column_PositionX.Index].Value = obj.PositionX;
row.Cells[Column_PositionY.Index].Value = obj.PositionY;
row.Cells[Column_Notes.Index].Value = obj.Notes;
row.Cells[Column_CompontentDes.Index].Value = obj.ComponentDes;
row.Cells[Column_del.Index].Value = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
dgvData.Rows.Add(row);
}
private void LoadData()
{
//dgvData.DataSource = dataList;
if (viewType == 0)
{
dgvData.Columns[0].Visible = false;
dgvData.Columns[Column_TagNo.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Num, "位号");
dgvData.Columns[Column_PN.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编码");
dgvData.Columns[Column_PositionNum.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置");
dgvData.Columns[Column_ComCount.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Count, "数量");
dgvData.Columns[Column_PositionX.Index].HeaderText = "X";
dgvData.Columns[Column_PositionY.Index].HeaderText = "Y";
dgvData.Columns[Column_Notes.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Notes, "注意事项");
dgvData.Columns[Column_CompontentDes.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Del, "描述");
dgvData.Columns[Column_del.Index].HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
dgvData.AllowUserToDeleteRows = true;
dgvData.AllowUserToOrderColumns = true;
for(int i =0;i<dgvData.Columns.Count;i++)
{
dgvData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
}
foreach(ComponetInfo obj in dataList)
{
addData(obj);
}
}
else if (viewType == 1)
{
if (dgvData.Columns.Count >= 6)
{
dgvData.Columns[0].Visible = false;
dgvData.Columns[1].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Num, "位号");
dgvData.Columns[2].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编码");
dgvData.Columns[3].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置");
dgvData.Columns[4].HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Count, "数量");
dgvData.Columns[5].HeaderText = ResourceCulture.GetString("Col_Count_N", "修改后数量");
dgvData.Columns[1].ReadOnly = true;
dgvData.Columns[2].ReadOnly = true;
dgvData.Columns[3].ReadOnly = true;
dgvData.Columns[4].ReadOnly = true;
}
}
if (dataList.Count <= 0)
{
btnOK.Visible = false;
btnCancel.Visible = true;
}
this.Text = ResourceCulture.GetString("FrmListViewer_Text", "数据预览");
btnCancel.Text = ResourceCulture.GetString("FrmListViewer_btnCancel_Text", "取消");
btnOK.Text = ResourceCulture.GetString("FrmListViewer_btnOK_Text", "确定");
}
private void GetList()
{
List<ComponetInfo> pointList = new List<ComponetInfo>();
foreach (DataGridViewRow row in dgvData.Rows)
{
if (row != null)
{
ComponetInfo point = getRowPointInfo(row);
if (point != null)
{
pointList.Add(point);
}
}
}
this.dataList = new List<ComponetInfo>(pointList);
}
private ComponetInfo getRowPointInfo(DataGridViewRow row)
{
ComponetInfo point = new ComponetInfo();
try
{
if (row.Cells[Column_TagNo.Name].Value == null)
{
return null;
}
point.Id = Convert.ToInt32( row.Cells[Column_ID.Name].Value.ToString());
point.PN = row.Cells[this.Column_PN.Name].Value.ToString();
point.TagNo = row.Cells[this.Column_TagNo.Name].Value.ToString();
point.PositionX = Math.Round(Convert.ToDouble(row.Cells[this.Column_PositionX.Name].Value.ToString()), 3);
point.PositionY = Math.Round(Convert.ToDouble(row.Cells[this.Column_PositionY.Name].Value.ToString()), 3);
point.PositionNum = row.Cells[this.Column_PositionNum.Name].Value.ToString();
point.ComCount = row.Cells[this.Column_ComCount.Name].Value.ToString();
point.ComponentDes = row.Cells[this.Column_CompontentDes.Name].Value.ToString();
point.Notes = row.Cells[this.Column_Notes.Name].Value.ToString();
}
catch (Exception ex)
{
LogUtil.error( "保存数据出错:" + ex.ToString());
return null;
}
return point;
}
private void btnOK_Click(object sender, EventArgs e)
{
GetList();
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
if(dataList.Count <= 0)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
DialogResult resul = MessageBox.Show(ResourceCulture.GetString("SureCancelData","确认取消数据上传?"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (resul == DialogResult.Yes)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
private void dgvData_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex >= 0)
{
string name = this.dgvData.Columns[e.ColumnIndex].Name;
if (name.Equals(this.Column_del.Name))
{
if (MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureDelete, "确认要删除该行数据吗?"),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示?"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
this.dgvData.Rows.RemoveAt(e.RowIndex);
}
}
}
}
private void linkDelete_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (dgvData.SelectedRows != null && dgvData.SelectedRows.Count > 0)
{
try
{
if (MessageBox.Show(ResourceCulture.GetString("SureDeleteSel", "确定删除选中的数据?"),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示?"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
List<DataGridViewRow> rows = new List<DataGridViewRow>();
foreach (DataGridViewRow row in dgvData.SelectedRows)
{
rows.Add(row);
}
foreach(DataGridViewRow row in rows)
{
this.dgvData.Rows.Remove(row);
}
}
catch (Exception ex)
{
LogUtil.error(ex.ToString());
}
}
}
private void dgvData_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
// 表头宽度
SizeF strSizeF = e.Graphics.MeasureString((e.RowIndex + 1).ToString(), this.dgvData.RowHeadersDefaultCellStyle.Font);
if (strSizeF.Width + 20 > this.dgvData.RowHeadersWidth)
this.dgvData.RowHeadersWidth = 20 + (int)strSizeF.Width;
// 序号显示
SolidBrush b = new SolidBrush(dgvData.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString(
(e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture),
this.dgvData.DefaultCellStyle.Font,
b,
e.RowBounds.Location.X + 10,
e.RowBounds.Location.Y + 4);
}
}
}