#include "myhead.h"
//转账处理
int Thread::transfer_check()
{
int writecnt = 0;
char sql[200] = {0};
int result = 0;
float account = 0; //存放长刺余额
float account1 = 0;
char date[100] = {0}; //暂时存放上一次的日期
MYSQL_RES* mysql_res;
MYSQL_FIELD* mysql_field;
MYSQL_ROW mysql_row;
unsigned int cols;
int flag = 0;
sprintf(sql,"select clientid,clientname from client where clientid = %d;",clientrecv.toclientid); //查找所转账的账号是否存在
result = mysql_query(mysql,sql);
mysql_res = mysql_store_result(mysql);
if(result > 0)
{
cout<<mysql_error(mysql)<<endl;
clientrecv.relay = TRANSFER_FAIL1;
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
else
{
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)
{
if(clientrecv.toclientid == atoi(mysql_row[0]))
{
strcpy(clientrecv.toname,mysql_row[1]);
flag = 1;
}
}
}
mysql_free_result(mysql_res);
}
if(flag == 0)
{
clientrecv.relay = TRANSFER_FAIL1;
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
else
{
sprintf(sql,"select clientid,deal_time,interest,balance from account where clientid = %d;",clientrecv.toclientid);
result = mysql_query(mysql,sql);
mysql_res = mysql_store_result(mysql);
if(result != 0)
{
cout<<mysql_error(mysql)<<endl;
cout<<"查询失败!"<<endl;
return -1;
}
else
{
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)
{
// strcpy(date,mysql_row[1]);
// interest1 = atof(mysql_row[2]);
account = atof(mysql_row[cols-1]);
}
}
mysql_free_result(mysql_res);
}
sprintf(sql,"select clientid,deal_time,interest,balance from account where clientid = %d;",clientrecv.clientid);
result = mysql_query(mysql,sql);
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)
{
// strcpy(date,mysql_row[1]);
// interest1 = atof(mysql_row[2]);
account1 = atof(mysql_row[cols-1]);
}
}
mysql_free_result(mysql_res);
}
if((account1 - clientrecv.captial) < 0)
{
clientrecv.relay = TRANSFER_FAIL2; //余额不足,转账失败
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
return -1;
}
if(account == 0.0) //原先没有余额
{
GetSystemTime(&clientrecv.intime);
clientrecv.sum_money = clientrecv.captial;
sprintf(sql,"insert into account(clientid ,deal_time,inaccount,balance) values(%d,'%d-%d-%d %d:%d:%d',%.2f,%.2f);",clientrecv.toclientid,clientrecv.intime.wYear,clientrecv.intime.wMonth,clientrecv.intime.wDay,clientrecv.intime.wHour,clientrecv.intime.wMinute,clientrecv.intime.wSecond,clientrecv.captial,clientrecv.sum_money);
result = mysql_query(mysql,sql);
clientrecv.sum_money = account1-clientrecv.captial;
sprintf(sql,"insert into account(clientid ,deal_time,outaccount,balance) values(%d,'%d-%d-%d %d:%d:%d',%.2f,%.2f);",clientrecv.clientid,clientrecv.intime.wYear,clientrecv.intime.wMonth,clientrecv.intime.wDay,clientrecv.intime.wHour,clientrecv.intime.wMinute,clientrecv.intime.wSecond,clientrecv.captial,clientrecv.sum_money);
result = mysql_query(mysql,sql);
if(result > 0) //转账失败
{
cout<<mysql_error(mysql)<<endl;
clientrecv.relay = TRANSFER_FAIL1;
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
else
{
clientrecv.relay = TRANSFER_OK; //转账成功
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
}
else //转钱操作
{
GetSystemTime(&clientrecv.intime);
clientrecv.sum_money = clientrecv.captial + account;
sprintf(sql,"insert into account(clientid ,deal_time,inaccount,balance) values(%d,'%d-%d-%d %d:%d:%d',%.2f,%.2f);",clientrecv.toclientid,clientrecv.intime.wYear,clientrecv.intime.wMonth,clientrecv.intime.wDay,clientrecv.intime.wHour,clientrecv.intime.wMinute,clientrecv.intime.wSecond,clientrecv.captial,clientrecv.sum_money);
result = mysql_query(mysql,sql);
clientrecv.sum_money = account1 - clientrecv.captial;
sprintf(sql,"insert into account(clientid ,deal_time,outaccount,balance) values(%d,'%d-%d-%d %d:%d:%d',%.2f,%.2f);",clientrecv.clientid,clientrecv.intime.wYear,clientrecv.intime.wMonth,clientrecv.intime.wDay,clientrecv.intime.wHour,clientrecv.intime.wMinute,clientrecv.intime.wSecond,clientrecv.captial,clientrecv.sum_money);
result = mysql_query(mysql,sql);
if(result > 0) //转账失败
{
cout<<mysql_error(mysql)<<endl;
clientrecv.relay = TRANSFER_FAIL1;
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
else
{
clientrecv.relay = TRANSFER_OK; //转账成功
writecnt = send(clientfd,(char *)&clientrecv,sizeof(User),0);
if(writecnt == -1)
{
cerr<<"send error!"<<endl;
return -1;
}
}
}
}
}
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
银行管理系统(C++) (150个子文件)
client.vcxprojResolveAssemblyReference.cache 713B
transfer_check.cpp 6KB
init_socket.cpp 5KB
login_reg.cpp 5KB
thread.cpp 5KB
deposit_check.cpp 3KB
open_account_check.cpp 3KB
withdrawal_check.cpp 3KB
login_check.cpp 2KB
close_account_check.cpp 2KB
look_check_check.cpp 2KB
main_menu.cpp 2KB
matching.cpp 2KB
changepass.cpp 2KB
open_account.cpp 1KB
look_balance_check.cpp 1KB
look_check.cpp 968B
transfer.cpp 876B
changepass_check.cpp 840B
register_check.cpp 802B
init_client.cpp 800B
look_balance.cpp 763B
withdrawal.cpp 761B
deposit.cpp 755B
exit_check.cpp 706B
close_account.cpp 532B
exit_log.cpp 258B
main.cpp 155B
main.cpp 130B
libmysql.dll 3.82MB
libmysql.dll 3.82MB
semisync_master.dll 233KB
semisync_slave.dll 157KB
libdaemon_example.dll 146KB
auth.dll 133KB
qa_auth_interface.dll 118KB
mypluglib.dll 117KB
auth_test_plugin.dll 117KB
adt_null.dll 116KB
qa_auth_client.dll 116KB
qa_auth_server.dll 116KB
client.exe 80KB
server.exe 68KB
server.vcxproj.filters 2KB
client.vcxproj.filters 2KB
myhead.h 6KB
myhead.h 5KB
vc100.idb 795KB
vc100.idb 787KB
client.ilk 651KB
server.ilk 569KB
client-c767fd4b.ipch 45MB
server-2e75de63.ipch 44.38MB
server.lastbuildstate 55B
client.lastbuildstate 48B
mysqlclient.lib 10.06MB
mysqlclient.lib 9.62MB
libmysql.lib 25KB
server.log 17KB
client.log 14KB
server.Build.CppClean.log 2KB
client.Build.CppClean.log 2KB
client.exe.embed.manifest 406B
server.exe.embed.manifest 406B
client.exe.intermediate.manifest 381B
server.exe.intermediate.manifest 381B
login_reg.obj 103KB
open_account.obj 93KB
thread.obj 80KB
init_socket.obj 77KB
transfer_check.obj 69KB
main_menu.obj 67KB
open_account_check.obj 67KB
deposit_check.obj 66KB
look_check.obj 66KB
withdrawal_check.obj 65KB
changepass.obj 65KB
login_check.obj 64KB
look_check_check.obj 64KB
close_account_check.obj 64KB
transfer.obj 64KB
init_client.obj 63KB
look_balance_check.obj 63KB
matching.obj 63KB
withdrawal.obj 63KB
deposit.obj 63KB
look_balance.obj 63KB
register_check.obj 62KB
exit_check.obj 62KB
close_account.obj 62KB
changepass_check.obj 62KB
exit_log.obj 60KB
main.obj 47KB
main.obj 47KB
client.pdb 843KB
server.pdb 763KB
vc100.pdb 316KB
vc100.pdb 300KB
server_manifest.rc 202B
client_manifest.rc 202B
共 150 条
- 1
- 2
资源评论
- 马克love2023-07-24这个银行管理系统的界面简洁明了,功能齐全,非常适合普通用户使用。
- zh2223332023-07-24使用这个文件中的银行管理系统,我能够更轻松地管理我的账户和交易记录。
- 柏傅美2023-07-24这个文件给了我很多灵感,让我对银行管理系统有了更清晰的理解。
- XiZi2023-07-24这个银行管理系统能够高效地处理大量数据,为银行提供了强大的支持。
- 优游的鱼2023-07-24这个银行管理系统的设计简单实用,解决了我平时处理银行业务时的痛点。
素心暮年
- 粉丝: 56
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功