// administrator adds a section bool Administrator::AddSection(const Section &s) const { /*insert a record into the section table*/ QSqlQuery query; query.prepare("insert into Section (courseID, secID, semester, year, capacity, vacancy, building, roomNo, timeSlotID) values (?, ?, ? ,?, ?, ?, ?, ?, ?)"); query.addBindValue(s.GetCourseID()); query.addBindValue(s.GetSecID()); query.addBindValue(s.GetSemester().data()); query.addBindValue(s.GetYear()); query.addBindValue(s.GetCapacity()); query.addBindValue(s.GetVacancy()); query.addBindValue(s.GetBuilding().data()); query.addBindValue(s.GetRoomNo()); query.addBindValue(s.GetTimeSlotID()); if(!query.exec()) return false; return true; }
bool Administrator::UpdateSection(const Section &s) const { /*update the section's capacity*/ QString str; str = "update Section set capacity = "; str += QString::number(s.GetCapacity()); str += " where courseID = "; str += QString::number(s.GetCourseID()); str += " and secID = "; str += QString::number(s.GetSecID()); str += " and semester = '"; str += s.GetSemester().data(); str += "' and year = "; str += QString::number(s.GetYear()); QSqlQuery query; if(!query.exec(str)) return false; /*update the section's building*/ str = "update Section set building = '"; str += s.GetBuilding().data(); str += "' where courseID = "; str += QString::number(s.GetCourseID()); str += " and secID = "; str += QString::number(s.GetSecID()); str += " and semester = '"; str += s.GetSemester().data(); str += "' and year = "; str += QString::number(s.GetYear()); if(!query.exec(str)) return false; /*update the section's roomNo*/ str = "update Section set roomNo = "; str += QString::number(s.GetRoomNo()); str += " where courseID = "; str += QString::number(s.GetCourseID()); str += " and secID = "; str += QString::number(s.GetSecID()); str += " and semester = '"; str += s.GetSemester().data(); str += "' and year = "; str += QString::number(s.GetYear()); if(!query.exec(str)) return false; /*update the section's timeSlotID*/ str = "update Section set timeSlotID = "; str += QString::number(s.GetTimeSlotID()); str += " where courseID = "; str += QString::number(s.GetCourseID()); str += " and secID = "; str += QString::number(s.GetSecID()); str += " and semester = '"; str += s.GetSemester().data(); str += "' and year = "; str += QString::number(s.GetYear()); if(!query.exec(str)) return false; return true; }