aijava

          welcome to my online log ! open java new world! Taste java charm........
          posts - 1, comments - 4, trackbacks - 0, articles - 42
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          C#編寫ATM模擬程序

          Posted on 2006-11-12 22:55 閱讀(1550) 評論(0)  編輯  收藏 所屬分類: ASP/ASP.NET

          先編寫一個(gè)連接數(shù)據(jù)庫的類
          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("產(chǎn)生錯(cuò)誤!");
          ????}
          ???}
          ???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("你當(dāng)前帳戶余額為:"+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("產(chǎn)生錯(cuò)誤請重新填寫!!","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("請輸入數(shù)字!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
          ?????this.textBox1.Text="";
          ????}
          ???}
          ???else
          ???{
          ????MessageBox.Show("產(chǎn)生錯(cuò)誤!請重新輸入!","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之間的整數(shù)??? ","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("請輸入內(nèi)容????????? ","What way?",MessageBoxButtons.OK,MessageBoxIcon.Warning);
          ???}
          ??}

          http://freehost13.websamba.com
          主站蜘蛛池模板: 乌什县| 灵石县| 包头市| 昭觉县| 资兴市| 历史| 远安县| 丹巴县| 台中市| 灌南县| 监利县| 天镇县| 巴里| 治县。| 淮安市| 巴林左旗| 蓬安县| 防城港市| 东阿县| 金华市| 大姚县| 五河县| 宝坻区| 喜德县| 颍上县| 石台县| 台中市| 蒙阴县| 台湾省| 绥化市| 宁南县| 英吉沙县| 当涂县| 南雄市| 陇南市| 亳州市| 沅陵县| 班戈县| 晋州市| 天气| 右玉县|