#include"zh.h"
FILE *fp;
//----------------身份证号输入及检查--------
//-----------------------------------------
bool inputId(ZH &p){
ZH p2;
system("cls");
p.idInput();
system("cls");
cout<<"你刚才输入的身份证号是:"<<p.id<<"吗?/n";
cout<<"0.重新输入/n1.确认/n";
char ch;
while(1){
ch=getch();
if(ch=='0')
return true;
if(ch=='1'){
fp=fopen("d://zh.txt","a+"); //打开文件并验证账号是否存在
if(fp==NULL){
cout<<"文件打开失败!";
system("pause");
exit(1);
}
if(fp!=NULL){
while(!feof(fp)){
fread(&p2,sizeof(ZH),1,fp);
if(strcmp(p.id,p2.id)==0){ //若存在此记录,则退出函数
fclose(fp);
return false;
}//if
}//while
fclose(fp);
system("cls");
cout<<"不存在账号为:"<<p.id<<"的用户!"<<endl;
MessageBox(0,"不存在此账号","温馨提示",0);
return true;
}//if
else{ //若文件空,则应关闭文件,返回信息
fclose(fp);
system("cls");
cout<<"不存在账号为:"<<p.id<<"的用户!"<<endl;
MessageBox(0,"不存在此账号","温馨提示",0);
return true;
}
}//if
}//while
}//inputId
//--------------------------------------------
//-----------存款模块-------------------------
//--------------------------------------------
void ck(){
ZH p,p2;
system("cls");
system("color 0A");
bool x=true; //输入要存款的用户id并提示是否重新输入
do{
x=inputId(p);
}while(x);
while(1){
system("cls");
cout<<"请输入你要存入的金额(至少10元):";
fflush(stdin);
fflush(stdin);
cin>>p.money;
fflush(stdin);
if(p.money<10){
MessageBox(0,"存款金额至少10元!请重新输入!","警告",0);
system("cls");
cout<<"存款金额至少10元!请重新输入:";
fflush(stdin);
continue;
}
else
break;
}
fp=fopen("d://zh.txt","r+w");
if(fp==NULL){
cout<<"文件打开失败!";
system("pause");
exit(1);
}
while(!feof(fp)){
fread(&p2,sizeof(ZH),1,fp);
if(!strcmp(p.id,p2.id)){
fseek(fp,-sizeof(ZH),SEEK_CUR); //将文件指针指向当前记录
p2.checkin(p.money); //修改该储户的余额
fwrite(&p2,sizeof(ZH),1,fp); //将修改后的储户信息存入文件之中
fclose(fp); //关闭该文件
system("cls"); //存款成功,打印一下该储户的当前信息
cout<<"存款成功!"<<endl;
cout<<"帐户:"<<p2.id<<"现在余额为:";
cout<<p2.money;
system("pause");
return;
}
}
}