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="OwnEvents" script:language="StarBasic">Option Explicit
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim JagielskiPublic Const SBDATEUNDEFINED as Double = -98765432.1
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim JagielskiSub Main
28*b1cdbd2cSJim Jagielski	Call CalAutopilotTable()
29*b1cdbd2cSJim JagielskiEnd Sub
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim JagielskiSub CalSaveOwnData()
33*b1cdbd2cSJim JagielskiDim FileName as String
34*b1cdbd2cSJim JagielskiDim FileChannel as Integer
35*b1cdbd2cSJim JagielskiDim i as Integer
36*b1cdbd2cSJim Jagielski	If bCalOwnDataChanged Then
37*b1cdbd2cSJim Jagielski		FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/&quot; &amp; &quot;DATE.DAT&quot;
38*b1cdbd2cSJim Jagielski		SaveDataToFile(FileName, DlgCalModel.lstOwnData.StringItemList())
39*b1cdbd2cSJim Jagielski	End If
40*b1cdbd2cSJim JagielskiEnd Sub
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim JagielskiSub CalLoadOwnData()
44*b1cdbd2cSJim JagielskiDim FileName as String
45*b1cdbd2cSJim JagielskiDim LocList() as String
46*b1cdbd2cSJim Jagielski	FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/DATE.DAT&quot;
47*b1cdbd2cSJim Jagielski	If LoadDataFromFile(FileName, LocList()) Then
48*b1cdbd2cSJim Jagielski		DlgCalModel.lstOwnData.StringItemList() = LocList()
49*b1cdbd2cSJim Jagielski	End If
50*b1cdbd2cSJim JagielskiEnd Sub
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim Jagielski
53*b1cdbd2cSJim JagielskiFunction CalCreateDateStrOfInput() as String
54*b1cdbd2cSJim JagielskiDim DateStr as String
55*b1cdbd2cSJim JagielskiDim CurOwnMonth as Integer
56*b1cdbd2cSJim JagielskiDim CurOwnDay as Integer
57*b1cdbd2cSJim JagielskiDim FormatDateStr as String
58*b1cdbd2cSJim JagielskiDim dblDate as Double
59*b1cdbd2cSJim JagielskiDim iLen as Integer
60*b1cdbd2cSJim JagielskiDim iDiff as Integer
61*b1cdbd2cSJim JagielskiDim i as Integer
62*b1cdbd2cSJim Jagielski	CurOwnDay = DlgCalModel.txtOwnEventDay.Value
63*b1cdbd2cSJim Jagielski	CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getselectedItemPos() + 1
64*b1cdbd2cSJim Jagielski	DateStr = DateSerial(0, CurOwnMonth, CurOwnDay)
65*b1cdbd2cSJim Jagielski	dblDate = CDbl(DateValue(DateStr))
66*b1cdbd2cSJim Jagielski	FormatDateStr = oNumberFormatter.convertNumberToString(lDateFormat, dblDate)
67*b1cdbd2cSJim Jagielski	iLen = Len(FormatDateStr)
68*b1cdbd2cSJim Jagielski	iDiff = 16 - iLen
69*b1cdbd2cSJim Jagielski	If iDiff &gt; 0 Then
70*b1cdbd2cSJim Jagielski		For i = 0 To iDiff
71*b1cdbd2cSJim Jagielski			FormatDateStr = FormatDateStr + &quot; &quot;
72*b1cdbd2cSJim Jagielski		Next i
73*b1cdbd2cSJim Jagielski	Else
74*b1cdbd2cSJim Jagielski    	MsgBox(&quot;Invalid DateFormat: &apos;FormatDateStr&apos;&quot;, 16, sWizardTitle)
75*b1cdbd2cSJim Jagielski		CalCreateDateStrOfInput = &quot;&quot;
76*b1cdbd2cSJim Jagielski    	Exit Function
77*b1cdbd2cSJim Jagielski    End If
78*b1cdbd2cSJim Jagielski	DateStr = FormatDateStr  &amp; Trim(DlgCalModel.txtEvent.Text)
79*b1cdbd2cSJim Jagielski	CalCreateDateStrOfInput = DateStr
80*b1cdbd2cSJim JagielskiEnd Function
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim JagielskiSub CalcmdInsertData()
85*b1cdbd2cSJim JagielskiDim MaxIndex as Integer
86*b1cdbd2cSJim JagielskiDim UIDateStr as String
87*b1cdbd2cSJim JagielskiDim DateStr as String
88*b1cdbd2cSJim JagielskiDim NewDate as Double
89*b1cdbd2cSJim JagielskiDim bInserted as Boolean
90*b1cdbd2cSJim JagielskiDim i as Integer
91*b1cdbd2cSJim JagielskiDim CurOwnDay as Integer
92*b1cdbd2cSJim JagielskiDim CurOwnMonth as Integer
93*b1cdbd2cSJim JagielskiDim CurOwnYear as Integer
94*b1cdbd2cSJim Jagielski	CurOwnDay = DlgCalModel.txtOwnEventDay.Value
95*b1cdbd2cSJim Jagielski	CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getSelectedItemPos() + 1
96*b1cdbd2cSJim Jagielski	UIDateStr = CalCreateDateStrOfInput()
97*b1cdbd2cSJim Jagielski	NewDate = GetDateUnits(CurOwnDay, CurOwnMonth, UIDateStr)
98*b1cdbd2cSJim Jagielski	If UIDateStr = &quot;&quot; Then Exit Sub
99*b1cdbd2cSJim Jagielski	MaxIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())
100*b1cdbd2cSJim Jagielski	If MaxIndex = -1 Then
101*b1cdbd2cSJim Jagielski		DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, 0 + 1)
102*b1cdbd2cSJim Jagielski		bInserted = True
103*b1cdbd2cSJim Jagielski	Else
104*b1cdbd2cSJim Jagielski		Dim CurEvMonth(MaxIndex) as Integer
105*b1cdbd2cSJim Jagielski		Dim CurEvDay(MaxIndex) as Integer
106*b1cdbd2cSJim Jagielski		Dim CurDate(MaxIndex) as Double
107*b1cdbd2cSJim Jagielski		&apos; same Years(&quot;no years&quot; are treated like same years) -&gt; delete old entry and insert new one
108*b1cdbd2cSJim Jagielski		i = 0
109*b1cdbd2cSJim Jagielski		Do
110*b1cdbd2cSJim Jagielski			CurDate(i) = GetSelectedDateUnits(CurEvDay(i), CurEvMonth(i), i)
111*b1cdbd2cSJim Jagielski			If CurDate(i) = NewDate Then
112*b1cdbd2cSJim Jagielski				DlgCalendar.GetControl(&quot;lstOwnData&quot;).RemoveItems(i,1)
113*b1cdbd2cSJim Jagielski				DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
114*b1cdbd2cSJim Jagielski				bInserted = True
115*b1cdbd2cSJim Jagielski			End If
116*b1cdbd2cSJim Jagielski			i = i + 1
117*b1cdbd2cSJim Jagielski		Loop Until bInserted Or i &gt; MaxIndex
118*b1cdbd2cSJim Jagielski
119*b1cdbd2cSJim Jagielski		&apos;  There exists already a date
120*b1cdbd2cSJim Jagielski		If Not bInserted Then
121*b1cdbd2cSJim Jagielski			i = 0
122*b1cdbd2cSJim Jagielski			Do
123*b1cdbd2cSJim Jagielski				If (CurEvMonth(i) = CurOwnMonth) And (CurEvDay(i) = CurOwnDay) Then
124*b1cdbd2cSJim Jagielski					bInserted = True
125*b1cdbd2cSJim Jagielski					DlgCalendar.GetControl(&quot;lstOwnData&quot;).RemoveItems(i,1)
126*b1cdbd2cSJim Jagielski					DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
127*b1cdbd2cSJim Jagielski				End If
128*b1cdbd2cSJim Jagielski				i = i + 1
129*b1cdbd2cSJim Jagielski			Loop Until bInserted Or i &gt; MaxIndex
130*b1cdbd2cSJim Jagielski		End If
131*b1cdbd2cSJim Jagielski
132*b1cdbd2cSJim Jagielski		&apos; The date is not yet existing and will will be sorted in accordingly
133*b1cdbd2cSJim Jagielski		If Not bInserted Then
134*b1cdbd2cSJim Jagielski			i = 0
135*b1cdbd2cSJim Jagielski			Do
136*b1cdbd2cSJim Jagielski				bInserted = NewDate &lt; CurDate(i)
137*b1cdbd2cSJim Jagielski				If bInserted Then
138*b1cdbd2cSJim Jagielski					DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, i)
139*b1cdbd2cSJim Jagielski				End If
140*b1cdbd2cSJim Jagielski				i = i + 1
141*b1cdbd2cSJim Jagielski			Loop Until bInserted Or i &gt; MaxIndex
142*b1cdbd2cSJim Jagielski			If Not bInserted  Then
143*b1cdbd2cSJim Jagielski				DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(UIDateStr, MaxIndex+1)
144*b1cdbd2cSJim Jagielski			End If
145*b1cdbd2cSJim Jagielski		End If
146*b1cdbd2cSJim Jagielski	End If
147*b1cdbd2cSJim Jagielski	bCalOwnDataChanged = True
148*b1cdbd2cSJim Jagielski	Call CalClearInputMask()
149*b1cdbd2cSJim JagielskiEnd Sub
150*b1cdbd2cSJim Jagielski
151*b1cdbd2cSJim Jagielski
152*b1cdbd2cSJim JagielskiFunction GetSelectedDateUnits(CurEvDay as Integer, CurEvMonth as Integer, i as Integer) as Double
153*b1cdbd2cSJim JagielskiDim dblDate as Double
154*b1cdbd2cSJim JagielskiDim DateStr as String
155*b1cdbd2cSJim Jagielski	dblDate = SBDATEUNDEFINED
156*b1cdbd2cSJim Jagielski	DateStr = DlgCalModel.lstOwnData.StringItemList(i)
157*b1cdbd2cSJim Jagielski	If DateStr &lt;&gt; &quot;&quot; Then
158*b1cdbd2cSJim Jagielski		dblDate = GetDateUnits(CurEvDay, CurEvMonth, DateStr)
159*b1cdbd2cSJim Jagielski	End If
160*b1cdbd2cSJim Jagielski	GetSelectedDateUnits() = dblDate
161*b1cdbd2cSJim JagielskiEnd Function
162*b1cdbd2cSJim Jagielski
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim JagielskiFunction GetDateUnits(CurEvDay as Integer, CurEvMonth as Integer, DateStr) as Double
165*b1cdbd2cSJim JagielskiDim bEventOnce as String
166*b1cdbd2cSJim JagielskiDim LocDateStr as String
167*b1cdbd2cSJim JagielskiDim dblDate as Double
168*b1cdbd2cSJim JagielskiDim lDate as Long
169*b1cdbd2cSJim Jagielski	LocDateStr = Mid(DateStr, 1, 15)
170*b1cdbd2cSJim Jagielski	LocDateStr = Trim(LocDateStr)
171*b1cdbd2cSJim Jagielski
172*b1cdbd2cSJim Jagielski	bEventOnce = True
173*b1cdbd2cSJim Jagielski	On Local Error Goto NODATEFORMAT
174*b1cdbd2cSJim Jagielski	dblDate = oNumberFormatter.convertStringToNumber(lDateFormat, LocDateStr)
175*b1cdbd2cSJim Jagielski	lDate = Clng(dblDate)
176*b1cdbd2cSJim Jagielski	CurEvMonth = Month(lDate)
177*b1cdbd2cSJim Jagielski	CurEvDay = Day(lDate)
178*b1cdbd2cSJim Jagielski	GetDateUnits() = dblDate
179*b1cdbd2cSJim Jagielski	Exit Function
180*b1cdbd2cSJim Jagielski	GetDateUnits() =SBDATEUNDEFINED
181*b1cdbd2cSJim JagielskiNODATEFORMAT:
182*b1cdbd2cSJim Jagielski	If Err &lt;&gt; 0 Then
183*b1cdbd2cSJim Jagielski	    MsgBox(&quot;Error: Date : &apos; &quot; &amp;  LocDateStr &amp; &quot;&apos; is not a valid Format&quot;, 16, sWizardTitle)
184*b1cdbd2cSJim Jagielski		Resume GETRETURNVALUE
185*b1cdbd2cSJim JagielskiGETRETURNVALUE:
186*b1cdbd2cSJim Jagielski		GetDateUnits() = SBDATEUNDEFINED
187*b1cdbd2cSJim Jagielski	End If
188*b1cdbd2cSJim JagielskiEnd Function
189*b1cdbd2cSJim Jagielski
190*b1cdbd2cSJim Jagielski
191*b1cdbd2cSJim JagielskiFunction CalGetNameOfEvent(ByVal ListIndex as Integer) as String
192*b1cdbd2cSJim JagielskiDim NameStr as String
193*b1cdbd2cSJim Jagielski	NameStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
194*b1cdbd2cSJim Jagielski	NameStr = Trim (Mid(NameStr, 16))
195*b1cdbd2cSJim Jagielski	CalGetNameOfEvent = NameStr
196*b1cdbd2cSJim JagielskiEnd Function
197*b1cdbd2cSJim Jagielski
198*b1cdbd2cSJim Jagielski
199*b1cdbd2cSJim Jagielski
200*b1cdbd2cSJim JagielskiSub CheckInsertedDates(Optional ControlEnvironment, Optional CurOwnMonth as Integer)
201*b1cdbd2cSJim JagielskiDim EvYear as Long
202*b1cdbd2cSJim JagielskiDim EvDay as Long
203*b1cdbd2cSJim JagielskiDim sEvMonth as String
204*b1cdbd2cSJim JagielskiDim bDoEnable as Boolean
205*b1cdbd2cSJim JagielskiDim ListboxName as String
206*b1cdbd2cSJim JagielskiDim MaxValue as Integer
207*b1cdbd2cSJim Jagielski	If Not IsMissing(ControlEnvironment) Then
208*b1cdbd2cSJim Jagielski		CurOwnMonth = DlgCalendar.GetControl(&quot;lstOwnEventMonth&quot;).getSelectedItemPos()+1
209*b1cdbd2cSJim Jagielski	End If
210*b1cdbd2cSJim Jagielski	EvYear =  Year(Now())
211*b1cdbd2cSJim Jagielski	bDoEnable = CurOwnMonth &lt;&gt; 0
212*b1cdbd2cSJim Jagielski	If bDoEnable Then
213*b1cdbd2cSJim Jagielski		MaxValue = CalMaxDayInMonth(EvYear, CurOwnMonth)
214*b1cdbd2cSJim Jagielski		DlgCalModel.txtOwnEventDay.ValueMax = MaxValue
215*b1cdbd2cSJim Jagielski		If DlgCalModel.txtOwnEventDay.Value &gt; MaxValue Then
216*b1cdbd2cSJim Jagielski			DlgCalModel.txtOwnEventDay.Value = MaxValue
217*b1cdbd2cSJim Jagielski		End If
218*b1cdbd2cSJim Jagielski		bDoEnable = DlgCalModel.txtOwnEventDay.Value &lt;&gt; 0
219*b1cdbd2cSJim Jagielski		If bDoEnable Then
220*b1cdbd2cSJim Jagielski			bDoEnable = Ubound(DlgCalModel.lstOwnEventMonth.SelectedItems()) &gt; -1
221*b1cdbd2cSJim Jagielski			If bDoEnable Then
222*b1cdbd2cSJim Jagielski				bDoEnable = LTrim(DlgCalModel.txtEvent.Text) &lt;&gt; &quot;&quot;
223*b1cdbd2cSJim Jagielski			End If
224*b1cdbd2cSJim Jagielski		End If
225*b1cdbd2cSJim Jagielski	End If
226*b1cdbd2cSJim Jagielski	DlgCalModel.cmdInsert.Enabled = bDoEnable
227*b1cdbd2cSJim JagielskiEnd Sub
228*b1cdbd2cSJim Jagielski
229*b1cdbd2cSJim Jagielski
230*b1cdbd2cSJim JagielskiSub GetOwnMonth()
231*b1cdbd2cSJim JagielskiDim EvYear as Integer
232*b1cdbd2cSJim JagielskiDim CurOwnMonth as Integer
233*b1cdbd2cSJim Jagielski	EvYear = year(now())
234*b1cdbd2cSJim Jagielski	CurOwnMonth = DlgCalModel.lstOwnEventMonth.SelectedItems(0) + 1
235*b1cdbd2cSJim Jagielski	DlgCalModel.txtOwnEventDay.ValueMax = CalMaxDayInMonth(EvYear, CurOwnMonth)
236*b1cdbd2cSJim Jagielski	CheckInsertedDates(,CurOwnMonth)
237*b1cdbd2cSJim JagielskiEnd Sub</script:module>
238