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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
<?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="Internet" script:language="StarBasic">REM ***** BASIC *****
Option Explicit
Public sNewSheetName as String
Function CheckHistoryControls()
Dim bLocGoOn as Boolean
Dim Firstdate as Date
Dim LastDate as Date
LastDate = CDateFromISO(StockRatesModel.txtEndDate.Date)
FirstDate = CDateFromISO(StockRatesModel.txtStartDate.Date)
bLocGoOn = FirstDate <> 0 And LastDate <> 0
If bLocGoOn Then
If FirstDate >= LastDate Then
Msgbox(sMsgStartDatebeforeEndDate,16, sProductname)
' Todo: Hier müsste eigentlich der Fokus auf die Textbox gelegt werden
' StockRatesModel.txtStartDate.Text = ""
bLocGoOn = False
End If
End If
CheckHistoryControls = bLocGoon
End Function
Sub InsertCompanyHistory()
Dim StockName as String
Dim CurRow as Integer
Dim sMsgInternetError as String
Dim CurRate
Dim oCell as Object
Dim sStockID as String
Dim ChartSource as String
If CheckHistoryControls() Then
StartDate = CDateFromISO(StockRatesModel.txtStartDate.Date)
EndDate = CDateFromISO(StockRatesModel.txtEndDate.Date)
DlgStockRates.EndExecute()
If StockRatesModel.optDaily.State = 1 Then
sInterval = "d"
iStep = 1
ElseIf StockRatesModel.optWeekly.State = 1 Then
sInterval = "w"
iStep = 7
StartDate = StartDate - WeekDay(StartDate) + 2
EndDate = EndDate - WeekDay(EndDate) + 2
End If
iEndDay = Day(EndDate)
iEndMonth = Month(EndDate)
iEndYear = Year(EndDate)
iStartDay = Day(StartDate)
iStartMonth = Month(StartDate)
iStartYear = Year(StartDate)
' oDocument.AddActionLock()
UnprotectSheets(oSheets)
InitializeStatusline("", 10, 1)
oBackGroundSheet = oSheets.GetbyName("Background")
StockName = DlgStockRates.GetControl("lstStockNames").GetSelectedItem()
CurRow = GetStockRowIndex(Stockname)
sStockID = oFirstSheet.GetCellByPosition(SBCOLUMNID1, CurRow).String
ChartSource = ReplaceString(HistoryChartSource, sStockID, "<StockID>")
ChartSource = ReplaceString(ChartSource, iStartDay, "<StartDay>")
ChartSource = ReplaceString(ChartSource, iStartMonth, "<StartMonth>")
ChartSource = ReplaceString(ChartSource, iStartYear, "<StartYear>")
ChartSource = ReplaceString(ChartSource, iEndDay, "<EndDay>")
ChartSource = ReplaceString(ChartSource, iEndMonth, "<EndMonth>")
ChartSource = ReplaceString(ChartSource, iEndYear, "<EndYear>")
ChartSource = ReplaceString(ChartSource, sInterval, "<interval>")
oStatusLine.SetValue(2)
If GetCurrentRate(ChartSource, CurRate, 1) Then
oStatusLine.SetValue(8)
UpdateValue(StockName, Today, CurRate)
oStatusLine.SetValue(9)
UpdateChart(StockName)
oStatusLine.SetValue(10)
Else
sMsgInternetError = Stockname & ": " & sNoInternetDataAvailable & chr(13) & sCheckInternetSettings
Msgbox(sMsgInternetError, 16, sProductname)
End If
ProtectSheets(oSheets)
oStatusLine.End
If oSheets.HasbyName(sNewSheetName) Then
oController.ActiveSheet = oSheets.GetByName(sNewSheetName)
End If
' oDocument.RemoveActionLock()
End If
End Sub
Sub InternetUpdate()
Dim i as Integer
Dim StocksCount as Integer
Dim iStartRow as Integer
Dim sUrl as String
Dim StockName as String
Dim CurRate
Dim oCell as Object
Dim sMsgInternetError as String
Dim sStockID as String
Dim ChartSource as String
' oDocument.AddActionLock()
Initialize(True)
UnprotectSheets(oSheets)
StocksCount = GetStocksCount(iStartRow)
InitializeStatusline("", StocksCount + 1, 1)
Today = CDate(Date)
For i = iStartRow + 1 To iStartRow + StocksCount
StockName = oFirstSheet.GetCellbyPosition(SBCOLUMNNAME1, i).String
sStockID = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
ChartSource = ReplaceString(sCurChartSource, sStockID, "<StockID>")
If GetCurrentRate(ChartSource, CurRate, 0) Then
InsertCurrentValue(CurRate, i, Now)
Else
sMsgInternetError = Stockname & ": " & sNoInternetDataAvailable & chr(13) & sCheckInternetSettings
Msgbox(sMsgInternetError, 16, sProductname)
End If
oStatusline.SetValue(i - iStartRow + 1)
Next
ProtectSheets(oSheets)
oStatusLine.End
' oDocument.RemoveActionLock
End Sub
Function GetCurrentRate(sUrl as String, fValue As Double, iValueCol as Integer) as Boolean
Dim sFilter As String
Dim sOptions As String
Dim oLinkSheet As Object
Dim sDate as String
If oSheets.hasByName("Link") Then
oLinkSheet = oSheets.getByName("Link")
Else
oLinkSheet = oDocument.createInstance("com.sun.star.sheet.Spreadsheet")
oSheets.insertByName("Link", oLinkSheet)
oLinkSheet.IsVisible = False
End If
sFilter = "Text - txt - csv (StarCalc)"
sOptions = sCurSeparator & ",34,SYSTEM,1,1/10/2/10/3/10/4/10/5/10/6/10/7/10/8/10/9/10"
oLinkSheet.LinkMode = com.sun.star.sheet.SheetLinkMode.NONE
oLinkSheet.link(sUrl, "", sFilter, sOptions, 1 )
fValue = oLinkSheet.getCellByPosition(1, iValueCol).Value
If fValue = 0 Then
Dim sValue as String
sValue = oLinkSheet.getCellByPosition(1, iValueCol).String
sValue = ReplaceString(sValue, ".",",")
fValue = Val(sValue)
End If
GetCurrentRate = fValue <> 0
End Function
Sub UpdateValue(ByVal sName As String, fDate As Double, fValue As Double )
Dim oSheet As Object
Dim iColumn As Long
Dim iRow As Long
Dim i as Integer
Dim oCell As Object
Dim LastDate as Date
Dim bLeaveLoop as Boolean
Dim RemoveCount as Integer
Dim iLastRow as Integer
Dim iLastLinkRow as Integer
'Dim sDate as String
Dim dDate as Date
Dim CurDate as Date
Dim oLinkSheet as Object
Dim StartIndex as Integer
Dim iCellValue as Long
' Insert Sheet with Company - Chart
sName = CheckNewSheetname(oSheets, sName)
If NOT oSheets.hasByName(sName) Then
oSheets.CopybyName("Background", sName, oSheets.Count)
oSheet = oSheets.getByName(sName)
iCurRow = SBSTARTROW
iMaxRow = iCurRow
oCell = oSheet.getCellByPosition(SBDATECOLUMN, iCurRow)
oCell.Value = fDate
End If
sNewSheetName = sName
oLinkSheet = oSheets.GetByName("Link")
oSheet = oSheets.getByName(sName)
iLastRow = GetLastUsedRow(oSheet)- 2
iLastLinkRow = GetLastUsedRow(oLinkSheet)
iCurRow = iLastRow
bLeaveLoop = False
RemoveCount = 0
' Delete all Cells in Date Area
Do
oCell = oSheet.GetCellbyPosition(SBDATECOLUMN,iCurRow)
If oCell.CellStyle = SBCOLUMNHEADER Then
bLeaveLoop = True
StartIndex = iCurRow
iCurRow = iCurRow + 1
Else
RemoveCount = RemoveCount + 1
iCurRow = iCurRow - 1
End If
Loop Until bLeaveLoop
If RemoveCount > 1 Then
oSheet.Rows.RemoveByIndex(iCurRow, RemoveCount-1)
End If
CurDate = EndDate
For i = 1 To iLastLinkRow ' To 1 Step -1
oCell = oSheet.GetCellbyPosition(SBDATECOLUMN,iCurRow)
iCellValue = oLinkSheet.GetCellByPosition(0,i).Value
If iCellValue > 0 Then
oCell.SetValue(oLinkSheet.GetCellByPosition(0,i).Value)
Else
oCell.SetValue(StringToDate(oLinkSheet.GetCellByPosition(0,i).String)
End If
oCell.SetValue(CurDate)
CurDate = CurDate - iStep
oCell = oSheet.GetCellbyPosition(SBVALUECOLUMN,iCurRow)
oCell.SetValue(oLinkSheet.GetCellByPosition(4,i).Value)
If i < iLastLinkRow Then
iCurRow = iCurRow + 1
oSheet.Rows.InsertByIndex(iCurRow,1)
End If
Next i
iMaxRow = iCurRow
End Sub
Function StringToDate(DateString as String) as Date
Dim ShortMonths(11)
Dim DateList() as String
Dim MaxIndex as Integer
Dim i as Integer
ShortMonths(0) = "Jan"
ShortMonths(1) = "Feb"
ShortMonths(2) = "Mar"
ShortMonths(3) = "Apr"
ShortMonths(4) = "May"
ShortMonths(5) = "Jun"
ShortMonths(6) = "Jul"
ShortMonths(7) = "Aug"
ShortMonths(8) = "Sep"
ShortMonths(9) = "Oct"
ShortMonths(10) = "Nov"
ShortMonths(11) = "Dec"
For i = 0 To 11
DateString = ReplaceString(DateString,CStr(i+1),ShortMonths(i))
Next i
DateString = ReplaceString(DateString, ".", "-")
StringToDate = CDate(DateString)
End Function
Sub UpdateChart(sName As String)
Dim oSheet As Object
Dim oCell As Object, oCursor As Object
Dim oChartRange As Object
Dim oEmbeddedChart As Object, oCharts As Object
Dim oChart As Object, oDiagram As Object
Dim oYAxis As Object, oXAxis As Object
Dim fMin As Double, fMax As Double
Dim nDateFormat As Long
Dim aPos As Variant
Dim aSize As Variant
Dim oContainerChart as Object
Dim mRangeAddresses(0) as New com.sun.star.table.CellRangeAddress
mRangeAddresses(0).Sheet = GetSheetIndex(oSheets, sNewSheetName)
mRangeAddresses(0).StartColumn = SBDATECOLUMN
mRangeAddresses(0).StartRow = SBSTARTROW-1
mRangeAddresses(0).EndColumn = SBVALUECOLUMN
mRangeAddresses(0).EndRow = iMaxRow
oSheet = oDocument.Sheets.getByName(sNewSheetName)
oCharts = oSheet.Charts
If Not oCharts.hasElements Then
oSheet.GetCellbyPosition(2,2).SetString(sName)
oChartRange = oSheet.getCellRangeByPosition(SBDATECOLUMN,6,5,SBSTARTROW-3)
aPos = oChartRange.Position
aSize = oChartRange.Size
Dim oRectangleShape As New com.sun.star.awt.Rectangle
oRectangleShape.X = aPos.X
oRectangleShape.Y = aPos.Y
oRectangleShape.Width = aSize.Width
oRectangleShape.Height = aSize.Height
oCharts.addNewByName(sName, oRectangleShape, mRangeAddresses(), True, False)
oContainerChart = oCharts.getByName(sName)
oChart = oContainerChart.EmbeddedObject
oChart.Title.String = ""
oChart.HasLegend = False
oChart.diagram = oChart.createInstance("com.sun.star.chart.XYDiagram")
oDiagram = oChart.Diagram
oDiagram.DataRowSource = com.sun.star.chart.ChartDataRowSource.COLUMNS
oChart.Area.LineStyle = com.sun.star.drawing.LineStyle.SOLID
oXAxis = oDiagram.XAxis
oXAxis.TextBreak = False
nDateFormat = oXAxis.NumberFormats.getStandardFormat(com.sun.star.util.NumberFormat.DATE, oDocLocale)
oYAxis = oDiagram.getYAxis()
oYAxis.AutoOrigin = True
Else
oChart = oCharts(0)
oChart.Ranges = mRangeAddresses()
oChart.HasRowHeaders = False
oEmbeddedChart = oChart.EmbeddedObject
oDiagram = oEmbeddedChart.Diagram
oXAxis = oDiagram.XAxis
End If
oXAxis.AutoStepMain = False
oXAxis.AutoStepHelp = False
oXAxis.StepMain = iStep
oXAxis.StepHelp = iStep
fMin = oSheet.getCellByPosition(SBDATECOLUMN,SBSTARTROW).Value
fMax = oSheet.getCellByPosition(SBDATECOLUMN,iMaxRow).Value
oXAxis.Min = fMin
oXAxis.Max = fMax
oXAxis.AutoMin = False
oXAxis.AutoMax = False
End Sub
Sub CalculateChartafterSplit(SheetName, NewNumber, OldNumber, NoteText, SplitDate)
Dim oSheet as Object
Dim i as Integer
Dim oValueCell as Object
Dim oDateCell as Object
Dim bLeaveLoop as Boolean
If oSheets.HasbyName(SheetName) Then
oSheet = oSheets.GetbyName(SheetName)
i = 0
bLeaveLoop = False
Do
oValueCell = oSheet.GetCellbyPosition(SBVALUECOLUMN, SBSTARTROW + i)
If oValueCell.CellStyle = CurrCellStyle Then
SplitCellValue(oSheet, OldNumber, NewNumber, SBVALUECOLUMN, SBSTARTROW + i, "")
i = i + 1
Else
bLeaveLoop = True
End If
Loop Until bLeaveLoop
oDateCell = oSheet.GetCellbyPosition(SBDATECOLUMN, SBSTARTROW + i-1)
' CellDate = oDateCell.Value
oDateCell.Annotation.SetString(NoteText)
End If
End Sub</script:module>
|