📄 atm.cs
字号:
{
Application.Run(new Form1());
}
//查询余额
private void button1_Click(object sender, System.EventArgs e)
{
decimal balance;
string CardNo=textBox1.Text;
if(IsVerified)
{
balance=bank.QueryByCardNo(CardNo);
if(balance!=-1)
{
richTextBox1.AppendText("你的余额是:"+balance.ToString()+"\r\n");
}
else
{
richTextBox1.AppendText("请输入你的卡号或者口令!");
}
}
else
{
richTextBox1.AppendText("请先验证卡号和口令!\r\n");
}
}
//取款
private void button2_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入取款金额:";
textBox3.ReadOnly=false;
IsWithdraw=true;
IsDeposit=false;
IsTransfer=false;
IsUpdatePwd=false;
}
else
{
richTextBox1.AppendText("请先验证卡号和口令!\r\n");
label3.Text="";
textBox3.ReadOnly=true;
}
}
//存款
private void button3_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入存款金额!";
textBox3.ReadOnly=false;
IsWithdraw=false;
IsDeposit=true;
IsTransfer=false;
IsUpdatePwd=false;
}
else
{
richTextBox1.AppendText("请先验证卡号和口令!\r\n");
label3.Text="";
textBox3.ReadOnly=true;
}
}
//转帐
private void button4_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入帐号:";
textBox3.ReadOnly=false;
IsWithdraw=false;
IsDeposit=false;
IsTransfer=true;
IsUpdatePwd=false;
}
else
{
richTextBox1.AppendText("请先验证卡号和口令!\r\n");
label3.Text="";
textBox3.ReadOnly=true;
}
}
//修改口令
private void button5_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入新的口令:";
textBox3.PasswordChar='*';
textBox3.ReadOnly=false;
IsWithdraw=false;
IsDeposit=false;
IsTransfer=false;
IsUpdatePwd=true;
}
else
{
richTextBox1.AppendText("请先验证卡号和口令!\r\n");
label3.Text="";
textBox3.ReadOnly=true;
}
}
//确认输入的信息
private void button6_Click(object sender, System.EventArgs e)
{
//取款
if(IsWithdraw)
{
string CardNo=textBox1.Text;
decimal amount=decimal.Parse(textBox3.Text);
if(bank.WithdrawByCardNo(CardNo,amount))
{
richTextBox1.AppendText("取款操作成功!你所取金额是:"+
amount.ToString()+"\r\n");
}
else
{
richTextBox1.AppendText("取款操作失败!\r\n");
richTextBox1.AppendText("你的存款余额可能不足!\r\n");
}
IsWithdraw=false;
}
//存款
if(IsDeposit)
{
string CardNo=textBox1.Text;
decimal amount=decimal.Parse(textBox3.Text);
if(bank.DepositByCardNo(CardNo,amount))
{
richTextBox1.AppendText("存款操作成功!你所存金额是:"+
amount.ToString()+"\r\n");
}
else
{
richTextBox1.AppendText("存款操作失败!\r\n");
}
IsDeposit=false;
}
//转帐
if(IsTransfer)
{
if(IsTransfering)
{
TransferAmount=decimal.Parse(textBox3.Text);
string FromCardNo=textBox1.Text;
string ToCardNo=TransferCardNo;
decimal amount=TransferAmount;
if(bank.TransferByCardNo(FromCardNo,ToCardNo,amount))
{
richTextBox1.AppendText("转帐成功操作成功!\r\n");
richTextBox1.AppendText("帐号是:"+ToCardNo+"\r\n");
richTextBox1.AppendText("转帐金额是:"+amount+"\r\n");
}
else
{
richTextBox1.AppendText("转帐操作失败,可能是余额不足!\r\n");
}
IsTransfering=false;
IsTransfer=false;
}
else
{
IsTransfering=true;
TransferCardNo=textBox3.Text;
label3.Text="请输入转帐金额:";
textBox3.ReadOnly=false;
}
}
//修改口令
if(IsUpdatePwd)
{
string CardNo;
string Password;
CardNo=textBox1.Text;
Password=textBox3.Text;
if(bank.UpdateCardPassword(CardNo,Password))
{
richTextBox1.AppendText("口令修改成功!\r\n");
}
else
{
richTextBox1.AppendText("口令修改失败!\r\n");
}
textBox3.PasswordChar=char.Parse("\0");
IsUpdatePwd=false;
}
if(!IsTransfering)
{
label3.Text="";
textBox3.ReadOnly=true;
}
}
//重新输入信息
private void button7_Click(object sender, System.EventArgs e)
{
if(textBox3.ReadOnly==false)
{
textBox3.Text="";
richTextBox1.AppendText("请重新输入你的信息!\r\n");
}
}
//操作结束,取卡,返回
private void button8_Click(object sender, System.EventArgs e)
{
richTextBox1.AppendText("谢谢你的使用!欢迎下次光临!\r\n");
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox3.ReadOnly=true;
}
//确认卡号和口令是否正确
private void button9_Click(object sender, System.EventArgs e)
{
string CardNo=textBox1.Text;
string Password=textBox2.Text;
if(bank.VerifyCardNo(CardNo,Password))
{
IsVerified=true;
richTextBox1.AppendText("卡号和口令正确,请执行其他操作!\r\n");
}
else
{
IsVerified=false;
richTextBox1.AppendText("卡号或口令错误,请重新输入!\r\n");
}
}
//检查输入的数据格式是否正确
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
if(textBox3.Text!="")
{
if(IsWithdraw==true||IsDeposit==true||IsTransfering==true)
{
try
{
decimal.Parse(textBox3.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message+"请输入正确的数据格式!\r\n");
richTextBox1.AppendText(ex.Message+"请输入正确的数据格式!\r\n");
}
}
}
else
{
MessageBox.Show("数据不能为空,请输入数据!");
richTextBox1.AppendText("数据不能为空,请输入数据!\r\n");
}
}
//验证卡号是否为空,如果不为空,验证卡号和口令是否正确
private void textBox1_Leave(object sender, System.EventArgs e)
{
if(textBox1.Text=="")
{
MessageBox.Show("卡号不能为空!");
richTextBox1.AppendText("卡号不能为空!\r\n");
}
else if(textBox2.Text!="")
{
string CardNo=textBox1.Text;
string Password=textBox2.Text;
if(!bank.VerifyCardNo(CardNo,Password))
{
IsVerified=false;
richTextBox1.AppendText("卡号或口令错误,请重新输入!\r\n");
}
}
}
//验证口令是否为空,如果不为空,验证卡号和口令是否正确
private void textBox2_Leave(object sender, System.EventArgs e)
{
if(textBox2.Text=="")
{
MessageBox.Show("口令不能为空!");
richTextBox1.AppendText("口令不能为空!\r\n");
}
else if(textBox1.Text!="")
{
string CardNo=textBox1.Text;
string Password=textBox2.Text;
if(!bank.VerifyCardNo(CardNo,Password))
{
IsVerified=false;
richTextBox1.AppendText("卡号或口令错误,请重新输入!\r\n");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -