先编写一个连接数据库的类
using System;
namespace ATM
{
public class CheckProcess
{
public int tid;
ConnDB db;
public CheckProcess()
{
db=new ConnDB();
}
public bool checkUser(string name,string pass)
{
int a=db.examine(name,pass);
if(a!=0)
{
return true;
}
return false;
}
public bool checknumber(string str){
float f=float.Parse(str);
if(f <=5000){
return true;
}
return false;
}
public bool checkinput(string str)
{
char[] c= str.ToCharArray();
for(int i=0;i<c.Length;i++)
{
if(c[i]<'.'||c[i]>'9'||c[i]=='/')
{
return false;
}
}
return true;
}
public bool checkPassword(string str)
{
char[] c= str.ToCharArray();
for(int i=0;i<c.Length;i++)
{
if(c[i]<'.'||c[i]>'9')
{
return false;
}
}
return true;
}
}
}
下面是处理用户输入的类:
using System;
namespace ATM
{
public class CheckProcess
{
public int tid;
ConnDB db;
public CheckProcess()
{
db=new ConnDB();
}
public bool checkUser(string name,string pass)
{
int a=db.examine(name,pass);
if(a!=0)
{
return true;
}
return false;
}
public bool checknumber(string str){
float f=float.Parse(str);
if(f <=5000){
return true;
}
return false;
}
public bool checkinput(string str)
{
char[] c= str.ToCharArray();
for(int i=0;i<c.Length;i++)
{
if(c[i]<'.'||c[i]>'9'||c[i]=='/')
{
return false;
}
}
return true;
}
public bool checkPassword(string str)
{
char[] c= str.ToCharArray();
for(int i=0;i<c.Length;i++)
{
if(c[i]<'.'||c[i]>'9')
{
return false;
}
}
return true;
}
}
}
Form1部分代码:
private void button1_Click(object sender, System.EventArgs e)
{
CheckProcess pro=new CheckProcess();
name=text1.Text;
pass=text2.Text;
if(!name.Equals("")||!pass.Equals(""))
{
if(pro.checkUser(name,pass))
{
ConnDB db=new ConnDB();
int a=db.getID(name,pass);
ATM.Form2 f2=new Form2();
f2.setUserID(a,name,pass);
this.Hide();
f2.Show();
}
else
{
MessageBox.Show("产生错误!");
}
}
else
{
label3.ForeColor=System.Drawing.Color.Red;
label3.Text="请输入正确的用户名或密码!";
}
}
Form2部分代码:
private int id;
private string name;
private string pwd;
public void setUserID(int id,string name,string pwd){
this.id=id;
this.name = name;
this.pwd=pwd;
}
private void Form2_Load(object sender, System.EventArgs e)
{
this.Text="欢迎用户"+name+"登陆请选择您需要的操作";
}
private void button5_Click(object sender, System.EventArgs e)
{
ATM.Form1 f1=new Form1();
this.Close();
f1.Show();
}
private void button1_Click(object sender, System.EventArgs e)
{
ConnDB db=new ConnDB();
ATM.Form3 f3=new Form3();
string price=db.getPrice(id);
f3.setUserID(id,price);
f3.Show();
}
private void button3_Click(object sender, System.EventArgs e)
{
ConnDB db=new ConnDB();
string price=db.getPrice(id);
MessageBox.Show("你当前帐户余额为:"+price+"元(RMB) ","用户"+name+"您好!",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void button2_Click(object sender, System.EventArgs e)
{
ConnDB db=new ConnDB();
string str =db.getPrice(id);
ATM.Form4 f4=new Form4();
f4.setUser(id,str);
f4.Show();
}
private void button4_Click(object sender, System.EventArgs e)
{
ATM.Form5 f5=new Form5();
f5.setUserName(name,pwd,id);
f5.Show();
}
form3部分代码:
private void button1_Click(object sender, System.EventArgs e)
{
ConnDB db=new ConnDB();
CheckProcess p=new CheckProcess();
if(!this.textBox1.Text.Equals("")&&this.textBox1.Text.Length<10)
{
if(p.checkinput(this.textBox1.Text)&&p.checknumber(this.textBox1.Text))
{
bool flan=db.ReduceMoney(this.textBox1.Text,id,price);
if(flan)
{
MessageBox.Show("输入金额已成功取出 ","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("对不起!您的帐户不足","Information",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
else
{
MessageBox.Show("您的输入有问题!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
else
{
MessageBox.Show("产生错误请重新填写!!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
form4部分代码:
private void button1_Click(object sender, System.EventArgs e)
{
ConnDB db=new ConnDB();
CheckProcess p=new CheckProcess();
if(!this.textBox1.Text.Equals("")&&this.textBox1.Text.Length < 10)
{
if(p.checkinput(this.textBox1.Text))
{
bool flan =db.AddMoney(this.textBox1.Text,id);
if(flan)
{
MessageBox.Show("输入金额已成功存入帐户","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("对不起! 输入金额没有存入 请重新输入!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
else
{
MessageBox.Show("请输入数字!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
else
{
MessageBox.Show("产生错误!请重新输入!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
}
}
form5部分代码:
private void button1_Click(object sender, System.EventArgs e)
{
CheckProcess p=new CheckProcess();
if(!this.textBox1.Text.Equals("")||!this.textBox2.Text.Equals(""))
{
if(this.textBox1.Text.Length == 6 || this.textBox2.Text.Length == 6)
{
if(p.checkPassword(this.textBox1.Text)&&p.checkPassword(this.textBox2.Text))
{
if(this.textBox1.Text.Equals(pwd))
{
ConnDB db=new ConnDB();
bool flan=db.checkUserpass(this.textBox2.Text,id);
if(flan)
{
MessageBox.Show("修改成功完成 ","Update Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("对不起! 修改失败! ","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.Close();
}
}
else
{
MessageBox.Show("对不起!您的密码不正确! ","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
this.textBox2.Text="";
}
}
else
{
MessageBox.Show("请输入0~9之间的整数 ","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
this.textBox2.Text="";
}
}
else{
MessageBox.Show("密码太长或太短请输入6位密码 ","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox1.Text="";
this.textBox2.Text="";
}
}
else
{
MessageBox.Show("请输入内容 ","What way?",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}