首页 > 编程 > C++ > 正文

c++ ABCBank项目(四)

2019-11-08 01:47:54
字体:
来源:转载
供稿:网友

               服务器接受到客户端选择的功能号后,跳转到每一个功能的相应选项中。

(1)存款:在存款中,数据库里会改变的有时间,操作职工号,利息,存取金额,剩余金额,由于改动的内容较多,自己便将改动后的信息全部赋给类中变量,然后将数据库里最新的动态消息删除,讲这些新的内容重新存放到数据库中,存放的同时一定要同时保存到文件中,这样每一个操作步骤都会在文件中,方便客户查看自己的操作记录,代码:

int result ;			char buff[100];			sPRintf(buff,"select * from kehu where id=%d;",object->cliid);			result = MySQL_query(mysql, buff);			if (result != 0)			{				printf("error: %s/n", mysql_error(mysql));				return fail;			}			MYSQL_RES* mysql_res;			MYSQL_FIELD* mysql_field;			MYSQL_ROW mysql_row;			unsigned int cols;			mysql_res = mysql_store_result(mysql);			cols = mysql_num_fields(mysql_res);			if (mysql_res)			{				while ((mysql_row = mysql_fetch_row(mysql_res)))				{					for (unsigned int i=0; i<cols; ++i)					{						printf("%s/t", mysql_row[i] ? mysql_row[i] : "NULL");					}					printf("/n");					if(atoi(mysql_row[5]) == object->cliid)					{						double sum;						sum = atof(mysql_row[9]) + (object->shrmb());						object->setclient((string)mysql_row[1],(string)mysql_row[2],(string)mysql_row[3],(string)mysql_row[4],object->shrmb(),sum);						object->cliid = atoi(mysql_row[5]);						object->bankname = (string)mysql_row[6];						object->mydate = gettime() ;						char buff2[100];//删除该行						sprintf(buff2,"delete from kehu where id = %d",object->cliid);						mysql_query(mysql,buff2);						char buff[300];//重新插入						sprintf(buff,"insert into kehu values(%d,'%s','%s','%s','%s',%d,'%s','%s',%lf,%lf)",(object->caozuohao),(object->shcliname()).c_str(),(object->shidentity()).c_str(),(object->shclipassWord()).c_str(),(object->shreclipassword()).c_str(),(object->cliid),(object->bankname).c_str(),(object->mydate).c_str(),(object->shrmb()),(object->shrest()));							mysql_query(mysql,buff);						table.yuangong = object->caozuohao;						strcpy(table.name,(object->shcliname()).c_str());						table.id = object->cliid ;						strcpy(table.identity ,(object->shidentity()).c_str());						strcpy(table.bank , (object->bankname).c_str()) ;						table.lixi =(object->shrest())*(0.0001);						strcpy(table.date , (object->mydate).c_str());						table.cunqu = object->shrmb();						table.rest = object->shrest();						ofstream outfile;						char repair[50];						sprintf(repair,"%s的存折账单.txt",(object->shcliname()).c_str());						outfile.open(repair,ios::binary | ios::app);						outfile.write((char *)&table,sizeof(table));						outfile.close();													return  success ;					}					else					{						return  fail ;					}				}				mysql_free_result(mysql_res);			}取款和转账同存款流程差不多,不过在取款和转账需要先对客户输入的账号和密码经行验证,验证对了才能继续进行操作,否则给个友好提醒,并返回到操作界面让客户重新操作,查询余额时同样需要对客户进行验证密码,再到数据库中相应的位置将余额保存到变量里返回给客户端并打印,查看详细账单则需要在服务器验证之后在客户端处从本地文件中找出对应客户的文件,将里面所有的信息都打印出来,接着则是更改密码,有了上面的思路后,后面的操作就会明了很多,下面是更改密码的代码:

int result ;			   char buff[100];			   sprintf(buff,"select * from kehu where id=%d;",object->cliid);			   result = mysql_query(mysql, buff);			   if (result != 0)			   {				   printf("error: %s/n", mysql_error(mysql));				   return fail;			   }			   MYSQL_RES* mysql_res;			   MYSQL_FIELD* mysql_field;			   MYSQL_ROW mysql_row;			   unsigned int cols;			   mysql_res = mysql_store_result(mysql);			   cols = mysql_num_fields(mysql_res);			   if (mysql_res)			   {				   while ((mysql_row = mysql_fetch_row(mysql_res)))				   {					   for (unsigned int i=0; i<cols; ++i)					   {						   printf("%s/t", mysql_row[i] ? mysql_row[i] : "NULL");					   }					   printf("/n");					  // if(atoi(mysql_row[5]) == object->cliid)					  if(((string)mysql_row[3] == object->shclipassword())&&((string)mysql_row[4] == object->shreclipassword()))//判断密码					   {						   object->setclient((string)mysql_row[1],(string)mysql_row[2],object->linshi,object->linshi,atof(mysql_row[8]),atof(mysql_row[9]));						   object->cliid = atoi(mysql_row[5]);						   object->bankname = (string)mysql_row[6];						   object->mydate = gettime() ;						   char buff2[100];//删除该行						   sprintf(buff2,"delete from kehu where id = %d",object->cliid);						   mysql_query(mysql,buff2);						   char buff3[300];//重新插入						   sprintf(buff3,"insert into kehu values(%d,'%s','%s','%s','%s',%d,'%s','%s',%lf,%lf)",(object->caozuohao),(object->shcliname()).c_str(),(object->shidentity()).c_str(),(object->shclipassword()).c_str(),(object->shreclipassword()).c_str(),(object->cliid),(object->bankname).c_str(),(object->mydate).c_str(),(object->shrmb()),(object->shrest()));							   mysql_query(mysql,buff3);						   return  success ;					   }					   else					   {						   return  fail ;					   }				   }				   mysql_free_result(mysql_res);			   }最后一个便是销户,验证好客户的账号和信息,在数据库中找到相应的位置,并删除该内容,给客户端一个正确的提示,销户便完成。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选