LibreOffice logo
BASEDOCUMENTER
The software tool for documenting your LibreOffice Base applications
 
Database file/home/jean-pierre/Documents/BaseDocumenter/www/databases/LODoc/Media_with_Macros.odb
File actual save date2018-06-27 15:23:25
Scanning done on2018-08-21 17:45:34
Documentation generated on2018-08-21 17:45:45
Table of contents
Media_with_Macros
Procedures by module
Library Module name Procedure name Missing Language Used by Number of code lines Procedure code
Standard Backup BackupNow   Basic   4
SUB BackupNow
WriteDataFromCache
DatabaseBackup(10)
END SUB
Standard Backup DatabaseBackup   Basic BackupNow (Procedure) 45
SUB DatabaseBackup(inMax AS INTEGER)
REM A copy of the databasefile *.odb would be created in the Backup-folder.
REM The amount is limited to 5 copies. After it has reached 5 copies, the oldest copy would be replaced by the new copy.
REM This procedure doesn't solve the problem, that input of data in the opened HSQLDB-database couldn't be solved.
REM Data of the internal HSQLDB were written in the *.odb-file, when the file will be closed.
REM The procedure "WriteDataFromCache" helps to write the data into the opened *.odb-file.
DIM oPath AS OBJECT
DIM oDoc AS OBJECT
DIM sTitel AS STRING
DIM sUrl_Target AS STRING
DIM sUrl_Start AS STRING
DIM i AS INTEGER
DIM k AS INTEGER
oDoc = ThisComponent
sTitel = oDoc.Title 'Name of the document, for example Media_with_Macros.odb
sUrl_Start = oDoc.URL 'Path to the title
oPath = createUnoService("com.sun.star.util.PathSettings")
FOR i = 1 TO inMax + 1
IF NOT FileExists(oPath.Backup & "/" & i & "_" & sTitel) THEN
REM Saved in the backup-path of the database-user of LO, beginning with the number, followed by a underscore and the title of the database.
IF i > inMax THEN
REM If i bigger than 5, 5 backupcopies do exist. Now we have to look, which copy is the oldest.
FOR k = inMax -1 TO 1 STEP -1
IF FileDateTime(oPath.Backup & "/" & k & "_" & sTitel) <= FileDateTime(oPath.Backup & "/" & k+1 & "_" & sTitel) THEN
REM File with number 4 must be created before number 5. If this is right, searchung is going on.
REM Searching begins with 4, counting downward. The number is matched with the number raised by one.
REM If 1 is reached and created before 2, 1 would be replaced by the new copy.
IF k = 1 THEN
i = k
EXIT FOR
END IF
ELSE
REM If a number of a file is found, where the file is created later as the file with the number raised by one, the file with the number raised by one would be replaced.
i = k+1
EXIT FOR
END IF
NEXT
END IF
EXIT FOR
END IF
NEXT
sUrl_Target = oPath.Backup & "/" & i &"_" & sTitel
REM The path for the targetfile is created and the document will be copied to this targetfile.
FileCopy(sUrl_Start,sUrl_Target)
END SUB
Standard Backup WriteDataFromCache   Basic BackupNow (Procedure) 9
SUB WriteDataFromCache
REM Writes data of the opened HSQLDB-database while running Base directly to the harddrive.
DIM oData AS OBJECT
DIM oDataSource AS OBJECT
oData = ThisDatabaseDocument.CurrentController
IF NOT ( oData.isConnected() ) THEN oData.connect()
oDataSource = oData.DataSource
oDataSource.flush
END SUB
Standard Comboboxes ColumnSize   Basic TextSelectionSaveValue (Procedure) 22
FUNCTION ColumnSize(Tablename AS STRING, Fieldname AS STRING) AS INTEGER
REM There could be the content of 2 fields shown in the comboboxes by '||'. GUI doesn't know the maximal length of this fields.
REM The systemtable INFORMATION_SCHEMA.SYSTEM_COLUMNS is used to get the size of the columns.
REM Connect to datasource
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oResult AS OBJECT
DIM oSQL_Command AS OBJECT
DIM i AS INTEGER
oDatasource = ThisComponent.Parent.CurrentController
If NOT (oDatasource.isConnected()) Then
oDatasource.connect()
End If
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql="SELECT ""COLUMN_SIZE"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_COLUMNS"" WHERE ""TABLE_NAME"" = '"+Tablename+"' AND ""COLUMN_NAME"" = '"+Fieldname+"'"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
i = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
ColumnSize = i
END FUNCTION
Standard Comboboxes DatasetActionGenerate Basic Media|comMed (Control)
Media|Author|comAdd (Control)
Media|Author|comAut (Control)
Media|comCat (Control)
Media|comTow (Control)
Media|comPub (Control)
Reader_Admission|Form|Adress|comPosTow (Control)
Reader_Admission|Form|Adress|comStr (Control)
   
