1 | unit UModuleSystem;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UChronisModule, SpecializedDictionary, SpecializedList;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TModuleSystem }
|
---|
13 |
|
---|
14 | TModuleSystem = class(TChronisModule)
|
---|
15 | private
|
---|
16 | procedure InitStructure;
|
---|
17 | procedure InitSystemValues;
|
---|
18 | public
|
---|
19 | procedure Install; override;
|
---|
20 | procedure Uninstall; override;
|
---|
21 | constructor Create; override;
|
---|
22 | destructor Destroy; override;
|
---|
23 | end;
|
---|
24 |
|
---|
25 |
|
---|
26 | implementation
|
---|
27 |
|
---|
28 | uses
|
---|
29 | USystem, USqlDatabase, UPDClient;
|
---|
30 |
|
---|
31 | { TModuleSystem }
|
---|
32 |
|
---|
33 | procedure TModuleSystem.InitSystemValues;
|
---|
34 | var
|
---|
35 | ObjectId: Integer;
|
---|
36 | ObjectGroupId: Integer;
|
---|
37 | PropertyParentId: Integer;
|
---|
38 | ObjectPropertyGroupId: Integer;
|
---|
39 | PropertyTypeId: Integer;
|
---|
40 | ObjectPropertyId: Integer;
|
---|
41 | ObjectPropertyIdGroup: Integer;
|
---|
42 | PropertyObjectId: Integer;
|
---|
43 | CustomTypeId: Integer;
|
---|
44 | CustomTypeIdType: Integer;
|
---|
45 | ObjectIdGroupId: Integer;
|
---|
46 | TypeNumber: Integer;
|
---|
47 | ObjectGroupParentId: Integer;
|
---|
48 | TypeString: Integer;
|
---|
49 | TypeBoolean: Integer;
|
---|
50 | GroupId: Integer;
|
---|
51 | EnumId: Integer;
|
---|
52 | ModuleId: Integer;
|
---|
53 | ModuleBaseId: Integer;
|
---|
54 | ActionId: Integer;
|
---|
55 | ObjectActionId: Integer;
|
---|
56 | begin
|
---|
57 | with TChronisBase(System) do begin
|
---|
58 | TypeNumber := AddType('Number', 'INT', vtInteger);
|
---|
59 | TypeString := AddType('String', 'VARCHAR(255)', vtString);
|
---|
60 | AddType('Text', 'TEXT', vtText);
|
---|
61 | AddType('Date and time', 'DATETIME', vtDateTime);
|
---|
62 | AddType('Floating number', 'FLOAT', vtFloat);
|
---|
63 | AddType('Image', 'BLOB', vtImage);
|
---|
64 | TypeBoolean := AddType('Boolean', 'BOOL', vtBoolean);
|
---|
65 | AddType('IPv4', 'BINARY(4)', vtIPv4);
|
---|
66 | AddType('IPv6', 'BINARY(16)', vtIPv6);
|
---|
67 | AddType('MAC address', 'BINARY(6)', vtMAC);
|
---|
68 | AddType('File', 'INT', vtFile);
|
---|
69 | AddType('GPS', 'INT', vtGPS);
|
---|
70 | AddType('Currency', 'FLOAT', vtCurrency);
|
---|
71 | AddType('Enumeration', 'INT', vtEnumeration);
|
---|
72 | AddType('Time', 'TIME', vtTime);
|
---|
73 | AddType('Date', 'DATE', vtDate);
|
---|
74 | AddType('Color', 'INT', vtColor);
|
---|
75 | AddType('Hyperlink', 'VARCHAR(255)', vtHyperlink);
|
---|
76 | AddType('RelationOne', 'INT', vtRelationOne);
|
---|
77 | AddType('RelationMany', 'INT', vtRelationMany);
|
---|
78 | AddType('Password', 'VARCHAR(255)', vtPassword);
|
---|
79 |
|
---|
80 | EnumId := AddEnumeration('Boolean');
|
---|
81 | AddEnumerationState(EnumId, 'False');
|
---|
82 | AddEnumerationState(EnumId, 'True');
|
---|
83 |
|
---|
84 | EnumId := AddEnumeration('Priority');
|
---|
85 | AddEnumerationState(EnumId, 'Low');
|
---|
86 | AddEnumerationState(EnumId, 'Normal');
|
---|
87 | AddEnumerationState(EnumId, 'High');
|
---|
88 |
|
---|
89 | ActionId := AddObject('Action', 'SystemAction', Client.Schema);
|
---|
90 | AddPropertyNumber(ActionId, 'Id', 'Id', False);
|
---|
91 | AddPropertyString(ActionId, 'Name', 'Name', True);
|
---|
92 |
|
---|
93 | ObjectGroupId := AddObject('Menu', 'SystemMenu', Client.Schema);
|
---|
94 | AddPropertyNumber(ObjectGroupId, 'Id', 'Id', False);
|
---|
95 | AddPropertyString(ObjectGroupId, 'Name', 'Name', True);
|
---|
96 | AddPropertyRelationOne(ObjectGroupId, 'Action', 'Action', True, ActionId);
|
---|
97 | ObjectGroupParentId := AddPropertyRelationOne(ObjectGroupId, 'Parent', 'Parent', True, ObjectGroupId);
|
---|
98 |
|
---|
99 | ObjectId := AddObject('Objects', 'Object', Client.Schema);
|
---|
100 | AddPropertyNumber(ObjectId, 'Id', 'Id', False);
|
---|
101 | AddPropertyString(ObjectId, 'Name', 'Name', True);
|
---|
102 | ObjectIdGroupId := AddPropertyRelationOne(ObjectId, 'Group', 'Group', True, ObjectGroupId);
|
---|
103 | AddPropertyString(ObjectId, 'Schema', 'Schema', True);
|
---|
104 | AddPropertyString(ObjectId, 'Table', 'Table', True);
|
---|
105 | AddPropertyString(ObjectId, 'Primary key', 'PrimaryKey', True);
|
---|
106 | AddPropertyNumber(ObjectId, 'Sequence', 'Sequence', True);
|
---|
107 | ObjectActionId := AddAction('Show objects', 'Object', ObjectId);
|
---|
108 | AddMenu('Objects', 0, ObjectActionId);
|
---|
109 |
|
---|
110 | PropertyTypeId := AddObject('Property types', 'Type', Client.Schema);
|
---|
111 | AddPropertyNumber(PropertyTypeId, 'Id', 'Id', False);
|
---|
112 | AddPropertyString(PropertyTypeId, 'Name', 'Name', True);
|
---|
113 | AddPropertyString(PropertyTypeId, 'Type', 'DbType', True);
|
---|
114 | //AddPropertyNumber(ObjectId, 'Parent', 'Parent');
|
---|
115 |
|
---|
116 | CustomTypeId := AddObject('Custom types', 'TypeCustom', Client.Schema);
|
---|
117 | AddPropertyNumber(CustomTypeId, 'Id', 'Id', False);
|
---|
118 | CustomTypeIdType := AddPropertyRelationOne(CustomTypeId, 'Type', 'Type', True, PropertyTypeId);
|
---|
119 |
|
---|
120 | ObjectPropertyGroupId := AddObject('Property groups', 'PropertyGroup', Client.Schema);
|
---|
121 | AddPropertyNumber(ObjectPropertyGroupId, 'Id', 'Id', False);
|
---|
122 |
|
---|
123 | ObjectPropertyId := AddObject('Properties', 'Property', Client.Schema);
|
---|
124 | AddPropertyNumber(ObjectPropertyId, 'Id', 'Id', False);
|
---|
125 | AddPropertyString(ObjectPropertyId, 'Name', 'Name', True);
|
---|
126 | PropertyParentId := AddPropertyRelationOne(ObjectPropertyId, 'Object', 'Object', True, ObjectId);
|
---|
127 | ObjectPropertyIdGroup := AddPropertyRelationOne(ObjectPropertyId, 'Property group', 'PropertyGroup', True, ObjectPropertyGroupId);
|
---|
128 | AddPropertyNumber(ObjectPropertyId, 'Custom type', 'CustomType', True);
|
---|
129 | AddProperty(ObjectPropertyId, 'Editable', 'Editable', TypeBoolean, True);
|
---|
130 | AddPropertyString(ObjectPropertyId, 'Column name', 'ColumnName', True);
|
---|
131 |
|
---|
132 | AddPropertyRelationMany(ObjectGroupId, 'Childs', 'Childs', True, PropertyParentId);
|
---|
133 | AddPropertyRelationMany(ObjectGroupId, 'Objects', 'Objects', True, ObjectIdGroupId);
|
---|
134 | AddPropertyRelationMany(ObjectId, 'Properties', 'Properties', True, PropertyParentId);
|
---|
135 | AddPropertyRelationMany(ObjectPropertyGroupId, 'Properties', 'Properties', True, ObjectPropertyIdGroup);
|
---|
136 | AddPropertyRelationMany(PropertyTypeId, 'Custom types', 'CustomTypes', True, CustomTypeIdType);
|
---|
137 |
|
---|
138 | ModuleId := AddObject('Modules', 'SystemModule', Client.Schema);
|
---|
139 | AddPropertyNumber(ModuleId, 'Id', 'Id', False);
|
---|
140 | AddPropertyString(ModuleId, 'System name', 'SysName', True);
|
---|
141 | AddPropertyString(ModuleId, 'Name', 'Name', True);
|
---|
142 | AddPropertyString(ModuleId, 'Creator', 'Creator', True);
|
---|
143 | AddPropertyString(ModuleId, 'Website', 'Website', False);
|
---|
144 | AddPropertyString(ModuleId, 'Version', 'Version', True);
|
---|
145 | AddPropertyText(ModuleId, 'Description', 'Description', False);
|
---|
146 | AddPropertyString(ModuleId, 'License', 'License', False);
|
---|
147 | AddPropertyBoolean(ModuleId, 'Installed', 'Installed', False);
|
---|
148 | end;
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TModuleSystem.Install;
|
---|
152 | begin
|
---|
153 | InitStructure;
|
---|
154 | inherited Install;
|
---|
155 | //InitSystemValues;
|
---|
156 | end;
|
---|
157 |
|
---|
158 | procedure TModuleSystem.InitStructure;
|
---|
159 | begin
|
---|
160 | with TChronisBase(System).Client do
|
---|
161 | try
|
---|
162 | with Types.AddType(SystemObjectTable) do begin
|
---|
163 | with Properties do begin
|
---|
164 | AddSimple('Name', 'String');
|
---|
165 | AddSimple('Schema', 'String');
|
---|
166 | AddSimple('Table', 'String');
|
---|
167 | AddSimple('PrimaryKey', 'String');
|
---|
168 | AddSimple('Sequence', 'Integer');
|
---|
169 | end;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | with Types.AddType(SystemMenuTable) do begin
|
---|
173 | with Properties do begin
|
---|
174 | AddSimple('Name', 'String');
|
---|
175 | AddSimple('Action', 'RelationOne');
|
---|
176 | AddSimple('Parent', 'RelationOne');
|
---|
177 | AddSimple('Sequence', 'Integer');
|
---|
178 | end;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | with Types.AddType(SystemActionTable) do begin
|
---|
182 | with Properties do begin
|
---|
183 | AddSimple('Name', 'String');
|
---|
184 | end;
|
---|
185 | end;
|
---|
186 |
|
---|
187 | with Types.AddType(PropertyTable) do begin
|
---|
188 | with Properties do begin
|
---|
189 | AddSimple('Name', 'String');
|
---|
190 | AddSimple('Object', 'RelationOne');
|
---|
191 | AddSimple('PropertyGroup', 'RelationOne');
|
---|
192 | AddSimple('CustomType', 'RelationOne');
|
---|
193 | AddSimple('Editable', 'Boolean');
|
---|
194 | AddSimple('ColumnName', 'String');
|
---|
195 | end;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | with Types.AddType(PropertyTypeTable) do begin
|
---|
199 | with Properties do begin
|
---|
200 | AddSimple('Name', 'String');
|
---|
201 | AddSimple('DbType', 'String');
|
---|
202 | end;
|
---|
203 | end;
|
---|
204 |
|
---|
205 | with Types.AddType(PropertyGroupTable) do begin
|
---|
206 | with Properties do begin
|
---|
207 | AddSimple('Name', 'String');
|
---|
208 | AddSimple('Object', 'RelationOne');
|
---|
209 | end;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | with Types.AddType(EnumerationState) do begin
|
---|
213 | with Properties do begin
|
---|
214 | AddSimple('Enumeration', 'RelationOne');
|
---|
215 | AddSimple('Name', 'String');
|
---|
216 | AddSimple('Sequence', 'Integer');
|
---|
217 | end;
|
---|
218 | end;
|
---|
219 |
|
---|
220 | with Types.AddType(Enumeration) do begin
|
---|
221 | with Properties do begin
|
---|
222 | AddSimple('Name', 'String');
|
---|
223 | end;
|
---|
224 | end;
|
---|
225 |
|
---|
226 | with Types.AddType(TypeEnumeration) do begin
|
---|
227 | with Properties do begin
|
---|
228 | AddSimple('Enumeration', 'RelationOne');
|
---|
229 | end;
|
---|
230 | end;
|
---|
231 |
|
---|
232 | with Types.AddType(TypeRelationOne) do begin
|
---|
233 | with Properties do begin
|
---|
234 | AddSimple('CustomType', 'RelationOne');
|
---|
235 | AddSimple('Object', 'Integer');
|
---|
236 | end;
|
---|
237 | end;
|
---|
238 |
|
---|
239 | with Types.AddType(TypeRelationMany) do begin
|
---|
240 | with Properties do begin
|
---|
241 | AddSimple('CustomType', 'RelationOne');
|
---|
242 | AddSimple('ObjectProperty', 'Integer');
|
---|
243 | end;
|
---|
244 | end;
|
---|
245 |
|
---|
246 | with Types.AddType(TypeFile) do begin
|
---|
247 | with Properties do begin
|
---|
248 | AddSimple('Name', 'String');
|
---|
249 | AddSimple('Size', 'Integer');
|
---|
250 | end;
|
---|
251 | end;
|
---|
252 |
|
---|
253 | with Types.AddType(TypeGPS) do begin
|
---|
254 | with Properties do begin
|
---|
255 | AddSimple('Latitude', 'Double');
|
---|
256 | AddSimple('Longitude', 'Double');
|
---|
257 | end;
|
---|
258 | end;
|
---|
259 |
|
---|
260 | with Types.AddType(CustomTypeTableName) do begin
|
---|
261 | with Properties do begin
|
---|
262 | AddSimple('Type', 'RelationOne');
|
---|
263 | end;
|
---|
264 | end;
|
---|
265 |
|
---|
266 | with Types.AddType(TypeNumber) do begin
|
---|
267 | with Properties do begin
|
---|
268 | AddSimple('CustomType', 'RelationOne');
|
---|
269 | AddSimple('Default', 'Integer');
|
---|
270 | AddSimple('Min', 'Integer');
|
---|
271 | AddSimple('Max', 'Integer');
|
---|
272 | end;
|
---|
273 | end;
|
---|
274 |
|
---|
275 | with Types.AddType(TypeFloat) do begin
|
---|
276 | with Properties do begin
|
---|
277 | AddSimple('CustomType', 'RelationOne');
|
---|
278 | AddSimple('Default', 'Double');
|
---|
279 | AddSimple('Min', 'Double');
|
---|
280 | AddSimple('Max', 'Double');
|
---|
281 | end;
|
---|
282 | end;
|
---|
283 |
|
---|
284 | with Types.AddType(TypeDateTime) do begin
|
---|
285 | with Properties do begin
|
---|
286 | AddSimple('CustomType', 'RelationOne');
|
---|
287 | AddSimple('Default', 'DateTime');
|
---|
288 | AddSimple('Min', 'DateTime');
|
---|
289 | AddSimple('Max', 'DateTime');
|
---|
290 | end;
|
---|
291 | end;
|
---|
292 |
|
---|
293 | with Types.AddType(TypeString) do begin
|
---|
294 | with Properties do begin
|
---|
295 | AddSimple('CustomType', 'RelationOne');
|
---|
296 | AddSimple('Default', 'String');
|
---|
297 | AddSimple('MaxLength', 'Integer');
|
---|
298 | end;
|
---|
299 | end;
|
---|
300 | CheckTypes;
|
---|
301 | finally
|
---|
302 | end;
|
---|
303 | end;
|
---|
304 |
|
---|
305 |
|
---|
306 | procedure TModuleSystem.Uninstall;
|
---|
307 | begin
|
---|
308 | inherited Uninstall;
|
---|
309 | end;
|
---|
310 |
|
---|
311 | constructor TModuleSystem.Create;
|
---|
312 | begin
|
---|
313 | inherited Create;
|
---|
314 | SysName := 'System';
|
---|
315 | Name := 'System';
|
---|
316 | Version := '1.0';
|
---|
317 | end;
|
---|
318 |
|
---|
319 | destructor TModuleSystem.Destroy;
|
---|
320 | begin
|
---|
321 | inherited Destroy;
|
---|
322 | end;
|
---|
323 |
|
---|
324 | end.
|
---|
325 |
|
---|