xref: /aoo42x/main/wizards/source/depot/Currency.xba (revision cdf0e10c)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Currency" script:language="StarBasic">REM  *****  BASIC  *****
4*cdf0e10cSrcweirOption Explicit
5*cdf0e10cSrcweir
6*cdf0e10cSrcweirDim bDoUnLoad as Boolean
7*cdf0e10cSrcweir
8*cdf0e10cSrcweir
9*cdf0e10cSrcweirSub Startup()
10*cdf0e10cSrcweirDim i as Integer
11*cdf0e10cSrcweirDim a as Integer
12*cdf0e10cSrcweirDim ListString as String
13*cdf0e10cSrcweirDim MarketListBoxControl as Object
14*cdf0e10cSrcweir	Initialize(False)
15*cdf0e10cSrcweir	MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
16*cdf0e10cSrcweir	a = 0
17*cdf0e10cSrcweir	For i = 0 To Ubound(sMarket(),1)
18*cdf0e10cSrcweir		ListString = sMarket(i,0)
19*cdf0e10cSrcweir		If sMarket(i,0) &lt;&gt; &quot;&quot; Then
20*cdf0e10cSrcweir			If sMarket(i,3) = &quot;&quot; Then
21*cdf0e10cSrcweir				ListString = ListString &amp; &quot;    (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
22*cdf0e10cSrcweir			Else
23*cdf0e10cSrcweir				ListString = ListString &amp; &quot;    (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
24*cdf0e10cSrcweir			End If
25*cdf0e10cSrcweir			MarketListBoxControl.AddItem(ListString, a)
26*cdf0e10cSrcweir			a = a + 1
27*cdf0e10cSrcweir		End If
28*cdf0e10cSrcweir	Next i
29*cdf0e10cSrcweir	MarketListBoxControl.SelectItemPos(GlobListIndex, True)
30*cdf0e10cSrcweir	DlgStartUp.Title = sDepotCurrency
31*cdf0e10cSrcweir	DlgStartUp.Model.cmdGoOn.DefaultButton = True
32*cdf0e10cSrcweir	DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
33*cdf0e10cSrcweir	DlgStartUp.Execute()
34*cdf0e10cSrcweir	DlgStartUp.Dispose()
35*cdf0e10cSrcweirEnd Sub
36*cdf0e10cSrcweir
37*cdf0e10cSrcweir
38*cdf0e10cSrcweirSub EnableGoOnButton()
39*cdf0e10cSrcweir	StartUpModel.cmdGoOn.Enabled = True
40*cdf0e10cSrcweir	StartUpModel.cmdGoOn.DefaultButton = True
41*cdf0e10cSrcweirEnd Sub
42*cdf0e10cSrcweir
43*cdf0e10cSrcweir
44*cdf0e10cSrcweirSub CloseStartUpDialog()
45*cdf0e10cSrcweir	DlgStartUp.EndExecute()
46*cdf0e10cSrcweir&apos;	oDocument.Dispose()
47*cdf0e10cSrcweirEnd Sub
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir
50*cdf0e10cSrcweirSub DisposeDocument()
51*cdf0e10cSrcweir	If bDoUnload Then
52*cdf0e10cSrcweir		oDocument.Dispose()
53*cdf0e10cSrcweir	End If
54*cdf0e10cSrcweirEnd Sub
55*cdf0e10cSrcweir
56*cdf0e10cSrcweir
57*cdf0e10cSrcweirSub ChooseMarket(Optional aEvent)
58*cdf0e10cSrcweirDim Index as Integer
59*cdf0e10cSrcweirDim bIsDocLanguage as Boolean
60*cdf0e10cSrcweirDim bIsDocCountry as Boolean
61*cdf0e10cSrcweir	oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
62*cdf0e10cSrcweir	If Not IsMissing(aEvent) Then
63*cdf0e10cSrcweir		Index = StartupModel.lstMarkets.SelectedItems(0)
64*cdf0e10cSrcweir		oInternetModel.Tag = Index
65*cdf0e10cSrcweir	Else
66*cdf0e10cSrcweir		Index = oInternetModel.Tag
67*cdf0e10cSrcweir	End If
68*cdf0e10cSrcweir	oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
69*cdf0e10cSrcweir	sCurCurrency = sMarket(Index,1)
70*cdf0e10cSrcweir	If Index = 0 Then
71*cdf0e10cSrcweir		HistoryChartSource = sMarket(Index,4)
72*cdf0e10cSrcweir	End If
73*cdf0e10cSrcweir	sCurStockIDLabel = sMarket(Index,5)
74*cdf0e10cSrcweir	sCurExtension = sMarket(Index,8)
75*cdf0e10cSrcweir	iValueCol = Val(sMarket(Index,10)
76*cdf0e10cSrcweir	If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
77*cdf0e10cSrcweir		&apos; Take the german extension as the stock place is Frankfurt
78*cdf0e10cSrcweir		sCurExtension = &quot;407&quot;
79*cdf0e10cSrcweir	End If
80*cdf0e10cSrcweir	sCurChartSource = sMarket(Index,3)
81*cdf0e10cSrcweir	bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
82*cdf0e10cSrcweir	bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0  OR SDocCountry = &quot;&quot;
83*cdf0e10cSrcweir	sCurSeparator = sMarket(Index,9)
84*cdf0e10cSrcweir	TransactModel.txtRate.CurrencySymbol = sCurCurrency
85*cdf0e10cSrcweir	TransactModel.txtFix.CurrencySymbol = sCurCurrency
86*cdf0e10cSrcweir	TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
87*cdf0e10cSrcweir	bEnableMarket = Index = 0
88*cdf0e10cSrcweir	bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
89*cdf0e10cSrcweir	oMarketModel.Enabled = bEnableMarket
90*cdf0e10cSrcweir	oInternetModel.Enabled = bEnableInternet
91*cdf0e10cSrcweir	If Not IsMissing(aEvent) Then
92*cdf0e10cSrcweir		ConvertStylesCurrencies()
93*cdf0e10cSrcweir		bDoUnload = False
94*cdf0e10cSrcweir		DlgStartUp.EndExecute()
95*cdf0e10cSrcweir	End If
96*cdf0e10cSrcweirEnd Sub
97*cdf0e10cSrcweir
98*cdf0e10cSrcweir
99*cdf0e10cSrcweirSub ConvertStylesCurrencies()
100*cdf0e10cSrcweirDim m as integer
101*cdf0e10cSrcweirDim aStyleFormat as Object
102*cdf0e10cSrcweirDim StyleName as String
103*cdf0e10cSrcweirDim bAddToList as Boolean
104*cdf0e10cSrcweirDim oStyle as Object
105*cdf0e10cSrcweirDim oStyles as Object
106*cdf0e10cSrcweir 	UnprotectSheets(oSheets)
107*cdf0e10cSrcweir	oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
108*cdf0e10cSrcweir	oStyles = oDocument.StyleFamilies.GetbyIndex(0)
109*cdf0e10cSrcweir	For m = 0 To oStyles.count-1
110*cdf0e10cSrcweir		oStyle = oStyles.GetbyIndex(m)
111*cdf0e10cSrcweir		StyleName = oStyle.Name
112*cdf0e10cSrcweir		bAddToList = CheckFormatType(oStyle)
113*cdf0e10cSrcweir		If bAddToList Then
114*cdf0e10cSrcweir			SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
115*cdf0e10cSrcweir		End If
116*cdf0e10cSrcweir	Next m
117*cdf0e10cSrcweir	ProtectSheets(oSheets)
118*cdf0e10cSrcweirEnd Sub
119*cdf0e10cSrcweir
120*cdf0e10cSrcweir
121*cdf0e10cSrcweirSub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
122*cdf0e10cSrcweirDim nFormatLanguage as Integer
123*cdf0e10cSrcweirDim nFormatDecimals as Integer
124*cdf0e10cSrcweirDim nFormatLeading as Integer
125*cdf0e10cSrcweirDim bFormatLeading as Integer
126*cdf0e10cSrcweirDim bFormatNegRed as Integer
127*cdf0e10cSrcweirDim bFormatThousands as Integer
128*cdf0e10cSrcweirDim aNewStr as String
129*cdf0e10cSrcweirDim iNumberFormat as Long
130*cdf0e10cSrcweirDim sSimpleStr as String
131*cdf0e10cSrcweirDim nSimpleKey as Long
132*cdf0e10cSrcweirDim aFormat()
133*cdf0e10cSrcweirDim oLocale as New com.sun.star.lang.Locale
134*cdf0e10cSrcweir	&apos; Numberformat with the new Symbol as Base for new Format
135*cdf0e10cSrcweir	sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
136*cdf0e10cSrcweir	nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
137*cdf0e10cSrcweir	On Local Error Resume Next
138*cdf0e10cSrcweir	iNumberFormat = oObject.NumberFormat
139*cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
140*cdf0e10cSrcweir		Msgbox &quot;Error Reading the Number Format&quot;
141*cdf0e10cSrcweir		Resume CLERROR
142*cdf0e10cSrcweir	End If
143*cdf0e10cSrcweir
144*cdf0e10cSrcweir	On Local Error GoTo NOKEY
145*cdf0e10cSrcweir	aFormat() = oFormats.getByKey(iNumberFormat)
146*cdf0e10cSrcweir	On Local Error GoTo 0
147*cdf0e10cSrcweir	&apos; set new currency format with according settings
148*cdf0e10cSrcweir	nFormatDecimals = aFormat.Decimals
149*cdf0e10cSrcweir	nFormatLeading = aFormat.LeadingZeros
150*cdf0e10cSrcweir	bFormatNegRed = aFormat.NegativeRed
151*cdf0e10cSrcweir	bFormatThousands = aFormat.ThousandsSeparator
152*cdf0e10cSrcweir	oLocale = aFormat.Locale
153*cdf0e10cSrcweir	aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
154*cdf0e10cSrcweir	oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
155*cdf0e10cSrcweir	NOKEY:
156*cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
157*cdf0e10cSrcweir		Resume CLERROR
158*cdf0e10cSrcweir	End If
159*cdf0e10cSrcweir	CLERROR:
160*cdf0e10cSrcweirEnd Sub
161*cdf0e10cSrcweir
162*cdf0e10cSrcweir
163*cdf0e10cSrcweirFunction Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
164*cdf0e10cSrcweirDim nRetkey
165*cdf0e10cSrcweir	nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
166*cdf0e10cSrcweir	If nRetKey = -1 Then
167*cdf0e10cSrcweir		nRetKey = oFormats.addNew( aFormatStr, oLocale )
168*cdf0e10cSrcweir		If nRetKey = -1 Then nRetKey = 0
169*cdf0e10cSrcweir	End If
170*cdf0e10cSrcweir	Numberformat = nRetKey
171*cdf0e10cSrcweirEnd Function
172*cdf0e10cSrcweir
173*cdf0e10cSrcweir
174*cdf0e10cSrcweirFunction CheckFormatType(oStyle as Object)
175*cdf0e10cSrcweirDim oFormatofObject as Object
176*cdf0e10cSrcweir	oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
177*cdf0e10cSrcweir  	CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
178*cdf0e10cSrcweirEnd Function</script:module>