📄 ccontrol.cpp
字号:
#include "CControl.h"
#include "CBlanceInfo.h"
#include "CFile.h"
#include "CPersonOperatInfo.h"
#include "CUserInfo.h"
#include "Disply.h"
#include <afx.h>
#include <string>
#include <conio.h>
using namespace std;
void CControl::setAccountNum(long int nNum)//设置帐户
{
nAccountNum=nNum;
}
void CControl::openAccount()//操作员开户
{
long int nUserCountNum=0;
ofstream foutUser, foutMoney;
foutUser.open("User.ini",ios_base::out|ios_base::app);
foutMoney.open("Money.txt",ios_base::out|ios_base::app);
string strDecsion;
string strName,strUserPd,strCardID,strAddress,strPhone;
cout<<"请输入用户名:";
cin>>strName;
cout<<"请输入密码:";
cin>>strUserPd;
cout<<"请输入身份证号:";
cin>>strCardID;
cout<<"请输入联系地址:";
cin>>strAddress;
cout<<"请输入手机号:";
cin>>strPhone;
system("cls");
DisplyDefineAccount();
cout <<"你输入的个人信息为:"<<endl<<"姓名:"<<strName<<endl<<"密码:"<<strUserPd<<endl
<<"身份证号:"<<strCardID<<endl<<"联系地址:"<<strAddress<<endl<<"联系电话:"<<strPhone<<endl;
C_File p;
p.ReadUserInfo();// 读取用户信息文件
nUserCountNum=p.FindMaxCardId()+1;//获取系统的最大账号
cout<<"系统生成的账号为:"<<nUserCountNum<<endl<<"请确认是否开户?(Y/N)";
while (1)
{
cin>>strDecsion;
if (strDecsion.compare("Y")==0||strDecsion.compare("y")==0)//把用户的信息写入到文件中
{
foutUser << "[" << nUserCountNum<< "]" <<endl;
foutUser << "UserName=" << strName << endl;
foutUser << "UserPasswd=" << strUserPd <<endl;
foutUser << "CardID=" << strCardID <<endl;
foutUser << "Address=" << strAddress <<endl;
foutUser << "Telephone=" << strPhone <<endl;
foutMoney<<nUserCountNum<<endl<<strUserPd<<endl<<"10"<<endl<<"1"<<endl;
foutUser.close();
foutMoney.close();
cout<<"开户成功,请记住账号密码,按任意键返回...... ";
getch();
break;
}
else if(strDecsion.compare("N")==0||strDecsion.compare("n")==0)
{
foutUser.close();
foutMoney.close();
break;
}
else
cout<<"您的输入不正确! 请重新输入(Y/N)";
}
return;
}
void CControl::DeleteAccount()//操作员销户
{
string strInput;
int i=0;
C_File file;
CBalanceInfoData *ppBalanceInfoData=NULL;
cout<<"请输入账号:";
cin>>strInput;
nAccountNum=atoi(strInput.c_str());
file.ReadBalanceInfo(); //获取用户的帐户信息
ppBalanceInfoData=file.pBalanceInfoData;
while(ppBalanceInfoData)//将标志和余额设置为0
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nAccountNum)
{
ppBalanceInfoData->UserBalanceInfo->SetFlag(0);
ppBalanceInfoData->UserBalanceInfo->SetBalance("0");
i++;
break;
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
if (i==1)
{
cout<<"销户成功,按任意键返回......";
file.SaveBalanceInfo();
getch();
}
else
{
cout<<"销户失败,请确认该帐户是否存在!"<<endl<<"按任意键返回......";
getch();
}
}
void CControl::LeadInInfo()//导入用户信息
{
C_File onefile;
string FileName;
string FileName2;
CUserInfoData *ppUserInfo=NULL;
ifstream fout;
FileName2="User.ini";
DisplyLeadInInfo();
cout<<">>请输入您要导入的文件名:";
cin>>FileName;
fout.open(&FileName[0]);
if (!fout.is_open())
{
cout<<"对不起没有找到你要导入的文件,请确定该文件是否存在!"<<endl;
cout<<"按任意键返回...";
getch();
}
else
{
fout.close();
onefile.ReadUserInfo(&FileName[0]);//读取被导入的文件
onefile.SaveUserInfo(&FileName2[0]);//将读取的数据写到用户信息文件中
ofstream foutMoney;
foutMoney.open("Money.txt",ios_base::out|ios_base::app);
ppUserInfo=onefile.pUserInfo;
while(ppUserInfo)//为每一个用户开户
{
foutMoney<<ppUserInfo->user->GetAccountNum()<<endl<<ppUserInfo->user->GetUserPasswd()<<endl<<"10"<<endl<<"1"<<endl;
ppUserInfo=ppUserInfo->pNext;
}
foutMoney.close();
cout<<"导入成功!"<<endl<<"按任意键返回...";
getch();
}
}
void CControl::LeadOutInfo()//导出用户信息
{
C_File onefile;
string FileName;
ifstream fin;
DisplyLeadOutInfo();
FileName="Content.ini";
fin.open("User.ini");
if (!fin.is_open())
{
cout<<"系统现无任何用户,无法导出!"<<endl;
cout<<"按任意键返回...";
getch();
}
else
{
fin.close();
onefile.ReadUserInfo();//读取用户信息文件
onefile.SaveUserInfo(&FileName[0]);//将读取的数据保存到指定的文件中
cout<<"导出成功!"<<endl<<"按任意键返回...";
getch();
}
}
void CControl::Deposit()//用户存款
{
CBalanceInfoData *ppBalanceInfoData=NULL;
string strInputMoney;
char szMoney[20];
long int nMoney;
C_File onefile;
cout<<" >>请输入金额:";
cin>>strInputMoney;
onefile.ReadBalanceInfo();//读取帐户信息
ppBalanceInfoData=onefile.pBalanceInfoData;
while(1)//修改该帐户的金额
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nAccountNum)
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
+atoi(strInputMoney.c_str());
itoa(nMoney,szMoney,10);
ppBalanceInfoData->UserBalanceInfo->SetBalance(szMoney);
break;
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
onefile.SaveBalanceInfo();//将修改后的数据写到文件中
ofstream fin;
char szNum[15];
itoa(nAccountNum,szNum,10);
strcat(szNum,".txt");
CTime Ct1 = CTime::GetCurrentTime();//获取系统的时间
fin.open(szNum,ios_base::out | ios_base::app);
if (!fin.is_open())
{
cout << "creat file failure!";
}
if(Ct1.GetMonth()<10)
{
fin << Ct1.GetYear() <<"0"<< Ct1.GetMonth()<<endl;
}
else //将时间和操作类型写入到文件中
{
fin << Ct1.GetYear() << Ct1.GetMonth()<<endl;
}
fin << 1 <<endl;
fin << strInputMoney<<endl;
cout<<"存款成功!"<<endl<<"按任意键返回...";
getch();
}
void CControl::WithDraw()//用户取款
{
char szMoney[20];
long int nMoney;
long int nType=0;
C_File onefile;
CBalanceInfoData *ppBalanceInfoData=NULL;
cout<<" 1)100 2)200 3)500 4)1000"<<endl<<endl<<">>请选择取款金额:"<<endl;
cin>>nType;
while (1)
{
if(nType<1 || nType>4)
{
cout<<"输入错误!请重新输入:"<<endl;
cout<<"请选择取款金额:";
nType=0;
cin>>nType;
}
else
break;
}
onefile.ReadBalanceInfo();// 读取帐户信息
ppBalanceInfoData=onefile.pBalanceInfoData;
while(ppBalanceInfoData)//修改该帐户的数据
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nAccountNum)
{
switch(nType)
{
case 1:
if(100<=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str()))
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
-100;
break;
}
else
{
cout<<"余额不足!"<<endl;
return;
}
case 2:
if(200<=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str()))
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
-200;
break;
}
else
{
cout<<"余额不足!"<<endl;
return;
}
case 3:
if(500<=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str()))
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
-500;
break;
}
else
{
cout<<"余额不足!"<<endl;
return;
}
case 4:
if(1000<=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str()))
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
-1000;
break;
}
else
{
cout<<"余额不足!"<<endl;
return;
}
}
itoa(nMoney,szMoney,10);
ppBalanceInfoData->UserBalanceInfo->SetBalance(szMoney);//修改数据金额
break;
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
onefile.SaveBalanceInfo();// 保存帐户信息
cout<<"请取走您的现金!"<<endl;
ofstream fin;
char szNum[15];
itoa(nAccountNum,szNum,10);
strcat(szNum,".txt");
CTime Ct1 = CTime::GetCurrentTime();//获取系统的时间
fin.open(szNum,ios_base::out | ios_base::app);
if (!fin.is_open())
{
cout << "creat file failure!";
}
if(Ct1.GetMonth()<10)
{
fin << Ct1.GetYear() <<"0"<< Ct1.GetMonth()<<endl;
}
else //将时间和操作类型写入到文件中
{
fin << Ct1.GetYear() << Ct1.GetMonth()<<endl;
}
fin << 2 <<endl;
switch(nType)
{
case 1:
fin << 100 << endl;
break;
case 2:
fin << 200 << endl;
break;
case 3:
fin << 500 << endl;
break;
case 4:
fin << 1000 << endl;
break;
}
cout<<"按任意键返回...";
getch();
}
void CControl::TransferAccount()//用户转账
{
int nType=0;
long int nnAccountNum=0;
CBalanceInfoData *ppBalanceInfoData=NULL;
CBalanceInfoData *pppBalanceInfoData=NULL;
C_File onefile;
string strInputMoney;
char szMoney[20];
long int nMoney;
onefile.ReadBalanceInfo();// 获取用户的帐户信息
ppBalanceInfoData=onefile.pBalanceInfoData;
cout<<">>请输入转账账号:"<<endl;
fflush(stdin);
cin>>nnAccountNum;
if(nnAccountNum==nAccountNum)
{
cout<<"输入错误!"<<endl<<"按任意键返回...";
getch();
return;
}
while(ppBalanceInfoData)//判断该帐户是否销户
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nnAccountNum
&& ppBalanceInfoData->UserBalanceInfo->GetFlag()!=0)
{
nType=1;
break;
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
if(nType==0)
{
cout<<"此帐户不存在!"<<endl<<"按任意键返回...";
getch();
return;
}
else if(nType==1)
{
cout<<">>请输入转账金额:"<<endl;
cin>>strInputMoney;
ppBalanceInfoData=onefile.pBalanceInfoData;
while(ppBalanceInfoData)//修改原帐户的数据
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nAccountNum)
{
if(atoi(strInputMoney.c_str())<=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
&& strInputMoney.length() <= ppBalanceInfoData->UserBalanceInfo->GetBalance().length()
)
{
nMoney=atoi((ppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
-atoi(strInputMoney.c_str());
itoa(nMoney,szMoney,10);
ppBalanceInfoData->UserBalanceInfo->SetBalance(szMoney);
pppBalanceInfoData=onefile.pBalanceInfoData;
while(pppBalanceInfoData)//修改导入的帐户的数据
{
if (pppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nnAccountNum)
{
nMoney=atoi((pppBalanceInfoData->UserBalanceInfo->GetBalance()).c_str())
+atoi(strInputMoney.c_str());
itoa(nMoney,szMoney,10);
pppBalanceInfoData->UserBalanceInfo->SetBalance(szMoney);
break;
}
else
{
pppBalanceInfoData=pppBalanceInfoData->pNext;
}
}
break;
}
else
{
cout<<"余额不足!"<<endl<<"按任意键返回...";
getch();
return;
}
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
onefile.SaveBalanceInfo();//将修改后的数据写入到文件中
ofstream fin;
char szNum[15];
itoa(nAccountNum,szNum,10);
strcat(szNum,".txt");
CTime Ct1 = CTime::GetCurrentTime();//获取系统的时间
fin.open(szNum,ios_base::out | ios_base::app);
if (!fin.is_open())
{
cout << "creat file failure!";
}
if(Ct1.GetMonth()<10)
{
fin << Ct1.GetYear() <<"0"<< Ct1.GetMonth()<<endl;
}
else //将时间和操作类型写入到文件中
{
fin << Ct1.GetYear() << Ct1.GetMonth()<<endl;
}
fin << 3 <<endl;
fin << strInputMoney <<endl;
}
cout<<"转账成功!"<<endl<<"按任意键返回...";
getch();
}
void CControl::CheckBalance()//用户查询余额
{
C_File onefile;
CBalanceInfoData *ppBalanceInfoData=NULL;
onefile.ReadBalanceInfo();//读取帐户信息
ppBalanceInfoData=onefile.pBalanceInfoData;
while(ppBalanceInfoData)//获取该帐户的金额
{
if (ppBalanceInfoData->UserBalanceInfo->GetAccountNum()==nAccountNum)
{
cout<<">>该帐户余额为:"<<ppBalanceInfoData->UserBalanceInfo->GetBalance()<< " RMB"<<endl;
break;
}
else
{
ppBalanceInfoData=ppBalanceInfoData->pNext;
}
}
cout<<"按任意键返回...";
getch();
return;
}
void CControl::CheckOperateInfo()//用户查询操作详单
{
C_File onefile;
CPersonOperatInfoData * ppPersonOperatInfoData;
char szFileName[32];
int i=0;
string strBeginTime;
string strEndTime;
itoa(nAccountNum,szFileName,10);
strcat(szFileName,".txt");
onefile.ReadPersonOperatInfo(szFileName);//读取用户的个人操作信息
ppPersonOperatInfoData=onefile.pPersonOperatInfoData;
cout<<" >>请输入起始时间:";
cin>>strBeginTime;
cout<<" >>请输入截止时间:";
cin>>strEndTime;
cout<<" 时间"<<" "<<"方式"<<" "<<"金额"<<endl;
while(ppPersonOperatInfoData)//获取改时间段内的操作信息
{
if (atoi(ppPersonOperatInfoData->UserOperatInfo->GetTime().c_str())>=atoi(strBeginTime.c_str()
)&&atoi(ppPersonOperatInfoData->UserOperatInfo->GetTime().c_str())<=atoi(strEndTime.c_str()))
{
cout<<" "<<ppPersonOperatInfoData->UserOperatInfo->GetTime();
if (ppPersonOperatInfoData->UserOperatInfo->GetTpype()==1)
{
cout<<" 存款";
}
else if (ppPersonOperatInfoData->UserOperatInfo->GetTpype()==2)
{
cout<<" 取款";
}
else
cout<<" 转账";
cout<<" "<<ppPersonOperatInfoData->UserOperatInfo->GetMoney()<<endl;
i++;
}
ppPersonOperatInfoData=ppPersonOperatInfoData->pNext;
}
if (i==0)
{
cout<<"该时间内您无任何操作记录!"<<endl;
}
cout<<"按任意键返回...";
getch();
}
CControl::CControl()//构造函数
{
nAccountNum=0;
}
CControl::~CControl()//析构函数
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -