From abbefe5dc266f16b48e6c04e8da1c4d8b0ce9c87 Mon Sep 17 00:00:00 2001 From: ziz wiz Date: Sat, 13 Jul 2024 10:41:35 +0100 Subject: [PATCH] Completed the Speed, Time, Fuel. --- myFlightInfo/Form1.Designer.cs | 35 +++++----- myFlightInfo/Form1.cs | 8 ++- myFlightInfo/KeyDowns.cs | 8 +++ myFlightInfo/SpeedTimeFuel.cs | 117 +++++++++++++++++++++++---------- 4 files changed, 116 insertions(+), 52 deletions(-) diff --git a/myFlightInfo/Form1.Designer.cs b/myFlightInfo/Form1.Designer.cs index 77ad823..68facf4 100644 --- a/myFlightInfo/Form1.Designer.cs +++ b/myFlightInfo/Form1.Designer.cs @@ -2256,7 +2256,7 @@ private void InitializeComponent() this.txtbx_runway_heading.MaxLength = 2; this.txtbx_runway_heading.Name = "txtbx_runway_heading"; this.txtbx_runway_heading.Size = new System.Drawing.Size(75, 30); - this.txtbx_runway_heading.TabIndex = 6; + this.txtbx_runway_heading.TabIndex = 3; this.txtbx_runway_heading.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Crosswind_Keydown); // // panel12 @@ -2319,7 +2319,7 @@ private void InitializeComponent() this.btn_calc_wind.Location = new System.Drawing.Point(0, 0); this.btn_calc_wind.Name = "btn_calc_wind"; this.btn_calc_wind.Size = new System.Drawing.Size(100, 48); - this.btn_calc_wind.TabIndex = 14; + this.btn_calc_wind.TabIndex = 4; this.btn_calc_wind.Text = "Calculate"; this.btn_calc_wind.UseVisualStyleBackColor = true; this.btn_calc_wind.Click += new System.EventHandler(this.btn_calc_wind_Click); @@ -2591,8 +2591,8 @@ private void InitializeComponent() this.txtbx_speed_course.MaxLength = 3; this.txtbx_speed_course.Name = "txtbx_speed_course"; this.txtbx_speed_course.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_course.TabIndex = 19; - this.txtbx_speed_course.Text = "270"; + this.txtbx_speed_course.TabIndex = 5; + this.txtbx_speed_course.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel159 // @@ -2621,8 +2621,8 @@ private void InitializeComponent() this.txtbx_speed_true_airspeed.MaxLength = 3; this.txtbx_speed_true_airspeed.Name = "txtbx_speed_true_airspeed"; this.txtbx_speed_true_airspeed.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_true_airspeed.TabIndex = 22; - this.txtbx_speed_true_airspeed.Text = "100"; + this.txtbx_speed_true_airspeed.TabIndex = 6; + this.txtbx_speed_true_airspeed.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel160 // @@ -2651,8 +2651,8 @@ private void InitializeComponent() this.txtbx_speed_wind_direction.MaxLength = 3; this.txtbx_speed_wind_direction.Name = "txtbx_speed_wind_direction"; this.txtbx_speed_wind_direction.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_wind_direction.TabIndex = 23; - this.txtbx_speed_wind_direction.Text = "300"; + this.txtbx_speed_wind_direction.TabIndex = 7; + this.txtbx_speed_wind_direction.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel161 // @@ -2681,8 +2681,8 @@ private void InitializeComponent() this.txtbx_speed_wind_speed.MaxLength = 2; this.txtbx_speed_wind_speed.Name = "txtbx_speed_wind_speed"; this.txtbx_speed_wind_speed.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_wind_speed.TabIndex = 21; - this.txtbx_speed_wind_speed.Text = "10"; + this.txtbx_speed_wind_speed.TabIndex = 8; + this.txtbx_speed_wind_speed.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel162 // @@ -2711,8 +2711,8 @@ private void InitializeComponent() this.txtbx_speed_distance.MaxLength = 3; this.txtbx_speed_distance.Name = "txtbx_speed_distance"; this.txtbx_speed_distance.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_distance.TabIndex = 20; - this.txtbx_speed_distance.Text = "34"; + this.txtbx_speed_distance.TabIndex = 9; + this.txtbx_speed_distance.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel163 // @@ -2741,8 +2741,9 @@ private void InitializeComponent() this.txtbx_speed_fuel_consumption.MaxLength = 2; this.txtbx_speed_fuel_consumption.Name = "txtbx_speed_fuel_consumption"; this.txtbx_speed_fuel_consumption.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_fuel_consumption.TabIndex = 13; + this.txtbx_speed_fuel_consumption.TabIndex = 10; this.txtbx_speed_fuel_consumption.Text = "12"; + this.txtbx_speed_fuel_consumption.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel164 // @@ -2771,8 +2772,9 @@ private void InitializeComponent() this.txtbx_min_landing_fuel.MaxLength = 2; this.txtbx_min_landing_fuel.Name = "txtbx_min_landing_fuel"; this.txtbx_min_landing_fuel.Size = new System.Drawing.Size(56, 30); - this.txtbx_min_landing_fuel.TabIndex = 15; + this.txtbx_min_landing_fuel.TabIndex = 11; this.txtbx_min_landing_fuel.Text = "10"; + this.txtbx_min_landing_fuel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel165 // @@ -2801,8 +2803,9 @@ private void InitializeComponent() this.txtbx_speed_fuel_specific_gravity.MaxLength = 4; this.txtbx_speed_fuel_specific_gravity.Name = "txtbx_speed_fuel_specific_gravity"; this.txtbx_speed_fuel_specific_gravity.Size = new System.Drawing.Size(56, 30); - this.txtbx_speed_fuel_specific_gravity.TabIndex = 17; + this.txtbx_speed_fuel_specific_gravity.TabIndex = 12; this.txtbx_speed_fuel_specific_gravity.Text = "0.72"; + this.txtbx_speed_fuel_specific_gravity.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SpeedTimeFuel_Keydown); // // panel168 // @@ -2864,7 +2867,7 @@ private void InitializeComponent() this.btn_calc_speed_time_fuel.Location = new System.Drawing.Point(0, 0); this.btn_calc_speed_time_fuel.Name = "btn_calc_speed_time_fuel"; this.btn_calc_speed_time_fuel.Size = new System.Drawing.Size(113, 48); - this.btn_calc_speed_time_fuel.TabIndex = 14; + this.btn_calc_speed_time_fuel.TabIndex = 13; this.btn_calc_speed_time_fuel.Text = "Calculate"; this.btn_calc_speed_time_fuel.UseVisualStyleBackColor = true; this.btn_calc_speed_time_fuel.Click += new System.EventHandler(this.btn_calc_speed_time_fuel_Click); diff --git a/myFlightInfo/Form1.cs b/myFlightInfo/Form1.cs index 726ed82..6d72299 100644 --- a/myFlightInfo/Form1.cs +++ b/myFlightInfo/Form1.cs @@ -552,8 +552,6 @@ private void btn_gransden_lodge_photo_update_Click(object sender, EventArgs e) } } - - @@ -561,6 +559,12 @@ private void btn_gransden_lodge_photo_update_Click(object sender, EventArgs e) + + + + + + //private void tabcnt_utils_Leave(object sender, EventArgs e) //{ // btn_navigation_calculations.Visible = false; diff --git a/myFlightInfo/KeyDowns.cs b/myFlightInfo/KeyDowns.cs index 1de9a14..7d22f9d 100644 --- a/myFlightInfo/KeyDowns.cs +++ b/myFlightInfo/KeyDowns.cs @@ -33,6 +33,14 @@ private void Navigation_Keydown(object sender, KeyEventArgs e) } } + private void SpeedTimeFuel_Keydown(object sender, KeyEventArgs e) + { + if ((e.KeyCode == Keys.Enter) && ((tabcnt_toplevel.SelectedTab == tab_utils) && (tabcnt_utils.SelectedTab == tab_crosswind))) + { + btn_calc_speed_time_fuel.PerformClick(); + } + } + private void txtbx_navigate_to_url_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) diff --git a/myFlightInfo/SpeedTimeFuel.cs b/myFlightInfo/SpeedTimeFuel.cs index e4ee1ce..7845831 100644 --- a/myFlightInfo/SpeedTimeFuel.cs +++ b/myFlightInfo/SpeedTimeFuel.cs @@ -12,28 +12,22 @@ public partial class Form1 private void btn_calc_speed_time_fuel_Click(object sender, EventArgs e) { - bool TimeFuelFlag = true; + rchtxbx_speed_time_fuel_output.Text = ""; try { - if ((txtbx_speed_distance.Text == "")||(txtbx_speed_fuel_consumption.Text == "")|| - (txtbx_min_landing_fuel.Text == "") || (txtbx_speed_fuel_specific_gravity.Text == "")) - - //&& TimeFuelCheck(txtbx_speed_fuel_consumption.Text,txtbx_min_landing_fuel.Text, txtbx_speed_fuel_specific_gravity.Text)) - { - TimeFuelFlag = false; - } - - if (SpeedDataCheck(txtbx_speed_wind_speed.Text, txtbx_speed_wind_direction.Text, - txtbx_speed_course.Text, txtbx_speed_true_airspeed.Text)) + txtbx_speed_course.Text, txtbx_speed_true_airspeed.Text)) { + bool TimeFuelFlag = TimeFuelCheck(txtbx_speed_distance.Text, txtbx_speed_fuel_consumption.Text, + txtbx_min_landing_fuel.Text, txtbx_speed_fuel_specific_gravity.Text); + var results = Speed_Time_Fuel.Calculate_Speed_Time_fuel(txtbx_speed_true_airspeed, txtbx_speed_wind_speed, txtbx_speed_course, txtbx_speed_wind_direction, txtbx_speed_distance, txtbx_speed_fuel_consumption, txtbx_min_landing_fuel, TimeFuelFlag); - + //results = WindCorrection, GroundSpeed, FlightTime, JourneyFuelLoad, FuelLoad @@ -70,13 +64,6 @@ private void btn_calc_speed_time_fuel_Click(object sender, EventArgs e) Double.Parse(txtbx_speed_fuel_specific_gravity.Text) + "kg"); } - - } - else - { - //It did not work instead of crashing just put up hint and return gracefully - MsgBox.Show("Something has gone wrong.\rPlease check data and try again", "Something is Wrong", - MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch @@ -91,13 +78,35 @@ private void btn_calc_speed_time_fuel_Click(object sender, EventArgs e) private bool SpeedDataCheck(string myWindStrength, string myDirection, string myCourse, string myAirspeed) { //catch for incomplete data - if ((myWindStrength == "") || (myDirection == "") || (myCourse == "") || (myAirspeed == "")) + if (myCourse == "") { - MsgBox.Show("Please fill in all the data", "Incomplete Data", MessageBoxButtons.OK, + MsgBox.Show("Please check Course has correct data", "Incomplete Course Data", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } + if (myAirspeed == "") + { + MsgBox.Show("Please check True Airspeed has correct data", "Incomplete True Airspeed Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + + if (myDirection == "") + { + MsgBox.Show("Please check Wind Direction has correct data", "Incomplete Wind Direction Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + + if (myWindStrength == "") + { + MsgBox.Show("Please check Wind Speed has correct data", "Incomplete Wind Speed Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + + //Check data is in fact doubles. if (!CheckData.IsItADouble(myWindStrength)) { @@ -105,14 +114,14 @@ private bool SpeedDataCheck(string myWindStrength, string myDirection, string my MessageBoxIcon.Error); return false; } - + if (double.Parse(myWindStrength) < 0) { MsgBox.Show("Check Wind speed is valid number (0 - 999)", "Data out of scope", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } - + if (double.Parse(myWindStrength) > 253) { 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 } else if ((double.Parse(myAirspeed) < 0) || (double.Parse(myAirspeed) > 999)) { - MsgBox.Show("Check True Air Speed Data is a valid number)", "Data out of scope", + MsgBox.Show("Check True Air Speed Data is a valid number >0 and <999)", "Data out of scope", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } + return true; + } + private bool TimeFuelCheck(string myDistance, string myFuelConsumption, string myMinLandingFuel, string myFuelSpecificGravity) + { + //catch for incomplete data + if (myDistance == "") + { + MsgBox.Show("Please add Distance and try again if you want Time and Fuel Calculations", "Incomplete Distance Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } - return true; - } + if (myFuelConsumption == "") + { + MsgBox.Show("Please check data is correct for Fuel Consumption", "Incomplete Fuel Consumption Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + if (myMinLandingFuel == "") + { + MsgBox.Show("Please check data is correct for Min Landing Fuel", "Incomplete Min Landing Fuel Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } - + if (myFuelSpecificGravity == "") + { + MsgBox.Show("Please check data is correct for Fuel Specific Gravity", "Incomplete Fuel Specific Gravity Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } - private bool TimeFuelCheck(string myFuelConsumption, string myMinLandingFuel, string myFuelSpecificGravity) - { - //catch for incomplete data - if ((myFuelConsumption == "") || (myMinLandingFuel == "") || (myFuelSpecificGravity == "")) + //Check data is in fact doubles. + if (!CheckData.IsItADouble(myDistance)) { - MsgBox.Show("Please data is correct for Fuel Consumption, Min Landing Fuel and Fuel Specific Gravity", "Incomplete Data", MessageBoxButtons.OK, + MsgBox.Show("Check Distance is a valid number.", "Incorrect Data", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } + if (!CheckData.IsItADouble(myFuelConsumption)) + { + MsgBox.Show("Check Fuel Consumption is a valid number.", "Incorrect Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + if (!CheckData.IsItADouble(myMinLandingFuel)) + { + MsgBox.Show("Check Minimum Landing Fuel is a valid number.", "Incorrect Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } + if (!CheckData.IsItADouble(myFuelSpecificGravity)) + { + MsgBox.Show("Check Specific Gravity of Fuel is a valid number.", "Incorrect Data", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return false; + } return true; } - - } }