📄 entrance.cpp
字号:
#include "Entrance.h"
#include "Student.h"
#include "Admin.h"
extern myIO io;
void IntoEntrance(Database& db)
{
String choice;
String id;
while (true)
{
io << "1. Register";
io << "2. Login(if you have registered)";
io << "3. Quit";
io << "your choice:";
io >> choice;
while (choice != "1" && choice != "2" && choice != "3")
{
io << "your choice between 1, 2 and 3";
io >> choice;
}
if (choice == "1")
{
id = IntoRegister(db);
IntoStudent(db, id);
}
else if (choice == "2")
IntoLogin(db);
else
return;
}
}
String IntoRegister(Database& db)
{
String str;
Recordset rs(&db);
while (true)
{
rs.Open();
rs.m_ParamNum = 7;
rs.m_Param = new String[7];
while (true)
{
io << "your ID(<= 10 char):";
io >> rs.m_Param[0];
io << "password(<= 45 char):";
rs.m_Param[4] = io.getIn();
io << "password again:";
str = io.getIn();
if (str == rs.m_Param[4])
break;
io << "password changed!";
io << "input again...";
}
io << "name:";
io >> rs.m_Param[1];
io << "college:";
io >> rs.m_Param[2];
io << "major:";
io >> rs.m_Param[3];
io << "class:";
io >> rs.m_Param[5];
io << "extra info:";
io >> rs.m_Param[6];
rs.m_Table = "student";
if (rs.Add())
{
io << "success";
io << "login...";
return rs.m_Param[0];
}
io << "ID" + rs.m_Param[0] + "has been used";
io << "input again...";
}
}
void IntoLogin(Database& db)
{
String type;
String choice, id, pass;
while (true)
{
io << "you are ...";
io << "1. admin----2. student----3. back";
io >> choice;
while (choice != "1" && choice != "2" && choice != "3")
{
io << "your choice is between 1, 2 and 3";
io >> choice;
}
if (choice == "1")
type = "admin";
else if (choice == "2")
type = "student";
else
return;
io << "ID:";
io >> id;
io << "Password:";
pass = io.getIn();
Recordset rs(&db);
rs.m_Where = "id='" + id + "'";
rs.m_ParamNum = 1;
rs.m_Param = new String[1];
rs.m_Param[0].Set(46);
if (!rs.Open("select pass from " + type) || !rs.m_Param[0].reGetlenth() || rs.m_Param[0] != pass)
io << "Sorry, we don't have such guy";
else
{
if (type == "student")
choice = IntoStudent(db, id);
else if (type == "admin")
choice = IntoAdmin(db, id);
if (choice == "0")
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -