|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+using System;
|
|
|
2
|
+using System.Collections.Generic;
|
|
|
3
|
+using System.Linq;
|
|
|
4
|
+using System.Text;
|
|
|
5
|
+using System.Windows;
|
|
|
6
|
+using System.Windows.Controls;
|
|
|
7
|
+using System.Windows.Data;
|
|
|
8
|
+using System.Windows.Documents;
|
|
|
9
|
+using System.Windows.Input;
|
|
|
10
|
+using System.Windows.Media;
|
|
|
11
|
+using System.Windows.Media.Imaging;
|
|
|
12
|
+using System.Windows.Shapes;
|
|
|
13
|
+using System.Collections.ObjectModel;
|
|
|
14
|
+using System.Data.SqlClient;
|
|
|
15
|
+using System.Data;
|
|
|
16
|
+namespace WpfApplication19
|
|
|
17
|
+{
|
|
|
18
|
+ /// <summary>
|
|
|
19
|
+ /// Interaction logic for DailyCheck.xaml
|
|
|
20
|
+ /// </summary>
|
|
|
21
|
+ public partial class DailyCheck : Window
|
|
|
22
|
+ {
|
|
|
23
|
+ ObservableCollection<DailyChecker> _dailyChecks = new ObservableCollection<DailyChecker>();
|
|
|
24
|
+ DataGridCellInfo _cell;
|
|
|
25
|
+ DataGridColumn _col;
|
|
|
26
|
+ DailyChecker _item;
|
|
|
27
|
+ SqlConnection _proConn;
|
|
|
28
|
+ DateTime _now, _tomorrow;
|
|
|
29
|
+ string _shift;
|
|
|
30
|
+ public DailyCheck()
|
|
|
31
|
+ {
|
|
|
32
|
+ InitializeComponent();
|
|
|
33
|
+
|
|
|
34
|
+ //nowLabel.Content = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
|
|
|
35
|
+ //var test = DateTime.Now + 1;
|
|
|
36
|
+ _now = DateTime.Now.Date;
|
|
|
37
|
+ _tomorrow = _now.AddDays(1);
|
|
|
38
|
+ var c = DateTime.Now.AddDays(1);
|
|
|
39
|
+
|
|
|
40
|
+ var hr = DateTime.Now.TimeOfDay.Hours;
|
|
|
41
|
+ //shiftCB.SelectionChanged -= shiftCB_SelectionChanged;
|
|
|
42
|
+ if(hr >= 8 && hr <= 19){
|
|
|
43
|
+ _shift = "day";
|
|
|
44
|
+ shiftCB.SelectedIndex = 0;
|
|
|
45
|
+ }else{
|
|
|
46
|
+ _shift = "night";
|
|
|
47
|
+ shiftCB.SelectedIndex = 1;
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+
|
|
|
51
|
+ datePicker.SelectedDateChanged -= datePicker_SelectedDateChanged;
|
|
|
52
|
+ datePicker.SelectedDate =_now;
|
|
|
53
|
+ datePicker.SelectedDateChanged += datePicker_SelectedDateChanged;
|
|
|
54
|
+
|
|
|
55
|
+ shiftCB.SelectionChanged += shiftCB_SelectionChanged;
|
|
|
56
|
+ try
|
|
|
57
|
+ {
|
|
|
58
|
+ _proConn = Utils.createSqlConnection("productionDbCS");
|
|
|
59
|
+
|
|
|
60
|
+ }
|
|
|
61
|
+ catch (SqlException se)
|
|
|
62
|
+ {
|
|
|
63
|
+ MessageBox.Show("productionDbCS : ", se.Message);
|
|
|
64
|
+ }
|
|
|
65
|
+ //var w = (MainWindow)Application.Current.MainWindow;
|
|
|
66
|
+ //_proConn = w.proConn;
|
|
|
67
|
+ initDataGrid();
|
|
|
68
|
+ //dailyCheckGrid.Focus();
|
|
|
69
|
+
|
|
|
70
|
+
|
|
|
71
|
+ }
|
|
|
72
|
+ void initDataGrid(){
|
|
|
73
|
+ setGrid(_now, _tomorrow, _shift);
|
|
|
74
|
+
|
|
|
75
|
+
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ private void setGrid(DateTime from, DateTime to, string shift)
|
|
|
79
|
+ {
|
|
|
80
|
+ var id = Utils.getSetting("currentMachine");
|
|
|
81
|
+ var sql = string.Format("select * from daily_checks where created_at >= '{0:yyyy-MM-dd}' and created_at < '{1:yyyy-MM-dd}' and machine_id = {2} and shift = '{3}'"
|
|
|
82
|
+ , from,to, id, shift);
|
|
|
83
|
+ var reader = Utils.Query(_proConn, sql);
|
|
|
84
|
+
|
|
|
85
|
+ dailyCheckGrid.ItemsSource = null;
|
|
|
86
|
+ _dailyChecks.Clear();
|
|
|
87
|
+ if (reader.HasRows)
|
|
|
88
|
+ {
|
|
|
89
|
+ while (reader.Read())
|
|
|
90
|
+ {
|
|
|
91
|
+
|
|
|
92
|
+ _dailyChecks.Add(new DailyChecker()
|
|
|
93
|
+ {
|
|
|
94
|
+ header = reader["header"].ToString().ToUpper(),
|
|
|
95
|
+ p1 = Math.Round(Convert.ToDouble(reader["p1"]), 2),
|
|
|
96
|
+ p2 = Math.Round(Convert.ToDouble(reader["p2"]), 2),
|
|
|
97
|
+ p3 = Math.Round(Convert.ToDouble(reader["p3"]), 2),
|
|
|
98
|
+ avg = Math.Round(Convert.ToDouble(reader["avg"]), 2),
|
|
|
99
|
+ result = reader["result"].ToString()
|
|
|
100
|
+ });
|
|
|
101
|
+ }
|
|
|
102
|
+
|
|
|
103
|
+ }
|
|
|
104
|
+ else
|
|
|
105
|
+ {
|
|
|
106
|
+ _dailyChecks.Add(new DailyChecker() { header = "OB", p1 = 0, p2 = 0, p3 = 0, avg = 0 });
|
|
|
107
|
+ _dailyChecks.Add(new DailyChecker() { header = "OC", p1 = 0, p2 = 0, p3 = 0, avg = 0 });
|
|
|
108
|
+ _dailyChecks.Add(new DailyChecker() { header = "RH", p1 = 0, p2 = 0, p3 = 0, avg = 0 });
|
|
|
109
|
+ }
|
|
|
110
|
+ reader.Close();
|
|
|
111
|
+ dailyCheckGrid.Items.Clear();
|
|
|
112
|
+ dailyCheckGrid.ItemsSource = _dailyChecks;
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
|
115
|
+
|
|
|
116
|
+ private void saveBtn_Click(object sender, RoutedEventArgs e)
|
|
|
117
|
+ {
|
|
|
118
|
+ int row, col;
|
|
|
119
|
+ string header;
|
|
|
120
|
+ //dailyCheckGrid.Focus();
|
|
|
121
|
+ try{
|
|
|
122
|
+ header = _cell.Column.Header.ToString();
|
|
|
123
|
+ row = _dailyChecks.IndexOf((_cell.Item as DailyChecker));
|
|
|
124
|
+ col = _col.DisplayIndex;
|
|
|
125
|
+ }catch{
|
|
|
126
|
+ dailyCheckGrid.Focus();
|
|
|
127
|
+ dailyCheckGrid.CurrentCell = new DataGridCellInfo(
|
|
|
128
|
+ dailyCheckGrid.Items[0], dailyCheckGrid.Columns[1]);
|
|
|
129
|
+ dailyCheckGrid.BeginEdit();
|
|
|
130
|
+ header = "P1";
|
|
|
131
|
+ row = 0;
|
|
|
132
|
+ col = 1;
|
|
|
133
|
+ _item = _dailyChecks[0];
|
|
|
134
|
+ }
|
|
|
135
|
+ switch(header){
|
|
|
136
|
+ case "P1":
|
|
|
137
|
+ //var c = dailyCheckGrid.CurrentItem as DailyChecker;
|
|
|
138
|
+ _item.p1 = Convert.ToDouble(measureBlock.Text);
|
|
|
139
|
+ break;
|
|
|
140
|
+ case "P2":
|
|
|
141
|
+ _item.p2 = Convert.ToDouble(measureBlock.Text);
|
|
|
142
|
+ break;
|
|
|
143
|
+ case "P3":
|
|
|
144
|
+ _item.p3 = Convert.ToDouble(measureBlock.Text);
|
|
|
145
|
+ break;
|
|
|
146
|
+
|
|
|
147
|
+ }
|
|
|
148
|
+ _item.avg = Math.Round((_item.p1 + _item.p2 + _item.p3)/3, 2);
|
|
|
149
|
+ if(_item.header == "OB"){
|
|
|
150
|
+ if(_item.avg >= 0.59 && _item.avg <= 0.70){
|
|
|
151
|
+ _item.result = "OK";
|
|
|
152
|
+ }else {
|
|
|
153
|
+ _item.result = "NG";
|
|
|
154
|
+ }
|
|
|
155
|
+ }
|
|
|
156
|
+ if(_item.header == "OC"){
|
|
|
157
|
+ if (_item.avg >= 0.28 && _item.avg <= 0.37)
|
|
|
158
|
+ {
|
|
|
159
|
+ _item.result = "OK";
|
|
|
160
|
+ }
|
|
|
161
|
+ else
|
|
|
162
|
+ {
|
|
|
163
|
+ _item.result = "NG";
|
|
|
164
|
+ }
|
|
|
165
|
+ }
|
|
|
166
|
+ dailyCheckGrid.Items.Refresh();
|
|
|
167
|
+ dailyCheckGrid.Focus();
|
|
|
168
|
+ if(header != "Header" && header != "Avg" && header != "P3"){
|
|
|
169
|
+ dailyCheckGrid.CurrentCell = new DataGridCellInfo(
|
|
|
170
|
+ dailyCheckGrid.Items[row], dailyCheckGrid.Columns[col + 1]);
|
|
|
171
|
+ dailyCheckGrid.BeginEdit();
|
|
|
172
|
+ }
|
|
|
173
|
+ if(header == "P3"){
|
|
|
174
|
+ try{
|
|
|
175
|
+ dailyCheckGrid.CurrentCell = new DataGridCellInfo(
|
|
|
176
|
+ dailyCheckGrid.Items[row+1], dailyCheckGrid.Columns[1]);
|
|
|
177
|
+ dailyCheckGrid.SelectedItem = dailyCheckGrid.Items[row + 1];
|
|
|
178
|
+ dailyCheckGrid.BeginEdit();
|
|
|
179
|
+ }catch{
|
|
|
180
|
+ dailyCheckGrid.CurrentCell = new DataGridCellInfo(
|
|
|
181
|
+ dailyCheckGrid.Items[0], dailyCheckGrid.Columns[1]);
|
|
|
182
|
+ dailyCheckGrid.SelectedItem = dailyCheckGrid.Items[0];
|
|
|
183
|
+ dailyCheckGrid.BeginEdit();
|
|
|
184
|
+ }
|
|
|
185
|
+ }
|
|
|
186
|
+
|
|
|
187
|
+ }
|
|
|
188
|
+
|
|
|
189
|
+
|
|
|
190
|
+
|
|
|
191
|
+
|
|
|
192
|
+
|
|
|
193
|
+ private void dailyCheckGrid_GotFocus(object sender, RoutedEventArgs e)
|
|
|
194
|
+ {
|
|
|
195
|
+ _cell = dailyCheckGrid.CurrentCell;
|
|
|
196
|
+ _col = dailyCheckGrid.CurrentColumn;
|
|
|
197
|
+ _item = dailyCheckGrid.CurrentItem as DailyChecker;
|
|
|
198
|
+
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+
|
|
|
202
|
+
|
|
|
203
|
+ private void dailyCheckGrid_Loaded(object sender, RoutedEventArgs e)
|
|
|
204
|
+ {
|
|
|
205
|
+ dailyCheckGrid.Focus();
|
|
|
206
|
+ dailyCheckGrid.CurrentCell = new DataGridCellInfo(
|
|
|
207
|
+ dailyCheckGrid.Items[0], dailyCheckGrid.Columns[1]);
|
|
|
208
|
+ dailyCheckGrid.BeginEdit();
|
|
|
209
|
+ }
|
|
|
210
|
+
|
|
|
211
|
+ private void commitBtn_Click(object sender, RoutedEventArgs e)
|
|
|
212
|
+ {
|
|
|
213
|
+ commitData();
|
|
|
214
|
+ MessageBox.Show("Commit Daily Check Complete");
|
|
|
215
|
+ Close();
|
|
|
216
|
+ }
|
|
|
217
|
+
|
|
|
218
|
+ private void commitData()
|
|
|
219
|
+ {
|
|
|
220
|
+ var id = Utils.getSetting("currentMachine");
|
|
|
221
|
+ var sql = string.Format("delete daily_checks where machine_id = {0} and created_at >= '{1:yyyy-MM-dd}' and created_at < '{2:yyyy-MM-dd}' and shift = '{3}'", id, _now, _tomorrow, _shift);
|
|
|
222
|
+ var reader = Utils.Query(_proConn, sql);
|
|
|
223
|
+ reader.Close();
|
|
|
224
|
+ string empid = GlobalVars.user.empid;
|
|
|
225
|
+ foreach (var item in _dailyChecks)
|
|
|
226
|
+ {
|
|
|
227
|
+
|
|
|
228
|
+ sql = string.Format("insert into daily_checks(header, p1, p2, p3, avg, created_at, updated_at,machine_id, empid, shift, result) values('{0}', {1}, {2}, {3}, {4}, '{5}', '{6}', {7}, '{8}', '{9}', '{10}')"
|
|
|
229
|
+ , item.header.ToUpper(), item.p1, item.p2, item.p3, item.avg, _now, DateTime.Now, id, empid, _shift, item.result);
|
|
|
230
|
+ reader = Utils.Query(_proConn, sql);
|
|
|
231
|
+ reader.Close();
|
|
|
232
|
+ }
|
|
|
233
|
+ }
|
|
|
234
|
+
|
|
|
235
|
+ private void datePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
|
|
|
236
|
+ {
|
|
|
237
|
+ //MessageBox.Show("change date");
|
|
|
238
|
+ if (commitBtn.IsEnabled == true)
|
|
|
239
|
+ commitData();
|
|
|
240
|
+ var d = (DateTime)datePicker.SelectedDate;
|
|
|
241
|
+ var shift = (shiftCB.SelectedItem as ComboBoxItem).Tag.ToString();
|
|
|
242
|
+ if (d.Date == DateTime.Now.Date && shift == _shift)
|
|
|
243
|
+ {
|
|
|
244
|
+ saveBtn.IsEnabled = true;
|
|
|
245
|
+ commitBtn.IsEnabled = true;
|
|
|
246
|
+ }
|
|
|
247
|
+ else
|
|
|
248
|
+ {
|
|
|
249
|
+ saveBtn.IsEnabled = false;
|
|
|
250
|
+ commitBtn.IsEnabled = false;
|
|
|
251
|
+ }
|
|
|
252
|
+ var from = (DateTime)datePicker.SelectedDate;
|
|
|
253
|
+
|
|
|
254
|
+ setGrid(from.Date, from.Date.AddDays(1), shift);
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
|
257
|
+ private void shiftCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
258
|
+ {
|
|
|
259
|
+ //var d = (DateTime)datePicker.SelectedDate;
|
|
|
260
|
+ if( commitBtn.IsEnabled == true)
|
|
|
261
|
+ commitData();
|
|
|
262
|
+ var d = (DateTime)datePicker.SelectedDate;
|
|
|
263
|
+ var shift = (shiftCB.SelectedItem as ComboBoxItem).Tag.ToString();
|
|
|
264
|
+ if (d.Date == DateTime.Now.Date && shift == _shift)
|
|
|
265
|
+ {
|
|
|
266
|
+ saveBtn.IsEnabled = true;
|
|
|
267
|
+ commitBtn.IsEnabled = true;
|
|
|
268
|
+ }
|
|
|
269
|
+ else
|
|
|
270
|
+ {
|
|
|
271
|
+ saveBtn.IsEnabled = false;
|
|
|
272
|
+ commitBtn.IsEnabled = false;
|
|
|
273
|
+ }
|
|
|
274
|
+ var from = (DateTime)datePicker.SelectedDate;
|
|
|
275
|
+
|
|
|
276
|
+ setGrid(from.Date, from.Date.AddDays(1), shift);
|
|
|
277
|
+ }
|
|
|
278
|
+
|
|
|
279
|
+ private void Window_Closed(object sender, EventArgs e)
|
|
|
280
|
+ {
|
|
|
281
|
+ if (commitBtn.IsEnabled == true)
|
|
|
282
|
+ commitData();
|
|
|
283
|
+ }
|
|
|
284
|
+
|
|
|
285
|
+
|
|
|
286
|
+
|
|
|
287
|
+
|
|
|
288
|
+
|
|
|
289
|
+
|
|
|
290
|
+
|
|
|
291
|
+
|
|
|
292
|
+ }
|
|
|
293
|
+}
|