int login_flag =0;
int passTry =0;
Admin admin;
User TmpStudent;
int exit_flag =0;
while(!login_flag)
{
cout<<"-----学生成绩管理系统-----"<<endl;
cout<<"-----------------------"<<endl;
cout<<"---------登录界面--------"<<endl;
cout<<"–请输入ID(输入0退出程序)–"<<endl;
string TmpUserNo;
cin>>TmpUserNo;
if(TmpUserNo=="0")
return 0;
cout<<"--------请输入密码--------"<<endl;
string TmpPasswd;
cin>>TmpPasswd;
if(admin.IDVertify(TmpUserNo,TmpPasswd))
{
TmpStudent.setUser(TmpUserNo);
login_flag=1;
}
else
{
passTry++;
}
if(passTry==5)
{
cout<<"您尝试的次数过多,请详询管理员"<<endl;
return 0;
}
}
void User::setUser(string newNo){
StudentNo = newNo ;
sscore = nullptr;
sstail = nullptr;
DB database;
sprintf(database.mquery, “SELECT * FROM users WHERE id=’%s’”, StudentNo.c_str());
mysql_query(database.conn, database.mquery);
database.res = mysql_use_result(database.conn);
if (database.res) {
database.row = mysql_fetch_row(database.res);
if (database.row) {
sname = database.row[1];
UserType = atoi(database.row[2]);
spassword = database.row[3];
} else {
cout<<“用户不存在!”<<endl;
UserType = 0;
return;
}
}
mysql_free_result(database.res);
sprintf(database.mquery, “SELECT * FROM score WHERE stuid=’%s’”, StudentNo.c_str());
mysql_query(database.conn, database.mquery);
database.res = mysql_use_result(database.conn);
int headflag = 1;
if(database.res) {
while((database.row = mysql_fetch_row(database.res))) {
Score *tmpscore;
tmpscore = new Score(StudentNo, database.row[0], atoi(database.row[2]));
if (headflag) {
tmpscore->head = tmpscore;
tmpscore->next = tmpscore;
sscore = tmpscore;
sstail = tmpscore;
headflag = 0;
} else {
tmpscore->head = sscore;
tmpscore->next = sscore;
sstail->next = tmpscore;
sstail = tmpscore;
}
}
}
}