C#语言和SQL Server数据库技术_My Bank银行系统
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace My Bank
{
class Bank
{
Person[] user = new Person[30];
public void CreatAccount()
{
bool result;
for (int i = 0; i < user.Length; i++)
{
if (user[i] == null)
{
user[i] = new Person();
Console.WriteLine("请输入用户名:");
user[i].name = Console.ReadLine();
user[i].number = user[i].name;
do
{
Console.WriteLine("请输入密码");
user[i].password = Console.ReadLine();
Console.WriteLine("请再次输入密码:");
string passwords = Console.ReadLine();
result = IsSame(user[i].password, passwords);
if (!result)
{
Console.WriteLine("两次密码不一致,重新输入:");
}
} while (!result);
Console.WriteLine("请输入身份证号:");
user[i].idNumber = Console.ReadLine();
Console.WriteLine("请输入存款金额:");
user[i].money = int.Parse(Console.ReadLine());
Console.WriteLine("账户:{0},用户名:{1},存款金额:{2},创建成功!", user[i].number, user[i].name, user[i].money);
break;
}
}
}
private bool IsSame(string password, string passwords)
{
if (password == passwords)
{
return true;
}
return false;
}
public void WithDraw()
{
Console.WriteLine("请输入账号:");
string account = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
Person a = checkOutAccount(account, pwd);
if (a != null)
{
Console.WriteLine("请输入取款金额");
double outmoney = double.Parse(Console.ReadLine());
double result = UserMoney(outmoney, a);
if (result == -1)
{
Console.WriteLine("取款失败");
}
else
{
Console.WriteLine("取款成功,当前金额{0}", a.money);
}
}
else
{
Console.WriteLine("账号或密码不存在");
}
}
private double UserMoney(double outmoney, Person people05)
{
if (outmoney > 0)
{
if (outmoney <= people05.money)
{
people05.money -= outmoney;
return people05.money;
}
else
{
return -1;
}
}
else
{
return -1;
}
}
public void Show()
{
Console.WriteLine("请输入账号:");
string account = Console.ReadLine();
Console.WriteLine("请输入密码:");
string password = Console.ReadLine();
Person checkIn = checkOutAccount(account, password);
if (checkIn == null)
{
Console.WriteLine("账号或密码错误");
}
else
{
Console.WriteLine("账户余额是{0}", string.Format("{0:F3}", checkIn.money.ToString()));
}
}
public void Theme()
{
Console.WriteLine("=================欢迎使用自动银行服务============================");
Console.WriteLine("1.存款2.取款3.转账4.查询余额5.退出6.修改密码 7.继续注册账户");
Console.WriteLine("================================================================");
do
{
Console.WriteLine("请选择:");
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
AddMoney();
continue;
case 2:
WithDraw();
continue;
case 3:
Transfer();
continue;
case 4:
Show();
continue;
case 5:
break;
case 6:
Change();
continue;
case 7:
CreatAccount();
continue;
default:
Console.WriteLine("输入无效");
continue;
}
break;
} while (true);
}
public void Transfer()
{
Console.WriteLine("请输入转出账号:");
string outAccount = Console.ReadLine();
Console.WriteLine("请输入转出账户密码");
string outPassword = Console.ReadLine();
Console.WriteLine("请输入转入账号");
string inAccount = Console.ReadLine();
Console.WriteLine("请输入转账金额");
double tranMoney = double.Parse(Console.ReadLine());
double outMoney = 0, inMoney = 0;
int result = Back(outAccount, outPassword, inAccount, tranMoney, ref outMoney, ref inMoney);
if (result == 1)
{
Console.WriteLine("转账成功,转出账号{0}余额为:{1},转入账号{2}余额为:{3}", outAccount, outMoney, inAccount, inMoney);
}
else if (result == -1)
{
Console.WriteLine("转出账户账号或密码错误");
}
else if (result == -2)
{
Console.WriteLine("转入账号不正确");
}
else if (result == -3)
{
Console.WriteLine("转账操作失败");
}
}
public void AddMoney()
{
Console.WriteLine("请输入账号:");
string account = Console.ReadLine();
Person a = InAccount(account);
if (a != null)
{
Console.WriteLine("请输入存款:");
int addMoney = int.Parse(Console.ReadLine());
a.money += addMoney;
Console.WriteLine("存款成功:余额{0}", a.money);
}
else
{
Console.WriteLine("账号不存在");
}
}
public void Change()
{
Console.WriteLine("请输入账号:");
string isAccount = Console.ReadLine();
Console.WriteLine("请输入密码:");
string isPassword = Console.ReadLine();
Person c = AChange(isAccount, isPassword);
if (c != null)
{
Console.WriteLine("请输入新密码:");
string password1 = Console.ReadLine();
Console.WriteLine("请再次输入密码:");
string password2 = Console.ReadLine();
if (PChange(password1, password2, ref c) == null)
{
Console.WriteLine("两次密码不一致");
}
else
{
Console.WriteLine("密码修改成功");
}
}
else
{
Console.WriteLine("账号或密码错误");
}
}
private Person InAccount(string inAccount)
{
foreach (Person temp in user)
{
if (inAccount == temp.number)
{
return temp;
}
}
return null;
}
private int Back(string outAccount, string outPassword, string inAccount, double tranMoney, ref double outMoney, ref double inMoney)
{
Person a = checkOutAccount(outAccount, outPassword);
if (a == null)
{
return -1;
}
Person b = checkInAccount(inAccount, outAccount);
if (b == null)
{
return -2;
}
outMoney = checkOutMoney(tranMoney, ref a);
if (outMoney <= 0)
{
return -3;
}
inMoney = checkInMoney(ref b, tranMoney);
if (inMoney < b.money)
{
return -3;
}
return 1;
}
private Person checkOutAccount(string outAccount, string outPassword)
{
foreach (Person temp in user)
{
if (outAccount == temp.number && outPassword == temp.password)
{
return temp;
}
}
return null;
}
private Person checkInAccount(string inAccount, string outAccount)
{
foreach (Person temp in user)
{
if (inAccount == temp.number && outAccount != inAccount)
{
return temp;
}
}
return null;
}
private double checkOutMoney(double tranMoney, ref Person people01)
{
if (people01 != null)
{
if (tranMoney <= people01.money)
{
people01.money -= tranMoney;
return people01.money;
}
return people01.money;
}
return people01.money;
}
private double checkInMoney(ref Person people02, double tranMoney)
{
people02.money += tranMoney;
return people02.money;
}
private Person AChange(string account, string oldPassword)
{
foreach (Person temp in user)
{
if (account == temp.number && oldPassword == temp.password)
{
return temp;
}
return null;
}
return null;
}
private string PChange(string num1, string num2, ref Person people03)
{
if (num1 == num2)
{
people03.password = num1;
return people03.password;
}
return null;
}
}
}
第二个类 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace My Bank
{
class Person
{
public string name;
public double money;
public string password;
public string idNumber;
public string number;
}
}
测试类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace My Bank
{
class Program
{
static void Main(string[] args)
{
Bank demo = new Bank();
demo.CreatAccount();
demo.Theme();
Console.ReadLine();
}
}
}
C#语言和SQL Server数据库技术_My Bank银行系统的更多相关文章
- C#语言和SQL Server数据库技术_前四章错题
1.在C#中,如果让某个方法只能被它所在的程序集内的其他方法访问,可使用(C)修饰这个方法. (选择一项) A:private B:protected C:internal D:以上都不对 2.下 ...
- C#语言和SQL Server 数据库处理
---恢复内容开始--- 第七章 用表组织数据 1:数据性分类: 1>实体完整性的约束:检验每行数据是否符合要求 检验每列数据是否符合要求 2>域完整性约束:给定列输入的有效性 3> ...
- C#语言和SQL Server第十三 十四章笔记
十三章 使用ADO.NET访问数据库 十四章使用ADO.NET查询和操作数据库 十三章: ...
- C#语言和SQL Server第八章笔记
一: ...
- C#语言和SQL Server第十章笔记
第十章 :使用关键字模糊查询 笔记 一:使用关键字 :LIKE BETWEEN IN进行模糊查询 通配符: 一类字符,代替一个或多个真正的字符 与LIKE关键字一起使用 通配符: 解释 实例 符 ...
- SQL Server数据库应用技术
SQL Server数据库应用技术 SQL是Structured Query Language的缩写.SQL是操作命令集,是一种功能齐全的数据库语言.SQL功能强大.简单.易学.使用方便,已经成为了数 ...
- Microsoft SQL Server 数据库 错误号大全
panchzh :Microsoft SQL Server 数据库 错误号大全0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒 ...
- C#操作access和SQL server数据库代码实例
在C#的学习中,操作数据库是比较常用的技术,而access和sql server 数据库的操作却有着不同.那么,有哪些不同呢? 首先,需要引用不同的类.因为有着不同的数据引擎. access:usin ...
- 在易语言中调用MS SQL SERVER数据库存储过程方法总结
Microsoft SQL SERVER 数据库存储过程,根据其输入输出数据,笼统的可以分为以下几种情况或其组合:无输入,有一个或多个输入参数,无输出,直接返回(return)一个值,通过output ...
随机推荐
- php自定义截取中文字符串-utf8版
php自定义截取中文字符串-utf8版 UTF-8的编码范围(utf-8使用1-6个字节编码字符,实际上只使用了1-4字节): 1个字节:00——7F 2个字节:C080——DFBF 3个字符:E08 ...
- 2019年PHP最新面试题(含答案)
1. 数据库设计经验,为什么进行分表?分库?一般多少数据量开始分表?分库?分库分表的目的?什么是数据库垂直拆分?水平拆分?分区等等 一:为什么要分表 当一张表的数据达到几百万时,你查询一次所花的时间会 ...
- hdu 2554 最短路 (dijkstra)
最短路Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- 利用Python学习线性代数 -- 1.1 线性方程组
利用Python学习线性代数 -- 1.1 线性方程组 本节实现的主要功能函数,在源码文件linear_system中,后续章节将作为基本功能调用. 线性方程 线性方程组由一个或多个线性方程组成,如 ...
- 物联网架构成长之路(47)-利用GitLab实现CI持续集成
0.前言 前段时间,考虑到要练习部署一套CI/CD的系统.一开始考虑到Jenkins,随着这两天的了解,发现最新版的GitLab已经提供有CI/CD集成了.所以本次博客,干脆一步到位,直接用GitLa ...
- H3C交换机、路由器 ssh登录配置
VLAN 10 创建vlan并配好ip inter vlan 10 ip add 20.1.1.1 24 qu ip route-static 0.0.0.0 0 20.1.1.254 写好静 ...
- 树莓派SSH篇
开启好树莓派后发现一个问题,怎么才可以输入进树莓派里面呢? 一.你需要和我一样准备一个无线(有线)键盘
- Windows之Java开发环境快速搭建
说明:Node.js非必须,通常中小公司或创业公司,基本上都要求全栈. 补充说明: 除此之外,当公司固定JDK.Maven.Idea.Git.Node.js及其相关IDE等版本时,运维人员或者Team ...
- C#面向对象--命名空间
一.在C#中,使用命名空间(Namespace)可以帮助控制自定义类型的作用范围,同时对大量的类型进行组织:使用namespace关键字声明命名空间,命名空间可以嵌套使用: namespace MyN ...
- 图解 Spring:HTTP 请求的处理流程与机制【3】
3. HTTP 请求在 Web 应用中的处理流程 在穿越了 Web 容器之后,HTTP 请求将被投送到 Web 应用,我们继续以 Tomcat 为例剖析后续流程.Web 容器与 Web 应用的衔接是通 ...