Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
McoreD committed Jul 8, 2016
1 parent 14c53d6 commit f8f0492
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 56 deletions.
9 changes: 9 additions & 0 deletions ERN9PDC/CalcHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ public static void SetHVGrowthRate_r2(string txt)

#endregion r1 and r2

#region d Lane Distribution Factor

public static void SetLaneDistributionFactor(string txt)
{
Settings.d_LaneDistributionFactor = TryParseUint(txt);
}

public static void SetLaneDistributionFactor(uint d)
{
Settings.d_LaneDistributionFactor = d;
}

#endregion d Lane Distribution Factor

public static void SetHVPerc(string txt)
{
Settings.c_HVPerc = TryParseDouble(txt);
Expand Down
2 changes: 1 addition & 1 deletion ERN9PDC/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</StackPanel>

<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Percentage of heavy vehicles using design lane, d (%)</TextBlock>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="txtLaneDistributionFactor" md:TextFieldAssist.Hint="100" VerticalContentAlignment="Center" Margin="5,0,0,0" HorizontalContentAlignment="Right" />
<TextBox Grid.Row="2" Grid.Column="1" x:Name="txtLaneDistributionFactor" md:TextFieldAssist.Hint="100" VerticalContentAlignment="Center" Margin="5,0,0,0" HorizontalContentAlignment="Right" TextChanged="txtLaneDistributionFactor_TextChanged" />
<Button Grid.Row="2" Grid.Column="2" Margin="5" ToolTip="Select d" Click="btnLaneDistributionFactor_Click" IsTabStop="False">...</Button>
</Grid>

Expand Down
176 changes: 121 additions & 55 deletions ERN9PDC/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ public partial class MainWindow : Window
{
private bool IsGuiReady = false;

private async Task<bool> IsNumeric(TextBox textBox)
{
bool isNumber = textBox.Text.IsNumber();

if (!isNumber)
{
var dlg = new CustomMessageBox("Entered value is not numeric.");
await DialogHost.Show(dlg);
textBox.Clear();
textBox.Focus();
}

return isNumber;
}

public MainWindow()
{
InitializeComponent();
Expand All @@ -36,17 +51,20 @@ public MainWindow()

#region Pavement data

private void txtP_TextChanged(object sender, TextChangedEventArgs e)
private async void txtP_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetPavementDesignLife(txtP_PavementDesignLife.Text);

if (CalcHelper.Settings.P_PavementDesignLife > 0)
if (await IsNumeric(txtP_PavementDesignLife))
{
spGrowthRate1.Visibility = Visibility.Visible;
sliderQ_PavementDesignLife.Value = sliderQ_PavementDesignLife.Maximum = CalcHelper.Settings.P_PavementDesignLife;
}
CalcHelper.SetPavementDesignLife(txtP_PavementDesignLife.Text);

UpdateGuiControls();
if (CalcHelper.Settings.P_PavementDesignLife > 0)
{
spGrowthRate1.Visibility = Visibility.Visible;
sliderQ_PavementDesignLife.Value = sliderQ_PavementDesignLife.Maximum = CalcHelper.Settings.P_PavementDesignLife;
}

UpdateGuiControls();
}
}

private void sliderSubgradeCBR_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
Expand All @@ -57,32 +75,49 @@ private void sliderSubgradeCBR_ValueChanged(object sender, RoutedPropertyChanged

#endregion Pavement data

private async void btnLaneDistributionFactor_Click(object sender, RoutedEventArgs e)
#region Traffic data

private async void txtAADT_TextChanged(object sender, TextChangedEventArgs e)
{
LaneDistributionFactorSelector dlg = new LaneDistributionFactorSelector();
await DialogHost.Show(dlg);
txtLaneDistributionFactor.Text = CalcHelper.Settings.d_LaneDistributionFactor.ToString();
if (await IsNumeric(txtAADT))
{
CalcHelper.SetAADT(txtAADT.Text);
UpdateGuiControls();
}
}

#region Traffic data

private void txtAADT_TextChanged(object sender, TextChangedEventArgs e)
private async void txtHVGrowthRate_r1_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetAADT(txtAADT.Text);
if (await IsNumeric(txtHVGrowthRate_r1))
{
CalcHelper.SetHVGrowthRate_r1(txtHVGrowthRate_r1.Text);
UpdateGuiControls();
}
}

UpdateGuiControls();
private async void txtHVGrowthRate_r2_TextChanged(object sender, TextChangedEventArgs e)
{
if (await IsNumeric(txtHVGrowthRate_r2))
{
CalcHelper.SetHVGrowthRate_r2(txtHVGrowthRate_r2.Text);
UpdateGuiControls();
}
}

private void txtHVGrowthRate_r1_TextChanged(object sender, TextChangedEventArgs e)
private async void txtLaneDistributionFactor_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetHVGrowthRate_r1(txtHVGrowthRate_r1.Text);
UpdateGuiControls();
if (await IsNumeric(txtLaneDistributionFactor))
{
CalcHelper.SetLaneDistributionFactor(txtLaneDistributionFactor.Text);
UpdateGuiControls();
}
}

