Okay so I am creating a windows form to basically act as a bank ledger for an individual. Pretty simple they must enter the account information, and a beginning balance. The key is the validation, it is really tripping me up. I need to ensure that upon clicking the continue button the textboxes are validated, the first should only be alphabetical components while the second two should only be numeric components. Additionally the last box must also be numeric only. Doubles are okay, it is currency after all. My code is below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class BankInfo : Form
{
double withdrawal;
double deposit;
double balance;
double newTotal;
public BankInfo()
{
InitializeComponent();
}
private void txtAcctBegBal_Validating(object sender, CancelEventArgs e)
{
try
{
int numberEntered = int.Parse(txtAcctBegBal.Text);
if (numberEntered == 0)
{
e.Cancel = true;
MessageBox.Show("Please enter an amount greater than 0.");
}
}
catch (FormatException)
{
e.Cancel = true;
MessageBox.Show("You need to enter an integer");
}
}
private void btnAcctInfo_Click(object sender, EventArgs e)
{
grpAcctInfo.Visible = true;
txtAcctName.Visible = true;
txtAcctNum.Visible = true;
txtAcctBegBal.Visible = true;
lblAcctName.Visible = true;
lblAcctNum.Visible = true;
lblBeginning.Visible = true;
btnCnt.Visible = true;
}
private void btnCnt_Click(object sender, EventArgs e)
{
txtAmt.Visible = true;
btnWithDraw.Visible = true;
btnDeposit.Visible = true;
lblAvailable.Visible = true;
lblBeginning.Visible = false;
}
private void btnClear_Click(object sender, EventArgs e)
{
grpAcctInfo.Visible = false;
txtAcctName.Visible = false;
txtAcctNum.Visible = false;
txtAcctBegBal.Visible = false;
lblAcctName.Visible = false;
lblAcctNum.Visible = false;
lblBeginning.Visible = false;
btnCnt.Visible = false;
txtAmt.Visible = false;
btnWithDraw.Visible = false;
btnDeposit.Visible = false;
lblAvailable.Visible = false;
lblBeginning.Visible = false;
txtAcctBegBal.Clear();
txtAcctNum.Clear();
txtAcctName.Clear();
}
private void btnWithDraw_Click(object sender, EventArgs e)
{
withdrawal = Convert.ToDouble(txtAmt.Text);
balance = Convert.ToDouble(txtAcctBegBal.Text);
newTotal = (balance - withdrawal);
txtAcctBegBal.Text = System.Convert.ToString(newTotal);
}
private void btnDeposit_Click(object sender, EventArgs e)
{
withdrawal = Convert.ToDouble(txtAmt.Text);
balance = Convert.ToDouble(txtAcctBegBal.Text);
newTotal = (balance + withdrawal);
txtAcctBegBal.Text = System.Convert.ToString(newTotal);
}
}
}
any help is appreciated.