cleaned all trailing white space from source files.
[sdk] / samples / db / MedDB / med.ec
1 #ifdef ECERE_STATIC
2 public import static "ecere"
3 public import static "EDA"
4 #else
5 public import "ecere"
6 public import "EDA"
7 #endif
8
9 class ConcentrationEditor : Window
10 {
11    DataBox formEditor;
12    DataBox amountEditor;
13    DataBox unitEditor;
14 }
15
16 default:
17 static void UnusedFunction()
18 {
19    int a;
20    a.OnGetString(0,0,0);
21 }
22 extern int __ecereVMethodID_class_OnSaveEdit;
23 extern int __ecereVMethodID_class_OnGetString;
24 private:
25
26 class Concentration
27 {
28 public:
29    Form form;
30    double amount;
31    Unit unit;
32
33    bool Window::NotifyChanged(bool closed)
34    {
35       master.master.modifiedDocument = true;
36       return true;
37    }
38
39    void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
40    {
41       char string[1024];
42       char amountString[256];
43
44       // TODO: FIX THIS
45       //amount.OnGetString(amountString, null, null);
46       if(!this)
47       {
48          sprintf(string, "(Click here to add)");
49       }
50       else
51       {
52          class(double)._vTbl[__ecereVMethodID_class_OnGetString](class(double), &amount, amountString, null, null);
53          if(form)
54          {
55             String formName = form.name;
56             String unitName = unit.name;
57             sprintf(string, "%s: %s %s", formName ? formName : "", amountString, unitName ? unitName : "");
58             delete formName;
59             delete unitName;
60          }
61          else
62             sprintf(string, "(Click here to add)");
63       }
64       surface.WriteText(x, y, string, strlen(string));
65    }
66
67    Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
68    {
69       if(this != null)
70       {
71          ConcentrationEditor editor
72          {
73             dataBox,
74             borderStyle = 0,
75             anchor = { 0, 0, 0, 0 };
76          };
77
78          editor.formEditor = { editor, type = class(Form), data = &form, anchor = { top = 0, bottom = 0, left = 0, right = 0.66 }, NotifyChanged = NotifyChanged };
79          editor.amountEditor = { editor, type = class(double), data = &amount, anchor = { top = 0, bottom = 0, left = 0.34, right = 0.33 }, NotifyChanged = NotifyChanged };
80          editor.unitEditor = { editor, type = class(Unit), data = &unit, anchor = { top = 0, bottom = 0, left = 0.66, right = 0 }, NotifyChanged = NotifyChanged };
81          editor.Create();
82          return editor;
83       }
84       return null;
85    }
86
87    bool OnSaveEdit(ConcentrationEditor editor, void * object)
88    {
89       Concentration _this = this;
90       if(this && !_this.form)
91       {
92          delete _this;
93          this = null;
94          return false;
95       }
96       else
97          editor.amountEditor.SaveData();
98       return false;
99    }
100
101    void OnFree() { }    // WE DON'T WANT THE LISTBOX TO DELETE THE INSTANCES...
102 };
103
104 struct FormConcentrations : DataList
105 {
106    class_property(type) = "Concentration";
107 };
108
109 dbtable "Restrictions" Restriction
110 {
111    Restriction id    "id";
112    String      name  "name";
113 };
114
115 dbtable "DrugClasses" DrugClass
116 {
117    DrugClass id   "id";
118    String name "name";
119 };
120
121 dbtable "SubClasses" SubClass
122 {
123    SubClass   id    "id";
124    String     name  "name";
125 };
126
127 dbtable "Forms" Form
128 {
129    Form    id   "id";
130    String   name "name";
131 };
132
133 dbtable "Units" Unit
134 {
135    Unit    id    "id";
136    String   name  "name";
137 };
138
139 dbtable "Drugs" Drug
140 {
141    Drug                 id                  "id";
142    String               genericName         "Generic Name";
143    StringList           commercialNames     "Commercial Names";
144    Restriction          restriction         "Restriction";
145    SubClass             subClass            "Sub Class";
146    DrugClass            drugClass           "Class";
147    FormConcentrations   formConcentrations  "Form and Concentrations";
148 };
149
150 DataSource ds;
151 Database db;
152
153 class MyApp : GuiApplication
154 {
155    MyApp()
156    {
157       RandomSeed((uint)(GetTime() * 1000));
158       SetDefaultIdField("id");
159       SetDefaultNameField("name");
160       ds = DataSource { driver = "EDB" };
161       db = database_open(ds, "med");
162    }
163    ~MyApp()
164    {
165       delete db;
166       delete ds;
167    }
168 }