C++银行管理系统设计分析及程序设计介绍

在这里插入图片描述


银行管理系统设计分析及程序设计介绍

在这里插入图片描述


信息

时间:2020年7月12日

语言:C++ mysql

项目开发环境:

(1操作系统:windows10 64位

(2编译环境:vs2015社区版

(3数据库: MySQL 8.0.19


设计分析介绍

一.管理员模式

1.登录页面

账号,密码,忘记密码

qt版本:账号和密码保存于后台数据库,根据输入的账号和密码,查询如正确,则登录成功,若不正确,则提示账户或密码错误(为了安全起见,只有3次机会),并且设有找回密码。利用邮箱验证是否为管理员本人操作。


2.管理界面

(1用户注册信息

包括注册人数,相关信息,等等。

(2冻结账户

包括冻结账户,冻结账户余额,部分余额。

(3控制账户

控制当前账户交易,等等其他行为。

(4返回上一级

二.用户模式

1.登录页面

账户,密码,忘记密码

账号和密码保存于后台数据库,根据输入的账号和密码,查询如正确,则登录成功,若不正确,则提示账户或密码错误(为了安全起见,只有3次机会),并且设有找回密码。利用邮箱验证是否为管理员本人操作。


2.qt版本:开户页面

输入开户者相关信息,包括姓名 ,年龄,性别,住址,电话,以及邮箱绑定,为了找回密码。

系统自动生成16位卡号,并要求用户设置密码,若不设置密码,初始密码为00000。


3.业务办理页面

(qt版本:1选择语言

为了防止语言障碍,使用汉语和英语作为界面语言。

(2存款

从登录界面得到账号,密码,验证通过,出现输入页面,事先设置500,1000,3000,10000,50000额度,也可由用户自行输入存款额度。

选择存款期限(活期,死期),并且显示利率,期满后可得利息。

(3取款

从登录界面得到账户,密码,验证通过,出现卡内剩余金额,事先设置500,1000,3000,10000,50000额度,也可由用户自行输入取款额度。并验证取款额是否大于现有额,若大于则给出提示信息,若小于,则重写当前余额。

(4转账

输入转入账户,输入转入金额,并做出相应提示。

(5查询信息

账户流水,显示当前账户半年的资金流水,以及发票显示(没打印就显示在屏幕)。

(6更改密码

输入原密码,并通过注册邮箱验证,确认新密码,并完成修改。

(7注销

从数据库删除当前账户,并返回登录页面。

(8返回上一级

注:只写功能,不讲美观。


程序设计介绍

一.框架结构图

在这里插入图片描述


二.C++代码模块

(1数据类

1.能验证账户是否存在

2.能获得数据表数据

3.能获得数据表条数

4.能修改数据表内容(账号,密码,金额之类的数据)

5.能查询数据(包括流水,金额,密码之类的数据)

class Sql
{
	string host;
	string user;
	string passwd;
	string db;
	unsigned int port;
	MYSQL sqlcon;
	MYSQL_RES * result;
	MYSQL_ROW row;
public:
	Sql();
	Sql(string host, string user, string passwd, string db, unsigned int port);
	~Sql();
	MYSQL getSqlCon();			//获取连接
	MYSQL_RES * getResult();	//获取res
	MYSQL_ROW  getRow();
	boolean isAccount(string user,string passwd,int type);  //账户验证
	int getDataCount();				 						//获取数据(返回值为条数条数)
	void FrozenAccount(string username);      		 		//冻结账户
	int getFundCount(Person * person);						//获取资金数量
	int getFundCount(string account);						//获取资金数量
	int FrozenMoney(string name , int fund);				//冻结提前判断不要超过全部
	string getPasswd(string username); 						//获取密码
	void RecordInfo(string username ,string event);			//记录流水
	int getMoneyInfo();    									//账户流水
	void Save_DrawMoney(Person * person,int fund);			//存款/取款
	int TransferAccounts(Person * person,string account ,int fund);	//转账
	void AlterPassword(Person * person,string str);					//修改密码
	int DeleteAccount(Person *person);								//注销账户 如果有金额必须要取出
};

(2抽象类

将用户类和管理员类的所共有的属性或行为进行提取,创建抽象类。

class Person
{
protected:
	std::string m_person;
	std::string m_passwd;
public:
	virtual std::string getM_Person() = 0;
	virtual std::string getM_Passwd() = 0;
	virtual void ShowBusiness(Sql * sqlcon) = 0;
};

(3管理员类

1.所有用户注册信息
2.冻结账户
3.冻结资金
4.查询用户密码
5.查询用户流水

class Administrator:public Person
{
public:
	Administrator();
	~Administrator();
	virtual std::string getM_Person();
	virtual std::string getM_Passwd();
	virtual void ShowBusiness(Sql * sqlcon);
	void getUserinfo(Sql * sqlcon);			//所有用户账户
	void BlockedAccount(Sql * sqlcon);		//冻结账户
	void FrozenCapital(Sql * sqlcon);		//冻结资金
	void getUserPasswd(Sql * sqlcon);		//查询用户密码
	void getUserStatement(Sql * sqlcon);	//查询用户流水
};

(4用户类

1.存款
2.取款
3.转账
4.查询用户流水
5.更改密码
6.注销账户

class User:public Person
{
public:
	User();
	~User();
	virtual std::string getM_Person();
	virtual std::string getM_Passwd();
	virtual void ShowBusiness(Sql *sqlcon);
	void Deposit(Sql * sqlcon);			//存款
	void Withdrawal(Sql * sqlcon);		//取款
	void TransferAccounts(Sql * sqlcon);//转账
	void getUserStatement(Sql * sqlcon);//查询用户流水
	void ChangePasswd(Sql * sqlcon);	//更改密码
	void LogoutUser(Sql * sqlcon);		//注销账户
};

(5数据类的实现
Sql::Sql()
	:host("127.0.0.1"),user("root"),passwd("3226960*"),db("db_banking_system"),port(3306)
{
	mysql_init(&(this->sqlcon));
	mysql_real_connect(&(this->sqlcon), this->host.c_str(), this->user.c_str(), 
		this->passwd.c_str(), this->db.c_str(), this->port, NULL, 0);
}
Sql::Sql(string host, string user, string passwd, string db, unsigned int port)
{
	this->host = host;
	this->user = user;
	this->passwd = passwd;
	this->db = db;
	this->port = port;
	mysql_init(&(this->sqlcon));
	mysql_real_connect(&(this->sqlcon), this->host.c_str(), this->user.c_str(), 
		this->passwd.c_str(), this->db.c_str(), this->port, NULL, 0);
}
Sql::~Sql()
{
	mysql_close(&(this->sqlcon));
}
MYSQL Sql::getSqlCon()
{
	return this->sqlcon;
}
MYSQL_RES * Sql::getResult()
{
	return this->result;
} 
MYSQL_ROW  Sql::getRow()
{
	return this->row;
}
boolean Sql::isAccount(string user,string passwd,int type)
{
	string str_a = "SELECT * FROM dt_administrator where user = '" + user + "' and passwd = '" + passwd + "'";
	string str_u = "SELECT * FROM dt_user where user = '" + user + "' and passwd = '" + passwd + "'";
	if (type == 0)
	{
		mysql_query(&(this->sqlcon), str_a.c_str());
		result = mysql_store_result(&(this->sqlcon));
		while ((row = mysql_fetch_row(result)))
		{
			return true;
		}
	}
	if(type == 1)
	{
		mysql_query(&(this->sqlcon), str_u.c_str());
		result = mysql_store_result(&(this->sqlcon));
		while ((row = mysql_fetch_row(result)))  
		{
			return true;
		}
	}
	return false;
}
int Sql::getDataCount()
{
	mysql_query(&(this->sqlcon),"select * from dt_user");
	this->result = mysql_store_result(&(this->sqlcon));
	return mysql_num_rows(this->result);//返回数据行数
}
void Sql::FrozenAccount(string username)
{
	string sqlstr = "update dt_user set isfrozen = 1 where user = '" + username + "'";
	mysql_query(&(this->sqlcon), sqlstr.c_str());
}
int Sql::getFundCount(Person * person) //获取资金量
{
	string sqlstr = "select * from dt_user where user = '"+person->getM_Person()+"'";
	mysql_query(&(this->sqlcon), sqlstr.c_str());
	this->result = mysql_store_result(&(this->sqlcon));
	this->row = mysql_fetch_row(result);
	stringstream ss;
	int fund_i = 0;
	string fun_s;
	fun_s = this->row[2];
	ss << fun_s;
	ss >> fund_i;
	return fund_i;
}
int Sql::getFundCount(string account) //获取资金量
{
	string strsql = "select * from dt_user where user = '" + account + "'";
	mysql_query(&(this->sqlcon), strsql.c_str());
	this->result = mysql_store_result(&(this->sqlcon));
	this->row = mysql_fetch_row(result);
	stringstream ss;
	int fund_i = 0;
	string fun_s;
	fun_s = this->row[2];
	ss << fun_s;
	ss >> fund_i;
	return fund_i;
}
int Sql::FrozenMoney(string account,int fund)
{
	//查现有余额
	int fund_now = getFundCount(account);
	if (fund_now >= fund)
	{
		int fund_i = fund_now - fund;
		string fund_s1;
		stringstream ss;
		ss << fund_i;
		ss >> fund_s1;
		stringstream s;
		string fund_s2;
		s << fund;
		s >> fund_s2;
		string str = "update dt_user set fund = " + fund_s1 + ",frozenfund = " + fund_s2 + " where user = '" + account + "'";
		cout << "sql:" << str << endl;
		mysql_query(&(this->sqlcon), str.c_str());
		system("pause");
		return 1;
	}
	else
	{
		return 0;
	}
}
string Sql::getPasswd(string username)
{
	string str = "select * from dt_user where user = '" + username + "'";
	mysql_query(&(this->sqlcon), str.c_str());
	this->result = mysql_store_result(&(this->sqlcon));
	this->row = mysql_fetch_row(result);
	return this->row[1];
}
void Sql::RecordInfo(string username,string event)
{
	//记录流水
	string strsql = "insert into dt_event(user,event) values('" + username + "','" + event + "')";
	mysql_query(&(this->sqlcon), "SET CHARACTER SET GBK");
	if (mysql_query(&(this->sqlcon), strsql.c_str()))
	{
		cout << "不成功";
	}
}
int Sql::getMoneyInfo()
{
	//流水
	string strsql = "select * from dt_event";
	mysql_query(&(this->sqlcon), strsql.c_str());
	this->result = mysql_store_result(&(this->sqlcon));
	return mysql_num_rows(this->result);
}
void Sql::Save_DrawMoney(Person * person,int fund)
{
	string fund_s;
	stringstream ss;
	ss << fund;
	ss >> fund_s;
	string str = "update dt_user set fund = " + fund_s + " where user = '" + person->getM_Person() + "'";
	mysql_query(&(this->sqlcon),str.c_str());
}
int Sql::TransferAccounts(Person * person, string account, int fund)
{
	//查账户
	string strsql = "select * from dt_user where user = '" + account + "'";
	mysql_query(&(this->sqlcon), strsql.c_str());
	result = mysql_store_result(&(this->sqlcon));
	while ((row = mysql_fetch_row(result)))
	{
		//查余额
		int fund_now = getFundCount(person);
		if (fund_now >= fund)
		{
			cout << "现有金额:" << fund_now << "  转出金额:" << fund << endl;
			Save_DrawMoney(person, fund_now - fund);
			stringstream ss;
			int fund_i = 0;
			string fun_s;
			fun_s = this->row[2];
			ss << fun_s;
			ss >> fund_i;
			stringstream ss_2;
			ss_2 << fund+fund_i;
			string fund_s2;
			ss_2 >> fund_s2;
			cout << "若确认转入";
			system("pause");
			strsql = "update dt_user set fund = " + fund_s2 + " where user = '" + account + "'";
			mysql_query(&(this->sqlcon), strsql.c_str());
			return 1;
		}
		else
		{
			return 0;
		}
	}
	return 0;
}
void Sql::AlterPassword(Person * person,string str)
{
	string passwd = "update dt_user set passwd = " + str + " where user = '" + person->getM_Person() + "'";
	mysql_query(&(this->sqlcon), passwd.c_str());
}
int Sql::DeleteAccount(Person *person)
{
	int fund = getFundCount(person);
	if (fund == 0)
	{
		string str = "delete from dt_user where user = '" + person->getM_Person() + "'";
		mysql_query(&(this->sqlcon), str.c_str());
		return 0;
	}
	else
	{
		return fund;
	}
	return fund;
}

(6主函数
int main()
{
	User * user = new User();
	int system_i = 0;
	Sql * sql = new Sql();
	while (true)
	{
		system("cls");
		cout << "\t\t================================================================" << endl;
		cout << "\t\t*                      请选择进入的系统                        *" << endl;
		cout << "\t\t*                                                              *" << endl;
		cout << "\t\t*               管理员                   客户                  *" << endl;
		cout << "\t\t*                                                              *" << endl;
		cout << "\t\t*                0                        1                    *" << endl;
		cout << "\t\t================================================================" << endl;
		cin >> system_i;
		cin.clear();
		cin.ignore(); //防止恶意输入导致死循环
		switch (system_i)
		{
		case 0:
			LoginIn(sql,system_i);
			break;
		case 1:
			LoginIn(sql,system_i);
			break;
		default:
			cout << "输入有误,请重新输入" << endl;
			system("pause");
			break;
		}
	}
	return 0;
}
void LoginIn(Sql * sqlcon,int type)
{
	string name;
	string passwd;
	Person * person = NULL;
	if (type == 0)
	{
		cout << "请输入管理员账户:" << endl;
		cin >> name;
		cout << "请输入管理员密码:" << endl;
		cin >> passwd;
		if (sqlcon->isAccount(name, passwd, type))
		{
			person = new Administrator();
			person->ShowBusiness(sqlcon);
		}
		return;
	}
	else
	{
		cout << "请输入账户:" << endl;
		cin >> name;
		cout << "请输入密码:" << endl;
		cin >> passwd;
		if (sqlcon->isAccount(name, passwd, type))
		{
			person = new User();
			person->ShowBusiness(sqlcon);
		}
		return;
	}
}

篇幅有限,不是核心代码就不通篇发了。


猜你喜欢

转载自blog.csdn.net/Fdog_/article/details/107477771
今日推荐