ATM机(c语言带界面)

目录

         项目描述        

        简单实现功能

        代码实现

        测试


项目描述

                 该项目需要以两种身份登录,以储户身份登录成功需要实现 取款 存款 转账 查余额 查流水 查开卡日期 注销该卡 这一系列操作,以管理原身份登录需要实现管理员账户号注册和登录,登录成功后需要实现注册储户账号,挂失储户账号,激活储户账号,注销管理员账号等一系列操作,并且登录储户同一账号错误三次之后实现自动锁卡操作。ATM机(c语言带界面)_第1张图片

整体项目需要实现的步骤如上图 

简单功能实现

        首先需要思考我们的两类身份,即两个结构体,首先储户,需要的成员变量有三类,储户,储户有效个数,储户预存个数,进一步储户结构体中有的变量为卡的账号,密码,是否挂失,是否被锁,本卡钱数,流水信息,开卡日期,流水记录的有效个数,登录错误的次数,储户信息,储户信息类又包括储户的姓名,身份证号,手机号,流水记录中包含当前时间,操作类型,钱数。

typedef struct User{
	char u_name[10];
	char idcard[20];//身份证
	char phone[12];//电话
}User;

//记录类型->存放该银行卡对应的流水信息的类型
typedef struct Record{
	char op_now[20];//当前操作卡的时间
	char op_type[10];//操作类型
	int money;//涉及金额:存款类型 100   -100
}Record;

//银行卡类型
typedef struct BankCard{
	int id;
	int passwd;
	int money;
	bool islocked;//是否被锁:错误三次 锁卡
	bool isloss;//是否被挂失
	User user;//存储储户信息
	Record *record;//流水记录信息
	int record_size;//流水记录有效个数
	char create_date[30];//开卡日期
	int count;//登陆错误的次数
}BankCard;
//卡槽
typedef struct SqList_BankCards{
	BankCard *cards_array;
	int cards_size;
	int cards_length;
}SqList_BankCards,*PList;

 管理员需要的结构体中需要管理员类,管理员有效个数,管理员预存个数,管理员类中有管理员卡的账号,密码,管理员身份类,管理员身份类中有管理员姓名,身份证号,手机号。

typedef struct Ator_user{
	char name[10];
	char idcard[20];//身份证
	char phone[12];
}Ator_user;
typedef struct ator_cards{
	int id;
	int passwd;
	Ator_user ator_user;
}ator_cards;
typedef struct Adminator{
	ator_cards *atorcards;
	int ator_cards_size;
	int ator_count ;

}Adminator,*ADator;

函数声明以及实现

关于储户身份的函数声明

void init_card(BankCard* pcard,int id,int passwd,int money,User user);//初始化卡
void init_sqlist_cards(PList list);//初始化init_sqlist_cards
void init_user(User* puser, const char* u_name, const char* u_phone, const char* u_idcard);//用户初始化
bool IsFull(PList list);//判满
void GrowCapacity(PList list);//扩容
int SearchCard(PList list, int id);//查找
bool  regieter_card(PList list, int id, int passwd, int money, User user);//注册
int login_card(PList list, int id, int passwd);//登录
//激活卡
void active(PList list, const char*idcard);
//挂失卡
void lost(PList list, const char*idcard);
//存款
bool savemoney(BankCard*card, int money);
//取款
bool withdrawmoney(BankCard*card, int money);
//转账
bool transfer(BankCard* card, BankCard* usercard, int money);
//查余额
void getmoney(BankCard* card);
//查看流水信息
void getwatermessage(BankCard *card);
//查看开卡日期
void get_create_card_date(BankCard* card);
//记录流水  数据存储 注册功能
void localrecard(BankCard* card, const char *type, int money);
//获取时间
void time(char* buff);
//注销卡
void destory_card(PList list,int index);
//卡free
void destory_card_record(BankCard* card);
void destory(PList list);

首先对结构体的初始化是每个项目必须需要的函数,注册储户卡时需要首先对储户卡进行判满,弱国超出预期的个数,需要进行扩容,然后再进行注册。存储流水的函数,需要再取款注册这一系列有流水的函数中进行调用赋值给流水信息函数,注销储户卡需要对储户卡类中开辟的动态内存进行释放(卡中的流水信息),然后将有效储户个数减一,最终程序运行结束时对整个卡槽进行内存释放。

