Example #1
0
 private void BtnWithdraw_Click(object sender, RoutedEventArgs e)
 {
     if (decimal.TryParse(TxtAmount.Text, out decimal bedrag))
     {
         try
         {
             ActiveAccount.Withdraw(bedrag);
         }
         catch (ArgumentException ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         catch (InvalidOperationException ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         }
         UpdateGUI();
     }
     else
     {
         MessageBox.Show("Invalid amount entered.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         TxtAmount.Focus();
         TxtAmount.Select(0, TxtAmount.Text.Length);
     }
 }
Example #2
0
 private void TxtAmount_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (decimal.TryParse(TxtAmount.Text.Replace(",", "").Replace(".", "").TrimStart('0'), out decimal result))
     {
         result /= 100;
         amount  = result;
         TxtAmount.TextChanged -= TxtAmount_TextChanged;
         TxtAmount.Text         = result.ToString("N2", nfi);
         TxtAmount.TextChanged += TxtAmount_TextChanged;
         TxtAmount.Select(TxtAmount.Text.Length, 0);
     }
 }