="75" Click="commitBtn_Click" /> 108
+		<DatePicker Height="29" HorizontalAlignment="Left" Margin="233.725,24.683,0,0" Name="datePicker" VerticalAlignment="Top" Width="142" Text="hello" SelectedDateChanged="datePicker_SelectedDateChanged" Style="{DynamicResource DatePickerStyle1}" RenderTransformOrigin="0.509,-0.966" />
109
+		<ComboBox Height="29.858" HorizontalAlignment="Left" Margin="41,24.254,0,0" Name="shiftCB" VerticalAlignment="Top" Width="172.853" SelectedIndex="0" FontSize="16">
110
+			<ComboBoxItem Content="Day ( 08.00 - 20.00 )" Tag="day" />
111
+			<ComboBoxItem Content="Night ( 20.00 - 08.00 )" Tag="night" />
112
+		</ComboBox>
113
+		<TextBlock Height="23" HorizontalAlignment="Left" Margin="41,269,0,0" Name="textBlock1" Text="Standard values,  OB :" VerticalAlignment="Top" Foreground="#CA000000" />
114
+		<TextBlock Height="23" HorizontalAlignment="Left" Margin="164,268,0,0" Name="textBlock2" Text="0.59 - 0.70" VerticalAlignment="Top" Foreground="#FF3063F0" FontWeight="Bold" FontSize="14" />
115
+		<TextBlock Foreground="#CA000000" Height="23" HorizontalAlignment="Left" Margin="265,270,0,0" Name="textBlock4" Text="OC :" VerticalAlignment="Top" />
116
+		<TextBlock FontSize="14" FontWeight="Bold" Foreground="#FF3063F0" Height="23" HorizontalAlignment="Left" Margin="297,268,0,0" Name="textBlock3" Text="0.28 - 0.37" VerticalAlignment="Top" />
117
+	</Grid>
118
+	</Viewbox>
119
+</Window>

+ 293 - 0
WpfApplication19/DailyCheck.xaml.cs

@@ -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
+}

+ 17 - 0
WpfApplication19/DailyChecker.cs

@@ -0,0 +1,17 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+
6
+namespace WpfApplication19
7
+{
8
+	class DailyChecker
9
+	{
10
+		public string header { get; set; }
11
+		public double p1 {get; set; }
12
+		public double p2 { get; set; }
13
+		public double p3 { get; set; }
14
+		public double avg { get; set; }
15
+		public string result {get; set; }
16
+	}
17
+}

+ 8 - 0
WpfApplication19/Debug.xaml

@@ -0,0 +1,8 @@
1
+<Window x:Class="WpfApplication19.Debug"
2
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
+        Title="Debug" Height="300" Width="300" Name="debugWindow">
5
+    <Grid>
6
+        <TextBox Margin="12,12,0,0" Name="debugTextBox" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" />
7
+    </Grid>
8
+</Window>

+ 26 - 0
WpfApplication19/Debug.xaml.cs

@@ -0,0 +1,26 @@
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
+
14
+namespace WpfApplication19
15
+{
16
+    /// <summary>
17
+    /// Interaction logic for Debug.xaml
18
+    /// </summary>
19
+    public partial class Debug : Window
20
+    {
21
+        public Debug()
22
+        {
23
+            InitializeComponent();
24
+        }
25
+    }
26
+}

+ 11 - 0
WpfApplication19/EditINWindow.xaml

@@ -0,0 +1,11 @@
1
+<Window x:Class="WpfApplication19.EditINWindow"
2
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
+        Title="IN* Editor" Height="140" Width="447" ResizeMode="NoResize" WindowStyle="None" BorderThickness="2" BorderBrush="Red" WindowStartupLocation="CenterScreen">
5
+		<Grid Name="grid1">
6
+			<Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="177,56,0,0" Name="saveBtn" VerticalAlignment="Top" Width="75" Click="saveBtn_Click" DataContext="{Binding}" />
7
+		<Label Content="Grain Size" Height="28" HorizontalAlignment="Left" Margin="25,10,0,0" Name="label1" VerticalAlignment="Top" FontWeight="Bold" FontSize="16" />
8
+		<TextBox Height="26" HorizontalAlignment="Left" Margin="116,12,0,0" Name="grainSizeInput" VerticalAlignment="Top" Width="249" FontSize="16" PreviewKeyDown="grainSizeInput_PreviewKeyDown" />
9
+	</Grid>
10
+	
11
+</Window>

+ 42 - 0
WpfApplication19/EditINWindow.xaml.cs

@@ -0,0 +1,42 @@
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
+
14
+namespace WpfApplication19
15
+{
16
+	/// <summary>
17
+	/// Interaction logic for EditINWindow.xaml
18
+	/// </summary>
19
+	public partial class EditINWindow : Window
20
+	{
21
+		public EditINWindow()
22
+		{
23
+			InitializeComponent();
24
+			var w = (MainWindow)Application.Current.MainWindow;
25
+			grainSizeInput.Text = w.inStarGS;
26
+		}
27
+
28
+		private void saveBtn_Click(object sender, RoutedEventArgs e)
29
+		{
30
+			var w = (MainWindow)Application.Current.MainWindow;
31
+			w.inStarGS = grainSizeInput.Text;
32
+			this.Close();
33
+		}
34
+
35
+		private void grainSizeInput_PreviewKeyDown(object sender, KeyEventArgs e)
36
+		{
37
+			if ((e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key == Key.Next || e.Key == Key.Back || e.Key == Key.Delete || e.Key == Key.Left || e.Key == Key.Right)
38
+				e.Handled = false;
39
+			else e.Handled = true;
40
+		}
41
+	}
42
+}

+ 0 - 0
WpfApplication19/EditMIDWindow.xaml


Some files were not shown because too many files changed in this diff

tum/OBAppSrc - Gogs: Simplico Git Service

Ei kuvausta

1031A.pdf 35KB