对管理员函数的声明

void init_Adminator(ADator adator);//初始化管理员卡槽
void init_ator_cards(ator_cards* ator_cards,int id,int passwd,Ator_user ator_user);//初始化卡
void init_Ator_user(Ator_user ator_user,char* u_name,char* idcard,char *phone);//初始化管理员
bool regieter_ator_cards(ADator adator, int id, int passwd, Ator_user ator_user);//注册管理员卡
bool isfull(ADator adator);//判满
void grop_ator(ADator adator);//扩容
int research(ADator adator,int id);//查找
int loge(ADator adator,int id,int passwd);//登录
void destory_ator_card(ADator adator, int index);//注销管理员卡
void destory_ator(ADator adator);//注销管理员

管理员类中函数基本和储户一样,不做解释。

代码实现:

        BankCard.h头文件:

#pragma once
//用户类型
typedef struct User{
	char u_name[10];
	char idcard[20];//身份证
	char phone[12];//电话
}User;

//记录类型->存放该银行卡对应的流水信息的类型
typedef struct Record{
	char op_now[20];//当前操作卡的时间
	char op_type[10];//操作类型
	int money;//涉及金额:存款类型 100   -100
}Record;

//银行卡类型
typedef struct BankCard{
	int id;
	int passwd;
	int money;
	bool islocked;//是否被锁:错误三次 锁卡
	bool isloss;//是否被挂失
	User user;//存储储户信息
	Record *record;//流水记录信息
	int record_size;//流水记录有效个数
	char create_date[30];//开卡日期
	int count;//登陆错误的次数
}BankCard;

//卡槽
typedef struct SqList_BankCards{
	BankCard *cards_array;
	int cards_size;
	int cards_length;
}SqList_BankCards,*PList;

void init_card(BankCard* pcard,int id,int passwd,int money,User user);//初始化卡
void init_sqlist_cards(PList list);//初始化init_sqlist_cards
void init_user(User* puser, const char* u_name, const char* u_phone, const char* u_idcard);//用户初始化
bool IsFull(PList list);//判满1
void GrowCapacity(PList list);//扩容2
int SearchCard(PList list, int id);//查找3
bool  regieter_card(PList list, int id, int passwd, int money, User user);//注册
int login_card(PList list, int id, int passwd);//登录
//激活卡
void active(PList list, const char*idcard);
//挂失卡
void lost(PList list, const char*idcard);
//存款
bool savemoney(BankCard*card, int money);
//取款
bool withdrawmoney(BankCard*card, int money);
//转账
bool transfer(BankCard* card, BankCard* usercard, int money);
//查余额
void getmoney(BankCard* card);
//查看流水信息
void getwatermessage(BankCard *card);
//查看开卡日期
void get_create_card_date(BankCard* card);
//记录流水  数据存储 注册功能
void localrecard(BankCard* card, const char *type, int money);
//获取时间
void time(char* buff);
//注销卡
void destory_card(PList list,int index);
//卡free
void destory_card_record(BankCard* card);
void destory(PList list);

adminator.h头文件

#pragma once
typedef struct Ator_user{
	char name[10];
	char idcard[20];//身份证
	char phone[12];
}Ator_user;
typedef struct ator_cards{
	int id;
	int passwd;
	Ator_user ator_user;
}ator_cards;
typedef struct Adminator{
	ator_cards *atorcards;
	int ator_cards_size;
	int ator_count ;

}Adminator,*ADator;
void init_Adminator(ADator adator);//初始化管理员卡槽
void init_ator_cards(ator_cards* ator_cards,int id,int passwd,Ator_user ator_user);//初始化卡
void init_Ator_user(Ator_user ator_user,char* u_name,char* idcard,char *phone);//初始化管理员
bool regieter_ator_cards(ADator adator, int id, int passwd, Ator_user ator_user);//注册管理员卡
bool isfull(ADator adator);//判满
void grop_ator(ADator adator);//扩容
int research(ADator adator,int id);//查找
int loge(ADator adator,int id,int passwd);//登录
void destory_ator_card(ADator adator, int index);//注销管理员卡
void destory_ator(ADator adator);//注销管理员

