1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="FormWizard" script:language="StarBasic">Option Explicit
' Todo: Gruppieren der DBControls mit den Textfeldern einbinden
' Evtl könnte dies auch am Ende geschehen
Public DocumentName as String
Public FormPath$, FormDBName$, FormReturnValue$
Public TemplatePath$
Public WizardPath as String
Public WebWizardPath as String
Public WorkPath as String
Public TexturePath as String
Public sQueryName as String
Public NumberofStyles as Integer
Public oDBConnection as Object
Public s_aCurrencySymbol As String
Public s_aPrependCurrencySymbol As Boolean
Public bNeedFieldRefresh as Boolean
Public bIsQuery as Boolean
Public oDBForm as Object
Public oColumns() as Object
Public sDatabaseList()
Public TableNames() as String
Public QueryNames() as String
Public FieldNames() as String
Public oDBContext as Object
Public oUcb as Object
Public oDocInfo as Object
'Public TemplateList(50,1) as String
Public WidthList(15,4)
Public ImgWidthList(3,4)
Public sDBName as String
Public Tablename as String
' Todo: 'Datenquelle' für 'Datenbank'
' 'Inhalte' oder 'Objekte' mit 'Tabellen und Abfragen' evtl als Hilfetext für 'Datenquelle'
Sub MainWithDefault(Optional DatasourceName as String, Optional Contenttype as Integer, Optional sContent as String, Optional oConnection as Object)
'On Local Error Goto GlobalError
BasicLibraries.LoadLibrary("Tools")
BasicLibraries.LoadLibrary("WebWizard")
' Todo: Variable is initialized due to Bug#88329
CurArrangement = 0
bControlsareCreated = False
MaxIndex = -1
If Not InitResources("Formwizard","dbw") Then
Exit Sub
End If
oDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
FormPath = GetOfficeSubPath("Template","wizard/bitmap")
WebWizardPath = GetOfficeSubPath("Template","wizard/web")
WizardPath = GetOfficeSubPath("Template","wizard/")
TexturePath = GetOfficeSubPath("Gallery", "www-back/")
WorkPath = GetPathSettings("Work")
OpenFormDocument()
GetDatabaseNames()
InitializeWidthList()
LoadLanguage
bNeedFieldRefresh = True
If Not IsMissing(DataSourceName) Then
CreateForm(DatasourceName, Contenttype, sContent, oConnection)
Else
CreateForm()
End If
GlobalError:
If Err <> 0 Then
ToggleWindow(True)
MsgBox(sMsgErrMsg , 16, sMsgWizardName)
End If
End Sub
Sub CreateForm(Optional DatasourceName as String, Optional Contenttype as Integer, Optional sContent as String, Optional oConnection as Object) as String
Dim i as Integer
With oDialogModel
.optIgnoreBinaries.State = True
.cmdBack.Enabled = False
.cmdGoOn.Enabled = False
.lblTables.Enabled = False
.lstSelFields.Tag = False
.Step = 1
.lstDatabases.StringItemList()= sDatabaseList()' = AddItem(sDatabaseList(i)
End With
If Not IsMissing(DataSourceName) Then
DlgFormDB.GetControl("lstDatabases").SelectItem(DataSourceName, True)
Set oDBConnection = oConnection
If GetDBMetaData() Then
oDialogModel.lstTables.StringItemList() = AddListToList(TableNames(), QueryNames()
DlgFormDB.GetControl("lstTables").SelectItem(sContent, True)
FillUpFieldsListbox()
End If
Else
ToggleListboxControls(oDialogModel, False)
End If
DlgFormDB.Title = WizardTitle(1)
NumberofStyles = FillupWebListbox(oUcb, "/stl", DlgFormDB, "lstStyles", Styles())
ImportStyles()
ToggleWindow(True)
oDialogModel.imgTheme.ImageURL = FormPath & "FormWizard_1.bmp"
DlgFormDB.Execute()
Exit Sub
GlobalError:
MsgBox(sMsgErrMsg , 16, sMsgWizardName)
ToggleWindow(True)
DlgFormDB.Execute()
Reset
Stop
End Sub
Sub FormGetFields()
Dim i as Integer
ToggleDatabasePage(False)
FillUpFieldsListbox()
ToggleDatabasePage(True)
End Sub
Sub FillUpFieldsListbox()
Dim n as Integer
n = Ubound(oDialogModel.lstTables.SelectedItems())
If n <> -1 Then
Tablename = Tablenames(oDialogModel.lstTables.SelectedItems(0))
bIsQuery = FieldinArray(QueryNames(), Ubound(QueryNames()), TableName)
If (bIsQuery) Then
oColumns = oDBConnection.Queries.GetByName(TableName).Columns
Else
oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
End If
GetSpecificFieldNames()
ToggleListboxControls(oDialogModel, True)
End If
Exit Sub
'TODO: Diese Fehlermarke sinnvoll einbinden
NOFIELDS:
MsgBox sMsgErrCouldNotOpenObject, 16, sMsgWizardName
End Sub
Sub CancelFormWizard()
DlgFormDB.EndExecute()
DlgFormDB.Dispose()
oDocument.Dispose()
Stop
End Sub
Sub PreviousStep()
With oDialogModel
.Step = 1
.cmdBack.Enabled = False
.cmdGoOn.Enabled = True
.lstSelFields.Tag = Not bControlsareCreated
.cmdGoOn.Label = sGoOn
.imgTheme.ImageUrl = FormPath & "FormWizard_1.bmp"
End With
DlgFormDB.Title = WizardTitle(1)
End Sub
Sub NextStep()
Dim bOldVisible
' Note: Unfortunately it is not possible to query the visibility of the imagecontrol directly
bOldVisible = oDialogModel.Height > 40
Select Case oDialogModel.Step
Case 1
bControlsAreCreated = Not (CBool(oDialogModel.lstSelFields.Tag))
If Not bControlsAreCreated Then
GetTableMetaData()
CreateDBForm()
RemoveShapes()
InitializeLayoutSettings()
oDBForm.Load
End If
oDialogModel.cmdGoOn.Label = sReady
oDialogModel.cmdBack.Enabled = True
oDialogModel.Step = 2
Case 2
StoreForm()
End Select
DlgFormDB.GetControl("imgTheme").Visible = bOldVisible
oDialogModel.imgTheme.ImageUrl = FormPath & "FormWizard_" & oDialogModel.Step & ".bmp"
DlgFormDB.Title = WizardTitle(oDialogModel.Step)
End Sub
Sub InitializeLayoutSettings()
If oPageStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.TILED Then
oDialogModel.optTiled.State = 1
Else
oDialogModel.optArea.State = 1
End If
SwitchArrangementButtons(cTabled)
SwitchAlignButtons(SBALIGNLEFT)
SwitchBorderButtons(SB3DBORDER)
ToggleBorderGroup(bControlsAreCreated)
ToggleAlignGroup(bControlsAreCreated)
ArrangeControls()
If OldAlignMode <> 0 Then
DlgFormDB.GetControl("cmdAlign" & OldAlignmode).Model.State = 0
End If
If OldAlignMode <> 0 Then
DlgFormDB.GetControl("cmdAlign" & OldAlignmode).Model.State = 0
End If
End Sub
Sub ToggleDatabasePage(bDoEnable as Boolean)
With oDialogModel
.hlnBinaries.Enabled = bDoEnable
.optIgnoreBinaries.Enabled = bDoEnable
.optBinariesasGraphics.Enabled = bDoEnable
.cmdHelp.Enabled = bDoEnable
End With
End Sub
Sub SwitchDialogHeight()
SwitchWizardDialogHeight(DlgFormDB, sReduceDialog, sHeightenDialog)
End Sub
Sub StoreForm()
Dim oFileDialog
Dim iAccept as Integer
Dim sPath as String
Dim ListAny(0)
ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
oFileDialog.AppendFilter(sWriterFiltername, "*.sxw")
oFileDialog.AppendFilter(sWriterTemplateFiltername, "*.stw")
oFileDialog.SetCurrentFilter("Writer 6.0")
oFileDialog.Initialize(ListAny())
oFileDialog.SetDisplayDirectory(WorkPath)
oFileDialog.SetDefaultName("Form_" & sDBName & "." & TableName
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
If oFileDialog.GetCurrentFilter() = sWriterTemplateFiltername Then
Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
oStoreProperties(0).Name = "FilterName"
oStoreProperties(0).Value = "swriter: writer_StarOffice_XML_Writer_Template"
oDocument.StoreAsUrl(sPath, oStoreProperties())
Else
Dim NoArgs() as New com.sun.star.beans.PropertyValue
oDocument.StoreAsUrl(sPath, NoArgs())
End If
DlgFormDB.EndExecute()
End If
End Sub
</script:module>
|