@@ -12,28 +12,22 @@ public partial class Form1
12
12
13
13
private void btn_calc_speed_time_fuel_Click ( object sender , EventArgs e )
14
14
{
15
- bool TimeFuelFlag = true ;
15
+ rchtxbx_speed_time_fuel_output . Text = "" ;
16
16
17
17
try
18
18
{
19
- if ( ( txtbx_speed_distance . Text == "" ) || ( txtbx_speed_fuel_consumption . Text == "" ) ||
20
- ( txtbx_min_landing_fuel . Text == "" ) || ( txtbx_speed_fuel_specific_gravity . Text == "" ) )
21
-
22
- //&& TimeFuelCheck(txtbx_speed_fuel_consumption.Text,txtbx_min_landing_fuel.Text, txtbx_speed_fuel_specific_gravity.Text))
23
- {
24
- TimeFuelFlag = false ;
25
- }
26
-
27
-
28
19
if ( SpeedDataCheck ( txtbx_speed_wind_speed . Text , txtbx_speed_wind_direction . Text ,
29
- txtbx_speed_course . Text , txtbx_speed_true_airspeed . Text ) )
20
+ txtbx_speed_course . Text , txtbx_speed_true_airspeed . Text ) )
30
21
{
22
+ bool TimeFuelFlag = TimeFuelCheck ( txtbx_speed_distance . Text , txtbx_speed_fuel_consumption . Text ,
23
+ txtbx_min_landing_fuel . Text , txtbx_speed_fuel_specific_gravity . Text ) ;
24
+
31
25
var results = Speed_Time_Fuel . Calculate_Speed_Time_fuel ( txtbx_speed_true_airspeed ,
32
26
txtbx_speed_wind_speed ,
33
27
txtbx_speed_course , txtbx_speed_wind_direction , txtbx_speed_distance ,
34
28
txtbx_speed_fuel_consumption ,
35
29
txtbx_min_landing_fuel , TimeFuelFlag ) ;
36
-
30
+
37
31
38
32
//results = WindCorrection, GroundSpeed, FlightTime, JourneyFuelLoad, FuelLoad
39
33
@@ -70,13 +64,6 @@ private void btn_calc_speed_time_fuel_Click(object sender, EventArgs e)
70
64
Double . Parse ( txtbx_speed_fuel_specific_gravity . Text ) +
71
65
"kg" ) ;
72
66
}
73
-
74
- }
75
- else
76
- {
77
- //It did not work instead of crashing just put up hint and return gracefully
78
- MsgBox . Show ( "Something has gone wrong.\r Please check data and try again" , "Something is Wrong" ,
79
- MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
80
67
}
81
68
}
82
69
catch
@@ -91,28 +78,50 @@ private void btn_calc_speed_time_fuel_Click(object sender, EventArgs e)
91
78
private bool SpeedDataCheck ( string myWindStrength , string myDirection , string myCourse , string myAirspeed )
92
79
{
93
80
//catch for incomplete data
94
- if ( ( myWindStrength == "" ) || ( myDirection == "" ) || ( myCourse == "" ) || ( myAirspeed == "" ) )
81
+ if ( myCourse == "" )
95
82
{
96
- MsgBox . Show ( "Please fill in all the data" , "Incomplete Data" , MessageBoxButtons . OK ,
83
+ MsgBox . Show ( "Please check Course has correct data" , "Incomplete Course Data" , MessageBoxButtons . OK ,
97
84
MessageBoxIcon . Error ) ;
98
85
return false ;
99
86
}
100
87
88
+ if ( myAirspeed == "" )
89
+ {
90
+ MsgBox . Show ( "Please check True Airspeed has correct data" , "Incomplete True Airspeed Data" , MessageBoxButtons . OK ,
91
+ MessageBoxIcon . Error ) ;
92
+ return false ;
93
+ }
94
+
95
+ if ( myDirection == "" )
96
+ {
97
+ MsgBox . Show ( "Please check Wind Direction has correct data" , "Incomplete Wind Direction Data" , MessageBoxButtons . OK ,
98
+ MessageBoxIcon . Error ) ;
99
+ return false ;
100
+ }
101
+
102
+ if ( myWindStrength == "" )
103
+ {
104
+ MsgBox . Show ( "Please check Wind Speed has correct data" , "Incomplete Wind Speed Data" , MessageBoxButtons . OK ,
105
+ MessageBoxIcon . Error ) ;
106
+ return false ;
107
+ }
108
+
109
+
101
110
//Check data is in fact doubles.
102
111
if ( ! CheckData . IsItADouble ( myWindStrength ) )
103
112
{
104
113
MsgBox . Show ( "Check Wind speed is a valid number." , "Incorrect Data" , MessageBoxButtons . OK ,
105
114
MessageBoxIcon . Error ) ;
106
115
return false ;
107
116
}
108
-
117
+
109
118
if ( double . Parse ( myWindStrength ) < 0 )
110
119
{
111
120
MsgBox . Show ( "Check Wind speed is valid number (0 - 999)" , "Data out of scope" , MessageBoxButtons . OK ,
112
121
MessageBoxIcon . Error ) ;
113
122
return false ;
114
123
}
115
-
124
+
116
125
if ( double . Parse ( myWindStrength ) > 253 )
117
126
{
118
127
if ( MsgBox . Show ( "Are you really sure that is the wind speed?" , "New World Record for Wind Speed" ,
@@ -154,37 +163,77 @@ private bool SpeedDataCheck(string myWindStrength, string myDirection, string my
154
163
}
155
164
else if ( ( double . Parse ( myAirspeed ) < 0 ) || ( double . Parse ( myAirspeed ) > 999 ) )
156
165
{
157
- MsgBox . Show ( "Check True Air Speed Data is a valid number)" , "Data out of scope" ,
166
+ MsgBox . Show ( "Check True Air Speed Data is a valid number >0 and <999 )" , "Data out of scope" ,
158
167
MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
159
168
return false ;
160
169
}
161
170
171
+ return true ;
172
+ }
162
173
163
174
175
+ private bool TimeFuelCheck ( string myDistance , string myFuelConsumption , string myMinLandingFuel , string myFuelSpecificGravity )
176
+ {
177
+ //catch for incomplete data
178
+ if ( myDistance == "" )
179
+ {
180
+ MsgBox . Show ( "Please add Distance and try again if you want Time and Fuel Calculations" , "Incomplete Distance Data" , MessageBoxButtons . OK ,
181
+ MessageBoxIcon . Error ) ;
182
+ return false ;
183
+ }
164
184
165
- return true ;
166
- }
185
+ if ( myFuelConsumption == "" )
186
+ {
187
+ MsgBox . Show ( "Please check data is correct for Fuel Consumption" , "Incomplete Fuel Consumption Data" , MessageBoxButtons . OK ,
188
+ MessageBoxIcon . Error ) ;
189
+ return false ;
190
+ }
167
191
192
+ if ( myMinLandingFuel == "" )
193
+ {
194
+ MsgBox . Show ( "Please check data is correct for Min Landing Fuel" , "Incomplete Min Landing Fuel Data" , MessageBoxButtons . OK ,
195
+ MessageBoxIcon . Error ) ;
196
+ return false ;
197
+ }
168
198
169
-
199
+ if ( myFuelSpecificGravity == "" )
200
+ {
201
+ MsgBox . Show ( "Please check data is correct for Fuel Specific Gravity" , "Incomplete Fuel Specific Gravity Data" , MessageBoxButtons . OK ,
202
+ MessageBoxIcon . Error ) ;
203
+ return false ;
204
+ }
170
205
171
206
172
- private bool TimeFuelCheck ( string myFuelConsumption , string myMinLandingFuel , string myFuelSpecificGravity )
173
- {
174
- //catch for incomplete data
175
- if ( ( myFuelConsumption == "" ) || ( myMinLandingFuel == "" ) || ( myFuelSpecificGravity == "" ) )
207
+ //Check data is in fact doubles.
208
+ if ( ! CheckData . IsItADouble ( myDistance ) )
176
209
{
177
- MsgBox . Show ( "Please data is correct for Fuel Consumption, Min Landing Fuel and Fuel Specific Gravity " , "Incomplete Data" , MessageBoxButtons . OK ,
210
+ MsgBox . Show ( "Check Distance is a valid number. " , "Incorrect Data" , MessageBoxButtons . OK ,
178
211
MessageBoxIcon . Error ) ;
179
212
return false ;
180
213
}
181
214
215
+ if ( ! CheckData . IsItADouble ( myFuelConsumption ) )
216
+ {
217
+ MsgBox . Show ( "Check Fuel Consumption is a valid number." , "Incorrect Data" , MessageBoxButtons . OK ,
218
+ MessageBoxIcon . Error ) ;
219
+ return false ;
220
+ }
182
221
222
+ if ( ! CheckData . IsItADouble ( myMinLandingFuel ) )
223
+ {
224
+ MsgBox . Show ( "Check Minimum Landing Fuel is a valid number." , "Incorrect Data" , MessageBoxButtons . OK ,
225
+ MessageBoxIcon . Error ) ;
226
+ return false ;
227
+ }
183
228
229
+ if ( ! CheckData . IsItADouble ( myFuelSpecificGravity ) )
230
+ {
231
+ MsgBox . Show ( "Check Specific Gravity of Fuel is a valid number." , "Incorrect Data" , MessageBoxButtons . OK ,
232
+ MessageBoxIcon . Error ) ;
233
+ return false ;
234
+ }
184
235
185
236
return true ;
186
237
}
187
-
188
-
189
238
}
190
239
}
0 commit comments