FrmSPC.cs
8.1 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
namespace App
{
public partial class FrmSPC : App.FrmBase
{
Fuction fuction = new Fuction();
List<string> product;
bool isInit;
DataTable dt_ProductTestData;
public FrmSPC()
{
isInit = true;
InitializeComponent();
Init();
this.SetLanguage(this);
}
private void Init()
{
GetProductList();
cmb_SPCType.SelectedIndex = 0;
}
private void GetProductList()
{
this.lb_Product.Items.Clear();
product = fuction.GetAllProjectName();
for (int i = 0; i < product.Count; i++)
{
this.lb_Product.Items.Add(product[i]);
}
this.lb_Product.SelectedIndex = 0;
GetDataGrid();
}
private void GetDataGrid()
{
string ProductName = this.lb_Product.SelectedItem.ToString();
dt_ProductTestData = fuction.GetProductTest(ProductName);
dataGridView1.DataSource = GetTable(Convert.ToDateTime("1900-1-1"), Convert.ToDateTime("2900-1-1"));
DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
CreatColumn(dataGridView1.Columns[i], dataGridViewCellStyle0, dt_ProductTestData.Columns[i].ColumnName);
}
if (dataGridView1.RowCount > 0)
{
dataGridView1.Rows[0].Selected = true;
}
}
private void CreatColumn(DataGridViewColumn Column, DataGridViewCellStyle CellStyle, string Name)
{
Column.DefaultCellStyle = CellStyle;
Column.FillWeight = 40F;
Column.Name = Name;
Column.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
Column.Width = 150;
if (Name == Const.TEST_MAX || Name == Const.TEST_MIN)
{
Column.Visible = false;
}
}
private void btn_Query_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = GetTable(Convert.ToDateTime(this.dtp_StartTime.Value.ToShortDateString()), Convert.ToDateTime(this.dtp_EndTime.Value.ToShortDateString()));
}
private DataTable GetTable(DateTime StartTime, DateTime EndTime)
{
DataRow[] drTemp = dt_ProductTestData.Select
(Const.TEST_STARTTIME + ">= #" + StartTime + "# and " + Const.TEST_STARTTIME + "<= #" + EndTime + "#", Const.TEST_STARTTIME);
DataTable table1 = new DataTable(Const.PARA_PRODUCT);
DataColumnCollection columns = table1.Columns;
columns.Add(Const.TestData, typeof(System.String));
columns.Add(Const.PARA_PRODUCT, typeof(System.String));
columns.Add(Const.TEST_STARTTIME, typeof(System.DateTime));
columns.Add(Const.TEST_MAX, typeof(System.Double));
columns.Add(Const.TEST_MIN, typeof(System.Double));
DataRow newRow;
foreach (DataRow dr in drTemp)
{
newRow = table1.NewRow();
newRow[Const.TestData] = dr[Const.TestData];
newRow[Const.PARA_PRODUCT] = dr[Const.PARA_PRODUCT];
newRow[Const.TEST_STARTTIME] = dr[Const.TEST_STARTTIME];
newRow[Const.TEST_MAX] = Fuction.m_UserResult == Const.RESULT_IN ?
Convert.ToDouble(fuction.ChangeAreaUnit(dr[Const.TEST_MAX].ToString())) :
Convert.ToDouble(dr[Const.TEST_MAX]);
newRow[Const.TEST_MIN] = Fuction.m_UserResult == Const.RESULT_IN ?
Convert.ToDouble(fuction.ChangeAreaUnit(dr[Const.TEST_MIN].ToString())) :
Convert.ToDouble(dr[Const.TEST_MIN]);
table1.Rows.Add(newRow);
}
return table1;
}
private void btn_Delete_Click(object sender, EventArgs e)
{
if (this.dataGridView1.CurrentRow !=null)
{
((DataTable)this.dataGridView1.DataSource).Rows.RemoveAt(this.dataGridView1.CurrentRow.Index);
}
}
private void btn_OK_Click(object sender, EventArgs e)
{
#region checkValid
if (!CheckNull(this.lbl_minValue.Text, txt_minValue) || !CheckNumber(this.lbl_minValue.Text, txt_minValue) ||
!CheckNull(this.lbl_maxValue.Text, txt_maxValue) || !CheckNumber(this.lbl_maxValue.Text, txt_maxValue) ||
!CheckNull(this.label1.Text, txt_TargetValue) || !CheckNumber(this.label1.Text, txt_TargetValue))
return;
#endregion
double minValue = Convert.ToDouble(txt_minValue.Text);
double maxValue = Convert.ToDouble(this.txt_maxValue.Text);
double targetValue = Convert.ToDouble(this.txt_TargetValue.Text);
if (minValue > maxValue ||
minValue > targetValue ||
targetValue > maxValue)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_GAUGE_DATA);
return;
}
FrmSPCCurve frmSPCCurve = new FrmSPCCurve((DataTable)this.dataGridView1.DataSource, maxValue, targetValue, minValue, cmb_SPCType.SelectedItem.ToString());
frmSPCCurve.Owner = this.ParentForm;
frmSPCCurve.MdiParent = this.ParentForm;
frmSPCCurve.ShowInTaskbar = false;
frmSPCCurve.StartPosition = FormStartPosition.CenterScreen;
frmSPCCurve.Show();
frmSPCCurve.Activate();//
this.Close();
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void lb_Product_SelectedIndexChanged(object sender, EventArgs e)
{
if (!isInit)
{
GetDataGrid();
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
dataGridView1.Rows[e.RowIndex].Selected = true;
this.btn_Delete.Enabled = true;
}
else
{
this.btn_Delete.Enabled = false;
}
}
private void ChangeNewPoint(Control ctrl,int bottom)
{
ctrl.Location = new Point(ctrl.Left, bottom - ctrl.Height-5);
}
private void FrmSPC_Shown(object sender, EventArgs e)
{
ResizeForm();
isInit = false;
int bottom = this.Bottom - 65;
lb_Product.Height = this.Height - lb_Product.Top-50;
ChangeNewPoint(label1,bottom);
ChangeNewPoint(txt_TargetValue,bottom-3);
ChangeNewPoint(lbl_SPCType,bottom);
ChangeNewPoint(cmb_SPCType, bottom-5);
int bottom1=this.Bottom - 100;
ChangeNewPoint(lbl_maxValue,bottom1);
ChangeNewPoint(lbl_minValue,bottom1);
ChangeNewPoint(txt_maxValue, bottom1-3);
ChangeNewPoint(txt_minValue, bottom1-3);
dataGridView1.Height = this.Height - dataGridView1.Top -150;
dataGridView1.Width = this.Width -dataGridView1.Top -150;
int right = dataGridView1.Right;
btn_OK.Location = new Point(right - btn_Cancel.Width - 70, bottom - btn_OK.Height);
btn_Delete.Location = new Point(right - btn_Delete.Width, bottom1 - btn_Delete.Height);
btn_Query.Location = new Point(right - btn_Query.Width, btn_Query.Top);
btn_Cancel.Location = new Point(right - btn_Cancel.Width, bottom - btn_Cancel.Height);
}
private void FrmSPC_LocationChanged(object sender, EventArgs e)
{
if (isInit)
{
this.Location = new Point(0, 0);
}
}
}
}