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