FrmComCountView.cs
7.2 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
using log4net.Repository.Hierarchy;
using NPOI.SS.Formula.Functions;
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 FrmComCountView : FrmBase
{
public List<ComponetUploadInfo> dataList = new List<ComponetUploadInfo>();
public FrmComCountView(List<ComponetUploadInfo> dataList )
{
InitializeComponent();
this.dataList = dataList;
}
private void FrmImageViewer_Load(object sender, EventArgs e)
{
LoadData();
this.WindowState = FormWindowState.Maximized;
}
private void addData (ComponetUploadInfo 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_nCount.Index].Value = obj.NewCount;
if (obj.NewCount != obj.ComCount)
{
row.DefaultCellStyle.BackColor = Color.LightBlue;
row.Cells[Column_ISUpdate.Index].Value = "√";
}
else
{
row.DefaultCellStyle.BackColor = Color.White;
row.Cells[Column_ISUpdate.Index].Value = "";
}
dgvData.Rows.Add(row);
}
private void LoadData()
{
//dgvData.DataSource = dataList;
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_nCount.Index].HeaderText = ResourceCulture.GetString("Col_Count_N", "修改后数量");
dgvData.Columns[Column_ISUpdate.Index].HeaderText = ResourceCulture.GetString("Column_ISUpdate", "是否修改");
dgvData.AllowUserToDeleteRows = false;
dgvData.AllowUserToOrderColumns = false;
Column_TagNo.ReadOnly = true;
Column_PN.ReadOnly = true;
Column_PositionNum.ReadOnly = true;
Column_ComCount.ReadOnly = true;
Column_nCount.ReadOnly = false;
foreach (ComponetUploadInfo obj in dataList)
{
addData(obj);
}
this.Text = ResourceCulture.GetString("FrmListViewer_Text", "数据预览");
btnCancel.Text = ResourceCulture.GetString("FrmListViewer_btnCancel_Text", "取消");
btnOK.Text = ResourceCulture.GetString("FrmListViewer_btnOK_Text", "确定");
}
private void GetList()
{
List<ComponetUploadInfo> pointList = new List<ComponetUploadInfo>();
foreach (DataGridViewRow row in dgvData.Rows)
{
if (row != null)
{
ComponetUploadInfo point = getRowPointInfo(row);
if (point != null)
{
pointList.Add(point);
}
}
}
this.dataList = new List<ComponetUploadInfo>(pointList);
}
private ComponetUploadInfo getRowPointInfo(DataGridViewRow row)
{
ComponetUploadInfo point = new ComponetUploadInfo();
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.PositionNum = row.Cells[this.Column_PositionNum.Name].Value.ToString();
point.ComCount = row.Cells[this.Column_ComCount.Name].Value.ToString();
point.NewCount = row.Cells[this.Column_nCount.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_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
ComponetUploadInfo com = getRowPointInfo(dgvData.Rows[e.RowIndex]);
if(com.NewCount.Equals(com.ComCount))
{
dgvData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
dgvData.Rows[e.RowIndex].Cells[Column_ISUpdate.Index].Value = "";
}
else
{
dgvData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightBlue;
dgvData.Rows[e.RowIndex].Cells[Column_ISUpdate.Index].Value = "√";
}
}
}
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);
}
}
}