wip II
[sdk] / samples / db / MedDB / mainForm.ec
1 import "ecere"
2 import "med"
3
4 extern int __ecereVMethodID_class_OnCompare;
5
6 class MainForm : Window
7 {
8    tabCycle = true;
9
10    text = "Drugs Database";
11    background = activeBorder;
12    borderStyle = sizable;
13    hasMaximize = true;
14    hasMinimize = true;
15    hasClose = true;
16    size = { 640, 480 };
17
18    Window            tabButtons { this, tabCycle = true, background = activeBorder, size = { h = 24 }, anchor = { bottom = 5, left = 10, right = 10 } };
19    MedTesting        testForm { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 } };
20    UnitesEditor      untEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
21    FormesEditor      frmEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
22    SubClassesEditor sclEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
23    ClassesEditor     clsEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
24    RestrictionEditor rstEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
25    MedEditor         medEditor { this, anchor = { left = 0, top = 0, right = 0, bottom = 30 }, autoCreate = false };
26
27    Window curView;
28    Button curButton;
29
30    curView = testForm;
31    curButton = tabTst;
32
33    bool NotifyClicked(Button button, int x, int y, Modifiers mods)
34    {
35       if(curView.Destroy(0))
36       {
37          curButton.checked = false;
38          button.checked = true;
39          curView = (Window)button.id;
40          curView.Create();
41          curButton = button;
42       }
43       return true;
44
45    }
46
47    Button tabTst { tabButtons, checked = true, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 6 * 80 },         text = "Test",  id = (int64)testForm, NotifyClicked = NotifyClicked };
48    Button tabUnt { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 5 * 80 },         text = "Units",  id = (int64)untEditor, NotifyClicked = NotifyClicked };
49    Button tabFrm { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 4 * 80 }, text = "Forms",        id = (int64)frmEditor, NotifyClicked = NotifyClicked };
50    Button tabScl { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 3 * 80 }, text = "Sub-Classes",  id = (int64)sclEditor, NotifyClicked = NotifyClicked };
51    Button tabCls { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 2 * 80 }, text = "Classes",       id = (int64)clsEditor, NotifyClicked = NotifyClicked };
52    Button tabRes { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 1 * 80 }, text = "Restrictions",  id = (int64)rstEditor, NotifyClicked = NotifyClicked };
53    Button tabMed { tabButtons, master = this, stayDown = true, size = { 70, 20 }, anchor = { right = 10 + 0 * 80},  text = "Drugs",   id = (int64)medEditor, NotifyClicked = NotifyClicked };
54 }
55
56 class RestrictionEditor : Window
57 {
58    tabCycle = true;
59
60    ListSection list { this, editor = editor, fldName = dbfield("Restrictions", name), table = dbtable("Restrictions"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
61    EditSection editor { this, table = dbtable("Restrictions"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
62
63    FieldDataBox boxName { editor = editor, field = dbfield("Restrictions", name), text = "Name", size = { 174, 20 }, position = { 20, 32 } };
64    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxName };
65 };
66
67 class ClassesEditor : Window
68 {
69    tabCycle = true;
70    background = activeBorder;
71
72    ListSection list { this, editor = editor, fldName = dbfield("DrugClasses", name), table = dbtable("DrugClasses"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
73    EditSection editor { this, table = dbtable("DrugClasses"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
74
75    FieldDataBox boxName { editor = editor, field = dbfield("DrugClasses", name), text = "Name", size = { 174, 20 }, position = { 20, 32 } };
76    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxName };
77 };
78
79 class SubClassesEditor : Window
80 {
81    tabCycle = true;
82    background = activeBorder;
83    ListSection list { this, editor = editor, fldName = dbfield("SubClasses", name), table = dbtable("SubClasses"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
84    EditSection editor { this, table = dbtable("SubClasses"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
85
86    FieldDataBox boxName { editor = editor, field = dbfield("SubClasses", name), text = "Name", size = { 174, 20 }, position = { 20, 32 } };
87    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxName };
88 };
89
90 class FormesEditor : Window
91 {
92    tabCycle = true;
93    background = activeBorder;
94
95    ListSection list { this, editor = editor, fldName = dbfield("Forms", name), table = dbtable("Forms"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
96    EditSection editor { this, table = dbtable("Forms"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
97
98    FieldDataBox boxName { editor = editor, field = dbfield("Forms", name), text = "Name", size = { 174, 20 }, position = { 20, 32 } };
99    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxName };
100 };
101
102 class UnitesEditor : Window
103 {
104    tabCycle = true;
105    background = activeBorder;
106    ListSection list { this, editor = editor, fldName = dbfield("Units", name), table = dbtable("Units"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
107    EditSection editor { this, table = dbtable("Units"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
108
109    FieldDataBox boxName { editor = editor, field = dbfield("Units", name), text = "Name", size = { 174, 20 }, position = { 20, 32 } };
110    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxName };
111 };
112
113 class MedEditor : Window
114 {
115    tabCycle = true;
116    background = activeBorder;
117    ListSection list { this, editor = editor, fldName = dbfield("Drugs", genericName), table = dbtable("Drugs"), anchor = { left = 0, top = 0, bottom = 0, right = 0.5 } };
118    EditSection editor { this, table = dbtable("Drugs"), anchor = { left = 0.5, top = 0, bottom = 0, right = 0 } };
119
120    FieldDataBox boxGenericName { editor = editor, field = dbfield("Drugs", genericName), text = "Generic Name", size = { h = 20 }, anchor = { left = 20, top = 32, right = 20 } };
121    FieldDataBox boxCommercialNames { editor = editor, field = dbfield("Drugs", commercialNames), text = "Commercial Names", size = { h = 67 }, anchor = { left = 20, top = 88, right = 20 } };
122
123    FieldDataBox boxSubClass { editor = editor, field = dbfield("Drugs", subClass), text = "Sub Class", size = { h = 20 }, anchor = { left = 20, top = 192, right = 20 } };
124    FieldDataBox boxClass { editor = editor, field = dbfield("Drugs", drugClass), text = "Class", size = { h = 20 }, anchor = { left = 20, top = 248, right = 20 } };
125
126    FieldDataBox boxRestriction { editor = editor, field = dbfield("Drugs", restriction), text = "Restriction", size = { h = 20 }, anchor = { left = 20, top = 290, right = 20 } };
127
128    FieldDataBox boxFormConcentrations { editor = editor, field = dbfield("Drugs", formConcentrations), text = "Form & Concentrations", size = { h = 80 }, anchor = { left = 20, top = 330, right = 20 } };
129
130    Label label1 { editor.editArea, position = { 20, 8 }, labeledWindow = boxGenericName };
131    Label label2 { editor.editArea, position = { 20, 64 }, labeledWindow = boxCommercialNames };
132    Label label3 { editor.editArea, position = { 20, 168 }, labeledWindow = boxSubClass };
133    Label label4 { editor.editArea, position = { 20, 224 }, labeledWindow = boxClass };
134    Label label5 { editor.editArea, position = { 20, 270 }, labeledWindow = boxRestriction };
135    Label label6 { editor.editArea, position = { 20, 310 }, labeledWindow = boxFormConcentrations };
136
137    Label spacer { editor.editArea, position = { 20, 420 }, size = { h = 10 } };
138 }
139
140 class MedTesting : Window
141 {
142    tabCycle = true;
143    RowDrugs row { };
144
145    background = activeBorder;
146    anchor = { left = 0, top = 0, right = 0, bottom = 30 };
147
148    FieldDataBox boxGenericName { this, text = "Generic Name", size = { 238, 20 }, position = { 16, 40 }, field = dbfield("Drugs", genericName), row = row};
149    FieldDataBox boxCommercialNames { this, text = "Commercial Names", size = { 238, 67 }, position = { 16, 96 }, field = dbfield("Drugs", commercialNames), row = row };
150    FieldDataBox boxClass { this, text = "Class", size = { 238, 20 }, position = { 272, 40 }, field = dbfield("Drugs", drugClass), row = row };
151    FieldDataBox boxSubClass { this, text = "Sub Class", size = { 238, 20 }, position = { 272, 96 }, field = dbfield("Drugs", subClass), row = row };
152    FieldDataBox boxRestriction { this, text = "Restriction", size = { 238, 20 }, position = { 272, 152 }, field = dbfield("Drugs", restriction), row = row };
153    FieldDataBox boxFormConcentrations { this, text = "Form & Concentrations", size = { 240, 80 }, position = { 272, 208 }, field = dbfield("Drugs", formConcentrations), row = row };
154
155    Label etude { this, text = "Study Method", inactive = false, size = { 233, 77 }, position = { 16, 176 }, isGroupBox = true };
156    Button generique
157    {
158       etude, this, "Give out generic name", size = { 146, 15 }, position = { 16, 24 }, isRadio = true, checked = true;
159
160       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
161       {
162          boxGenericName.Load();
163          return true;
164       }
165    };
166    Button commercial
167    {
168       etude, this, "Give out commercial names", size = { 170, 15 }, position = { 16, 48 }, isRadio = true;
169
170       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
171       {
172          boxCommercialNames.Load();
173          return true;
174       }
175    };
176
177    Button next
178    {
179       this, text = "Draw Next", position = { 16, 264 };
180
181       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
182       {
183          if(row.Last())
184          {
185             int range = row.id;
186             Drug id = GetRandom(1, range);
187             if(row.Find(dbfield("Drugs", id), middle, 0, id))
188             {
189                boxCommercialNames.foreground = black;
190                boxGenericName.foreground = black;
191                boxSubClass.foreground = black;
192                boxClass.foreground = black;
193                boxRestriction.foreground = black;
194                boxFormConcentrations.foreground = black;
195
196                if(generique.checked)
197                {
198                   boxGenericName.Load();
199                   boxCommercialNames.Clear();
200                }
201                else
202                {
203                   boxCommercialNames.Load();
204                   boxGenericName.Clear();               
205                }
206                boxSubClass.Clear();
207                boxClass.Clear();
208                boxRestriction.Clear();
209                boxFormConcentrations.Clear();
210
211                answers.disabled = false;
212             }
213          }         
214          return true;
215       }
216    };
217    Button answers
218    {
219       this, text = "Give out Answers", position = { 136, 264 };
220
221       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
222       {
223          StringList commercialNames = row.commercialNames;
224          String genericName = row.genericName;
225          SubClass subClass = row.subClass;
226          DrugClass drugClass = row.drugClass;
227          Restriction restriction = row.restriction;
228          FormConcentrations formConcentrations = row.formConcentrations;         
229
230          // if(commercialNames.OnCompare(*(void **)boxCommercialNames.data))
231          if(class(StringList)._vTbl[__ecereVMethodID_class_OnCompare](class(StringList), commercialNames, *(void **)boxCommercialNames.data))
232             boxCommercialNames.foreground = red;
233
234          // if(genericName.OnCompare(*(void **)boxGenericName.data))
235          if(class(String)._vTbl[__ecereVMethodID_class_OnCompare](class(String), genericName, *(void **)boxGenericName.data))
236             boxGenericName.foreground = red;
237          
238          if(drugClass.OnCompare(boxClass.data))
239             boxClass.foreground = red;
240
241          if(subClass.OnCompare(boxSubClass.data))
242             boxSubClass.foreground = red;
243
244          if(restriction.OnCompare(boxRestriction.data))
245             boxRestriction.foreground = red;
246
247          if(formConcentrations.OnCompare(boxFormConcentrations.data))
248             boxFormConcentrations.foreground = red;
249
250          boxCommercialNames.Load();
251          boxGenericName.Load();
252          boxSubClass.Load();
253          boxClass.Load();
254          boxRestriction.Load();
255          boxFormConcentrations.Load();
256          answers.disabled = true;
257
258          delete commercialNames;
259          delete genericName;
260          formConcentrations.OnFree();
261          return true;
262       }
263    };
264
265    Label label1 { this, position = { 16, 16 }, labeledWindow = boxGenericName };
266    Label label2 { this, position = { 16, 72 }, labeledWindow = boxCommercialNames };
267    Label label3 { this, position = { 272, 72 }, labeledWindow = boxSubClass };
268    Label label4 { this, position = { 272, 16 }, labeledWindow = boxClass };
269    Label label5 { this, position = { 272, 128 }, labeledWindow = boxRestriction };
270    Label label6 { this, position = { 272, 184 }, labeledWindow = boxFormConcentrations };
271    Label spacer { this, position = { 20, 420 }, size = { h = 10 } };
272
273    bool OnPostCreate()
274    {
275       next.NotifyClicked(this, next, 0,0, 0);
276       return true;
277    }
278 }
279
280 MainForm mainForm {};