BankCard .cpp源文件

#define _CRT_SECURE_NO_WARNINGS
#include"BankCard.h"
#include
#include
#include
#include
#include
#include
#define CA 100
#define DA 100
void init_sqlist_cards(PList list){
	list->cards_array = (BankCard*)malloc(sizeof(BankCard)*CA);
	assert(list->cards_array != NULL);
	list->cards_length = CA;//卡槽数组容量
	list->cards_size = 0;//有效数据
}
void init_user(User* puser, const char* u_name, const char* u_phone, const char* idcard){
	strcpy(puser->idcard, idcard);
	strcpy(puser->phone, u_phone);
	strcpy(puser->u_name, u_name);
}
void init_card(BankCard* pcard, int id, int passwd, int money, User user){
	pcard->id = id;
	pcard->passwd = passwd;
	pcard->money = money;
	init_user(&pcard->user, user.u_name, user.phone, user.idcard);
	//strcpy(pcard->user.idcard, user.idcard);
	//strcpy(pcard->user.phone, user.phone);
	//strcpy(pcard->user.u_name, user.u_name);
	pcard->islocked = false;
	pcard->isloss = false;
	pcard->record_size = 0;
	pcard->count = 0;
	pcard->record= (Record*)malloc(sizeof(Record)*DA);
	assert(pcard->record!=NULL);
}
bool IsFull(PList list){//判满
	assert(list!=NULL);
	return list->cards_size == list->cards_length;
}
void GrowCapacity(PList list){//扩容
	int newlen = 2 * list->cards_length;
	BankCard* temp = (BankCard*)realloc(list->cards_array, newlen*sizeof(Record));
	list->cards_length = newlen;
	list->cards_array = temp;
}
int SearchCard(PList list, int id){//查找卡
	assert(list != NULL);
	for (int i = 0; i < list->cards_size; i++) {
		if (list->cards_array[i].id == id){
			return i;
		}
	}
	return -1;
}
//注册卡
bool  regieter_card(PList list, int id, int passwd, int money, User user){
	assert(list!=NULL);
	if (IsFull(list))  {	//判满->是否扩容
		GrowCapacity(list);
	}
	int index = SearchCard(list, id);
	if (index != -1){
		MessageBox(0, "已经注册过", "注册", MB_OK);
		return false;
	}
	BankCard card;
	init_card(&card,id,passwd,money ,user);
	list->cards_array[list->cards_size] = card;
	localrecard(&list->cards_array[list->cards_size], "注册", money*-1);
	char buff[20];
	time(buff);
	strcpy(list->cards_array[list->cards_size++].create_date,buff);
	MessageBox(0, "注册成功", "注册", MB_OK);
	return true;

};

