xref: /aoo4110/main/wizards/source/depot/Currency.xba (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<!--***********************************************************
4*b1cdbd2cSJim Jagielski *
5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
6*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
7*b1cdbd2cSJim Jagielski * distributed with this work for additional information
8*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
11*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
14*b1cdbd2cSJim Jagielski *
15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
20*b1cdbd2cSJim Jagielski * under the License.
21*b1cdbd2cSJim Jagielski *
22*b1cdbd2cSJim Jagielski ***********************************************************-->
23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Currency" script:language="StarBasic">REM  *****  BASIC  *****
24*b1cdbd2cSJim JagielskiOption Explicit
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim JagielskiDim bDoUnLoad as Boolean
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim JagielskiSub Startup()
30*b1cdbd2cSJim JagielskiDim i as Integer
31*b1cdbd2cSJim JagielskiDim a as Integer
32*b1cdbd2cSJim JagielskiDim ListString as String
33*b1cdbd2cSJim JagielskiDim MarketListBoxControl as Object
34*b1cdbd2cSJim Jagielski	Initialize(False)
35*b1cdbd2cSJim Jagielski	MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
36*b1cdbd2cSJim Jagielski	a = 0
37*b1cdbd2cSJim Jagielski	For i = 0 To Ubound(sMarket(),1)
38*b1cdbd2cSJim Jagielski		ListString = sMarket(i,0)
39*b1cdbd2cSJim Jagielski		If sMarket(i,0) &lt;&gt; &quot;&quot; Then
40*b1cdbd2cSJim Jagielski			If sMarket(i,3) = &quot;&quot; Then
41*b1cdbd2cSJim Jagielski				ListString = ListString &amp; &quot;    (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
42*b1cdbd2cSJim Jagielski			Else
43*b1cdbd2cSJim Jagielski				ListString = ListString &amp; &quot;    (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
44*b1cdbd2cSJim Jagielski			End If
45*b1cdbd2cSJim Jagielski			MarketListBoxControl.AddItem(ListString, a)
46*b1cdbd2cSJim Jagielski			a = a + 1
47*b1cdbd2cSJim Jagielski		End If
48*b1cdbd2cSJim Jagielski	Next i
49*b1cdbd2cSJim Jagielski	MarketListBoxControl.SelectItemPos(GlobListIndex, True)
50*b1cdbd2cSJim Jagielski	DlgStartUp.Title = sDepotCurrency
51*b1cdbd2cSJim Jagielski	DlgStartUp.Model.cmdGoOn.DefaultButton = True
52*b1cdbd2cSJim Jagielski	DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
53*b1cdbd2cSJim Jagielski	DlgStartUp.Execute()
54*b1cdbd2cSJim Jagielski	DlgStartUp.Dispose()
55*b1cdbd2cSJim JagielskiEnd Sub
56*b1cdbd2cSJim Jagielski
57*b1cdbd2cSJim Jagielski
58*b1cdbd2cSJim JagielskiSub EnableGoOnButton()
59*b1cdbd2cSJim Jagielski	StartUpModel.cmdGoOn.Enabled = True
60*b1cdbd2cSJim Jagielski	StartUpModel.cmdGoOn.DefaultButton = True
61*b1cdbd2cSJim JagielskiEnd Sub
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim JagielskiSub CloseStartUpDialog()
65*b1cdbd2cSJim Jagielski	DlgStartUp.EndExecute()
66*b1cdbd2cSJim Jagielski&apos;	oDocument.Dispose()
67*b1cdbd2cSJim JagielskiEnd Sub
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski
70*b1cdbd2cSJim JagielskiSub DisposeDocument()
71*b1cdbd2cSJim Jagielski	If bDoUnload Then
72*b1cdbd2cSJim Jagielski		oDocument.Dispose()
73*b1cdbd2cSJim Jagielski	End If
74*b1cdbd2cSJim JagielskiEnd Sub
75*b1cdbd2cSJim Jagielski
76*b1cdbd2cSJim Jagielski
77*b1cdbd2cSJim JagielskiSub ChooseMarket(Optional aEvent)
78*b1cdbd2cSJim JagielskiDim Index as Integer
79*b1cdbd2cSJim JagielskiDim bIsDocLanguage as Boolean
80*b1cdbd2cSJim JagielskiDim bIsDocCountry as Boolean
81*b1cdbd2cSJim Jagielski	oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
82*b1cdbd2cSJim Jagielski	If Not IsMissing(aEvent) Then
83*b1cdbd2cSJim Jagielski		Index = StartupModel.lstMarkets.SelectedItems(0)
84*b1cdbd2cSJim Jagielski		oInternetModel.Tag = Index
85*b1cdbd2cSJim Jagielski	Else
86*b1cdbd2cSJim Jagielski		Index = oInternetModel.Tag
87*b1cdbd2cSJim Jagielski	End If
88*b1cdbd2cSJim Jagielski	oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
89*b1cdbd2cSJim Jagielski	sCurCurrency = sMarket(Index,1)
90*b1cdbd2cSJim Jagielski	If Index = 0 Then
91*b1cdbd2cSJim Jagielski		HistoryChartSource = sMarket(Index,4)
92*b1cdbd2cSJim Jagielski	End If
93*b1cdbd2cSJim Jagielski	sCurStockIDLabel = sMarket(Index,5)
94*b1cdbd2cSJim Jagielski	sCurExtension = sMarket(Index,8)
95*b1cdbd2cSJim Jagielski	iValueCol = Val(sMarket(Index,10)
96*b1cdbd2cSJim Jagielski	If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
97*b1cdbd2cSJim Jagielski		&apos; Take the german extension as the stock place is Frankfurt
98*b1cdbd2cSJim Jagielski		sCurExtension = &quot;407&quot;
99*b1cdbd2cSJim Jagielski	End If
100*b1cdbd2cSJim Jagielski	sCurChartSource = sMarket(Index,3)
101*b1cdbd2cSJim Jagielski	bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
102*b1cdbd2cSJim Jagielski	bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0  OR SDocCountry = &quot;&quot;
103*b1cdbd2cSJim Jagielski	sCurSeparator = sMarket(Index,9)
104*b1cdbd2cSJim Jagielski	TransactModel.txtRate.CurrencySymbol = sCurCurrency
105*b1cdbd2cSJim Jagielski	TransactModel.txtFix.CurrencySymbol = sCurCurrency
106*b1cdbd2cSJim Jagielski	TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
107*b1cdbd2cSJim Jagielski	bEnableMarket = Index = 0
108*b1cdbd2cSJim Jagielski	bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
109*b1cdbd2cSJim Jagielski	oMarketModel.Enabled = bEnableMarket
110*b1cdbd2cSJim Jagielski	oInternetModel.Enabled = bEnableInternet
111*b1cdbd2cSJim Jagielski	If Not IsMissing(aEvent) Then
112*b1cdbd2cSJim Jagielski		ConvertStylesCurrencies()
113*b1cdbd2cSJim Jagielski		bDoUnload = False
114*b1cdbd2cSJim Jagielski		DlgStartUp.EndExecute()
115*b1cdbd2cSJim Jagielski	End If
116*b1cdbd2cSJim JagielskiEnd Sub
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski
119*b1cdbd2cSJim JagielskiSub ConvertStylesCurrencies()
120*b1cdbd2cSJim JagielskiDim m as integer
121*b1cdbd2cSJim JagielskiDim aStyleFormat as Object
122*b1cdbd2cSJim JagielskiDim StyleName as String
123*b1cdbd2cSJim JagielskiDim bAddToList as Boolean
124*b1cdbd2cSJim JagielskiDim oStyle as Object
125*b1cdbd2cSJim JagielskiDim oStyles as Object
126*b1cdbd2cSJim Jagielski 	UnprotectSheets(oSheets)
127*b1cdbd2cSJim Jagielski	oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
128*b1cdbd2cSJim Jagielski	oStyles = oDocument.StyleFamilies.GetbyIndex(0)
129*b1cdbd2cSJim Jagielski	For m = 0 To oStyles.count-1
130*b1cdbd2cSJim Jagielski		oStyle = oStyles.GetbyIndex(m)
131*b1cdbd2cSJim Jagielski		StyleName = oStyle.Name
132*b1cdbd2cSJim Jagielski		bAddToList = CheckFormatType(oStyle)
133*b1cdbd2cSJim Jagielski		If bAddToList Then
134*b1cdbd2cSJim Jagielski			SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
135*b1cdbd2cSJim Jagielski		End If
136*b1cdbd2cSJim Jagielski	Next m
137*b1cdbd2cSJim Jagielski	ProtectSheets(oSheets)
138*b1cdbd2cSJim JagielskiEnd Sub
139*b1cdbd2cSJim Jagielski
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim JagielskiSub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
142*b1cdbd2cSJim JagielskiDim nFormatLanguage as Integer
143*b1cdbd2cSJim JagielskiDim nFormatDecimals as Integer
144*b1cdbd2cSJim JagielskiDim nFormatLeading as Integer
145*b1cdbd2cSJim JagielskiDim bFormatLeading as Integer
146*b1cdbd2cSJim JagielskiDim bFormatNegRed as Integer
147*b1cdbd2cSJim JagielskiDim bFormatThousands as Integer
148*b1cdbd2cSJim JagielskiDim aNewStr as String
149*b1cdbd2cSJim JagielskiDim iNumberFormat as Long
150*b1cdbd2cSJim JagielskiDim sSimpleStr as String
151*b1cdbd2cSJim JagielskiDim nSimpleKey as Long
152*b1cdbd2cSJim JagielskiDim aFormat()
153*b1cdbd2cSJim JagielskiDim oLocale as New com.sun.star.lang.Locale
154*b1cdbd2cSJim Jagielski	&apos; Numberformat with the new Symbol as Base for new Format
155*b1cdbd2cSJim Jagielski	sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
156*b1cdbd2cSJim Jagielski	nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
157*b1cdbd2cSJim Jagielski	On Local Error Resume Next
158*b1cdbd2cSJim Jagielski	iNumberFormat = oObject.NumberFormat
159*b1cdbd2cSJim Jagielski	If Err &lt;&gt; 0 Then
160*b1cdbd2cSJim Jagielski		Msgbox &quot;Error Reading the Number Format&quot;
161*b1cdbd2cSJim Jagielski		Resume CLERROR
162*b1cdbd2cSJim Jagielski	End If
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim Jagielski	On Local Error GoTo NOKEY
165*b1cdbd2cSJim Jagielski	aFormat() = oFormats.getByKey(iNumberFormat)
166*b1cdbd2cSJim Jagielski	On Local Error GoTo 0
167*b1cdbd2cSJim Jagielski	&apos; set new currency format with according settings
168*b1cdbd2cSJim Jagielski	nFormatDecimals = aFormat.Decimals
169*b1cdbd2cSJim Jagielski	nFormatLeading = aFormat.LeadingZeros
170*b1cdbd2cSJim Jagielski	bFormatNegRed = aFormat.NegativeRed
171*b1cdbd2cSJim Jagielski	bFormatThousands = aFormat.ThousandsSeparator
172*b1cdbd2cSJim Jagielski	oLocale = aFormat.Locale
173*b1cdbd2cSJim Jagielski	aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
174*b1cdbd2cSJim Jagielski	oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
175*b1cdbd2cSJim Jagielski	NOKEY:
176*b1cdbd2cSJim Jagielski	If Err &lt;&gt; 0 Then
177*b1cdbd2cSJim Jagielski		Resume CLERROR
178*b1cdbd2cSJim Jagielski	End If
179*b1cdbd2cSJim Jagielski	CLERROR:
180*b1cdbd2cSJim JagielskiEnd Sub
181*b1cdbd2cSJim Jagielski
182*b1cdbd2cSJim Jagielski
183*b1cdbd2cSJim JagielskiFunction Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
184*b1cdbd2cSJim JagielskiDim nRetkey
185*b1cdbd2cSJim Jagielski	nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
186*b1cdbd2cSJim Jagielski	If nRetKey = -1 Then
187*b1cdbd2cSJim Jagielski		nRetKey = oFormats.addNew( aFormatStr, oLocale )
188*b1cdbd2cSJim Jagielski		If nRetKey = -1 Then nRetKey = 0
189*b1cdbd2cSJim Jagielski	End If
190*b1cdbd2cSJim Jagielski	Numberformat = nRetKey
191*b1cdbd2cSJim JagielskiEnd Function
192*b1cdbd2cSJim Jagielski
193*b1cdbd2cSJim Jagielski
194*b1cdbd2cSJim JagielskiFunction CheckFormatType(oStyle as Object)
195*b1cdbd2cSJim JagielskiDim oFormatofObject as Object
196*b1cdbd2cSJim Jagielski	oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
197*b1cdbd2cSJim Jagielski  	CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
198*b1cdbd2cSJim JagielskiEnd Function</script:module>
199