private void txtHVGrowthRate_r2_TextChanged(object sender, TextChangedEventArgs e)
private async void btnLaneDistributionFactor_Click(object sender, RoutedEventArgs e)
{
CalcHelper.SetHVGrowthRate_r2(txtHVGrowthRate_r2.Text);
UpdateGuiControls();
LaneDistributionFactorSelector dlg = new LaneDistributionFactorSelector();
await DialogHost.Show(dlg);
txtLaneDistributionFactor.Text = CalcHelper.Settings.d_LaneDistributionFactor.ToString();
}

private void sliderQ_PavementDesignLife_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
Expand Down Expand Up @@ -138,64 +173,94 @@ private void rbTrafficMethod1_Checked(object sender, RoutedEventArgs e)

#region Traffic Method 1 - Grid for c

private void txtC3_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC3_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(3, txtC3.Text, txtF3.Text);
UpdateGuiControls();
if (await IsNumeric(txtC3))
{
CalcHelper.SetTrafficData(3, txtC3.Text, txtF3.Text);
UpdateGuiControls();
}
}

private void txtC4_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC4_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(4, txtC4.Text, txtF4.Text);
UpdateGuiControls();
if (await IsNumeric(txtC4))
{
CalcHelper.SetTrafficData(4, txtC4.Text, txtF4.Text);
UpdateGuiControls();
}
}

private void txtC5_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC5_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(5, txtC5.Text, txtF5.Text);
UpdateGuiControls();
if (await IsNumeric(txtC5))
{
CalcHelper.SetTrafficData(5, txtC5.Text, txtF5.Text);
UpdateGuiControls();
}
}

private void txtC6_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC6_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(6, txtC6.Text, txtF6.Text);
UpdateGuiControls();
if (await IsNumeric(txtC6))
{
CalcHelper.SetTrafficData(6, txtC6.Text, txtF6.Text);
UpdateGuiControls();
}
}

private void txtC7_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC7_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(7, txtC7.Text, txtF7.Text);
UpdateGuiControls();
if (await IsNumeric(txtC7))
{
CalcHelper.SetTrafficData(7, txtC7.Text, txtF7.Text);
UpdateGuiControls();
}
}

private void txtC8_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC8_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(8, txtC8.Text, txtF8.Text);
UpdateGuiControls();
if (await IsNumeric(txtC8))
{
CalcHelper.SetTrafficData(8, txtC8.Text, txtF8.Text);
UpdateGuiControls();
}
}

private void txtC9_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC9_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(9, txtC9.Text, txtF9.Text);
UpdateGuiControls();
if (await IsNumeric(txtC9))
{
CalcHelper.SetTrafficData(9, txtC9.Text, txtF9.Text);
UpdateGuiControls();
}
}

private void txtC10_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC10_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(10, txtC10.Text, txtF10.Text);
UpdateGuiControls();
if (await IsNumeric(txtC10))
{
CalcHelper.SetTrafficData(10, txtC10.Text, txtF10.Text);
UpdateGuiControls();
}
}

private void txtC11_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC11_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(11, txtC11.Text, txtF11.Text);
UpdateGuiControls();
if (await IsNumeric(txtC11))
{
CalcHelper.SetTrafficData(11, txtC11.Text, txtF11.Text);
UpdateGuiControls();
}
}

private void txtC12_TextChanged(object sender, TextChangedEventArgs e)
private async void txtC12_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetTrafficData(12, txtC12.Text, txtF12.Text);
UpdateGuiControls();
if (await IsNumeric(txtC12))
{
CalcHelper.SetTrafficData(12, txtC12.Text, txtF12.Text);
UpdateGuiControls();
}
}

#endregion Traffic Method 1 - Grid for c
Expand Down Expand Up @@ -228,9 +293,10 @@ private void btnRandomC_Click(object sender, RoutedEventArgs e)

#region Axle Equivalency Factor methods, F

private void txtAxleEquivalencyFactor_TextChanged(object sender, TextChangedEventArgs e)
private async void txtAxleEquivalencyFactor_TextChanged(object sender, TextChangedEventArgs e)
{
CalcHelper.SetAxleEquivalencyFactor(txtAxleEquivalencyFactor.Text);
if (await IsNumeric(txtAxleEquivalencyFactor))
CalcHelper.SetAxleEquivalencyFactor(txtAxleEquivalencyFactor.Text);
}

private async void btnAxleEquivalencyFactor_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit f8f0492

Please sign in to comment.