Standard Comboboxes GenerateRecordAction   Basic   7
SUB GenerateRecordAction(oEvent AS OBJECT)
REM Macro is only needed if datasource of the form isn't a query.
REM The form doesn't recognize any changing in fields, which aren't connected to the datasource.
DIM oForm AS OBJECT
oForm = oEvent.Source.Model.Parent 'Form will be determined by the event.
oForm.isModified = TRUE 'Changing of content will be recognized.
END SUB
Standard Comboboxes ShowText   Basic Media (Form)
Media|Author (Control)
Reader_Admission|Form|Adress (Control)
54
SUB ShowText(oEvent AS OBJECT)
REM Macro should be connected to 'Form' → 'After Rowchange'
REM Macro is only needed if the content of the form isn't defined by a query, which contains the content of the comboboxes also.
REM which contains the content of the comboboxes also.
DIM oForm AS OBJECT
DIM inCom AS INTEGER
DIM oFieldList AS OBJECT
DIM stFieldID AS STRING
DIM stQuery AS STRING
DIM stFieldValue AS STRING
oForm = oEvent.Source
aComboboxen() = Split(oForm.getByName("combofields").Tag,",") 'Name of comboboxes is written down in the tag of a hidden control
FOR inCom = LBound(aComboboxen) TO UBound(aComboboxen)
oFieldList = oForm.getByName(Trim(aComboboxen(inCom)))
stFieldID = oForm.getString(oForm.findColumn(oFieldList.Tag)) 'Value of foreignkey - string, because default of integer is '0'
oFieldList.Refresh() REM Refresh() for showing new values, which could be inserted directly before.
REM Value of ID-field
IF stFieldID <> "" THEN
REM Only if ID isn't empty there will be connected to database
stQuery = oFieldList.ListSource 'Query of the combobox
IF InStr(stQuery,"order by") > 0 THEN
stSql = Left(stQuery, InStr(stQuery,"order by")-1)
ELSE
stSql = stQuery
END IF
REM Create for the SQL-code, which should describe the text, which should be connected to the foreignkey
IF InStr(stSql,"where") THEN
st = Right(stSql, Len(stSql)-InStr(stSql,"where")-4)
IF InStr(Left(st, InStr(st,"=")),".""ID""") THEN
a() = Split(Right(st, Len(st)-InStr(st,"=")-1),".")
ELSE
a() = Split(Left(st, InStr(st,"=")-1),".")
END IF
stSql = stSql + "AND "+a(0)+".""ID"" = "+stFieldID
ELSE
stSql = stSql + "WHERE ""ID"" = "+stFieldID
END IF
oDatasource = ThisComponent.Parent.CurrentController
IF NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
stFieldValue = oResult.getString(1) 'First field of the row
WEND 'go on, if there are more fields - no more in this special case
REM Set combobox to the text
oFieldList.Text = stFieldValue
ELSE
oFieldList.Text = ""
END IF
NEXT inCom
END SUB
Standard Comboboxes String_to_SQL   Basic TextSelectionSaveValue (Procedure) 7
REM " ' " must be masked for SQL-Code sometimes. For dBase it's essential.
FUNCTION String_to_SQL(st AS STRING)
IF InStr(st,"'") THEN
st = Join(Split(st,"'"),"''")
END IF
String_to_SQL = st
END FUNCTION
Standard Comboboxes TextSelectionSaveValue   Basic Media (Form)
Media|Author (Control)
Reader_Admission|Form|Adress (Control)
263
SUB TextSelectionSaveValue(oEvent AS OBJECT)
REM Macro should be connected to 'Form' → 'Before Rowchange'
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oResult AS OBJECT
DIM oSQL_Command AS OBJECT
DIM NameIDField AS STRING
DIM NameTableField1 AS STRING
DIM NameTableField2 AS STRING
DIM stFieldSeparator AS STRING
DIM NameTable1 AS STRING
DIM NameTable2 AS STRING
DIM NameTab12ID AS STRING
DIM Position AS INTEGER
DIM oFieldList AS OBJECT
DIM oField AS OBJECT
DIM oForm AS OBJECT
DIM stQuery AS STRING
DIM stContent AS STRING
DIM i AS INTEGER
DIM stContentField2 AS STRING
DIM a_stParts() AS STRING
DIM stmsgbox1 AS STRING
DIM stmsgbox2 AS STRING
DIM inID1 AS INTEGER
DIM inID2 AS INTEGER
DIM LengthField1 AS INTEGER
DIM LengthField2 AS INTEGER

