1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: db_Relations.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 07:43:42 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 '* owner : marc.neumann@sun.com
36 '* short description : Base Level 1 Create Relations between Test Tables
38 '\***********************************************************************
39 function tRelation( sFileName, sPWD, sRelTable1, sRelTable2 )
40 '/// create an 1:1 and 1:n relation between two test tables
41 Dim i, j, ix as integer 'counter
42 Dim iNoDS as integer 'number of data source in listbox
43 Dim iNoTab as integer 'number of tables in grid
44 Dim DSOK as boolean 'datasource present check
46 call fOpenDatabase(sFileName, sPWD)
48 call fOpenRelationDesign
50 '/// searching and adding of the two needed testtables
52 bDelete_Container() 'delete all disturbing table container
55 '/// insert add tables dialog if not present
57 if (AddTables.exists(1) = false) then
58 printlog "open add table dialog"
59 Kontext "RelationDesign"
61 RelationDesign.UseMenu
69 'call fChooseTableInAddTableDialog(sRelTable1)
71 '/// searching and adding the two needed testtables
73 dim sRelTable as string 'buffer variable
74 dim breltablefound as integer 'control if both needed table are found
79 sRelTable = sRelTable1 'first table
81 sRelTable = sRelTable2 'second table
83 ix = TableName.getItemCount
86 TableName.TypeKeys "<ADD>" 'adding test table
87 if TableName.getItemCount > ix then
88 ix = TableName.getItemCount
90 if TableName.getSeltext = sRelTable then
91 printlog "table found: " + sRelTable
92 breltablefound = breltablefound +1
102 if breltablefound <> 2 then 'two needed tables not found if variable <> 2
103 warnlog "proper tables: " + sRelTable1 + " and/or " + sRelTable2 + " not found - test abort"
104 call fCloseRelationDesign
108 printlog "both needed tables found and added"
112 Kontext "RelationDesign"
113 '/// open relation property menue
115 RelationDesign.UseMenu
121 Kontext "RelationProperties"
122 '/// create 1:1 relation: open relation design and choose the ID fields from each table/listbox
124 printlog "open relation design and choose the ID fields from each table/listbox"
125 RelationProperties.TypeKeys "<TAB>",TRUE
126 RelationProperties.TypeKeys "<TAB>",TRUE
127 RelationProperties.TypeKeys "<MOD2 DOWN>",TRUE
129 RelationProperties.TypeKeys "<DOWN>",TRUE
130 ' RelationProperties.TypeKeys "<RETURN>",TRUE
132 RelationProperties.TypeKeys "<TAB>",TRUE
133 RelationProperties.TypeKeys "<MOD2 DOWN>",TRUE
135 RelationProperties.TypeKeys "<DOWN>",TRUE
136 ' RelationProperties.TypeKeys "<RETURN>",TRUE
138 RelationProperties.OK
139 printlog "1:1 relation between test tables created"
142 Kontext "RelationDesign"
143 '/// delete relation connector
144 dim k as integer 'injurance that routine do not loop
145 dim l as integer 'buffer for hMenuItemGetCount
148 '/// checkout wich kontext has two entries (only relation connector has)
149 Kontext "RelationDesign"
150 RelationDesign.TypeKeys "<TAB>",TRUE
152 RelationDesign.TypeKeys "<SHIFT F10>",TRUE
155 l = hMenuItemGetCount
162 'printlog "hMenuItemGetCount = " + l
163 Loop Until k = 10 or l = 2
165 warnlog "abort deleting relation: searching for relation connector went wrong"
167 printlog "relation connector deleted"
168 RelationDesign.TypeKeys "<SHIFT F10>",TRUE
172 '/// create 1:n relation
173 Kontext "RelationDesign"
174 '/// open relation property menue
175 printlog "open relation property menue for 1:n relation"
177 RelationDesign.UseMenu
183 Kontext "RelationProperties"
184 '/// open relation design and change listbox content
185 printlog "open relation design and choose proper fields from table/listbox"
186 RelationProperties.TypeKeys "<TAB>",TRUE
187 RelationProperties.TypeKeys "<TAB>",TRUE
188 RelationProperties.TypeKeys "<MOD2 DOWN>",TRUE
190 RelationProperties.TypeKeys "<DOWN>",TRUE
191 RelationProperties.TypeKeys "<DOWN>",TRUE
193 RelationProperties.TypeKeys "<TAB>",TRUE
194 RelationProperties.TypeKeys "<MOD2 DOWN>",TRUE
196 RelationProperties.TypeKeys "<DOWN>",TRUE
197 RelationProperties.TypeKeys "<RETURN>",TRUE
199 RelationProperties.OK
200 printlog "1:n relation between test tables created"
203 bDelete_Container() 'delete all table container to leave place clear
206 fCloseRelationDesign(true)'close relation design and save it"
211 '-------------------------------------------------------------------------
212 function tDoubleRelation( sFileName, sPWD, sRelTable1, sRelTable2, sRelTable3 )
213 '/// create an 1:1 relation, close and save relation dialog,
214 '/// reopen the dialog and add an 1:n relation with third test table
215 Dim i, j, ix as integer 'counter
216 Dim iNoDS as integer 'number of data source in listbox
217 Dim iNoTab as integer 'number of tables in grid
218 Dim DSOK as boolean 'datasource present check
221 call fOpenDatabase(sFileName, sPWD)
223 call fOpenRelationDesign
225 '/// searching and adding of the two needed testtables
227 bDelete_Container() 'init
229 '/// insert add tables dialog if not present
231 if (AddTables.exists(1) = false) then
232 '/// open add table dialog
233 printlog "open add table dialog"
234 Kontext "RelationDesign"
236 RelationDesign.UseMenu
245 '/// add the needed testtables
247 dim sRelTable as string 'buffer for tablenames
248 dim breltablefound as integer 'control if both needed table are found
252 sRelTable = sRelTable1 'first table
254 sRelTable = sRelTable2 'second table
256 ix = TableName.getItemCount
259 TableName.TypeKeys "<ADD>"
260 if TableName.getItemCount > ix then
261 ix = TableName.getItemCount
263 if TableName.getSeltext = sRelTable then
264 printlog "table found: " + sRelTable
265 breltablefound = breltablefound +1
275 if breltablefound <> 2 then 'two needed tables not found if variable <> 2
276 warnlog "proper tables: " + sRelTable1 + " and/or " + sRelTable2 + " not found - test abort"
277 call fCloseRelationDesign
281 printlog "both tables found and added"
285 '/// create 1:1 relation
286 Kontext "RelationDesign"
287 '/// open relation property menue
288 printlog "open relation property menue"
290 RelationDesign.UseMenu
296 Kontext "RelationProperties"
297 '/// open relation design and choose proper fields from table/listbox
298 printlog "open relation design and choose proper fields from table/listbox"
299 RelationProperties.TypeKeys "<TAB>",TRUE
300 RelationProperties.TypeKeys "<TAB>",TRUE
301 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
303 RelationProperties.TypeKeys "<TAB>",TRUE
304 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
306 RelationProperties.OK
307 printlog "1:1 relation between test tables created"
309 '/// close and save relation design and save design
310 call fCloseRelationDesign(true)
312 '/// Second Part: adding 1:n relation
314 printlog "Second Part: adding 1:n relation"
316 call fOpenRelationDesign
318 '/// insert add tables dialog if not present
320 if (AddTables.exists(1) = false) then
321 '/// open add table dialog
322 printlog "open add table dialog"
323 Kontext "RelationDesign"
325 RelationDesign.UseMenu
334 '/// searching and adding proper table
338 sRelTable = sRelTable3 'third table
339 ix = TableName.getItemCount
342 TableName.TypeKeys "<ADD>"
343 if TableName.getItemCount > ix then
344 ix = TableName.getItemCount
346 if TableName.getSeltext = sRelTable then
347 printlog "table found: " + sRelTable
348 breltablefound = breltablefound +1
358 if breltablefound <> 1 then 'needed table not found if variable <> 1
359 warnlog "proper table: " + sRelTable3 + " not found - test abort"
360 call fCloseRealtionDesign
364 printlog "third table found and added"
369 '/// add 1:n relation
370 Kontext "RelationDesign"
371 '/// open relation property menue
372 printlog "open relation property menue"
374 RelationDesign.UseMenu
380 Kontext "RelationProperties"
381 '/// open relation design and choose the proper fields from table/listbox
382 printlog "open relation design and choose the proper fields from table/listbox"
383 RelationProperties.TypeKeys "<TAB>",TRUE
384 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
385 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
387 RelationProperties.TypeKeys "<TAB>",TRUE
388 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
389 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
391 RelationProperties.TypeKeys "<TAB>",TRUE
392 RelationProperties.TypeKeys "<MOD1 DOWN>",TRUE
394 RelationProperties.OK
397 if MessageBox.exists(1) then
399 Kontext "RelationProperties"
400 RelationProperties.OK
402 printlog "1:n relation between test tables created"
405 bDelete_Container() 'delete all table container to leave place clear
409 call fCloseRelationDesign 'close relation design and save init design"
416 function bDelete_Container() as boolean
417 dim bcontainer_exist as boolean
418 bcontainer_exist = true
419 '/// delete container if present
422 Kontext "RelationDesign"
423 RelationDesign.MouseDown(2,2)
424 RelationDesign.MouseUp(2,2)
426 RelationDesign.TypeKeys "<DELETE>",TRUE
429 '/// container present if opening context menue possible
430 if MessageBox.exists(2) then
433 bcontainer_exist = false
435 Loop Until bcontainer_exist = false
436 printlog "deleted container to init relation design"