00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "TimeSlot.h"
00022
00023 int TimeSlot::insertSQL = 0;
00024 int TimeSlot::updateSQL = 0;
00025 int TimeSlot::deleteSQL = 0;
00026
00027 int TimeSlot::errorSQL = 0;
00028
00029 void TimeSlot::PrepareSQL(sql * dbConn)
00030 {
00031 if (dbConn != 0)
00032 {
00033 insertSQL = dbConn->prepare("basic.timeslot_insert",4,*dbConn->useModuleConn());
00034 deleteSQL = dbConn->prepare("basic.timeslot_delete",3,*dbConn->useModuleConn());
00035
00036 errorSQL = dbConn->prepare("basic.timeslot_error",1,*dbConn->useModuleConn());
00037 }
00038 }
00039
00040 TimeSlot::TimeSlot()
00041 :DataClass()
00042 {
00043 parent = 0;
00044 day = Invalid;
00045 duration =0;
00046 startTime = QTime();
00047 p_rtti = TIMESLOT_CLASS;
00048 }
00049
00050 TimeSlot::TimeSlot(int onDB
00051 ,Institute * inst
00052 ,days theDay
00053 ,int duration
00054 ,QTime startTime)
00055 :DataClass(onDB)
00056 {
00057 parent = inst;
00058
00059 day = theDay;
00060 this->duration = duration;
00061 this->startTime = startTime;
00062 p_rtti = TIMESLOT_CLASS;
00063 }
00064
00065 void TimeSlot::bindValues(int preparedSQL, int start)
00066 {
00067 sql::Instance()->bind(start,day,preparedSQL);
00068 sql::Instance()->bind(++start,startTime.toString("h:mm"));
00069 sql::Instance()->bind(++start,duration);
00070 sql::Instance()->bind(++start,getInstitute()->getID());
00071 }
00072
00073 int TimeSlot::remove(int deleteSQL, int errorSQL)
00074 {
00075 sql::Instance()->bind(0,day,deleteSQL);
00076 sql::Instance()->bind(1,startTime.toString("h:mm"));
00077 sql::Instance()->bind(2,getInstitute()->getID());
00078 try
00079 {
00080 sql::Instance()->query();
00081 id = sql::Instance()->getFirst(0).toInt();
00082 return id;
00083 }
00084 catch (sqlE &e)
00085 {
00086 return -1;
00087 }
00088 }
00089
00090 QString TimeSlot::getDOW()const
00091 {
00092 switch (day)
00093 {
00094 case Invalid:
00095 return "Invalid";
00096 case Monday:
00097 return "Monday";
00098 case Tuesday:
00099 return "Tuesday";
00100 case Wednesday:
00101 return "Wednesday";
00102 case Thursday:
00103 return "Thursday";
00104 case Friday:
00105 return "Friday";
00106 case Saturday:
00107 return "Saturday";
00108 case Sunday:
00109 return "Sunday";
00110 }
00111 return "Invalid";
00112 }
00113
00114 TimeSlot::days TimeSlot::getDays(QString DOW)
00115 {
00116 if (DOW == "Monday")
00117 return Monday;
00118 if (DOW == "Tuesday")
00119 return Tuesday;
00120 if (DOW == "Wednesday")
00121 return Wednesday;
00122 if (DOW == "Thursday")
00123 return Thursday;
00124 if (DOW == "Friday")
00125 return Friday;
00126 if (DOW == "Saturday")
00127 return Saturday;
00128 if (DOW == "Sunday")
00129 return Sunday;
00130 return Invalid;
00131 }
00132
00133 QString TimeSlot::getTimeRange()
00134 {
00135 QTime finishTime = startTime.addSecs(duration*60);
00136 return startTime.toString("H:mm") + " - " + finishTime.toString("H:mm");
00137 }
00138
00139 QString TimeSlot::getSortValue()
00140 {
00141 return QString::number(getInstitute()->getID())
00142 + "~"
00143 + QString::number(day)
00144 + "~"
00145 + startTime.toString("hh:mm");
00146 }
00147