IF InStr(oEvent.Source.ImplementationName,"ODatabaseForm") THEN
REM 'Before Rowchange' fires two different events.
REM Only one event is needed. With this event the form could be detected.
oForm = oEvent.Source
aComboboxen() = Split(oForm.getByName("combofields").Tag,",") 'Name of comboboxes is written down in the tag of a hidden control
FOR inCom = LBound(aComboboxen) TO UBound(aComboboxen)
NameTable2 = "" 'If there are more comboboxes and one is related to more than one table NameTable2 must be set empty before looking for next combobox.
a() = Split(Trim(aComboboxen(inCom)),">") 'Split only needed for tablecontrol to get contact to the fields
IF Ubound(a) > 0 THEN
oFieldList = oForm.getByName(a(0)).getByName(a(1)) 'Field in a tablecontrol
ELSE
oFieldList = oForm.getByname(a(0))
END IF
stQuery = oFieldList.ListSource 'SQL-Code of combobox will be read.
aFields() = Split(stQuery, """")
stContent = ""
FOR i=LBound(aFields)+1 TO UBound(aFields)
REM All what is not needed for creating a new query will be cut.
REM Parts will be joined again with a unusual combination of chacaters (§§) as a new array.
REM FROM separates fields, the sohwn content in the combobox, from tables.
REM WHERE separates relations from tables. Joins are not supported by this macro.
IF Trim(UCASE(aFields(i))) = "ORDER BY" THEN
EXIT FOR
ELSEIF Trim(UCASE(aFields(i))) = "FROM" THEN
stContent = stContent+" §§ "
ELSEIF Trim(UCASE(aFields(i))) = "WHERE" THEN
stContent = stContent+" §§ "
ELSE
stContent = stContent+Trim(aFields(i))
END IF
NEXT i
aContent() = Split(stContent, " §§ ")
REM The shown content of teh combobox would be split to the content of different fields if necessary.
aFirst() = Split(aContent(0),"||")
IF UBound(aFirst) > 0 THEN
IF UBound(aContent) > 1 THEN
REM First part contains 2 fields. Both are written down as "table"."field" .
REM Second part contains 2 tables, which could be detected also by analyzing the first part.
REM Third part contains a relation to a foreignkey, separated by '=' .
aTest() = Split(aFirst(0),".")
NameTable1 = aTest(0)
NameTableField1 = aTest(1)
Erase aTest
stFieldSeparator = Join(Split(aFirst(1),"'"),"")
aTest() = Split(aFirst(2),".")
NameTable2 = aTest(0)
NameTableField2 = aTest(1)
Erase aTest
aTest() = Split(aContent(2),"=")
aTest1() = Split(aTest(0),".")
IF aTest1(1) <> "ID" THEN
NameTab12ID = aTest1(1)
IF aTest1(0) = NameTable1 THEN
Position = 2
ELSE
Position = 1
END IF
ELSE
Erase aTest1
aTest1() = Split(aTest(1),".")
NameTab12ID = aTest1(1)
IF aTest1(0) = NameTable1 THEN
Position = 2
ELSE
Position = 1
END IF
END IF
ELSE
REM First part contains 2 fields without tablenames. Could contain also a separator.
REM Second part contains 1 table.
REM No third part available
IF UBound(aFirst) > 1 THEN
NameTableField1 = aFirst(0)
stFieldSeparator = Join(Split(aFirst(1),"'"),"")
NameTableField2 = aFirst(2)
ELSE
NameTableField1 = aFirst(0)
NameTableField2 = aFirst(1)
END IF
NameTable1 = aContent(1)
END IF
ELSE
REM Only one field of one table
NameTableField1 = aFirst(0)
NameTable1 = aContent(1)
END IF
LengthField1 = ColumnSize(NameTable1,NameTableField1)
IF NameTableField2 <> "" THEN
IF NameTable2 <> "" THEN
LengthField2 = ColumnSize(NameTable2,NameTableField2)
ELSE
LengthField2 = ColumnSize(NameTable1,NameTableField2)
END IF
ELSE
LengthField2 = 0
END IF
stContent = oFieldList.getCurrentValue()
REM Spaces at beginning and end of text will be cut
stContent = Trim(stContent)
IF stContent <> "" THEN
IF NameTableField2 <> "" THEN
REM If there is a second field of a table the content of the combobox must be splitted.
a_stParts = Split(stContent, stFieldSeparator, 2)
REM Maximum are 2 parts
IF Position = 2 THEN
stContent = Trim(a_stParts(0))
IF UBound(a_stParts()) > 0 THEN
stContentField2 = Trim(a_stParts(1))
ELSE
stContentField2 = ""
END IF
ELSE
stContentField2 = Trim(a_stParts(0))
IF UBound(a_stParts()) > 0 THEN
stContent = Trim(a_stParts(1))
ELSE
stContent = ""
END IF
END IF
END IF
IF (LengthField1 > 0 AND Len(stContent) > LengthField1) OR (LengthField2 > 0 AND Len(stContentField2) > LengthField2) THEN
stmsgbox1 = "Field "+NameTableField1+" must not be "+LengthField1+ " characters long."+CHR(13)
stmsgbox2 = "Field "+NameTableField2+" must not be "+LengthField2+ " characters long."+CHR(13)
IF (LengthField1 > 0 AND Len(stContent) > LengthField1) AND (LengthField2 > 0 AND Len(stContentField2) > LengthField2) THEN
msgbox ("The inputted text is too long."+CHR(13)+stmsgbox1+stmsgbox2+"Please reduce text.",64,"Wrong Input")
ELSEIF (LengthField1 > 0 AND Len(stContent) > LengthField1) THEN
msgbox ("The inputted text is too long."+CHR(13)+stmsgbox1+"Please reduce text.",64,"Wrong Input")
ELSE
msgbox ("The inputted text is too long."+CHR(13)+stmsgbox2+"Please reduce text.",64,"Wrong Input")
END IF
ELSE
REM Content of the field should be masked for input in SQL
stContent = String_to_SQL(stContent)
IF stContentField2 <> "" THEN
stContentField2 = String_to_SQL(stContentField2)
END IF
REM The foreignkey of the combobox would be completely ignored.
REM Changing of the content should not change the content in other fields connected to the foreignkey.
REM Example: '48431 Rheine' has ID 14. Value would be changed to '48429 Rheine'. If ID 14 would change the postcode to 48429
REM all rows would be changed from '48431' to '48429'. Former correct addresses would be wrong, because there are more than one postcode for 'Rheine'.
inID1 = -1 'Set ID to a value no ID would get, because standard for integer variables is 0 and could also be value for ID
inID2 = -1 'inID2 isn't known in the dotasource of the form.
REM Connect to datasource
oDatasource = ThisComponent.Parent.CurrentController
If NOT (oDatasource.isConnected()) Then
oDatasource.connect()
End If
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
IF NameTableField2 <> "" AND NOT IsEmpty(stContentField2) AND NameTable2 <> "" THEN
REM If a second field exists the second rlation must be cleared first. First: Does exist the entry of the field?
stSql = "SELECT ""ID"" FROM """+NameTable2+""" WHERE """+NameTableField2+"""='"+stContentField2+"'"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID2 = oResult.getInt(1)'First field of the row
WEND 'go on, if there are more fields
REM If inID2 > -1 the query got an existing content. Otherwise new value must be inserted.
IF inID2 = -1 THEN
stSql = "INSERT INTO """+NameTable2+""" ("""+NameTableField2+""") VALUES ('"+stContentField2+"') "
oSQL_Command.executeUpdate(stSql)
REM And read out the new ID
stSql = "CALL IDENTITY()"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID2 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
END IF
REM Test, if combination of inID2 and stContent exists in first table.
REM If a combobox is empty and a new value is inserted oField is empty before.
REM Whithout this query the existing entries of the combobox would be duplicated while inserting new values.
stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTab12ID+"""='"+inID2+"' AND """+NameTableField1+""" = '"+stContent+"'"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1)'First field of the row
WEND 'go on, if there are more fields
REM If there isn't any primarykeythe combination must be saved and the new key must read out.
REM The foreignkey of the combobox would be completely ignored.
REM Changing of the content should not change the content in other fields connected to the foreignkey.
IF inID1 = -1 THEN
stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""","""+NameTab12ID+""") VALUES ('"+stContent+"','"+inID2+"') "
oSQL_Command.executeUpdate(stSql)
REM Und die entsprechende ID direkt wieder auslesen
stSql = "CALL IDENTITY()"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
END IF
END IF
IF NameTableField2 <> "" AND NameTable2 = "" THEN
stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTableField1+"""='"+stContent+"' AND """+NameTableField2+"""='"+stContentField2+"'"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
IF inID1 = -1 THEN
REM ... if there exists no second table ...
stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""","""+NameTableField2+""") VALUES ('"+stContent+"','"+stContentField2+"') "
oSQL_Command.executeUpdate(stSql)
REM Read out the new ID
stSql = "CALL IDENTITY()"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
END IF
END IF
IF NameTableField2 = "" THEN
stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTableField1+"""='"+stContent+"'"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
IF inID1 = -1 THEN
REM ... if there isn't a second field
stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""") VALUES ('"+stContent+"') "
oSQL_Command.executeUpdate(stSql)
REM Read out the new ID
stSql = "CALL IDENTITY()"
oResult = oSQL_Command.executeQuery(stSql) 'Save result in an object
WHILE oResult.next
inID1 = oResult.getInt(1) 'First field of the row
WEND 'go on, if there are more fields
END IF
END IF
REM ID-Value must be saved in the datasource of the form
oForm.updateLong(oForm.findColumn(oFieldList.Tag),inID1)
END IF
ELSE
oForm.updateNULL(oForm.findColumn(oFieldList.Tag),NULL)
END IF
NEXT inCom
END IF
END SUB
Standard Maintenance DatabaseCompressing   Basic   20
SUB DatabaseCompressing
REM If changing much content of the database, the database would expand a lot. This procedure will conpress the database.
REM With LO 3.6 the compression is running, when closing the database. This procedure isn't necessary
DIM stMessage AS STRING
oDataSource = ThisComponent.Parent.CurrentController ' Access from form
IF NOT (oDataSource.isConnected()) THEN
oDataSource.connect()
END IF
oConnection = oDataSource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "SHUTDOWN COMPACT" ' Database would be zipped and closed
oSQL_Command.executeQuery(stSql)
stMessage = "Database has been compressed." + CHR(13) + "The form will be closed."
stMessage = stMessage + CHR(13) + "After closing the form you should close the whole database."
stMessage = stMessage + CHR(13) + "You could work with the database again, when reopening the database."
msgbox stMessage
ThisDatabaseDocument.FormDocuments.getByName( "Maintenance" ).close
REM Closing of the database document is possible with the following command. But if you start LO new, it will start with recovery for the database file.
' ThisDatabaseDocument.close(True)
END SUB
Standard Maintenance DialogTableAdjustmentCB1Selected   Basic Dialog_TableAdjustment|CheckBox1 (Control) 9
SUB DialogTableAdjustmentCB1Selected
DIM oCtlList2 AS OBJECT
DIM oCtlText AS OBJECT
rem Disable other fields
oCtlText = oDlg.GetControl("TextField1")
oCtlText.Model.Enabled=False
oCtlList2 = oDlg.GetControl("ListBox2")
oCtlList2.Model.Enabled=False
END SUB
Standard Maintenance DialogTableAdjustmentLB1selected   Basic Dialog_TableAdjustment|ListBox1 (Control) 25
SUB DialogTableAdjustmentLB1selected
STATIC stContent AS STRING 'Definition as STATIC keeps the value of the variable
STATIC inPos AS Integer
DIM oCtlList1 AS OBJECT
DIM oCtlList2 AS OBJECT
DIM oCtlText AS OBJECT
DIM oCtlCheck1 AS OBJECT
rem If new, the content should be written to ListBox2.
IF Len(stContent) >0 THEN
oCtlList2 = oDlg.GetControl("ListBox2")
oCtlList2.addItem(stContent,inPos)
END IF
rem Read chosen content for ListBox2
oCtlList1 = oDlg.GetControl("ListBox1")
inPos = oCtlList1.selectedItemPos
stContent = oCtlList1.getSelectedItem() 'necessary for write back content, when chosen from ListBox1 as new.
rem Enable fields in the dialog
oCtlText = oDlg.GetControl("TextField1")
oCtlText.Model.Enabled=True
oCtlList2 = oDlg.GetControl("ListBox2")
oCtlList2.removeItems(inPos,1) 'remove content from ListBox2
oCtlList2.Model.Enabled=True
oCtlCheck1 = oDlg.GetControl("CheckBox1")
oCtlCheck1.Model.Enabled=True
END SUB
Standard Maintenance DialogTableAdjustmentLB2Selected   Basic Dialog_TableAdjustment|ListBox2 (Control) 9
SUB DialogTableAdjustmentLB2Selected
DIM oCtlText AS OBJECT
DIM oCtlCheck1 AS OBJECT
rem Disable other fields
oCtlText = oDlg.GetControl("TextField1")
oCtlText.Model.Enabled=False
oCtlCheck1 = oDlg.GetControl("CheckBox1")
oCtlCheck1.Model.Enabled=False
END SUB
Standard Maintenance DialogTableAdjustmentTextSelected   Basic Dialog_TableAdjustment|TextField1 (Control) 9
SUB DialogTableAdjustmentTextSelected
DIM oCtlList2 AS OBJECT
DIM oCtlCheck1 AS OBJECT
REM Disable other fields
oCtlList2 = oDlg.GetControl("ListBox2")
oCtlList2.Model.Enabled=False
oCtlCheck1 = oDlg.GetControl("CheckBox1")
oCtlCheck1.Model.Enabled=False
END SUB
Standard Maintenance IndexAllTablesDown   Basic   8
SUB IndexAllTablesDown(oEvent AS OBJECT)
DIM stTag AS STRING
stTag = oEvent.Source.Model.Tag 'Input of the tag in "Additional information" of the control
aTabs() = Split(stTag, ",") 'First is written the name for the new form, then the name for the old form.
FOR i = LBound(aTabs()) TO UBound(aTabs())
TableIndexDown(Trim(aTabs(i))
NEXT
END SUB
Standard Maintenance TableAdjustment   Basic Media|Button 5 (Control)
Media|Button 6 (Control)
Media|Button 7 (Control)
Media|Button 8 (Control)
Media|Button 10 (Control)
Media|Button 9 (Control)
Reader_Admission|Button 6 (Control)
Reader_Admission|Button 5 (Control)
383
SUB TableAdjustment(oEvent AS OBJECT)
REM Adjust of tables, which aren't main tables in the form. Orthographic mistakes and redundant content could be cleared.
REM 0: form, 1: subform, 2: subsubform, 3:combo box or field of tablecontrol, 4: foreignkey in form, empty when there is a tablecontrol field,
REM 5: tablename second table, 6: field1 second table, 7: field2 second table, if any 8: tablename second table for field2
DIM oCtlList1 AS OBJECT
DIM oCtlList2 AS OBJECT
DIM oCtlText AS OBJECT
DIM oCtlCheck1 AS OBJECT
DIM oCtlCheck2 AS OBJECT
DIM oCtlLabel1 AS OBJECT
DIM oFieldList AS OBJECT
DIM oFieldID AS OBJECT
DIM aContent()
DIM aColumns()
DIM aForeignTables(0, 0 to 1)
DIM aForeignTables2(0, 0 to 1)
DIM stTag AS STRING
DIM stFieldList AS STRING
DIM stCondition AS STRING
DIM stText AS STRING
DIM stContent1 AS STRING
DIM stContent2 AS STRING
DIM stFieldHeader AS STRING
DIM stSideTable AS STRING
DIM stForeignIDTab1Tab2 AS STRING
DIM stForeignIDTab2Tab1 AS STRING
DIM inRepeat AS INTEGER
DIM inLB1 AS INTEGER
DIM inLB2 AS INTEGER
DIM inCounter AS INTEGER
DIM i AS INTEGER
DIM inK AS INTEGER
DIM inID AS INTEGER
DIM inUnique AS INTEGER
DIM inRow AS INTEGER
stTag = oEvent.Source.Model.Tag 'Input of the tag in "Additional information" of the control
aTable() = Split(stTag, ", ") 'Ordered see above, max. 9 entries. Must be clarified, if enty 8 and entry 9 does exist.
FOR i = LBound(aTable()) TO UBound(aTable())
aTable(i) = trim(aTable(i))
NEXT
REM Clearing relations of the base-table to other tables
REM All relations will be cleared by the system tables.
REM Foreignkeys will be saved in this multidimensional array.
oDataSource = ThisComponent.Parent.CurrentController
If NOT (oDataSource.isConnected()) THEN
oDataSource.connect()
END IF
oConnection = oDataSource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "SELECT ""FKTABLE_NAME"", ""FKCOLUMN_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_CROSSREFERENCE"" WHERE ""PKTABLE_NAME"" = '" + aTable(5) + "'"
inCounter = 0 'Counter for array, where values of the other table would be saved.
stForeignIDTab1Tab2 = "ID" 'Standard primarykey is called "ID"
stForeignIDTab2Tab1 = "ID"
stSideTable = aTable(5) 'Standard side table, which is connected to the main table. Example: Postcode and town - table postcode.
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
ReDim Preserve aForeignTables(inCounter,0 to 1) 'Dimensioning of array, former content must be saved (Preserve)
aForeignTables(inCounter,0) = oResult.getString(1) 'Read the first field with name of the tablename containing the foreignkey.
aForeignTables(inCounter,1) = oResult.getString(2) 'Read the second field with name of the foreignkey.
IF UBound(aTable()) = 8 THEN
IF aTable(8) = aForeignTables(inCounter,0) THEN
stForeignIDTab2Tab1 = aForeignTables(inCounter,1)
stSideTable = aTable(8)
END IF
END IF
inCounter = inCounter + 1 'Extension of counter to new dimension
WEND
IF UBound(aTable()) = 8 THEN
stSql = "SELECT ""FKTABLE_NAME"", ""FKCOLUMN_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_CROSSREFERENCE"" WHERE ""PKTABLE_NAME"" = '" + aTable(8) + "'"
oResult = oSQL_Command.executeQuery(stSql)
inCounter = 0 'Counter for array, where values of the table 2 would be saved.
WHILE oResult.next
ReDim Preserve aForeignTables2(inCounter,0 to 1) 'Dimensioning of array, former content must be saved (Preserve)
aForeignTables2(inCounter,0) = oResult.getString(1) 'Read the first field
aForeignTables2(inCounter,1) = oResult.getString(2) 'Read the second field
IF aTable(5) = aForeignTables2(inCounter,0) THEN
stForeignIDTab1Tab2 = aForeignTables2(inCounter,1)
END IF
inCounter = inCounter + 1 'Extension of counter to new dimension
WEND
END IF
oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName(aTable(0))
inRow = -1 'Set row to an impossible value - form would not be reloaded
IF aTable(1) <> "" THEN
oSubForm = oForm.getByName(aTable(1))
IF aTable(2) <> "" THEN
oSubSubForm = oSubForm.getByName(aTable(2))
IF aTable(4) <> "" THEN
oFieldList = oSubSubForm.getByName(aTable(3))
oFieldID = oSubSubForm.getByName(aTable(4))
inRow = oSubSubForm.Row
END IF
ELSE
IF aTable(4) <> "" THEN
oFieldList = oSubForm.getByName(aTable(3))
oFieldID = oSubForm.getByName(aTable(4))
inRow = oSubForm.Row
END IF
END IF
ELSE
IF aTable(4) <> "" THEN
oFieldList = oForm.getByName(aTable(3))
oFieldID = oForm.getByName(aTable(4))
inRow = oForm.Row
END IF
END IF
inID = -1 'ID is set to a value, which isn't used by any ID with auto-value. Otherwise empty integer fields will get value 0.
IF aTable(4) <> "" THEN
IF oFieldID.getCurrentValue() THEN 'If field is empty, nothing will be assigned.
inID = oFieldID.getCurrentValue()
END IF
END IF
DO 'Loop, for the dialog must exist up to unchecked the check box.
REM Read all fields of the second table. At the same time have a look, if 2 fields must be shown.
IF UBound(aTable()) = 6 THEN
stSql = "SELECT """ + aTable(6) + """ FROM """ + aTable(5) + """ ORDER BY """ + aTable(6) + """"
ELSEIF UBound(aTable()) = 7 THEN
stSql = "SELECT """ + aTable(6) + """||' > '||""" + aTable(7) + """ FROM """ + aTable(5) + """ ORDER BY """ + aTable(6) + """"
ELSE
stSql = "SELECT """ + aTable(5) + """.""" + aTable(6) + """||' > '||""" + aTable(8) + """.""" + aTable(7) + """ FROM """ + aTable(5) + """, """ + aTable(8) + """"
stSql = stSql + " WHERE """ + aTable(8) + """.""" + stForeignIDTab2Tab1 + """ = """ + aTable(5) + """.""" + stForeignIDTab1Tab2 + """ ORDER BY """ + aTable(6) + """"
END IF
oResult = oSQL_Command.executeQuery(stSql)
inCounter = 0 'Counter for the array, where values of the second table would be saved.
WHILE oResult.next
ReDim Preserve aContent(inCounter) 'Dimensioning of array, former content must be saved (Preserve)
aContent(inCounter) = oResult.getString(1) 'Read the first field
inCounter = inCounter+1 'Extension of counter to new dimension
WEND
REM Connect to the fist list box
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog_TableAdjustment)
oCtlList1 = oDlg.GetControl("ListBox1")
oCtlList1.addItems(aContent(),0) 'Read values of the array to the list
oCtlList2 = oDlg.GetControl("ListBox2")
oCtlList2.addItems(aContent(),0) 'Read values of the array to the list
oCtlLabel1 = oDlg.GetControl("Label1")
oCtlLabel1.setText(aTable(5)) 'Write the header for the dialog
oCtlCheck1 = oDlg.GetControl("CheckBox1") 'Connect to check box 1 for deleting all redundant entries
oCtlText = oDlg.GetControl("TextField1") 'Connect to text field for changing the value
IF inRepeat = 1 THEN
oCtlCheck2 = oDlg.GetControl("CheckBox2")
oCtlCheck2.SetState(1)
END IF
REM Dialog starten
Select Case oDlg.Execute()
Case 1 'Case 1, if button "OK" is pressed
stContent1 = oCtlList1.getSelectedItem() 'Reda values of the list box ...
REM ... and connect to the corresponding ID-value.
IF UBound(aTable()) = 6 THEN
stSql = "SELECT ""ID"" FROM """ + aTable(5) + """ WHERE """ + aTable(6) + """='" + stContent1 + "'"
ELSEIF UBound(aTable()) = 7 THEN
stSql = "SELECT ""ID"" FROM """ + aTable(5) + """ WHERE """ + aTable(6) + """||' > '||""" + aTable(7) + """='" + stContent1 + "'"
ELSE
stSql = "SELECT """ + stSideTable + """.""ID"" FROM """ + aTable(5) + """, """ + aTable(8) + """"
stSql = stSql + " WHERE """ + aTable(8) + """.""" + stForeignIDTab2Tab1 + """ = """ + aTable(5) + """.""" + stForeignIDTab1Tab2 + """"
stSql = stSql + " AND """ + aTable(5) + """.""" + aTable(6) + """||' > '||""" + aTable(8) + """.""" + aTable(7) + """='" + stContent1 + "'"
END IF
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
inLB1 = oResult.getInt(1)
WEND
stText = oCtlText.Text ' Read the vaule of the field.
REM If text field isn't empty, only the entry in this field will be worked out. Neither thr list field (other value) nor the check box (delete redundant) will be regarded.
REM Its sown in the dialog by disabling these controls, when there is an input in the text field.
IF stText <> "" THEN ' Isn't the text field empty?
REM Replace the old value with the new value at the readed ID-field
REM 2 entries must be possible, as they are possible for list boxes. Separator is '>'
aText() = Sting_to_SQL(Split(stText, ">"))
IF UBound(aTable()) = 6 OR UBound(aText()) = 0 THEN
stSql = "UPDATE """ + aTable(5) + """ SET """ + aTable(6) + """='" + trim(stText) + "' WHERE ""ID""='" + inLB1 + "'"
ELSEIF UBound(aTable()) = 7 THEN
stSql = "UPDATE """ + aTable(5) + """ SET """ + aTable(6) + """='" + trim(aText(0)) + "', """ + aTable(7) + """='" + trim(aText(1)) + "' WHERE ""ID""='" + inLB1 + "'"
ELSE
stSql = "UPDATE """ + aTable(5) + """ SET """ + aTable(6) + """='" + trim(aText(0)) + "' WHERE "
stSql = stSql + " ""ID""= (SELECT """ + stForeignIDTab2Tab1 + """ FROM """ + stSideTable + """ WHERE ""ID"" = '" + inLB1 + "');"
REM Two updates at the same time, separated by ';'
stSql = stSql + "UPDATE """ + aTable(8) + """ SET """ + aTable(7) + """='" + trim(aText(1)) + "' WHERE "
stSql = stSql + " ""ID""= (SELECT """ + stForeignIDTab1Tab2 + """ FROM """ + stSideTable + """ WHERE ""ID"" = '" + inLB1 + "')"
END IF
oSQL_Command.executeQuery(stSql)
ELSEIF oCtlList2.getSelectedItem() <> "" THEN 'If text field is empty and Listbox2 isn't ...
stContent2 = oCtlList2.getSelectedItem() ' ... read the value of the list box.
REM Look for the ID connected to the value of the list box.
IF UBound(aTable()) = 6 THEN
stSql = "SELECT ""ID"" FROM """ + aTable(5) + """ WHERE """ + aTable(6) + """='" + stContent2 + "'"
ELSEIF UBound(aTable()) = 7 THEN
stSql = "SELECT ""ID"" FROM """ + aTable(5) + """ WHERE """ + aTable(6) + """||' > '||""" + aTable(7) + """='" + stContent2 + "'"
ELSE
stSql = "SELECT """ + stSideTable + """.""ID"" FROM """ + aTable(5) + """, """ + aTable(8) + """"
stSql = stSql + " WHERE """ + aTable(8) + """.""" + stForeignIDTab2Tab1 + """ = """ + aTable(5) + """.""" + stForeignIDTab1Tab2 + """"
stSql = stSql + " AND """ + aTable(5) + """.""" + aTable(6) + """||' > '||""" + aTable(8) + """.""" + aTable(7) + """='" + stContent2 + "'"
END IF
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
inLB2 = oResult.getInt(1)
WEND
IF stSideTable = aTable(5) THEN
FOR i = LBound(aForeignTables()) TO UBound(aForeignTables())
REM Replace the old ID-value by the new ID-value.
REM Problematic with n:m-relationships, because the same value for ID could just exist.
REM This must be avoided, if foreignkey of the table is part of a primary key in the other table.
REM Example: Table "rel_Media_Author" couldn't connect a medium for the same author two times.
REM Primary key of "rel_Media_Author" are Media_ID and Author_ID together.
REM With this query all key fields with property UNIQUE will be examined.
stSql = "SELECT ""COLUMN_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_INDEXINFO"" WHERE ""TABLE_NAME"" = '" + aForeignTables(i,0) + "' AND "
stSql = stSql + """NON_UNIQUE"" = False AND ""INDEX_NAME"" = (SELECT ""INDEX_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_INDEXINFO"""
stSql = stSql + "WHERE ""TABLE_NAME"" = '" + aForeignTables(i,0) + "' AND ""COLUMN_NAME"" = '" + aForeignTables(i,1) + "')"
oResult = oSQL_Command.executeQuery(stSql)
REM If the field name of the foreign key in primary key or index with property UNIQUE in the second table, the name of the other keys should be evaluated.
REM Isn't there another field, no update could be executed.
stFieldHeader = ""
inUnique = 0
inCounter = 0
WHILE oResult.next
stFieldHeader = oResult.getString(1)
IF aForeignTables(i,1) = stFieldHeader THEN
inUnique = 1
ELSE
ReDim Preserve aColumns(inCounter) 'Dimensioning of array, former content must be saved (Preserve)
aColumns(inCounter) = oResult.getString(1) 'Read the first field
inCounter = inCounter + 1 'Extension of counter to new dimension
END IF
WEND
IF inUnique = 1 THEN
stSql = "UPDATE """ + aForeignTables(i,0) + """ AS ""a"" SET """ + aForeignTables(i,1) + """='" + inLB2 + "' WHERE """ + aForeignTables(i,1) + """='" + inLB1 + "' AND "
stSql = stSql + "( SELECT COUNT(*) FROM """ + aForeignTables(i,0) + """ WHERE """ + aForeignTables(i,1) + """='" + inLB2 + "' )"
IF inCounter > 0 THEN
stFieldgruppe = Join(aColumns(), """|| ||""") 'Connect more fields with a space for a SQL-group, if there is more than one primary key.
stFieldHeader = ""
FOR ink = LBound(aColumns()) TO UBound(aColumns())
REM A new counter for lower limit and upper limit must be created.,
REM because this loop is inside the loop with counter i.
stFieldHeader = stFieldHeader + "AND """ + aColumns(ink) + """ = ""a"".""" + aColumns(ink) + """ " 'Connect for a correlating subquery
NEXT
stSql = Left(stSql, Len(stSql) - 1) ' Delete the right bracket
stSql = stSql + stFieldHeader + "GROUP BY (""" + stFieldgruppe + """) ) < 1"
END IF
ELSE
REM If the field name of the foreign key isnt connected with the primary key the content of the foreign key could be doubled withot any problem.
stSql = "UPDATE """ + aForeignTables(i,0) + """ SET """ + aForeignTables(i,1) + """='" + inLB2 + "' WHERE """ + aForeignTables(i,1) + """='" + inLB1 + "'"
END IF
oSQL_Command.executeQuery(stSql)
NEXT
rem The old value will be deleted from the list box, because it isn't connected to any table with it's foreign key.
stSql = "DELETE FROM """ + aTable(5) + """ WHERE ""ID""='" + inLB1 + "'"
oSQL_Command.executeQuery(stSql)
END IF
IF UBound(aTable()) = 8 THEN
IF stSideTable = aTable(8) THEN
FOR i = LBound(aForeignTables2()) TO UBound(aForeignTables2())
REM Replace the old ID-value by the new ID-value.
REM Problematic with n:m-relationships, because the same value for ID could just exist.
REM This must be avoided, if foreignkey of the table is part of a primary key in the other table.
REM Example: Table "rel_Media_Author" couldn't connect a medium for the same author two times.
REM Primary key of "rel_Media_Author" are Media_ID and Author_ID together.
REM With this query all key fields with property UNIQUE will be examined.
stSql = "SELECT ""COLUMN_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_INDEXINFO"" WHERE ""TABLE_NAME"" = '" + aForeignTables2(i,0) + "' AND "
stSql = stSql + """NON_UNIQUE"" = False AND ""INDEX_NAME"" = (SELECT ""INDEX_NAME"" FROM ""INFORMATION_SCHEMA"".""SYSTEM_INDEXINFO"""
stSql = stSql + "WHERE ""TABLE_NAME"" = '" + aForeignTables2(i,0) + "' AND ""COLUMN_NAME"" = '" + aForeignTables2(i,1) + "')"
oResult = oSQL_Command.executeQuery(stSql)
REM Must the field be UNIQUE or UNIQUE together with other fields?
stFieldHeader = ""
inUnique = 0
inCounter = 0
WHILE oResult.next
stFieldHeader = oResult.getString(1)
IF aForeignTables2(i,1) = stFieldHeader THEN
inUnique = 1
ELSE
ReDim Preserve aColumns(inCounter) 'Dimensioning of array, former content must be saved (Preserve)
aColumns(inCounter) = oResult.getString(1) 'Read the first field
inCounter = inCounter + 1 'Extension of counter to new dimension
END IF
WEND
IF inUnique = 1 THEN
REM If the field name of the foreign key in primary key or index with property UNIQUE in the second table, the name of the other keys should be evaluated.
REM Isn't there another field, no update could be executed.
stSql = "UPDATE """ + aForeignTables2(i,0) + """ AS ""a"" SET """ + aForeignTables2(i,1) + """='" + inLB2 + "' WHERE """ + aForeignTables2(i,1) + """='" + inLB1 + "' AND "
stSql = stSql + "( SELECT COUNT(*) FROM """ + aForeignTables2(i,0) + """ WHERE """ + aForeignTables2(i,1) + """='" + inLB2 + "'"
IF inCounter > 0 THEN
stFieldgruppe = Join(aColumns(), """|| ||""") 'Connect more fields with a space for a SQL-group, if there is more than one primary key.
stFieldHeader = ""
FOR ink = LBound(aColumns()) TO UBound(aColumns())
REM A new counter for lower limit and upper limit must be created.,
REM because this loop is inside the loop with counter i.
stFieldHeader = stFieldHeader + " AND """ + aColumns(ink) + """ = ""a"".""" + aColumns(ink) + """ " 'Connect for a correlating subquery
NEXT
stSql = Left(stSql, Len(stSql) - 1) ' Delete the right bracket
stSql = stSql + stFieldHeader + "GROUP BY (""" + stFieldgruppe + """) ) < 1"
END IF
ELSE
REM If the field name of the foreign key isnt connected with the primary key the content of the foreign key could be doubled withot any problem.
stSql = "UPDATE """ + aForeignTables2(i,0) + """ SET """ + aForeignTables2(i,1) + """='" + inLB2 + "' WHERE """ + aForeignTables2(i,1) + """='" + inLB1 + "'"
END IF
oSQL_Command.executeQuery(stSql)
NEXT
rem The old value will be deleted from the list box, because it isn't connected to any table with it's foreign key.
stSql = "DELETE FROM """ + aTable(8) + """ WHERE ""ID""='" + inLB1 + "'"
oSQL_Command.executeQuery(stSql)
END IF
END IF
IF inID = inLB1 THEN
inID = inLB2
REM Content of the field could be indifferent, therefore it has been changed by the former updates.
END IF
REM The table must be reloaded, because there has been changed more than one value.
REM The row counter will be changed to another value - not the default -1.
inRow = 1
ELSEIF oCtlCheck1.State = 1 THEN 'If text field and Listbox2 are empty and all redundant values should be deleted
stCondition = ""
IF stSideTable = aTable(5) THEN
FOR i = LBound(aForeignTables()) TO UBound(aForeignTables())
stCondition = stCondition + """ID"" NOT IN (SELECT """ + aForeignTables(i,1) + """ FROM """ + aForeignTables(i,0) + """) AND "
NEXT
ELSE
FOR i = LBound(aForeignTables2()) TO UBound(aForeignTables2())
stCondition = stCondition + """ID"" NOT IN (SELECT """ + aForeignTables2(i,1) + """ FROM """ + aForeignTables2(i,0) + """) AND "
NEXT
END IF
stCondition = Left(stCondition, Len(stCondition) - 4) ' Last "AND" has to be cut.
stSql = "DELETE FROM """ + stSideTable + """ WHERE " + stCondition + ""
oSQL_Command.executeQuery(stSql)
TableIndexDown(stSideTable)
ELSE
msgbox "Nothing to do - nothing done!"
END IF
oCtlCheck2 = oDlg.GetControl("CheckBox2") 'The dialog will restart
IF oCtlCheck2.State = 1 THEN
inRepeat = 1
ELSE
inRepeat = 0
END IF
Case 0 'If button "Cancel" is pressed
inRepeat = 0
End Select
LOOP WHILE inRepeat = 1
rem Content of the list box in the main form should be refreshed
IF aTable(3) <> "" THEN
oFieldList.refresh()
END IF
IF inID <> "" AND aTable(4) <>"" AND inRow <> -1 THEN
REM Looking for the content of the list box corresponding to the ID-value.
IF UBound(aTable()) = 6 THEN
stSql = "SELECT """ + aTable(6) + """ FROM """ + aTable(5) + """ WHERE ""ID""='" + inID + "'"
ELSEIF UBound(aTable()) = 7 THEN
stSql = "SELECT """ + aTable(6) + """||' > '||""" + aTable(7) + """ FROM """ + aTable(5) + """ WHERE ""ID""='" + inID + "'"
ELSE
stSql = "SELECT """ + aTable(5) + """.""" + aTable(6) + """||' > '||""" + aTable(8) + """.""" + aTable(7) + """"
stSql = stSql + " FROM """ + aTable(5) + """, """ + aTable(8) + """ WHERE """ + aTable(8) + """.""" + stForeignIDTab2Tab1 + """ = "
stSql = stSql + """" + aTable(5) + """.""" + stForeignIDTab1Tab2 + """ AND """ + stSideTable + """.""ID""='" + inID + "'"
END IF
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
stFieldList = oResult.getString(1)
WEND
REM Combo box will changed to the content, detected by the query
oDocCrl = ThisComponent.getCurrentController()
oCtlView = oDocCrl.GetControl(oFieldList)
oCtlView.setText(stFieldList)
ELSE
REM Table must be reloaded and set to the current row.
REM If only the current field is set to the new value, all other fields with the same value will not be changed.
REM The content of the old form is still cached.
IF aTable(2) <> "" THEN
inRow = oSubSubForm.Row
oSubSubForm.reload()
oSubSubForm.absolute(inRow)
ELSEIF aTable(1) <> "" THEN
inRow = oSubForm.Row
oSubForm.reload()
oSubForm.absolute(inRow)
ELSE
inRow = oForm.Row
oForm.reload()
oForm.absolute(inRow)
END IF
END IF
oDlg.endExecute() ' End the dialog ...
oDlg.Dispose() ' ... and delete it from memory
END SUB
Standard Maintenance TableIndexDown   Basic TableAdjustment (Procedure)
IndexAllTablesDown (Procedure)
24
SUB TableIndexDown(stTable AS STRING)
REM This procedure will set the primary key, which is set by auto value, to the lowest possible value.
DIM inCount AS INTEGER
DIM inSequenceValue AS INTEGER
oDataSource = ThisComponent.Parent.CurrentController ' Access from form
IF NOT (oDataSource.isConnected()) THEN
oDataSource.connect()
END IF
oConnection = oDataSource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "SELECT MAX(""ID"") FROM """+stTable+"""" ' Maximum value of "ID" is read.
oResult = oSQL_Command.executeQuery(stSql) ' Start query and save the result in variable "oResult"
WHILE oResult.next
inCount = oResult.getInt(1) ' First data field is read
WEND ' Next row (isn't a next row, because maximum is only one value)
IF inCount = "" THEN ' If table is empty, there is no maximum value. So it is set to -1.
inCount = -1
END IF
inSequenceValue = inCount+1 ' Raise the value by 1
REM A new command to the database will be prepared. ID will start new from inCount+1.
REM This command don't get any return as a normal query.
oSQL_Command1 = oConnection.createStatement()
oSQL_Command1.executeQuery("ALTER TABLE """ + stTable + """ ALTER COLUMN ""ID"" RESTART WITH " + inSequenceValue + "")
END SUB
Standard Navigation MainformOpen   Basic   3
SUB MainformOpen
ThisDatabaseDocument.FormDocuments.getByName( "Media" ).open
END SUB
Standard Navigation ToFormFromForm   Basic Loan|Button 4 (Control)
Loan|Button 3 (Control)
Loan|Button 2 (Control)
Media|Button 1 (Control)
Media|Button 2 (Control)
Media|Button 3 (Control)
Reader_Admission|Button 4 (Control)
Reader_Admission|Button 2 (Control)
Reader_Admission|Button 1 (Control)
Recall|Button 4 (Control)
Recall|Button 3 (Control)
Recall|Button 1 (Control)
7
SUB ToFormFromForm(oEvent AS OBJECT)
DIM stTag AS STRING
stTag = oEvent.Source.Model.Tag 'Input of the tag in "Additional information" of the control
aForms() = Split(stTag, ",") 'First is written the name for the new form, followed by the old form
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms(0)) ).open
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms(1)) ).close
END SUB
Standard Navigation ToFormFromFormWithFolder   Basic   20
SUB ToFormFromFormWithFolder(oEvent AS OBJECT)
REM Form, that should be opened, ist the first
REM Is the form in a separate folder, this folder is defined with "/".
REM So the subfolder could be found
DIM stTag AS STRING
stTag = oEvent.Source.Model.Tag 'Input of the tag in "Additional information" of the control
aForms() = Split(stTag, ",") 'First is written the name for the new form, followed by the old form
aForms1() = Split(aForms(0),"/")
aForms2() = Split(aForms(1),"/")
IF UBound(aForms1()) = 0 THEN
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms1(0)) ).open
ELSE
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms1(0)) ).getByName( Trim(aForms1(1)) ).open
END IF
IF UBound(aForms2()) = 0 THEN
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms2(0)) ).close
ELSE
ThisDatabaseDocument.FormDocuments.getByName( Trim(aForms2(0)) ).getByName( Trim(aForms2(1)) ).close
END IF
END SUB
Standard Print ReportStart   Basic Media|butMediaChart (Control)
Recall|Button 5 (Control)
15
SUB ReportStart(oEvent AS OBJECT)
DIM stTag AS String
stTag = oEvent.Source.Model.Tag 'Input of the tag in "Additional information" of the control
IF stTag = "Recall" THEN
oDataSource = ThisComponent.Parent.CurrentController
If NOT (oDataSource.isConnected()) Then
oDataSource.connect()
End If
oConnection = oDataSource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "INSERT INTO ""Recall"" (""Loan_ID"",""Date"") SELECT ""ID"",""Today"" FROM ""View_Reminder"""
oSQL_Command.executeUpdate(stSql)
END IF
ThisDatabaseDocument.ReportDocuments.getByName( stTag ).open
END SUB
Standard Refreshing LoanRefresh   Basic Loan|Choose_Reader|Show_Reader|Loan|Input|Listfield 1 (Control) 20
SUB LoanRefresh
DIM oDoc AS OBJECT
DIM oDrawpage AS OBJECT
DIM oForm AS OBJECT
DIM oSubForm AS OBJECT
DIM oSubSubForm AS OBJECT
DIM oField AS OBJECT
oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName("Filter")
oSubForm = oForm.getByName("Choose_Reader")
oSubSubForm = oSubForm.getByName("Show_Reader")
oSubSubSubForm = oSubSubForm.getByName("Loan")
oSubSubSubSubForm = oSubSubSubForm.getByName("Input")
oField = oSubSubSubSubForm.getByName("Listfield 1")
oField.commit()
oSubSubSubSubForm.insertRow()
oField.refresh()
oSubSubSubForm.reload()
END SUB
Standard Refreshing LoanWindowRefresh   Basic ReturnRefresh (Procedure) 19
SUB LoanWindowRefresh
DIM oDoc AS OBJECT
DIM oDrawpage AS OBJECT
DIM oForm AS OBJECT
DIM oSubForm AS OBJECT
DIM oSubSubForm AS OBJECT
DIM oSubSubSubForm AS OBJECT
DIM oSubSubSubSubForm AS OBJECT
DIM oField AS OBJECT
oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName("Filter")
oSubForm = oForm.getByName("Choose_Reader")
oSubSubForm = oSubForm.getByName("Show_Reader")
oSubSubSubForm = oSubSubForm.getByName("Loan")
oSubSubSubSubForm = oSubSubSubForm.getByName("Input")
oField = oSubSubSubSubForm.getByName("Listfield 1")
oField.refresh()
END SUB
Standard Refreshing ReturnRefresh   Basic Loan|Choose_Reader|Return|Tablecontrol|Return_Date (Control) 25
SUB ReturnRefresh
DIM oDoc AS OBJECT
DIM oDrawpage AS OBJECT
DIM oForm AS OBJECT
DIM oSubForm AS OBJECT
DIM oSubSubForm AS OBJECT
DIM oSubSubForm2 AS OBJECT
DIM oTable AS OBJECT
DIM oField1 AS OBJECT
DIM oField2 AS OBJECT
oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName("Filter")
oSubForm = oForm.getByName("Choose_Reader")
oSubSubForm = oSubForm.getByName("Return")
oTable = oSubSubForm.getByName("Tablecontrol")
oField1 = oTable.getByIndex(2)
oField1.commit()
oField2 = oTable.getByIndex(3)
oField2.commit()
oSubSubForm.updateRow()
oSubSubForm2 = oSubForm.getByName("Show_Reader")
oSubSubForm2.reload()
LoanWindowRefresh
END SUB