class Bank
{
//Dictionary<long,Account> dictionary=new Dictionary<long,Account>();
DataTable table = new DataTable();//存储,储蓄账户集合
DataTable table1 = new DataTable();//存储信用账户集合
SavingAccount account = new SavingAccount();//储蓄账户类的实例化
CreditAccount account1 = new CreditAccount();//信用账户类的实例化
public void init() {
table.Columns.Add("账号");
table.Columns.Add("密码");
table.Columns.Add("真名");
table.Columns.Add("身份证");
table.Columns.Add("邮箱");
table.Columns.Add("类型");
table.Columns.Add("余额");
table.PrimaryKey = new DataColumn[] { table.Columns["账号"] };
DataRow row = table.NewRow();
row["账号"] = ;
row["密码"] = "";
row["真名"] = "小明";
row["身份证"] = "";
row["邮箱"] = "1@163";
row["类型"] = ;
row["余额"] = ;
table.Rows.Add(row);
table.Columns["类型"].DefaultValue = ;
table.Columns["余额"].DefaultValue = ; table1.Columns.Add("账号");
table1.Columns.Add("密码");
table1.Columns.Add("真名");
table1.Columns.Add("身份证");
table1.Columns.Add("邮箱");
table1.Columns.Add("类型");
table1.Columns.Add("余额");
table1.Columns.Add("额度");
table1.PrimaryKey = new DataColumn[] { table1.Columns["账号"] };
DataRow row1 = table1.NewRow();
row1["账号"] = ;
row1["密码"] = "";
row1["真名"] = "小王";
row1["身份证"] = "";
row1["邮箱"] = "2@163";
row1["类型"] = ;
row1["余额"] = ;
row1["额度"] = ;
table1.Rows.Add(row1);
table1.Columns["类型"].DefaultValue = ;
table1.Columns["余额"].DefaultValue = ;
table1.Columns["额度"].DefaultValue = ;
index();
}//初始化
public void index() { Console.WriteLine("1.开户 2.登录");
int choice=int.Parse(Console.ReadLine());
if (choice == ) {
register();
}
else if (choice == )
{ login();
}
else {
Console.WriteLine("您输入的有误,请重新输入!");
index();
}
}//主页面
public void login() {
Console.WriteLine("请选择你要登录的账户种类0.储蓄账户1.信用账户 ");
int type = int.Parse(Console.ReadLine());
if (type == ) {
Console.WriteLine("请输入用户名:");
account.Id = long.Parse(Console.ReadLine());
Console.WriteLine("请输入密码:");
account.Password = Console.ReadLine();
if (table.Rows.Contains(account.Id) && table.Rows.Find(account.Id)["密码"].ToString().Equals(account.Password))
{
Console.WriteLine("登录成功");
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录4.还信用卡");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit(table.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw(table.Rows.Find(account.Id));
}
else if (choice == )
{
transfer(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
}
else if (choice == )
{
transfer1(table.Rows.Find(account.Id));
}
}
else
{
Console.WriteLine("您的帐户名和密码有误,请重新输入");
index();
}
}
else if (type == )
{
Console.WriteLine("请输入用户名:");
account1.Id = long.Parse(Console.ReadLine());
Console.WriteLine("请输入密码:");
account1.Password = Console.ReadLine();
if (table1.Rows.Contains(account1.Id) && table1.Rows.Find(account1.Id)["密码"].ToString().Equals(account1.Password))
{
Console.WriteLine("登录成功");
for (int i = ; i < table1.Columns.Count; i++)
{
Console.Write(table1.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table1.Rows.Find(account1.Id)["账号"].ToString() + "\t" + table1.Rows.Find(account1.Id)["密码"].ToString() + "\t" + table1.Rows.Find(account1.Id)["真名"].ToString() + "\t" + table1.Rows.Find(account1.Id)["身份证"].ToString() + "\t" + table1.Rows.Find(account1.Id)["邮箱"].ToString() + "\t" + table1.Rows.Find(account1.Id)["类型"].ToString() + "\t" + table1.Rows.Find(account1.Id)["余额"].ToString() + "\t" + table1.Rows.Find(account1.Id)["额度"].ToString());
Console.WriteLine("0.存款1.取款3.退出账户");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
withdraw1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
index();
}
}
else
{
Console.WriteLine("您的帐户名和密码有误,请重新输入");
index();
}
} }//登录
public void register()
{
Console.WriteLine("请选择你要开户的种类0.储蓄账户1.信用账户");
int type = int.Parse(Console.ReadLine());
if (type == ) {
account.Id = table.Rows.Count + ;
Console.WriteLine("请输入密码");
account.Password = Console.ReadLine();
Console.WriteLine("请输入真名");
account.Name = Console.ReadLine();
Console.WriteLine("请输入身份证");
account.PersonId = Console.ReadLine();
Console.WriteLine("请输入邮箱");
account.Email = Console.ReadLine();
DataRow row = table.NewRow();
row["账号"] = account.Id;
row["密码"] = account.Password;
row["真名"] = account.Name;
row["身份证"] = account.PersonId;
row["邮箱"] = account.Email;
table.Rows.Add(row);
Console.WriteLine("开户成功,信息如下:");
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString());
Console.WriteLine("请登录");
index();
}
else if (type == )
{
account1.Id = table1.Rows.Count + ;
Console.WriteLine("请输入密码");
account1.Password = Console.ReadLine();
Console.WriteLine("请输入真名");
account1.Name = Console.ReadLine();
Console.WriteLine("请输入身份证");
account1.PersonId = Console.ReadLine();
Console.WriteLine("请输入邮箱");
account1.Email = Console.ReadLine();
DataRow row1 = table1.NewRow();
row1["账号"] = account1.Id;
row1["密码"] = account1.Password;
row1["真名"] = account1.Name;
row1["身份证"] = account1.PersonId;
row1["邮箱"] = account1.Email;
table1.Rows.Add(row1);
Console.WriteLine("开户成功,信息如下:");
for (int i = ; i < table1.Columns.Count; i++)
{
Console.Write(table1.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table1.Rows.Find(account1.Id)["账号"].ToString() + "\t" + table1.Rows.Find(account1.Id)["密码"].ToString() + "\t" + table1.Rows.Find(account1.Id)["真名"].ToString() + "\t" + table1.Rows.Find(account1.Id)["身份证"].ToString() + "\t" + table1.Rows.Find(account1.Id)["邮箱"].ToString() + "\t" + table1.Rows.Find(account1.Id)["类型"].ToString() + "\t" + table1.Rows.Find(account1.Id)["余额"].ToString() + "\t" + table1.Rows.Find(account1.Id)["额度"].ToString());
Console.WriteLine("请登录");
index();
}
}//注册
public void deposit(DataRow dr) {
if (dr != null)
{
Console.WriteLine("请输入你要存入的金额:");
double money = double.Parse(Console.ReadLine());
dr["余额"] = Convert.ToDouble((dr["余额"])) + money;
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录4.还信用卡");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit(table.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw(table.Rows.Find(account.Id));
}
else if (choice == )
{
transfer(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
}
else if (choice == )
{
transfer1(table.Rows.Find(account.Id));
}
}
else {
Console.WriteLine("您还没有登录");
login();
}
}//储蓄账户存款
public void deposit1(DataRow dr)
{
if (dr != null)
{
Console.WriteLine("请输入你要存入的金额:");
double money = double.Parse(Console.ReadLine());
dr["余额"] = Convert.ToDouble((dr["余额"])) + money;
for (int i = ; i < table1.Columns.Count; i++)
{
Console.Write(table1.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table1.Rows.Find(account1.Id)["账号"].ToString() + "\t" + table1.Rows.Find(account1.Id)["密码"].ToString() + "\t" + table1.Rows.Find(account1.Id)["真名"].ToString() + "\t" + table1.Rows.Find(account1.Id)["身份证"].ToString() + "\t" + table1.Rows.Find(account1.Id)["邮箱"].ToString() + "\t" + table1.Rows.Find(account1.Id)["类型"].ToString() + "\t" + table1.Rows.Find(account1.Id)["余额"].ToString() + "\t" + table1.Rows.Find(account1.Id)["额度"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款3.退出登录");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
withdraw1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
index();
}
}
else
{
Console.WriteLine("您还没有登录");
login();
}
}//信用账户存款
public void withdraw(DataRow dr)
{
if (dr != null)
{
Console.WriteLine("请输入你要取出的金额:");
double money = double.Parse(Console.ReadLine());
if (Convert.ToDouble((dr["余额"])) >= money)
{
dr["余额"] = Convert.ToDouble((dr["余额"])) - money;
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录4.还信用卡");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit(table.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw(table.Rows.Find(account.Id));
}
else if (choice == )
{
transfer(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
}
else if (choice == )
{
transfer1(table.Rows.Find(account.Id));
}
}
else {
Console.WriteLine("您的余额不足!");
withdraw(table.Rows.Find(account.Id));
}
}
else
{
Console.WriteLine("您还没有登录");
login();
}
}//储蓄账户取款
public void withdraw1(DataRow dr)
{
if (dr != null)
{
Console.WriteLine("请输入你要取出的金额:");
double money = double.Parse(Console.ReadLine());
if (Convert.ToDouble((dr["余额"])) >= money)
{
dr["余额"] = Convert.ToDouble((dr["余额"])) - money;
for (int i = ; i < table1.Columns.Count; i++)
{
Console.Write(table1.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table1.Rows.Find(account1.Id)["账号"].ToString() + "\t" + table1.Rows.Find(account1.Id)["密码"].ToString() + "\t" + table1.Rows.Find(account1.Id)["真名"].ToString() + "\t" + table1.Rows.Find(account1.Id)["身份证"].ToString() + "\t" + table1.Rows.Find(account1.Id)["邮箱"].ToString() + "\t" + table1.Rows.Find(account1.Id)["类型"].ToString() + "\t" + table1.Rows.Find(account1.Id)["余额"].ToString() + "\t"+table1.Rows.Find(account1.Id)["额度"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款3.退出登录");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
withdraw1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
index();
}
}
else if (Convert.ToDouble((dr["余额"])) < money && Convert.ToDouble((dr["余额"])) + Convert.ToDouble((dr["额度"])) >= money) {
dr["余额"] = Convert.ToDouble((dr["余额"])) - money;
for (int i = ; i < table1.Columns.Count; i++)
{
Console.Write(table1.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table1.Rows.Find(account1.Id)["账号"].ToString() + "\t" + table1.Rows.Find(account1.Id)["密码"].ToString() + "\t" + table1.Rows.Find(account1.Id)["真名"].ToString() + "\t" + table1.Rows.Find(account1.Id)["身份证"].ToString() + "\t" + table1.Rows.Find(account1.Id)["邮箱"].ToString() + "\t" + table1.Rows.Find(account1.Id)["类型"].ToString() + "\t" + table1.Rows.Find(account1.Id)["余额"].ToString() +"\t"+ table1.Rows.Find(account1.Id)["额度"].ToString());
Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit1(table1.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw1(table1.Rows.Find(account1.Id));
}
else if (choice == )
{
withdraw1(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
} }
else
{
Console.WriteLine("您的余额和额度不够!");
withdraw1(table1.Rows.Find(account1.Id));
}
}
else
{
Console.WriteLine("您还没有登录");
login();
}
}//信用账户取款
public void transfer(DataRow dr) {
Console.WriteLine("请输入你要转账的金额");
double money = double.Parse(Console.ReadLine());
if (Convert.ToDouble((dr["余额"])) >= money)
{
Console.WriteLine("请输入对方账号");
long toId = long.Parse(Console.ReadLine());
dr["余额"] = Convert.ToDouble((dr["余额"])) - money;
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString()); table.Rows.Find(toId)["余额"] = double.Parse(table.Rows.Find(toId)["余额"].ToString()) + money; Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit(table.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw(table.Rows.Find(account.Id));
}
else if (choice == )
{
transfer(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
}
}
else { }
}//储蓄账户之间转账
public void transfer1(DataRow dr)
{
Console.WriteLine("请输入你要转账的金额");
double money = double.Parse(Console.ReadLine());
if (Convert.ToDouble((dr["余额"])) >= money)
{
Console.WriteLine("请输入信用卡账号");
long toId = long.Parse(Console.ReadLine());
dr["余额"] = Convert.ToDouble((dr["余额"])) - money;
for (int i = ; i < table.Columns.Count; i++)
{
Console.Write(table.Columns[i] + "\t");
}
Console.WriteLine();
Console.WriteLine(table.Rows.Find(account.Id)["账号"].ToString() + "\t" + table.Rows.Find(account.Id)["密码"].ToString() + "\t" + table.Rows.Find(account.Id)["真名"].ToString() + "\t" + table.Rows.Find(account.Id)["身份证"].ToString() + "\t" + table.Rows.Find(account.Id)["邮箱"].ToString() + "\t" + table.Rows.Find(account.Id)["类型"].ToString() + "\t" + table.Rows.Find(account.Id)["余额"].ToString()); table1.Rows.Find(toId)["余额"] = double.Parse(table1.Rows.Find(toId)["余额"].ToString()) + money; Console.WriteLine("选择您要的操作0.存款1.取款2.转账3.退出登录4.还信用卡");
int choice = int.Parse(Console.ReadLine());
if (choice == )
{
deposit(table.Rows.Find(account.Id));
}
else if (choice == )
{
withdraw(table.Rows.Find(account.Id));
}
else if (choice == )
{
transfer(table.Rows.Find(account.Id));
}
else if (choice == )
{
index();
}
else if (choice == )
{
transfer1(table.Rows.Find(account.Id));
}
}
else
{ }
}//还信用卡 }
本系列教程:
C#基础总结之八面向对象知识点总结-继承与多态-接口-http://www.cnblogs.com/spring_wang/p/6113531.html
C#基础总结之七面向对象知识点总结1http://www.cnblogs.com/spring_wang/p/6113526.html
C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习http://www.cnblogs.com/spring_wang/p/6113520.html
C#基础总结之五Dictionary<string, string[]>和while循环http://www.cnblogs.com/spring_wang/p/6113514.html
C#基础总结之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html
C#基础总结之三循环控制-for-数组-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html
C#基础总结之二循环控制-运算符http://www.cnblogs.com/spring_wang/p/6113484.html
C#基础总结之一变量常量-if嵌套语句-witch结构-类型转换http://www.cnblogs.com/spring_wang/p/6113476.html
C#基础课程之六(临时表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html
C#基础课程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html
C#基础课程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html
C#基础课程之三循环语句http://www.cnblogs.com/spring_wang/p/6113383.html
C#基础课程之二变量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html
C#基础课程之一注释和控制台、一些常识http://www.cnblogs.com/spring_wang/p/6113361.html
C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html
C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html
C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113274.html
C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113258.html
C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113232.html
C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113224.html
C#基础第六天-作业-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113028.html
C#基础第六天-作业答案-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113033.html
C#基础第五天-作业答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html
C#基础第五天-作业-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html
C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113005.html
C#基础第四天-作业-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113000.html
C#基础第三天-作业答案-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112888.html
C#基础第三天-作业-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112885.html
C#基础第二天-作业答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html
C#基础第二天-作业-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html
C#基础第一天-作业答案http://www.cnblogs.com/spring_wang/p/6112872.html
C#基础第一天-作业http://www.cnblogs.com/spring_wang/p/6112867.html
C#-string.Format对C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html