ATM模拟操作系统
- 格式:doc
- 大小:51.50 KB
- 文档页数:10
文章转自:http://www.tipsviet.com 参考资料:sql server数据库开发与运用 asp.net开发 哈尔滨白癜风最好医院 1 ATM模拟操作系统 数据库:ATM_System dbhelp.cs类中数据库连接代码: class DBHelp { public static SqlConnection connection = new SqlConnection("data source=.\\sqlexpress;database=ATM_System;integrated security=true"); }
Savemoney存钱代码 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; using System.Data.SqlClient; namespace ATM { public partial class Savemoney : Form { public Savemoney() { InitializeComponent(); }
private void 返回ToolStripMenuItem_Click(object sender, EventArgs e) { Operate o = new Operate(); o.Show(); this.Hide(); } /// /// 存入金额 /// 1、ATM_Money表做更改操作(total,balance) /// 2、ATM_Record表做插入操作(account,record,time) /// /// /// private void button1_Click(object sender, EventArgs e) { 文章转自:http://www.tipsviet.com 参考资料:sql server数据库开发与运用 asp.net开发 哈尔滨白癜风最好医院 2 double money = 0;//存钱的金额 double sum = 0;//总数 double difference = 0;//余额 string time=DateTime .Now.ToString ();
DBHelp.connection.Open(); string command = "select * from ATM_Money where account='" + Login.account + "'"; SqlCommand comm = new SqlCommand(command, DBHelp.connection); SqlDataReader dat = comm.ExecuteReader(); while (dat .Read ()) { sum = Convert.ToDouble(dat["total"].ToString()); difference = Convert.ToDouble(dat["balance"].ToString());
} DBHelp .connection .Close ();
DBHelp .connection .Open (); money = Convert.ToDouble(textBox1.Text); string command1 = "update ATM_Money set total='" + (sum + money) + "',balance='" + (difference + money) + "' where account='" + Login.account + "' "; SqlCommand comm1 = new SqlCommand(command1, DBHelp.connection); comm1.ExecuteNonQuery(); DBHelp.connection.Close();
DBHelp.connection.Open(); string command2 = "insert into ATM_Record(account,record,time) values('" + Login.account + "','存入'+'"+money +"'+'元','" + time + "')"; SqlCommand comm2 = new SqlCommand(command2, DBHelp.connection); comm2.ExecuteNonQuery(); label2.Visible = true; label2.Text ="您已存入"+ money.ToString()+"元"; DBHelp.connection.Close(); } } }
Getmoney取钱代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; 文章转自:http://www.tipsviet.com 参考资料:sql server数据库开发与运用 asp.net开发 哈尔滨白癜风最好医院 3 using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;
namespace ATM { public partial class Getmoney : Form { public Getmoney() { InitializeComponent(); }
/// /// 取100元 /// /// /// private void button1_Click(object sender, EventArgs e) { string time = DateTime.Now.ToString(); int money = 0; string a = ""; DBHelp.connection.Open(); string command = "select * from ATM_Money where account='" + Login.account + "'"; SqlCommand comm = new SqlCommand(command, DBHelp.connection); SqlDataReader dat = comm.ExecuteReader(); while (dat.Read()) {
money = Convert.ToInt32(dat["balance"]); a = (Convert.ToInt32(dat["balance"]) - 100).ToString(); } if (100 < money) { DBHelp.connection.Close(); DBHelp.connection.Open(); string command1 = "update ATM_Money set balance='" + a + "' where account='" + Login.account + "'"; SqlCommand comm1 = new SqlCommand(command1, DBHelp.connection); comm1.ExecuteNonQuery(); 文章转自:http://www.tipsviet.com 参考资料:sql server数据库开发与运用 asp.net开发 哈尔滨白癜风最好医院 4 DBHelp.connection.Close(); DBHelp.connection.Open(); string command2 = "insert into ATM_Record(account,record,time) values('" + Login.account + "','取出100元','" + time + "')"; SqlCommand comm2 = new SqlCommand(command2, DBHelp.connection); comm2.ExecuteNonQuery(); DBHelp.connection.Close(); MessageBox.Show("交易成功!!!");
} else { MessageBox.Show("超出余额!!!"); }
DBHelp.connection.Close(); }
private void 返回ToolStripMenuItem_Click(object sender, EventArgs e) { Operate o = new Operate(); o.Show(); this.Hide(); } /// /// 取200元 /// /// /// private void button2_Click(object sender, EventArgs e) { string time = DateTime.Now.ToString(); int money = 0; string a = ""; DBHelp.connection.Open(); string command = "select * from ATM_Money where account='" + Login.account + "'"; SqlCommand comm = new SqlCommand(command, DBHelp.connection); SqlDataReader dat = comm.ExecuteReader(); while (dat.Read()) {
money = Convert.ToInt32(dat["balance"]); a = (Convert.ToInt32(dat["balance"]) - 200).ToString();