LibreOffice logo
BASEDOCUMENTER
The software tool for documenting your LibreOffice Base applications
 
Database file/home/jean-pierre/Documents/BaseDocumenter/www/databases/LODoc/Example_Dialogs.odb
File actual save date2018-06-27 11:12:23
Scanning done on2018-08-21 17:18:03
Documentation generated on2018-08-21 17:18:14
Table of contents
Example_Dialogs
Procedures by module
Library Module name Procedure name Language Used by Number of code lines Procedure code
Standard Module1 Data1Save Basic Dialog1|CommandButton1 (Control) 28
SUB Data1Save
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oSQL_Command AS OBJECT
DIM loID AS LONG
DIM stForename AS STRING
DIM stSurname AS STRING
loID = oDialog1.getControl("NumericField1").Value
stForename = oDialog1.getControl("TextField1").Text
stSurname = oDialog1.getControl("TextField2").Text
IF loID > 0 AND stSurname <> "" THEN
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "SELECT ""ID"" FROM ""name"" WHERE ""ID"" = '"+loID+"'"
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
MsgBox ("The value for field 'ID' already exist",16,"Duplicate Value")
EXIT SUB
WEND
stSql = "INSERT INTO ""name"" (""ID"", ""forename"", ""surname"") VALUES ('"+loID+"','"+stForename+"','"+stSurname+"')"
oSQL_Command.executeUpdate(stSql)
DatafieldsClear
END IF
END SUB
Standard Module1 Data2Save Basic Dialog2|CommandButton1 (Control) 49
SUB Data2Save(oEvent AS OBJECT)
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oSQL_Command AS OBJECT
DIM oDlg AS OBJECT
DIM loID AS LONG
DIM stForename AS STRING
DIM stSurname AS STRING
DIM inMsg AS INTEGER
DIM loRow AS LONG
DIM loRowMax AS LONG
DIM stSql AS STRING
oDlg = oEvent.Source.getContext()
loID = oDlg.getControl("NumericField1").Value
stForename = oDlg.getControl("TextField1").Text
stSurname = oDlg.getControl("TextField2").Text
IF loID > 0 AND stSurname <> "" THEN
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
loRow = oDlg.getControl("NumericField2").Value
loRowMax = oDlg.getControl("NumericField3").Value
IF loRowMax < loRow THEN
IF loRowMax > 0 THEN
stSql = "SELECT ""ID"" FROM ""name"" WHERE ""ID"" = '"+loID+"'"
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
inMsg = MsgBox ("The value for field 'ID' already exist." & CHR(13) & "Should the row be updated?",20,"Duplicate Value")
IF inMsg = 6 THEN
stSql = "UPDATE ""name"" SET ""forename""='"+stForename+"', ""surname""='"+stSurname+"' WHERE ""ID"" = '"+loID+"'"
oSQL_Command.executeUpdate(stSql)
DataLoad(loID) ' With update a row has been rewritten. Rowcount must be resetted
END IF
EXIT SUB
WEND
END IF
stSql = "INSERT INTO ""name"" (""ID"", ""forename"", ""surname"") VALUES ('"+loID+"','"+stForename+"','"+stSurname+"')"
oSQL_Command.executeUpdate(stSql)
oDlg.getControl("NumericField3").Value = loRowMax + 1 ' After instert one row is added
Datafields2Clear ' After instert would be moved to next insert
ELSE
stSql = "UPDATE ""name"" SET ""forename""='"+stForename+"', ""surname""='"+stSurname+"' WHERE ""ID"" = '"+loID+"'"
oSQL_Command.executeUpdate(stSql)
END IF
END IF
END SUB
Standard Module1 DataDelete Basic Dialog2|CommandButton6 (Control) 27
SUB DataDelete(oEvent AS OBJECT)
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oSQL_Command AS OBJECT
DIM oDlg AS OBJECT
DIM loID AS LONG
oDlg = oEvent.Source.getContext()
loID = oDlg.getControl("NumericField1").Value
IF loID > 0 THEN
inMsg = MsgBox ("Should current data be deleted?",20,"Delete current row")
IF inMsg = 6 THEN
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "DELETE FROM ""name"" WHERE ""ID"" = '"+loID+"'"
oSQL_Command.executeUpdate(stSql)
loRowMax = oDlg.getControl("NumericField3").Value
oDlg.getControl("NumericField3").Value = loRowMax - 1 ' after delete one row is missing
NextRow
END IF
ELSE
MsgBox ("No row deleted." & CHR(13) & "No data selected.",64,"Delete impossible")
END IF
END SUB
Standard Module1 Datafields2Clear Basic Dialog2|CommandButton2 (Control)
NextRow (Procedure)
Data2Save (Procedure)
11
SUB Datafields2Clear
loRowMax = oDialog2.getControl("NumericField3").Value ' All rows
oDialog2.getControl("NumericField1").Text = "" ' ID
oDialog2.getControl("TextField1").Text = "" ' forename
oDialog2.getControl("TextField2").Text = "" ' surname
oDialog2.getControl("NumericField2").Value = loRowMax + 1 ' this row
oDialog2.getControl("CommandButton4").Model.enabled = True ' previous row
oDialog2.getControl("CommandButton5").Model.enabled = False ' next row
oDialog2.getControl("CommandButton2").Model.enabled = False ' new row
oDialog2.getControl("CommandButton6").Model.enabled = False ' delete
END SUB
Standard Module1 DatafieldsClear Basic Dialog1|CommandButton3 (Control)
Data1Save (Procedure)
5
SUB DatafieldsClear
oDialog1.getControl("NumericField1").Text = ""
oDialog1.getControl("TextField1").Text = ""
oDialog1.getControl("TextField2").Text = ""
END SUB
Standard Module1 DataLoad Basic Dialog2Start (Procedure)
PreviousRow (Procedure)
NextRow (Procedure)
Data2Save (Procedure)
66
SUB DataLoad(loID AS LONG)
DIM oDatasource AS OBJECT
DIM oConnection AS OBJECT
DIM oSQL_Command AS OBJECT
DIM stForename AS STRING
DIM stSurname AS STRING
DIM loRow AS LONG
DIM loRowMax AS LONG
DIM inStart AS INTEGER
loRow = 1 ' Startvalue first row, without data new row at position 1
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
IF loID < 1 THEN
stSql = "SELECT MIN(""ID"") FROM ""name"""
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loID = oResult.getInt(1)
WEND
inStart = 1
END IF
IF loID > 0 THEN
stSql = "SELECT * FROM ""name"" WHERE ""ID"" = '"+loID+"'"
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loID = oResult.getInt(1)
stForename = oResult.getString(2)
stSurname = oResult.getString(3)
WEND
stSql = "SELECT COUNT(""ID"") FROM ""name"""
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loRowMax = oResult.getInt(1)
WEND
stSql = "SELECT COUNT(""ID"") FROM ""name"" WHERE ""ID"" <= '"+loID+"'"
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loRow = oResult.getInt(1)
WEND
oDialog2.getControl("NumericField1").Value = loID
oDialog2.getControl("TextField1").Text = stForename
oDialog2.getControl("TextField2").Text = stSurname
END IF
oDialog2.getControl("NumericField2").Value = loRow
oDialog2.getControl("NumericField3").Value = loRowMax
IF loRow = 1 THEN
oDialog2.getControl("CommandButton4").Model.enabled = False ' previous row
ELSE
oDialog2.getControl("CommandButton4").Model.enabled = True ' previous row
END IF
IF loRow <= loRowMax THEN
oDialog2.getControl("CommandButton5").Model.enabled = True ' next row
oDialog2.getControl("CommandButton2").Model.enabled = True ' new row
oDialog2.getControl("CommandButton6").Model.enabled = True ' delete
ELSE
oDialog2.getControl("CommandButton5").Model.enabled = False ' next row
oDialog2.getControl("CommandButton2").Model.enabled = False ' new row
oDialog2.getControl("CommandButton6").Model.enabled = False ' delete
END IF
IF inStart = 1 THEN
oDialog2.Execute()
END IF
END SUB
Standard Module1 Dialog0End Basic   3
SUB Dialog0End
oDialog0.EndExecute()
END SUB
Standard Module1 Dialog0Start Basic Example_Dialogs.odb (Database) 5
SUB Dialog0Start
DialogLibraries.LoadLibrary("Standard")
oDialog0 = createUnoDialog(DialogLibraries.Standard.Dialog0) 'Sometimes direct starting of the dialog seems to be impossible ...
oDialog0.Execute()
END SUB
Standard Module1 Dialog1End Basic Dialog1|CommandButton2 (Control) 3
SUB Dialog1End
oDialog1.EndExecute()
END SUB
Standard Module1 Dialog1Start Basic Dialog0|CommandButton1 (Control) 5
SUB Dialog1Start
DialogLibraries.LoadLibrary("Standard")
oDialog1 = createUnoDialog(DialogLibraries.Standard.Dialog1)
oDialog1.Execute()
END SUB
Standard Module1 Dialog2End Basic Dialog2|CommandButton3 (Control) 3
SUB Dialog2End
oDialog2.EndExecute()
END SUB
Standard Module1 Dialog2Start Basic Dialog0|CommandButton2 (Control) 5
SUB Dialog2Start
DialogLibraries.LoadLibrary("Standard")
oDialog2 = createUnoDialog(DialogLibraries.Standard.Dialog2)
DataLoad(0)
END SUB
Standard Module1 NextRow Basic Dialog2|CommandButton5 (Control)
DataDelete (Procedure)
21
SUB NextRow
DIM loID AS LONG
DIM loIDnew AS LONG
loID = oDialog2.getControl("NumericField1").Value
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
stSql = "SELECT MIN(""ID"") FROM ""name"" WHERE ""ID"" > '"+loID+"'"
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loIDnew = oResult.getInt(1)
WEND
IF loIDnew > 0 THEN
DataLoad(loIDnew)
ELSE
Datafields2Clear
END IF
END SUB
Standard Module1 PreviousRow Basic Dialog2|CommandButton4 (Control) 23
SUB PreviousRow
DIM loID AS LONG
DIM loIDnew AS LONG
loID = oDialog2.getControl("NumericField1").Value
oDatasource = thisDatabaseDocument.CurrentController
If NOT (oDatasource.isConnected()) THEN
oDatasource.connect()
END IF
oConnection = oDatasource.ActiveConnection()
oSQL_Command = oConnection.createStatement()
IF loID < 1 THEN
stSql = "SELECT MAX(""ID"") FROM ""name"""
ELSE
stSql = "SELECT MAX(""ID"") FROM ""name"" WHERE ""ID"" < '"+loID+"'"
END IF
oResult = oSQL_Command.executeQuery(stSql)
WHILE oResult.next
loIDnew = oResult.getInt(1)
WEND
IF loIDnew > 0 THEN
DataLoad(loIDnew)
END IF
END SUB