00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef DBSTRUCTURE_H
00024 #define DBSTRUCTURE_H
00025
00026 #include <QString>
00027 #include <QVariant>
00028
00048 template<typename T>
00049 class BaseEntry
00050 {
00051 public:
00053 void setData(int index, QVariant value) {
00054 if (int *data = static_cast<T*>(this)->dataInt(index))
00055 *data = value.toInt();
00056 else if (QString *data = static_cast<T*>(this)->dataString(index))
00057 *data = value.toString();
00058 }
00059 };
00060
00061 enum
00062 {
00063 ACCOUNT_ENTRY_FIELDS = 4,
00064 CUSTOMER_ENTRY_FIELDS = 7,
00065 CUSTOMER_DIAGNOSTIC_FIELDS = 3,
00066 CUSTOMER_SYMPTOM_FIELDS = 3,
00067 CUSTOMER_PRESCRIPTION_FIELDS = 5,
00068 CUSTOMER_URGENCY_FIELDS = 1,
00069 GROUP_ENTRY_FIELDS = 2,
00070 INVOICE_ENTRY_FIELDS = 4,
00071 MEDICINE_ENTRY_FIELDS = 4,
00072 MEDICINELEVEL_ENTRY_FIELDS = 2,
00073 RADIO_ENTRY_FIELDS = 7,
00074 SCAN_ENTRY_FIELDS = 6
00075 };
00076
00084 struct AccountEntry : public BaseEntry<AccountEntry>
00085 {
00086 int id;
00087 QString name;
00088 QString password;
00089 int level;
00092 int *dataInt(int index) {
00093 switch (index) {
00094 case 0: return &id;
00095 case 3: return &level;
00096 default: return NULL;
00097 }
00098 }
00100 QString *dataString(int index) {
00101 switch (index) {
00102 case 1: return &name;
00103 case 2: return &password;
00104 default: return NULL;
00105 }
00106 }
00107 };
00108
00116 struct CustomerEntry : public BaseEntry<CustomerEntry>
00117 {
00118 int id;
00119 QString name;
00120 int gender;
00121 int birthyear;
00122 QString address;
00123 int canGoHome;
00124 int isDead;
00127 int *dataInt(int index) {
00128 switch (index) {
00129 case 0: return &id;
00130 case 2: return &gender;
00131 case 3: return &birthyear;
00132 case 5: return &canGoHome;
00133 case 6: return &isDead;
00134 default: return NULL;
00135 }
00136 }
00138 QString *dataString(int index) {
00139 switch (index) {
00140 case 1: return &name;
00141 case 4: return &address;
00142 default: return NULL;
00143 }
00144 }
00145 };
00146
00154 struct CustomerDiagnosticEntry : public BaseEntry<CustomerDiagnosticEntry>
00155 {
00156 int customer_id;
00157 int date;
00158 QString diagnostic;
00161 int *dataInt(int index) {
00162 switch (index) {
00163 case 0: return &customer_id;
00164 case 1: return &date;
00165 default: return NULL;
00166 }
00167 }
00169 QString *dataString(int index) {
00170 switch (index) {
00171 case 2: return &diagnostic;
00172 default: return NULL;
00173 }
00174 }
00175 };
00176
00184 struct CustomerPrescriptionEntry : public BaseEntry<CustomerPrescriptionEntry>
00185 {
00186 int id;
00187 int customer_id;
00188 int medicine_id;
00189 int date;
00190 QString duration;
00193 int *dataInt(int index) {
00194 switch (index) {
00195 case 0: return &id;
00196 case 1: return &customer_id;
00197 case 2: return &medicine_id;
00198 case 3: return &date;
00199 default: return NULL;
00200 }
00201 }
00203 QString *dataString(int index) {
00204 switch (index) {
00205 case 4: return &duration;
00206 default: return NULL;
00207 }
00208 }
00209 };
00210
00218 struct CustomerSymptomEntry : public BaseEntry<CustomerSymptomEntry>
00219 {
00220 int customer_id;
00221 int date;
00222 QString symptom;
00225 int *dataInt(int index) {
00226 switch (index) {
00227 case 0: return &customer_id;
00228 case 1: return &date;
00229 default: return NULL;
00230 }
00231 }
00233 QString *dataString(int index) {
00234 switch (index) {
00235 case 2: return &symptom;
00236 default: return NULL;
00237 }
00238 }
00239 };
00240
00248 struct CustomerUrgencyEntry : public BaseEntry<CustomerUrgencyEntry>
00249 {
00250 int customer_id;
00253 int *dataInt(int index) {
00254 switch (index) {
00255 case 0: return &customer_id;
00256 default: return NULL;
00257 }
00258 }
00260 QString *dataString(int ) {
00261 return NULL;
00262 }
00263 };
00264
00272 struct GroupEntry : public BaseEntry<GroupEntry>
00273 {
00274 int id;
00275 QString name;
00278 int *dataInt(int index) {
00279 switch (index) {
00280 case 0: return &id;
00281 default: return NULL;
00282 }
00283 }
00285 QString *dataString(int index) {
00286 switch (index) {
00287 case 1: return &name;
00288 default: return NULL;
00289 }
00290 }
00291 };
00292
00300 struct InvoiceEntry : public BaseEntry<InvoiceEntry>
00301 {
00302 int id;
00303 int customer_id;
00304 int pay_date;
00305 QString credit_card_number;
00308 int *dataInt(int index) {
00309 switch (index) {
00310 case 0: return &id;
00311 case 1: return &customer_id;
00312 case 2: return &pay_date;
00313 default: return NULL;
00314 }
00315 }
00317 QString *dataString(int index) {
00318 switch (index) {
00319 case 3: return &credit_card_number;
00320 default: return NULL;
00321 }
00322 }
00323 };
00324
00332 struct MedicineEntry : public BaseEntry<MedicineEntry>
00333 {
00334 int id;
00335 int level;
00336 QString name;
00337 QString description;
00340 int *dataInt(int index) {
00341 switch (index) {
00342 case 0: return &id;
00343 case 1: return &level;
00344 default: return NULL;
00345 }
00346 }
00348 QString *dataString(int index) {
00349 switch (index) {
00350 case 2: return &name;
00351 case 3: return &description;
00352 default: return NULL;
00353 }
00354 }
00355 };
00356
00364 struct MedicineLevelEntry : public BaseEntry<MedicineLevelEntry>
00365 {
00366 int id;
00367 QString name;
00370 int *dataInt(int index) {
00371 switch (index) {
00372 case 0: return &id;
00373 default: return NULL;
00374 }
00375 }
00377 QString *dataString(int index) {
00378 switch (index) {
00379 case 1: return &name;
00380 default: return NULL;
00381 }
00382 }
00383 };
00384
00392 struct RadioEntry : public BaseEntry<RadioEntry>
00393 {
00394 int id;
00395 int customer_id;
00396 int group_id;
00397 int x_parts;
00398 int y_parts;
00399 QString name;
00400 QString format;
00403 int *dataInt(int index) {
00404 switch (index) {
00405 case 0: return &id;
00406 case 1: return &customer_id;
00407 case 2: return &group_id;
00408 case 3: return &x_parts;
00409 case 4: return &y_parts;
00410 default: return NULL;
00411 }
00412 }
00414 QString *dataString(int index) {
00415 switch (index) {
00416 case 5: return &name;
00417 case 6: return &format;
00418 default: return NULL;
00419 }
00420 }
00421 };
00422
00430 struct ScanEntry : public BaseEntry<ScanEntry>
00431 {
00432 int id;
00433 int customer_id;
00434 int group_id;
00435 int parts;
00436 QString name;
00437 QString format;
00440 int *dataInt(int index) {
00441 switch (index) {
00442 case 0: return &id;
00443 case 1: return &customer_id;
00444 case 2: return &group_id;
00445 case 3: return &parts;
00446 default: return NULL;
00447 }
00448 }
00450 QString *dataString(int index) {
00451 switch (index) {
00452 case 4: return &name;
00453 case 5: return &format;
00454 default: return NULL;
00455 }
00456 }
00457 };
00458
00459 #endif // DBSTRUCTURE_H