資源簡介
使用C#控制臺實現ATM模擬程序:
(1)登錄驗證
(2)顯示賬戶信息
(3)查詢賬戶交易信息
(4)賬戶存款
(5)賬戶取款
(6)本行賬戶轉賬
(7)修改賬戶密碼
(8)注銷賬戶

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Data;
using?System.Data.SqlClient;
namespace?ATM
{
????public?class?ATM
????{
????????SqlDBHelper?sdb?=?new?SqlDBHelper();
????????///?
????????///?星號覆蓋密碼
????????///?
????????private?string?Star()
????????{
????????????string?password?=?““;
????????????ConsoleKeyInfo?info?=?Console.ReadKey(true);
????????????while?(info.Key?!=?ConsoleKey.Enter)
????????????{
????????????????Console.Write(“*“);
????????????????password?+=?info.KeyChar;
????????????????info?=?Console.ReadKey(true);
????????????}
????????????return?password;
????????}
????????///?
????????///?是否存在卡號
????????///?
????????private?bool?LoginMenu(string?id)
????????{
????????????SqlParameter?para?=?new?SqlParameter(“@id“?id);
????????????string?sql?=?@“select?count(*)?from?銀行卡?where?卡號=@id“;
????????????if?((int)sdb.ExecuteSqlScalar(sql?para)?>?0)
????????????{
????????????????return?true;
????????????}
????????????return?false;
????????}
????????///?
????????///?銀行卡是否被鎖定
????????///?
????????///?
????????private?bool?IsLocked(string?id)
????????{
????????????SqlParameter?para?=?new?SqlParameter(“@id“?id);
????????????string?sql?=?@“select?是否鎖定?from?銀行卡?where?卡號=@id“;
????????????DataTable?dt?=?sdb.ExecuteSqlDataTable(sql?para);
????????????if?(dt.Rows.Count?>?0)
????????????{
????????????????if?(Convert.ToBoolean(dt.Rows[0][0]))
????????????????{
????????????????????return?true;
????????????????}
????????????}
????????????return?false;
????????}
????????///?
????????///?登錄
????????///?
????????///?
????????public?int?Login()
????????{
????????????string?id?=?““?pwd?=?““;
????????????Console.Write(“\n----歡迎登錄XX銀行儲蓄管理系統----\n\n請輸入銀行卡號:“);
????????????id?=?Console.ReadLine();
????????????if?(LoginMenu(id)?==?true)
????????????{
????????????????if?(IsLocked(id)?==?true)
????????????????{
????????????????????return?2;//卡被鎖定,無法登錄
????????????????}
????????????????else
????????????????{
????????????????????int?n?=?3;
????????????????????do
????????????????????{
????????????????????????n--;
????????????????????????Console.Write(“\n請輸入密碼:“);
????????????????????????pwd?=?Star();
????????????????????????Console.WriteLine();
????????????????????????SqlParameter[]?paras?=
????????????????????????{
????????????????????????????new?SqlParameter(“@id“id)
????????????????????????????new?SqlParameter(“@pwd“pwd)
????????????????????????};
????????????????????????string?sql?=?@“select?count(*)?from?銀行卡?where?卡號=@id?and?密碼=@pwd“;
????????????????????????if?((int)sdb.ExecuteSqlScalar(sql?paras)?>?0)
????????????????????????{
????????????????????????????Program.loginID?=?id;
????????????????????????????return?1;//成功
????????????????????????}
????????????????????????else
??????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????238??2015-02-01?23:29??ATM\ATM\App.config
?????文件??????16962??2015-02-02?02:49??ATM\ATM\ATM.cs
?????文件???????2619??2015-02-01?23:53??ATM\ATM\ATM.csproj
?????文件??????18944??2015-02-02?02:49??ATM\ATM\bin\Debug\ATM.exe
?????文件????????238??2015-02-01?23:29??ATM\ATM\bin\Debug\ATM.exe.config
?????文件??????50688??2015-02-02?02:49??ATM\ATM\bin\Debug\ATM.pdb
?????文件??????11600??2015-02-02?02:50??ATM\ATM\bin\Debug\ATM.vshost.exe
?????文件????????238??2015-02-01?23:29??ATM\ATM\bin\Debug\ATM.vshost.exe.config
?????文件????????490??2013-03-18?17:00??ATM\ATM\bin\Debug\ATM.vshost.exe.manifest
?????文件????3145728??2015-02-02?02:55??ATM\ATM\DB\ATM.mdf
?????文件????1048576??2015-02-02?02:55??ATM\ATM\DB\ATM_log.ldf
?????文件????????255??2015-02-02?02:50??ATM\ATM\obj\x86\Debug\ATM.csproj.FileListAbsolute.txt
?????文件??????18944??2015-02-02?02:49??ATM\ATM\obj\x86\Debug\ATM.exe
?????文件??????50688??2015-02-02?02:49??ATM\ATM\obj\x86\Debug\ATM.pdb
?????文件???????6010??2015-02-02?02:49??ATM\ATM\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1343??2015-02-02?01:15??ATM\ATM\Program.cs
?????文件???????1356??2015-02-01?23:26??ATM\ATM\Properties\AssemblyInfo.cs
?????文件??????31810??2015-02-01?23:28??ATM\ATM\SqlDBHelper.cs
?????文件????????851??2015-02-01?23:26??ATM\ATM.sln
????..A..H.?????18432??2015-02-02?02:50??ATM\ATM.suo
?????目錄??????????0??2015-02-01?23:26??ATM\ATM\obj\x86\Debug\TempPE
?????目錄??????????0??2015-02-02?02:49??ATM\ATM\obj\x86\Debug
?????目錄??????????0??2015-02-01?23:29??ATM\ATM\bin\Debug
?????目錄??????????0??2015-02-01?23:26??ATM\ATM\obj\x86
?????目錄??????????0??2015-02-01?23:26??ATM\ATM\bin
?????目錄??????????0??2015-02-02?02:56??ATM\ATM\DB
?????目錄??????????0??2015-02-01?23:26??ATM\ATM\obj
?????目錄??????????0??2015-02-01?23:26??ATM\ATM\Properties
?????目錄??????????0??2015-02-02?02:58??ATM\ATM
?????目錄??????????0??2015-02-02?02:58??ATM
............此處省略3個文件信息
評論
共有 條評論