private void WeightTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { double enteredValue = 0; e.Cancel = !double.TryParse(WeightTextBox.Text, out enteredValue); if (!e.Cancel) { GarminFitnessDoubleRange valueInKilos = new GarminFitnessDoubleRange(0, Constants.MinWeight, Constants.MaxWeightInKg); e.Cancel = !valueInKilos.IsInRange(Weight.Convert(enteredValue, PluginMain.GetApplication().SystemPreferences.WeightUnits, Weight.Units.Kilogram)); } if (e.Cancel) { double minValue = Weight.Convert(Constants.MinWeight, Weight.Units.Kilogram, PluginMain.GetApplication().SystemPreferences.WeightUnits); double maxValue = Weight.Convert(Constants.MaxWeightInKg, Weight.Units.Kilogram, PluginMain.GetApplication().SystemPreferences.WeightUnits); MessageBox.Show(String.Format(TextResourceManager.DoubleRangeValidationText, minValue, maxValue), TextResourceManager.ValueValidationTitleText, MessageBoxButtons.OK, MessageBoxIcon.Warning); System.Media.SystemSounds.Asterisk.Play(); // Reset old valid value WeightTextBox.Text = GarminProfileManager.Instance.UserProfile.GetWeightInUnits(PluginMain.GetApplication().SystemPreferences.WeightUnits).ToString("0.0"); } }
private void OdometerTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { double enteredValue; e.Cancel = !double.TryParse(OdometerTextBox.Text, out enteredValue); if(!e.Cancel) { GarminFitnessDoubleRange valueInMeters = new GarminFitnessDoubleRange(0, Constants.MinOdometer, Constants.MaxOdometer); e.Cancel = !valueInMeters.IsInRange(Length.Convert(enteredValue, m_CurrentProfile.BaseSpeedUnit, Length.Units.Kilometer)); } if (e.Cancel) { double minValue = Length.Convert(Constants.MinOdometer, Length.Units.Kilometer, m_CurrentProfile.BaseSpeedUnit); double maxValue = Length.Convert(Constants.MaxOdometer, Length.Units.Kilometer, m_CurrentProfile.BaseSpeedUnit); MessageBox.Show(String.Format(TextResourceManager.DoubleRangeValidationText, minValue, maxValue), TextResourceManager.ValueValidationTitleText, MessageBoxButtons.OK, MessageBoxIcon.Warning); System.Media.SystemSounds.Asterisk.Play(); // Reset old valid value OdometerTextBox.Text = Length.Convert(m_CurrentBikeProfile.OdometerInMeters, Length.Units.Meter, m_CurrentProfile.BaseSpeedUnit).ToString("0.0"); } }