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