00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __DataClass_H
00022 #define __DataClass_H
00023
00024 #include <iostream>
00025
00026 #include <QString>
00027 #include "sql.h"
00028
00029 class DataClass;
00030 typedef bool (*CompareDC)(const DataClass*, const DataClass*);
00031
00032
00033 class DataClass
00034 {
00035 public:
00036
00037 enum ClassName {DATA_CLASS
00038 ,INSTITUTE_CLASS
00039 ,PROGRAMME_CLASS
00040 ,MODULE_CLASS
00041 ,FACULTY_CLASS
00042 ,DEPARTMENT_CLASS
00043 ,STAFF_CLASS
00044 ,ROOM_CLASS
00045 ,MOD_LEC_ALLOC_CLASS
00046 ,MOD_LEC_ENROL_CLASS
00047 ,TIMESLOT_CLASS
00048 };
00049 protected:
00050 int id;
00051 QString errorMsg;
00052 ClassName p_rtti;
00053 DataClass * parent;
00054 public:
00055 static const int NOT_ON_DB;
00056 static const int NO_PARENT;
00057
00058 public:
00059
00060 DataClass(int pID=NO_PARENT);
00061
00062 virtual ~DataClass(){};
00063
00064
00065
00066 inline int getID() {return id;}
00067 virtual QString getDescription() const =0;
00068 inline DataClass * getParent() {return parent;}
00069 inline int getParentID();
00070
00071 QString getClassName();
00072 inline ClassName rtti() {return p_rtti;}
00073 inline bool isParent(DataClass *);
00074 virtual QString getSortValue()const;
00075
00076
00077 inline QString Dump() {return getClassName() + ": " + getDescription();}
00078
00079
00080 static bool unique(int uniqueSQL);
00081
00082 static bool uniqueTrue(QString, int){return true;}
00083 int save(int insertSQL, int updateSQL, int errorSQL);
00084
00085
00086 static bool dcCompareCI(const DataClass *p1, const DataClass * p2);
00087 static bool dcCompareCS(const DataClass *p1, const DataClass * p2);
00088
00089 protected:
00090
00091 virtual int bindPKey(int preparedSQL){sql::Instance()->bind(0,id,preparedSQL); return 1;}
00092 virtual void bindValues(int preparedSQL, int start)=0;
00093 int insert (int insertSQL, int errorSQL);
00094 int update (int updateSQL, int errorSQL);
00095 virtual int remove (int deleteSQL, int errorSQL);
00096
00097
00098 };
00099
00100 inline bool DataClass::isParent(DataClass * p)
00101 {
00102 if (p == 0)
00103 return false;
00104 if (p == parent)
00105 return true;
00106 return parent->isParent(p);
00107 }
00108
00109 inline int DataClass::getParentID()
00110 {
00111 if (parent == 0)
00112 return NO_PARENT;
00113 else
00114 return parent->getID();
00115 }
00116 #endif