bugdb.cpp

来自「一个功能强大的内存数据库源代码,c++编写,有详细的注释」· C++ 代码 · 共 2,061 行 · 第 1/5 页

CPP
2,061
字号
	   "</SELECT><BR><INPUT TYPE=submit NAME=\"action\" VALUE=\"Select\">";    } else { 	con << TAG << EMPTY_LIST;    }    con << TAG << "</FORM>";    mainMenuReference(con);    return true;}bool removeBugForm(WWWconnection& con){    con << TAG << 	HTML_HEAD "<TITLE>Remove a bug</TITLE></HEAD>"	BODY	"<H2>Remove a bug</H2>"	"<FORM METHOD=POST ACTION=\"" << con.getStub() << "\">"	"<INPUT TYPE=HIDDEN NAME=\"socket\" VALUE=\"" << con.getAddress() << 	"\"><INPUT TYPE=hidden NAME=\"page\" VALUE=\"removeBug\">"	"<INPUT TYPE=hidden NAME=\"myself\" VALUE=\"" << con.get("myself") << 	"\"><SELECT SIZE=15 NAME=\"bug\">";    if (bugs.select() != 0) { 	print(con, bugs);	con << TAG << "</SELECT><BR><INPUT TYPE=submit VALUE=\"Remove\">";    } else { 	con << TAG << EMPTY_LIST;    }    con << TAG << "</FORM>";    mainMenuReference(con);    return true;}bool changePasswordForm(WWWconnection& con){    con << TAG << 	HTML_HEAD "<TITLE>Change password</TITLE></HEAD>"	BODY	"<H2>Change password</H2>"	"<FORM METHOD=POST ACTION=\"" << con.getStub() << "\">"	"<INPUT TYPE=HIDDEN NAME=\"socket\" VALUE=\"" << con.getAddress() << 	"\"><INPUT TYPE=hidden NAME=\"page\" VALUE=\"changePassword\">"	"<INPUT TYPE=hidden NAME=\"myself\" VALUE=\"" << con.get("myself") << 	"\"><INPUT TYPE=hidden NAME=\"name\" VALUE=\"" << con.get("name") << 	"\"><TABLE>"	"<TR><TH ALIGN=LEFT>New password:</TH>"	"<TD><INPUT TYPE=password NAME=\"password\" SIZE=20</TD></TR>"	"<TR><TH ALIGN=LEFT>Re-type password:</TH>"	"<TD><INPUT TYPE=password NAME=\"password2\" SIZE=20</TD></TR>"	"</TABLE><P>"	"<INPUT TYPE=submit VALUE=\"Change\">&nbsp;"	"<INPUT TYPE=reset VALUE=\"Reset\">"	"</FORM>";    con << TAG << "</FORM>";    mainMenuReference(con);    return true;}	bool shutdown(WWWconnection& con){    con << TAG << 	HTML_HEAD "<TITLE>BUGDB message</TITLE></HEAD><BODY>"	"<H1>BUGDB server is terminated</H1></BODY></HTML>";    return false;}bool userForm(WWWconnection& con);bool userGroupForm(WWWconnection& con);bool softwareForm(WWWconnection& con);bool addUser(WWWconnection& con){    Person person;    person.sName = key = con.get("name");       person.sEmailAddress = con.get("email");    person.sPassword = "";    person.status = Person::isUser;    person.nReports = 0;    if (persons.select(qPerson) != 0) { 	error(con, "Person already exists");	return true;    }    insert(person);    return userForm(con);}bool addEngineer(WWWconnection& con){    Person person;    person.sName = key = con.get("name");       person.sEmailAddress = con.get("email");    person.sPassword = "";    person.status = Person::isEngineer;    person.nReports = 0;    if (persons.select(qPerson) != 0) { 	error(con, "Person already exists");	return true;    }    insert(person);    return userForm(con);}bool removePerson(WWWconnection& con){    key = con.get("name");    if (key == NULL) { 	error(con, "No person was selected");	return true;    }    if (persons.select(qPerson) == 0) { 	error(con, "No such person");    } else if (persons->nReports > 0 	       || persons->setReportedBugs.length() > 0)     {	error(con, "It is not possible to delete person who is author "	      "of existed bug reports");    } else {	persons.remove();	message(con, "Person is removed");    }    return true;}bool addSoftware(WWWconnection& con){    Software software;    Version  version;    software.sName = key = con.get("software");    if (products.select(qSoftware) != 0) { 	error(con, "Software product already exists");	return true;    }    char* versionStr = con.get("version");    if (sscanf(versionStr, "%d.%d", &version.majorVersionNumber, 	       &version.minorVersionNumber) != 2)     { 	error(con, "Bad version number (MAJOR.MINOR expected)");	return true;    }      version.sComment = con.get("comment");    version.sLabel = con.get("label");    version.released = dbDateTime::current();    software.pVersions = insert(version);    insert(software);    con.addPair("action", "Select");    return softwareForm(con);}		bool removeSoftware(WWWconnection& con){    key = con.get("software");    if (products.select(qSoftware) == 0) { 	error(con, "No such software product");	return true;    }    if (products->setBugs.length() != 0) { 	error(con, "Can not remove software with non-empty reported bug list");	return true;    }    products.remove();    message(con, "Software product is removed");    return true;}bool removeBug(WWWconnection& con){    char* bug = con.get("bug");    if (bug == NULL) { 	error(con, "No bug was selected");    } else { 	bugId = atoi(bug);	if (bugs.select(qBug) == 0) { 	    error(con, "No such bug");	} else { 	    if (bugs->pReportHistory != null ||		bugs->pWorkArounds != null)	    {		error(con, "Can not remove bug with existed reports");		return true;	    }	    bugs.remove();	    message(con, "Bug is removed");	}    }    return true;}bool changePassword(WWWconnection& con){    char* password = con.get("password");    char* password2 = con.get("password2");    if (strcmp(password, password2) != 0) { 	error(con, "Passwords are not equal");    } else { 	key = con.get("name");	if (persons.select(qPerson) == 0) { 	    error(con, "No such person");	} else { 	    persons->sPassword = password;	    persons.update();	    message(con, "Password changed");	}    }    return true;}bool updatePerson(WWWconnection& con){    char* name = con.get("name");    key = name;    if (persons.select(qPerson) == 0) { 	error(con, "No such person");	return true;    } else { 	char* newName = con.get("newname");	char* eMail = con.get("email");	if (eMail != NULL) { 	    persons->sEmailAddress = eMail;	}	if (newName != NULL) { 	    persons->sName = newName;	    con.addPair("name", newName);	    if (strcmp(name, con.get("myself")) == 0) { 		con.addPair("myself", newName);	    }	}	persons.update();    }    return userForm(con);}bool login(WWWconnection& con){    char* name = con.get("name");    key = con.get("name");    if (persons.select(qPerson) == 0) { 	error(con, "No such person");	return true;    }     if (!persons->checkPassword(con.get("password"))) { 	error(con, "Incorrect password");	return true;    }     con.addPair("myself", name);        return userForm(con);}bool bugQueryForm(WWWconnection& con){    int i;    con << TAG << 	HTML_HEAD "<TITLE>Query to locate bug</TITLE></HEAD>"	BODY	"<H2>Bug query</H2>"	"<FORM METHOD=POST ACTION=\"" << con.getStub() << "\">"	"<INPUT TYPE=HIDDEN NAME=\"socket\" VALUE=\"" << con.getAddress() << 	"\"><INPUT TYPE=hidden NAME=\"page\" VALUE=\"bugQuery\">"	"<INPUT TYPE=hidden NAME=\"myself\" VALUE=\"" << con.get("myself") << 	"\"><TABLE>"	"<TR><TH ALIGN=LEFT>Description substring:</TH>"	"<TD><INPUT TYPE=text NAME=\"summary\" SIZE=30</TD></TR>"	"<TR><TH ALIGN=LEFT>Category:</TH>"	"<TD><SELECT NAME=\"category\" SIZE=1>"	"<OPTION VALUE=0 SELECTED></OPTION>";    for (i = 1; eCATEGORY_STRING[i] != NULL; i++) { 	con << TAG << "<OPTION VALUE=" << i << ">"	    << eCATEGORY_STRING[i] << "</OPTION>";    }    con << TAG << "</SELECT></TD></TR>"	"<TR><TH ALIGN=LEFT>Severity:</TH>"	"<TD><SELECT NAME=\"severity\" SIZE=1>"	"<OPTION VALUE=0 SELECTED></OPTION>";    for (i = 1; eSEVERITY_STRING[i] != NULL; i++) { 	con << TAG << "<OPTION VALUE=" << i << ">"	    << eSEVERITY_STRING[i] << "</OPTION>";    }    con << TAG << "</SELECT></TD></TR>"	"<TR><TH ALIGN=LEFT>Fixing priority:</TH>"	"<TD><SELECT NAME=\"priority\" SIZE=1>"	"<OPTION VALUE=0 SELECTED></OPTION>";    for (i = 1; eFIXING_PRIORITY_STRING[i] != NULL; i++) { 	con << TAG << "<OPTION VALUE=" << i << ">"	    << eFIXING_PRIORITY_STRING[i] << "</OPTION>";    }    con << TAG << 	"</SELECT></TD></TR>"	"<TR><TH ALIGN=LEFT>Platform:</TH>"	"<TD><INPUT TYPE=text NAME=\"platform\"</TD></TR>"	"<TR><TH ALIGN=LEFT>OS</TH>"	"<TD><INPUT TYPE=text NAME=\"os\"</TD></TR>"	"<TR><TH ALIGN=LEFT>Software:</TH>"	"<TD><INPUT TYPE=text NAME=\"software\"</TD></TR>"	"<TR><TH ALIGN=LEFT>Assigned to:</TH>"	"<TD><INPUT TYPE=text NAME=\"engineer\"</TD></TR>"	"<TR><TH ALIGN=LEFT>Reported by:</TH>"	"<TD><INPUT TYPE=text NAME=\"user\"</TD></TR>"	"<TR><TH ALIGN=LEFT>Major version number:</TH>"	"<TD>from <INPUT TYPE=text NAME=\"minmajor\" SIZE=4>"	" to <INPUT TYPE=text NAME=\"maxmajor\" SIZE=4</TD></TR>"	"<TR><TH ALIGN=LEFT>Minor version number:</TH>"	"<TD>from <INPUT TYPE=text NAME=\"minminor\" SIZE=4</TD>"	" to <INPUT TYPE=text NAME=\"maxminor\" SIZE=4</TD></TR></TABLE><P>"	"<INPUT TYPE=submit VALUE=\"Search\">&nbsp;"	"<INPUT TYPE=reset VALUE=\"Reset\">"	"</FORM></BODY></HTML>";    return true;}bool bugQuery(WWWconnection& con) {    char* p;    dbQuery query;    query.reset();    p = con.get("software");    if (*p != '\0') { 	query.add("pSoftware.sName like").add(p);    }    int4 category = atoi(con.get("category"));    if (category != 0) { 	query.And("eCategory=").add(category);   }    int4 severity = atoi(con.get("severity"));    if (severity != 0) { 	query.And("eSeverity=").add(severity);    }    int4 priority = atoi(con.get("priority"));    if (priority != 0) { 	query.And("eFixingPriority=").add(priority);    }    p = con.get("os");    if (*p != '\0') { 	query.And("sOperatingSystem like").add(p);    }    p = con.get("platform");    if (*p != '\0') { 	query.And("sHardwarePlatform like").add(p);    }    p = con.get("engineer");    if (*p != '\0') { 	query.And("pAssignedTo is not null and pAssignedTo.sName like").add(p);    }    p = con.get("user");    if (*p != '\0') { 	query.And("pReportedBy.sName like").add(p);    }    p = con.get("summary");    if (*p != '\0') { 	query.And("sOneLineSummary like").add(p);    }    p = con.get("minmajor");    int minMajorVersionNumber = (*p == '\0') ? 0 : atoi(p);    p = con.get("maxmajor");    int maxMajorVersionNumber = (*p == '\0') ? INT_MAX : atoi(p);    p = con.get("minminor");    int minMinorVersionNumber = (*p == '\0') ? 0 : atoi(p);    p = con.get("maxminor");    int maxMinorVersionNumber = (*p == '\0') ? INT_MAX : atoi(p);    if (minMajorVersionNumber != 0) { 	if (maxMajorVersionNumber != INT_MAX) { 	    query.And("pVersion.majorVersionNumber between")		.add(minMajorVersionNumber)		.add("and").add(maxMajorVersionNumber);	} else { 	    query.And("pVersion.majorVersionNumber>=")		.add(minMajorVersionNumber);	}    } else if (maxMajorVersionNumber != INT_MAX) {		query.And("pVersion.majorVersionNumber<=").add(maxMajorVersionNumber);    }    if (minMinorVersionNumber != 0) { 	if (maxMinorVersionNumber != INT_MAX) { 	    query.And("pVersion.minorVersionNumber between")		.add(minMinorVersionNumber)		.add("and").add(maxMinorVersionNumber);	} else { 	    query.And("pVersion.minorVersionNumber>=")		.add(minMinorVersionNumber);	}    } else if (maxMinorVersionNumber != INT_MAX) {		query.And("pVersion.minorVersionNumber<=").add(maxMinorVersionNumber);    }    con << TAG << 	HTML_HEAD "<TITLE>List of selected bugs</TITLE></HEAD>"	BODY	"<H2>Selected bugs</H2>"	"<FORM METHOD=POST ACTION=\"" << con.getStub() << "\">"	"<INPUT TYPE=HIDDEN NAME=\"socket\" VALUE=\"" << con.getAddress() << 	"\"><INPUT TYPE=hidden NAME=\"page\" VALUE=\"bugForm\">"	"<INPUT TYPE=hidden NAME=\"myself\" VALUE=\"" << con.get("myself") << 	"\"><SELECT NAME=\"bug\" SIZE=20>";    if (bugs.select(query) != 0) { 	print(con, bugs);	con << TAG << 	   "</SELECT><BR><INPUT TYPE=submit NAME=\"action\" VALUE=\"Select\">";    } else { 	con << TAG << EMPTY_LIST;    }    con << TAG << "</FORM>";    mainMenuReference(con);    return true;}bool userForm(WWWconnection& con){    char* name = con.get("name");    if (name == NULL) { 	error(con, "No person was selected");	return true;    }    char* myself = con.get("myself");    key = myself;    if (persons.select(qPerson) == 0) { 	error(con, "Person authorization failed");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?