1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="forms_OTimeModel" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36' REQUIRED VARIABLES for interface/service tests:
37
38' for XComponent
39Global oComponentInstance As Object
40
41' for XPersistObject
42Global oPersistInstance As Object
43
44' for XUpdateBroadcaster
45Global bCustomUpdate As Boolean
46
47Global oForm As Object
48
49Global oConnection As Object
50
51
52Sub CreateObj()
53
54'*************************************************************************
55' COMPONENT:
56' forms.OTimeModel
57'*************************************************************************
58On Error Goto ErrHndl
59
60    Dim bOK As Boolean
61    Dim oShape As Object, oDrawPage As Object
62
63    bOK = true
64    ' --- create a document if needed
65
66    oDoc = utils.createDocument("swriter", cObjectName)
67
68    oShape = toolkittools.addControlToDefaultForm("TimeField", 1000, 1000, 2000, 1000)
69    oObj = oShape.getControl()
70    oShape = toolkittools.addControlToDefaultForm("TimeField", 1000, 3000, 2000, 1000)
71    oComponentInstance = oShape.getControl()
72    oShape = toolkittools.addControlToDefaultForm("TimeField", 1000, 5000, 2000, 1000)
73    oPersistInstance = oShape.getControl()
74
75    'get control from document
76    oDrawPage = oDoc.DrawPage
77    oForm = oDrawPage.Forms.getByName("Standard")
78
79    Dim oRowSet As Object, facc As Object, dbSource As Object
80    Dim srcFile As String, dstFile As String, dbSrcURL As String
81
82    ' Copying DB file to temp location
83    srcFile = utils.Path2URL(cTestDocsDir) + "TestDB/testDB.dbf"
84    dstFile = utils.getTempFileURL("OTimeModelDB.dbf")
85    dbSrcURL = "sdbc:dbase:" + utils.StrReplace(dstFile, "/OTimeModelDB.dbf", "")
86
87    facc = createUnoService("com.sun.star.ucb.SimpleFileAccess")
88    if (facc.exists(dstFile)) then facc.kill(dstFile)
89    facc.copy(srcFile, dstFile)
90
91    dbtools.RegisterDataSource("DBTest", dbSrcURL)
92
93	oForm.DataSourceName = "DBTest"
94	oForm.Command = "OTimeModelDB"
95	oForm.CommandType = com.sun.star.sdb.CommandType.TABLE
96
97    oObj.DataField = "_DOUBLE"
98
99    oForm.load()
100
101    oConnection = oForm.ActiveConnection
102
103    ' for XUpdateBroadcaster
104    bCustomUpdate = true
105
106Exit Sub
107ErrHndl:
108    Test.Exception()
109End Sub
110
111Global aChangedValue As Variant
112
113' for XBoundComponent
114Sub prepareCommit()
115On Error Goto ErrHndl
116
117    Out.Log("prepareCommit() called.")
118    if NOT (isNull(oObj.Time) OR isEmpty(oObj.Time)) then
119        Out.Log("The old value was: " + oObj.Time)
120        aChangedValue = oObj.Time + 150000 ' adding 15 minutes
121    else
122        aChangedValue = 150000 ' setting to 0:15
123    end if
124    oObj.Time = aChangedValue
125
126    exit sub
127ErrHndl:
128    Test.Exception()
129End Sub
130
131' for XBoundComponent
132Function checkCommit() As Boolean
133On Error Goto ErrHndl
134    Out.Log("checkCommit() called.")
135    Dim rowValue As Variant
136
137    oForm.updateRow()
138    oForm.reload()
139    rowValue = oObj.Time
140    Out.Log("Value was set to " + aChangedValue )
141    Out.Log("the value in current row is " + rowValue)
142    checkCommit() = abs(rowValue - aChangedValue) &lt; 100
143
144    exit function
145ErrHndl:
146    Test.Exception()
147    checkCommit() = false
148End Function
149
150' for XUpdateBroadcaster
151Sub UpdateComponent()
152    Out.Log("UpdateComponent() called.")
153    if NOT (isNull(oObj.Time) OR isEmpty(oObj.Time)) then
154        oObj.Time = oObj.Time + 150000
155    else
156        oObj.Time = 150000
157    end if
158    oObj.commit()
159
160    exit sub
161ErrHndl:
162    Test.Exception()
163End Sub
164
165Sub DisposeObj()
166On Error Goto ErrHndl
167    Out.Log("Closing DB connection ...")
168    oConnection.close()
169
170    Out.Log("Revoking 'DBTest' datasource ...")
171    dbtools.RevokeDB("DBTest")
172Exit Sub
173ErrHndl:
174    Test.Exception()
175    resume next
176End Sub
177</script:module>
178