1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="OwnEvents" script:language="StarBasic">Option Explicit
24
25Public Const SBDATEUNDEFINED as Double = -98765432.1
26
27Sub Main
28	Call CalAutopilotTable()
29End Sub
30
31
32Sub CalSaveOwnData()
33Dim FileName as String
34Dim FileChannel as Integer
35Dim i as Integer
36	If bCalOwnDataChanged Then
37		FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/&quot; &amp; &quot;DATE.DAT&quot;
38		SaveDataToFile(FileName, DlgCalModel.lstOwnData.StringItemList())
39	End If
40End Sub
41
42
43Sub CalLoadOwnData()
44Dim FileName as String
45Dim LocList() as String
46	FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/DATE.DAT&quot;
47	If LoadDataFromFile(FileName, LocList()) Then
48		DlgCalModel.lstOwnData.StringItemList() = LocList()
49	End If
50End Sub
51
52
53Function CalCreateDateStrOfInput() as String
54Dim DateStr as String
55Dim CurOwnMonth as Integer
56Dim CurOwnDay as Integer
57Dim FormatDateStr as String
58Dim dblDate as Double
59Dim iLen as Integer
60Dim iDiff as Integer
61Dim i as Integer
62	CurOwnDay = DlgCalModel.txtOwnEventDay.Value
63	CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getselectedItemPos() + 1
64	DateStr = DateSerial(0, CurOwnMonth, CurOwnDay)
65	dblDate = CDbl(DateValue(DateStr))
66	FormatDateStr = oNumberFormatter.convertNumberToString(lDateFormat, dblDate)
67	iLen = Len(FormatDateStr)
68	iDiff = 16 - iLen
69	If iDiff &gt; 0 Then
70		For i = 0 To iDiff
71			FormatDateStr = FormatDateStr + &quot; &quot;
72		Next i
73	Else
74    	MsgBox(&quot;Invalid DateFormat: &apos;FormatDateStr&apos;&quot;, 16, sWizardTitle)
75		CalCreateDateStrOfInput = &quot;&quot;
76    	Exit Function
77    End If
78	DateStr = FormatDateStr  &amp; Trim(DlgCalModel.txtEvent.Text)
79	CalCreateDateStrOfInput = DateStr
80End Function
81
82
83
84Sub CalcmdInsertData()
85Dim MaxIndex as Integer
86Dim UIDateStr as String
87Dim DateStr as String
88Dim NewDate as Double
89Dim bInserted as Boolean
90Dim i as Integer
91Dim CurOwnDay as Integer
92Dim CurOwnMonth as Integer
93Dim CurOwnYear as Integer
94	CurOwnDay = DlgCalModel.txtOwnEventDay.Value
95	CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getSelectedItemPos() + 1
96	UIDateStr = CalCreateDateStrOfInput()
97	NewDate = GetDateUnits(CurOwnDay, CurOwnMonth, UIDateStr)
98	If UIDateStr = &quot;&quot; Then Exit Sub
99	MaxIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())
100	If MaxIndex = -1 Then
101		DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, 0 + 1)
102		bInserted = True
103	Else
104		Dim CurEvMonth(MaxIndex) as Integer
105		Dim CurEvDay(MaxIndex) as Integer
106		Dim CurDate(MaxIndex) as Double
107		&apos; same Years(&quot;no years&quot; are treated like same years) -&gt; delete old entry and insert new one
108		i = 0
109		Do
110			CurDate(i) = GetSelectedDateUnits(CurEvDay(i), CurEvMonth(i), i)
111			If CurDate(i) = NewDate Then
112				DlgCalendar.GetControl(&quot;lstOwnData&quot;).RemoveItems(i,1)
113				DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
114				bInserted = True
115			End If
116			i = i + 1
117		Loop Until bInserted Or i &gt; MaxIndex
118
119		&apos;  There exists already a date
120		If Not bInserted Then
121			i = 0
122			Do
123				If (CurEvMonth(i) = CurOwnMonth) And (CurEvDay(i) = CurOwnDay) Then
124					bInserted = True
125					DlgCalendar.GetControl(&quot;lstOwnData&quot;).RemoveItems(i,1)
126					DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
127				End If
128				i = i + 1
129			Loop Until bInserted Or i &gt; MaxIndex
130		End If
131
132		&apos; The date is not yet existing and will will be sorted in accordingly
133		If Not bInserted Then
134			i = 0
135			Do
136				bInserted = NewDate &lt; CurDate(i)
137				If bInserted Then
138					DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
139				End If
140				i = i + 1
141			Loop Until bInserted Or i &gt; MaxIndex
142			If Not bInserted  Then
143				DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, MaxIndex+1)
144			End If
145		End If
146	End If
147	bCalOwnDataChanged = True
148	Call CalClearInputMask()
149End Sub
150
151
152Function GetSelectedDateUnits(CurEvDay as Integer, CurEvMonth as Integer, i as Integer) as Double
153Dim dblDate as Double
154Dim DateStr as String
155	dblDate = SBDATEUNDEFINED
156	DateStr = DlgCalModel.lstOwnData.StringItemList(i)
157	If DateStr &lt;&gt; &quot;&quot; Then
158		dblDate = GetDateUnits(CurEvDay, CurEvMonth, DateStr)
159	End If
160	GetSelectedDateUnits() = dblDate
161End Function
162
163
164Function GetDateUnits(CurEvDay as Integer, CurEvMonth as Integer, DateStr) as Double
165Dim bEventOnce as String
166Dim LocDateStr as String
167Dim dblDate as Double
168Dim lDate as Long
169	LocDateStr = Mid(DateStr, 1, 15)
170	LocDateStr = Trim(LocDateStr)
171
172	bEventOnce = True
173	On Local Error Goto NODATEFORMAT
174	dblDate = oNumberFormatter.convertStringToNumber(lDateFormat, LocDateStr)
175	lDate = Clng(dblDate)
176	CurEvMonth = Month(lDate)
177	CurEvDay = Day(lDate)
178	GetDateUnits() = dblDate
179	Exit Function
180	GetDateUnits() =SBDATEUNDEFINED
181NODATEFORMAT:
182	If Err &lt;&gt; 0 Then
183	    MsgBox(&quot;Error: Date : &apos; &quot; &amp;  LocDateStr &amp; &quot;&apos; is not a valid Format&quot;, 16, sWizardTitle)
184		Resume GETRETURNVALUE
185GETRETURNVALUE:
186		GetDateUnits() = SBDATEUNDEFINED
187	End If
188End Function
189
190
191Function CalGetNameOfEvent(ByVal ListIndex as Integer) as String
192Dim NameStr as String
193	NameStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
194	NameStr = Trim (Mid(NameStr, 16))
195	CalGetNameOfEvent = NameStr
196End Function
197
198
199
200Sub CheckInsertedDates(Optional ControlEnvironment, Optional CurOwnMonth as Integer)
201Dim EvYear as Long
202Dim EvDay as Long
203Dim sEvMonth as String
204Dim bDoEnable as Boolean
205Dim ListboxName as String
206Dim MaxValue as Integer
207	If Not IsMissing(ControlEnvironment) Then
208		CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getSelectedItemPos()+1
209	End If
210	EvYear =  Year(Now())
211	bDoEnable = CurOwnMonth &lt;&gt; 0
212	If bDoEnable Then
213		MaxValue = CalMaxDayInMonth(EvYear, CurOwnMonth)
214		DlgCalModel.txtOwnEventDay.ValueMax = MaxValue
215		If DlgCalModel.txtOwnEventDay.Value &gt; MaxValue Then
216			DlgCalModel.txtOwnEventDay.Value = MaxValue
217		End If
218		bDoEnable = DlgCalModel.txtOwnEventDay.Value &lt;&gt; 0
219		If bDoEnable Then
220			bDoEnable = Ubound(DlgCalModel.lstOwnEventMonth.SelectedItems()) &gt; -1
221			If bDoEnable Then
222				bDoEnable = LTrim(DlgCalModel.txtEvent.Text) &lt;&gt; &quot;&quot;
223			End If
224		End If
225	End If
226	DlgCalModel.cmdInsert.Enabled = bDoEnable
227End Sub
228
229
230Sub GetOwnMonth()
231Dim EvYear as Integer
232Dim CurOwnMonth as Integer
233	EvYear = year(now())
234	CurOwnMonth = DlgCalModel.lstOwnEventMonth.SelectedItems(0) + 1
235	DlgCalModel.txtOwnEventDay.ValueMax = CalMaxDayInMonth(EvYear, CurOwnMonth)
236	CheckInsertedDates(,CurOwnMonth)
237End Sub</script:module>
238