Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

ModLecAlloc.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "ModLecAlloc.h"
00022 
00023 int ModLecAlloc::insertSQL = 0;
00024 int ModLecAlloc::updateSQL = 0;
00025 int ModLecAlloc::deleteSQL = 0;
00026 int ModLecAlloc::addClassSizeSQL = 0;
00027 int ModLecAlloc::addGroupsSQL = 0;
00028 int ModLecAlloc::addLabHoursSQL = 0;
00029 int ModLecAlloc::addLabGroupsSQL = 0;
00030 
00031 int ModLecAlloc::idSQL = 0;
00032 
00033 int ModLecAlloc::errorSQL = 0;
00034 
00035 void ModLecAlloc::PrepareSQL(sql * dbConn)
00036 {
00037         if (dbConn != 0)
00038         {
00039                 insertSQL = dbConn->prepare("basic.mod_lec_alloc_insert",3,*dbConn->useModuleConn());
00040                 updateSQL = dbConn->prepare("basic.mod_lec_alloc_update",3,*dbConn->useModuleConn());
00041                 deleteSQL = dbConn->prepare("basic.mod_lec_alloc_delete",2,*dbConn->useModuleConn());
00042                 addClassSizeSQL = dbConn->prepare("basic.mod_lec_alloc_add_class_size",3,*dbConn->useModuleConn());
00043                 addGroupsSQL =  dbConn->prepare("basic.mod_lec_alloc_add_groups",3,*dbConn->useModuleConn());
00044                 addLabHoursSQL =  dbConn->prepare("basic.mod_lec_alloc_add_lab_hours",3,*dbConn->useModuleConn());
00045                 addLabGroupsSQL =  dbConn->prepare("basic.mod_lec_alloc_add_lab_groups",3,*dbConn->useModuleConn());
00046                 
00047                 idSQL     = dbConn->prepare("basic.mod_lec_alloc_id"    ,2,*dbConn->useModuleConn());
00048                 
00049                 errorSQL = dbConn->prepare("basic.mod_lec_alloc_error",1,*dbConn->useModuleConn());
00050         }
00051 }
00052 
00053 ModLecAlloc::ModLecAlloc()
00054 :DataClass()
00055 {
00056         modObj = 0;
00057         lecObj = 0;
00058         hours  = 0;
00059         semester = 0;
00060         class_size = 0;
00061         groups = 1;
00062         lab_hours = 0;
00063         lab_groups = 0;
00064         p_rtti = MOD_LEC_ALLOC_CLASS;
00065 }
00066 
00067 ModLecAlloc::ModLecAlloc(int onDB
00068                                                                 ,Module * mod
00069                                                                 ,Staff * lec
00070                                                                 ,int hrs
00071                                                                 ,int sem
00072                                                                 ,int c_size
00073                                                                 ,int c_groups
00074                                                                 ,int l_hours
00075                                                                 ,int l_groups)
00076 :DataClass(onDB)
00077 {
00078         modObj = mod;
00079         lecObj = lec;
00080         // Don't calculate the id if it is not yet on the database
00081         // Otherwise calculate the id from the database (hence it will be consistent)
00082         if (id != NOT_ON_DB)
00083         {
00084                 sql::Instance()->setCursor();
00085                 bindPKey(idSQL);
00086                 sql::Instance()->query(idSQL);
00087                 id = sql::Instance()->getFirst(0).toInt();
00088                 sql::Instance()->restoreCursor();
00089         }
00090         hours = hrs;
00091         semester = sem;
00092         class_size = c_size;
00093         groups = c_groups;
00094         lab_hours = l_hours;
00095         lab_groups = l_groups;
00096         parent = mod->getParent();
00097         p_rtti = MOD_LEC_ALLOC_CLASS;
00098 }
00099 
00100 int ModLecAlloc::bindPKey(int preparedSQL)
00101 {
00102         sql::Instance()->bind(0,modObj->getID(),preparedSQL);
00103         sql::Instance()->bind(1,lecObj->getID());
00104         return 2;
00105 }
00106 
00107 void ModLecAlloc::bindValues(int preparedSQL, int start)
00108 {
00109         // Set up the primary key for the Insert
00110         if (start == 0)
00111                 start = bindPKey(preparedSQL);
00112         sql::Instance()->bind(start,hours,preparedSQL);
00113 }
00114 
00115 void ModLecAlloc::updateClassSizeonDB(int classSize)
00116 {
00117         if (classSize == class_size)
00118                 return;
00119         bindPKey(addClassSizeSQL);
00120         sql::Instance()->bind(2,classSize,addClassSizeSQL);
00121         try
00122         {
00123                 sql::Instance()->query();
00124                 id = sql::Instance()->getFirst(0).toInt();
00125                 setClassSize(classSize);
00126         }
00127         catch (sqlE &e){}
00128 }
00129 
00130 void ModLecAlloc::updateGroupsonDB(int classGroups)
00131 {
00132         if (classGroups == groups)
00133                 return;
00134         bindPKey(addGroupsSQL);
00135         sql::Instance()->bind(2,classGroups,addGroupsSQL);
00136         try
00137         {
00138                 sql::Instance()->query();
00139                 id = sql::Instance()->getFirst(0).toInt();
00140                 setGroups(classGroups);
00141         }
00142         catch (sqlE &e){}
00143 }
00144 
00145 void ModLecAlloc::updateLabHoursonDB(int labHours)
00146 {
00147         if (labHours == lab_hours)
00148                 return;
00149         bindPKey(addLabHoursSQL);
00150         sql::Instance()->bind(2,labHours,addLabHoursSQL);
00151         try
00152         {
00153                 sql::Instance()->query();
00154                 id = sql::Instance()->getFirst(0).toInt();
00155                 setLabHours(labHours);
00156         }
00157         catch (sqlE &e){}
00158 }
00159 
00160 void ModLecAlloc::updateLabGroupsonDB(int labGroups)
00161 {
00162         if (labGroups == lab_groups)
00163                 return;
00164         bindPKey(addLabGroupsSQL);
00165         sql::Instance()->bind(2,labGroups,addLabGroupsSQL);
00166         try
00167         {
00168                 sql::Instance()->query();
00169                 id = sql::Instance()->getFirst(0).toInt();
00170                 setLabGroups(labGroups);
00171         }
00172         catch (sqlE &e){}
00173 }

Generated on Thu Apr 6 16:27:16 2006 for time-table by  doxygen 1.4.4