//账号密码输入正确&&没有被挂失&&没有被锁
int  login_card(PList list, int id, int passwd){
	int result = SearchCard(list,id);
	if (result == -1)  return -1;
	printf("id:%d   passwd:%d",list->cards_array[result].id,list->cards_array[result].passwd);
	if (!list->cards_array[result].islocked&&
		!list->cards_array[result].isloss&&
		result != -1&&list->cards_array [result].passwd==passwd){
		MessageBox(0, "登陆成功", "登录", MB_OK);
			list->cards_array[result].count = 0;
			return result;
	}
	else  {
		//MessageBox(0, "登录失败", "登录", MB_OK);
		list->cards_array[result].count++;
		if (list->cards_array[result].count == 3){
			list->cards_array[result].islocked = true;
		}
		return -1;
	}
	
}
//激活卡
void active(PList list, const char* idcard){
	for (int i = 0; i < list->cards_size; i++){
		if (strcmp(list->cards_array[i].user.idcard, idcard)==0){
			list->cards_array[i].islocked = false;
			list->cards_array[i].isloss = false;
			list->cards_array[i].count = 0;
			MessageBox(0, "激活成功", "激活", MB_OK);
			return;
		}
	}
	MessageBox(0, "激活失败", "激活", MB_OK);
	return;
}
//挂失卡
void lost(PList list, const char* idcard){
	for (int i = 0; i < list->cards_size; i++){
		if (strcmp(list->cards_array[i].user.idcard, idcard)==0){
			list->cards_array[i].isloss = true;
			list->cards_array[i].count = 0;
			MessageBox(0, "挂失成功", "挂失", MB_OK);
			return;
		}
	}
	MessageBox(0, "挂失失败", "挂失", MB_OK);
	return;
}
//存款
bool savemoney(BankCard*card, int money){
	card->money += money;
	localrecard(card, "存款", money);
	MessageBox(0, "存款成功", "存款", MB_OK);
	return true;
}
//取款
bool withdrawmoney(BankCard*card, int money){
	if (card->money >= money){
		card->money -= money;
		localrecard(card, "取款", money*-1);
		MessageBox(0, "取款成功", "取款", MB_OK);
		return true;
	}
	else {
		MessageBox(0, "取款失败,余额不足", "取款", MB_OK);
		return false;
	}
}
//转账
bool transfer(BankCard* card, BankCard* usercard, int money){
	if (card->money >= money){
		card->money -= money;
		usercard->money += money;
		localrecard(card, "转账", money*-1);
		localrecard(usercard, "转账", money);
		MessageBox(0, "转账成功", "转账", MB_OK);
		return true;
	}
	else {
		MessageBox(0, "余额不足,转账失败", "转账", MB_OK);
		return false;
	}	
}
//查余额
void getmoney(BankCard* card){
	char buff[50] = { 0 };
	sprintf(buff, "余额为%d",card->money );
	MessageBox(0, buff, "结果提示", MB_OK);
}
//查看流水信息
void getwatermessage(BankCard *card){
	initgraph(1000,600);//设置背景
	setbkcolor(BLACK);//背景颜色
	int count = 0;
	char buff[256] = {0};//
	sprintf(buff,"序号        时间          类型  金额  ");
	settextstyle(15,15,"楷体");//文字类型
	setbkcolor(TRANSPARENT);//文字背景
	int y = 10;
	outtextxy(5,y,buff);//将buff在背景(5,y)的位置上进行输出
	for (int i = 0; i < card->record_size; i++) {
		memset(buff,0,sizeof(buff));//对buff进行初始化
		count++;
		y += 20;
		sprintf(buff," %d  %s   %s  %d  ",count, card->record[i].op_now,
			card->record[i].op_type, card->record[i].money);
		outtextxy(5,y,buff);
	}
	MessageBox(0,"输出完毕","提示",MB_OK);
}
//查看开卡日期
void get_create_card_date(BankCard* card){
	        char buff[30] = { 0 };
			sprintf(buff,"注册时间:%s\n", card->create_date);
			MessageBox(0,buff,"开卡日期",MB_OK);
}
//获取时间
void time(char* buff){
	time_t t;
	time(&t);
	struct tm* p = localtime(&t);//获取此刻时间
	sprintf(buff, "%d-%d-%d  %d:%d:%d", p->tm_year + 1900,
		p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
}
//记录流水  
void localrecard(BankCard* card, const char *type, int money){
	char buff[20];
	time(buff);
	strcpy(card->record[card->record_size].op_now, buff);
	strcpy(card->record[card->record_size].op_type, type);
	card->record[card->record_size].money = money;
	(card->record_size)++;
}
//注销 
void destory_card(PList list,int index){
	destory_card_record(&list->cards_array[index]);//释放原卡动态开辟的内存(流水记录)
	for (int i = index; i < list->cards_size; i++){
		list->cards_array[index] = list->cards_array[index + 1];
	}
	list->cards_size--;
	MessageBox(0, "注销成功", "注销", MB_OK);
}
//释放流水记录
void destory_card_record(BankCard* card){
	free(card->record);
	card->record = NULL;
}
//释放卡
void destory(PList list){
	for (int i = 0; i < list->cards_size; i++)
	{
		destory_card_record(&list->cards_array[i]);
	}
	free(list->cards_array);
	list->cards_array = NULL;
}

adminator.cpp源文件:

#define _CRT_SECURE_NO_WARNINGS
#include"adminator.h"
#include"BankCard.h"
#include
#include
#include
#include
#include
#include
#define AC 100
void init_Adminator(ADator adator){
	adator->ator_cards_size = 0;
	adator->ator_count = AC;
	adator->atorcards = (ator_cards*)malloc(sizeof(ator_cards)*AC);
}
void init_Ator_user(Ator_user* ator_user, char* name, char* idcard, char *phone){

	strcpy(ator_user->name, name);
	strcpy(ator_user->idcard, idcard);
	strcpy(ator_user->phone, phone);
}
void init_ator_cards(ator_cards* ator_cards, int id, int passwd, Ator_user ator_user){
	ator_cards->id = id;
	ator_cards->passwd = passwd;
	init_Ator_user(&ator_cards->ator_user,ator_user.name,ator_user.idcard,ator_user.phone);

}

bool regieter_ator_cards(ADator adator, int id, int passwd, Ator_user ator_user){//注册
	assert(adator != NULL);
	if (isfull(adator))   grop_ator(adator);
	int result = research(adator, id);
	if (result != -1)  {
		return false;
	}
	else{
		init_ator_cards(&adator->atorcards[adator->ator_cards_size++], id, passwd, ator_user);
		return true;
	}
}
bool isfull(ADator adator){
	if (adator->ator_cards_size == adator->ator_count)
		return true;
	return false;
}
int research(ADator adator,int id){
	for (int i = 0; i < adator->ator_cards_size; i++){
		if (adator->atorcards[i].id == id){
			return i;
		}
	}
	return -1;
}
void grop_ator(ADator adator){
	int newlen = AC * 2;
	ator_cards* p = (ator_cards*)realloc(adator->atorcards, sizeof(ator_cards)*newlen);
	adator->ator_cards_size = newlen;
	adator->atorcards = p;

}
int loge(ADator adator, int id, int passwd){
	int result = research(adator, id);
	if (result == -1)  {
		MessageBox(0, "查无此账号", " ", MB_OK);
		return -1;
	}
	else if (id == adator->atorcards[result].id&&passwd == adator->atorcards[result].passwd){
		MessageBox(0, "登陆成功", " ", MB_OK);
		return result;
	}
	else {
		MessageBox(0, "密码错误,请重新登录", " ", MB_OK);
		return -1;
	}
}
void destory_ator_card(ADator adator, int index){
	for (int i = index; i < adator->ator_cards_size; i++){
		adator->atorcards[i] = adator->atorcards[i + 1];
	}
	adator->ator_cards_size -= 1;
}
void destory_ator(ADator adator){
		free(adator->atorcards);
		adator->atorcards = NULL;
}

测试

这些便是函数的实现,下面两个cpp文件为函数的测试文件

atm_op.cpp

#define _CRT_SECURE_NO_WARNINGS
#include"BankCard.h"
#include"adminator.h"
#include
#include
void text_ator(ADator adator, PList list) {//管理员操作函数
	User user = { 0 };
	int ator_id = 0, passwd=0, money = 0, bankcard_id = 0;
	Ator_user ator_user = { 0 };
	
	while (true) {
		int fall = 1;
		int fal = 1;
		initgraph(700, 800, SHOWCONSOLE);
		IMAGE image;
		loadimage(&image, "D:/ps图片/ATM.png", 700, 800, true);
		putimage(0, 0, &image);
		int arr[] = { 200,260,280,290 };
		fillrectangle(arr[0], arr[1], arr[2], arr[3]);
		RECT rect = { arr[0], arr[1], arr[2], arr[3] };
		settextcolor(BLACK);
		setbkmode(TRANSPARENT);
		drawtext("注册", &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
		int brr[] = { 200,300,280,330 };
		fillrectangle(brr[0], brr[1], brr[2], brr[3]);
		RECT rect1 = { brr[0], brr[1], brr[2], brr[3] };
		settextcolor(BLACK);
		setbkmode(TRANSPARENT);
		drawtext("登录", &rect1, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
		int crr[] = { 200,340,280,370 };
		fillrectangle(crr[0], crr[1], crr[2], crr[3]);
		RECT rect2 = { crr[0], crr[1], crr[2], crr[3] };
		settextcolor(BLACK);
		setbkmode(TRANSPARENT);
		drawtext("退出", &rect2, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
		MOUSEMSG msg;
		while (1) {
			if (MouseHit()) {
				msg = GetMouseMsg();
				if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= crr[0] && msg.x <= crr[2] && msg.y >= crr[1] && msg.y <= crr[3]) {
					//退出
					fall = 0;
					break;
				}
				if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= arr[0] && msg.x <= arr[2] && msg.y >= arr[1] && msg.y <= arr[3]) {
					//注册管理员
					char s[10];
					InputBox(s, 10, "账号");
					int ator_id = atoi(s);
					char s1[10];
					InputBox(s1, 10, "密码");
					int passwd = atoi(s1);
					char s2[5];
					InputBox(s2, 5, "姓名");
					strcpy(ator_user.name, s2);
					char s3[16];
					InputBox(s3, 16, "身份证号");
					strcpy(ator_user.idcard, s3);
					char s4[12];
					InputBox(s4, 12, "手机号");
					strcpy(ator_user.phone, s4);
					bool fase = regieter_ator_cards(adator, ator_id, passwd, ator_user);
					if (!fase) {
						MessageBox(0, "注册失败", "注册管理员", MB_OK);
					}
					else {
						MessageBox(0, "注册成功", "注册管理员", MB_OK);
					}
					break;
				}
				if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= brr[0] && msg.x <= brr[2] && msg.y >= brr[1] && msg.y <= brr[3]) {
					//登录管理员账号
					char s[10];
					InputBox(s, 10, "账号");
					int id = atoi(s);
					char s1[10];
					InputBox(s1, 10, "密码");
					int passwd = atoi(s1);
					int result = loge(adator, id, passwd);
					if (result == -1) continue;
					if (result != -1) {
						//登录成功界面
						while (true) {
							initgraph(700, 800, SHOWCONSOLE);
							IMAGE image;
							loadimage(&image, "D:/ps图片/ATM.png", 700, 800, true);
							putimage(0, 0, &image);
							int arr[] = { 200,260,280,290 };
							fillrectangle(arr[0], arr[1], arr[2], arr[3]);
							RECT rect = { arr[0], arr[1], arr[2], arr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("注册储户", &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int brr[] = { 200,300,280,330 };
							fillrectangle(brr[0], brr[1], brr[2], brr[3]);
							RECT rect1 = { brr[0], brr[1], brr[2], brr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("挂失储户", &rect1, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int crr[] = { 200,340,280,370 };
							fillrectangle(crr[0], crr[1], crr[2], crr[3]);
							RECT rect2 = { crr[0], crr[1], crr[2], crr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("激活储户", &rect2, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int drr[] = { 200,380,280,410 };
							fillrectangle(drr[0], drr[1], drr[2], drr[3]);
							RECT rect3 = { drr[0], drr[1], drr[2], drr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("注销管理", &rect3, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int err[] = { 440,260,520,290 };
							fillrectangle(err[0], err[1], err[2], err[3]);
							RECT rect4 = { err[0], err[1], err[2], err[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("退出", &rect4, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							MOUSEMSG msg;
							while (1) {
								if (MouseHit()) {
									msg = GetMouseMsg();
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= crr[0] && msg.x <= crr[2] && msg.y >= crr[1] && msg.y <= crr[3]) {
										//激活
										char s3[16];
										InputBox(s3, 16, "身份证号");
										strcpy(user.idcard, s3);
										active(list, user.idcard);
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= brr[0] && msg.x <= brr[2] && msg.y >= brr[1] && msg.y <= brr[3]) {
										//挂失
										char s3[16];
										InputBox(s3, 16, "身份证号");
										strcpy(user.idcard, s3);
										lost(list, user.idcard);
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= arr[0] && msg.x <= arr[2] && msg.y >= arr[1] && msg.y <= arr[3]) {
										//注册
										char s[10];
										InputBox(s, 10, "账号");
										int bankcard_id = atoi(s);
										char s1[10];
										InputBox(s1, 10, "密码");
										int passwd = atoi(s1);
										char s2[5];
										InputBox(s2, 5, "姓名");
										strcpy(user.u_name, s2);
										char s3[16];
										InputBox(s3, 16, "身份证号");
										strcpy(user.idcard, s3);
										char s4[12];
										InputBox(s4, 12, "手机号");
										strcpy(user.phone, s4);
										char s5[10];
										InputBox(s5, 10, "总金额");
										int money = atoi(s5);
										regieter_card(list, bankcard_id, passwd, money, user);
										break;

									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= drr[0] && msg.x <= drr[2] && msg.y >= drr[1] && msg.y <= drr[3]) {
										//注销管理员卡
										destory_ator_card(adator, result);
										MessageBox(0, "注销成功", "注销", MB_OK);
										fal = 0;
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= err[0] && msg.x <= err[2] && msg.y >= err[1] && msg.y <= err[3]) {
										//printf("退出");
										fal = 0;
										break;
									}

								}
							}
							if (fal == 0)  break;
						}
					}
					break;
				}

			}
		}
		if (fall == 0) break;//标记
	}
}
void text_bankcards(PList list){//储户操作函数
	
	User user = { 0 };
	int id = 0, passwd=0, money=0;
	while (true){
		int choice1 = 1;
		int choice=1;
		initgraph(700, 800, SHOWCONSOLE);
		IMAGE image;
		loadimage(&image, "D:/ps图片/ATM.png", 700, 800, true);
		putimage(0, 0, &image);
		int arr[] = { 200,260,280,290 };
		fillrectangle(arr[0], arr[1], arr[2], arr[3]);
		RECT rect = { arr[0], arr[1], arr[2], arr[3] };
		settextcolor(BLACK);
		setbkmode(TRANSPARENT);
		drawtext("登录", &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
		int brr[] = { 200,300,280,330 };
		fillrectangle(brr[0], brr[1], brr[2], brr[3]);
		RECT rect1 = { brr[0], brr[1], brr[2], brr[3] };
		settextcolor(BLACK);
		setbkmode(TRANSPARENT);
		drawtext("退出", &rect1, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
		//printf("请选择:1 登录 2 退出\n");
		MOUSEMSG msg;
		while (1) {
			if (MouseHit()) {
				msg = GetMouseMsg();			
				if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= brr[0] && msg.x <= brr[2] && msg.y >= brr[1] && msg.y <= brr[3]) {
					//退出
					choice = 0;
					break;
				}
				if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= arr[0] && msg.x <= arr[2] && msg.y >= arr[1] && msg.y <= arr[3]) {
			        //登录
					char s[10];
					InputBox(s, 10, "卡号");
					int id = atoi(s);
					char s1[10];
					InputBox(s1, 10, "密码");
					int passwd = atoi(s1);
					int result = login_card(list, id, passwd);
					if (result == -1) {
						MessageBox(0, "登录失败", "登录", MB_OK);
					}
					else {
						while (true) {
							initgraph(700, 800, SHOWCONSOLE);
							IMAGE image;
							loadimage(&image, "D:/ps图片/ATM.png", 700, 800, true);
							putimage(0, 0, &image);
							int arr[] = { 200,260,280,290 };
							fillrectangle(arr[0], arr[1], arr[2], arr[3]);
							RECT rect = { arr[0], arr[1], arr[2], arr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("取款", &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int brr[] = { 200,300,280,330 };
							fillrectangle(brr[0], brr[1], brr[2], brr[3]);
							RECT rect1 = { brr[0], brr[1], brr[2], brr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("存款", &rect1, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int crr[] = { 200,340,280,370 };
							fillrectangle(crr[0], crr[1], crr[2], crr[3]);
							RECT rect2 = { crr[0], crr[1], crr[2], crr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("转账", &rect2, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int drr[] = { 200,380,280,410 };
							fillrectangle(drr[0], drr[1], drr[2], drr[3]);
							RECT rect3 = { drr[0], drr[1], drr[2], drr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("余额", &rect3, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int err[] = { 440,260,520,290 };
							fillrectangle(err[0], err[1], err[2], err[3]);
							RECT rect4 = { err[0], err[1], err[2], err[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("流水", &rect4, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int frr[] = { 440,300,520,330 };
							fillrectangle(frr[0], frr[1], frr[2], frr[3]);
							RECT rect5 = { frr[0], frr[1], frr[2], frr[3]};
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("开卡日期", &rect5, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							int grr[] = { 440,340,520,370 };
							fillrectangle(grr[0], grr[1], grr[2], grr[3]);
							RECT rect6 = { grr[0], grr[1], grr[2], grr[3] };
							settextcolor(BLACK);
							drawtext("注销", &rect6, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							setbkmode(TRANSPARENT);
							int hrr[] = { 440,380,520,410 };
							fillrectangle(hrr[0], hrr[1], hrr[2], hrr[3]);
							RECT rect7 = { hrr[0], hrr[1], hrr[2], hrr[3] };
							settextcolor(BLACK);
							setbkmode(TRANSPARENT);
							drawtext("退出", &rect7, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
							MOUSEMSG msg;
							while (1) {
								if (MouseHit()) {
									msg = GetMouseMsg();
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= arr[0] && msg.x <= arr[2] && msg.y >= arr[1] && msg.y <= arr[3]) {
										//取款
										char s[10];
										InputBox(s, 10, "取款金额");
										int money = atoi(s);
										withdrawmoney(&(list->cards_array[result]), money);
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= brr[0] && msg.x <= brr[2] && msg.y >= brr[1] && msg.y <= brr[3]) {
										//存款
										char s[10];
										InputBox(s, 10, "存款金额");
										int money = atoi(s);
										savemoney(&(list->cards_array[result]), money);
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= crr[0] && msg.x <= crr[2] && msg.y >= crr[1] && msg.y <= crr[3]) {
										//转账
										char s[10];
										InputBox(s, 10, "转账金额");
										int money = atoi(s);
										char s1[10];
										InputBox(s1, 10, "卡号");
										int id = atoi(s1);
										int result_u = SearchCard(list, id);
										printf("\n");
										if (result_u != -1) {

											transfer(&(list->cards_array[result]), &(list->cards_array[result_u]), money);

										}
										else {
											MessageBox(0, "转账失败", "转账", MB_OK);
										}
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= drr[0] && msg.x <= drr[2] && msg.y >= drr[1] && msg.y <= drr[3]) {
										//查余额
										getmoney(&(list->cards_array[result]));
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= err[0] && msg.x <= err[2] && msg.y >= err[1] && msg.y <= err[3]) {
										//查流水
										getwatermessage(&(list->cards_array[result]));
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= frr[0] && msg.x <= frr[2] && msg.y >= frr[1] && msg.y <= frr[3]) {
										//开卡日期
										get_create_card_date(&(list->cards_array[result])); 
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= grr[0] && msg.x <= grr[2] && msg.y >= grr[1] && msg.y <= grr[3]) {
										//注销
										destory_card(list, result); 
										choice1 = 0;
										break;
									}
									if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= hrr[0] && msg.x <= hrr[2] && msg.y >= hrr[1] && msg.y <= hrr[3]) {
										//退出
										choice1 = 0;
										break;
									}

								}
							}
							if (choice1 == 0)  break;
						}
					}
					break;
				}

			}
		}
		if (0 ==choice )  break;
	}
}

main.cpp

#define _CRT_SECURE_NO_WARNINGS
#include"BankCard.h"
#include"adminator.h"
#include
void text_bankcards(PList list);
void text_ator(ADator adator,PList list);
int main() {
	SqList_BankCards cards ;
	init_sqlist_cards(&cards);
	PList list = &cards;
	Adminator adminator;
	init_Adminator(&adminator);
	ADator adator=&adminator;
	while (true){
		int n;
		printf("请选择身份:1 储户  2 管理员 3 退出 \n");
		printf("请输入:");
		scanf("%d", &n);
		if (n == 3){
			break;
		}
		switch (n){
		case 1:{
				   text_bankcards(list);
		}break;
		case 2:{
				   text_ator(adator, list);
		}break;
		default:
			break;
		}
	}
		destory(list);
		destory_ator(adator);
	return 0;
}

你可能感兴趣的:(项目,java,数据库,servlet)