summaryrefslogtreecommitdiff
path: root/wizards/source/schedule/OwnEvents.xba
blob: 2f2d3074887dfd61816ca80a679346e3214d83cb (plain)
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
<?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="OwnEvents" script:language="StarBasic">Option Explicit

Dim CurOwnMonth as Integer

Sub Main
	Call CalAutopilotTable()
End Sub



Sub CalSaveOwnData()
Dim FileName as String
Dim FileChannel as Integer
Dim i as Integer
	If bCalOwnDataChanged Then
		FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/&quot; &amp; &quot;DATE.DAT&quot;
		SaveDataToFile(FileName, DlgCalModel.lstOwnData.StringItemList())
	End If
End Sub


Sub CalLoadOwnData()
Dim FileName as String
Dim LocList() as String
	FileName = GetPathSettings(&quot;UserConfig&quot;, False) &amp; &quot;/DATE.DAT&quot;
	If LoadDataFromFile(FileName, LocList()) Then
		DlgCalModel.lstOwnData.StringItemList() = LocList()
	End If
End Sub


Function CalCreateDateFromInput() as Date
&apos;	Generiert aus den Eingabedaten der Ereignisseite 
&apos;	ein Datum im Dateserial Format, 
Dim newDate as Date
Dim EvDay as Integer
Dim EvYear as Integer
	EvDay = DlgCalModel.txtOwnEventDay.Value
	If DlgCalModel.chkEventOnce.State = 1 Then
		EvYear = DlgCalModel.txtOwnEventYear.Value
		newDate = DateSerial(EvYear, CurOwnMonth, EvDay)
	Else
		newDate = DateSerial(0, CurOwnMonth, EvDay)
	End If
	CalCreateDateFromInput = newDate
End Function



Function CalCreateDateStrOfInput() as String
Dim DateStr as String
Dim EvMonth as Integer
Dim EvDay as Integer
Dim CurMonthStr as String
	EvDay = DlgCalModel.txtOwnEventDay.Value
	If EvDay &lt; 10 Then
		DateStr = &quot;0&quot; &amp; EvDay &amp; &quot;. &quot;
	Else
		DateStr = Cstr(EvDay) &amp; &quot;. &quot;
	End If
	CurMonthStr = DlgCalModel.lstOwnEventMonth.StringItemList(CurOwnMonth-1)
	If Len(CurMonthStr) = 2 Then
		CurMonthStr = CurMonthStr &amp; &quot; &quot;
	End If
	DateStr = DateStr &amp; CurMonthStr
	
	If DlgCalModel.chkEventOnce.State = 1 And DlgCalModel.txtOwnEventYear.Value &lt;&gt; 0 Then
		DateStr = DateStr &amp; &quot;  &quot; + DlgCalModel.txtOwnEventYear.Value
	Else
		DateStr = DateStr + &quot;      &quot;
	End If
	DateStr = DateStr  + &quot;  &quot; + Trim(DlgCalModel.txtEvent.Text)
	CalCreateDateStrOfInput = DateStr
End Function


Function CalGetDateWithoutYear&amp;(ByVal i as Integer)
	CalGetDateWithoutYear&amp; = DateSerial(0, CalGetMonthOfEvent(i), CalGetDayOfEvent(i))
End Function


Sub CalcmdInsertData()
Dim DateStr as String
Dim LastIndex as Integer
Dim bGetYear as Boolean
Dim NewDate as Date
Dim bInserted as Boolean
Dim bDateDoubled as Boolean
Dim EvYear as Integer
Dim i as Integer
Dim CurDate as Date
Dim CurEvYear as Integer
Dim CurEvMonth as Integer
Dim CurEvDay as Integer

	bGetYear = DlgCalModel.chkEventOnce.State = 1
	LastIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())			
	If bGetYear Then
		EvYear = DlgCalModel.txtOwnEventYear.Value
	End If

	newDate = CalCreateDateFromInput()
	DateStr = CalCreateDateStrOfInput()
	If DateStr = &quot;&quot; Then Exit Sub

	&apos;	Es ist noch garnichts vorhanden
	If Ubound(DlgCalModel.lstOwnData.StringItemList()) = -1 Then
		DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(DateStr, 0 + 1)
		bInserted = True
	Else
		&apos;	gleiche jahre(auch keine Jahre sind gleiche jahre)-&gt;alt löschen neu rein
		i = 0
		Do
			CurEvYear = CalGetYearOfEvent(i)
			CurEvMonth = CalGetMonthOfEvent(i)
			CurEvDay = CalGetDayOfEvent(i)
			If DateSerial(CurEvYear, CurEvMonth, CurEvDay) = NewDate Then
				&apos; Todo: Abchecken wie das ist mit &apos;Ereignis einmalig&apos; oder nicht
				DlgCalendar.GetControl(&quot;lstOwnData&quot;).RemoveItems(i,1)
				DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(DateStr, i)
				bInserted = True
			End If
			i = i + 1
		Loop Until bInserted Or i &gt; LastIndex
		
		&apos;	Es existiert ein Datum mit Jahreszahl. Es wird dasselbe Datum
		&apos;	ohne Angabe der Jahreszahl angegeben.
		If Not bInserted And Not bGetYear Then
			i = 0
			Do
				bInserted = CalGetDateWithoutYear(i) = newDate
				If bInserted Then
					If CalGetYearOfEvent(i) &lt;&gt; 0 Then
						DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(DateStr, i+1)
					End If
				End If	
				i = i + 1
			Loop Until bInserted Or i &gt; LastIndex
		End If
	
		&apos;	Das einzufügende Datum besitzt eine Jahreszahl, es gibt bereits
		&apos;	das Datum in der Liste, jedoch ohne Datum.
		If Not bInserted And bGetYear Then
			i = 0
			Do
				bInserted = CalGetDateWithoutYear(i) = newDate
				i = i + 1
				If bInserted Then
					DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(DateStr, i)
				End If
			Loop Until bInserted Or i &gt; LastIndex
		End If
	
		&apos;	Das Datum ist noch nicht vorhanden und wird richtig einsortiert
		If Not bInserted And Not bDateDoubled Then
			i = 0
			Do 
				CurDate = CalGetDateWithoutYear(i)
				bInserted = newDate &lt; CurDate
				If bInserted Then
					Exit Do
				End If
				i = i + 1
			Loop Until bInserted Or i &gt; LastIndex
			DlgCalendar.GetControl(&quot;lstOwnData&quot;).AddItem(DateStr, i)
		End If
	End If
	
	bCalOwnDataChanged = True
	
	Call CalClearInputMask()
End Sub


Function CalGetYearOfEvent(ByVal ListIndex as Integer) as Integer
Dim YearStr as String
	YearStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
	CalGetYearOfEvent = Val(Mid(YearStr, 10, 4))
End Function


Function CalGetDayOfEvent(ByVal ListIndex as Integer) as Integer
Dim DayStr as String
	DayStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
	CalGetDayOfEvent = Val(Left(DayStr,2))
End Function


Function CalGetNameOfEvent(ByVal ListIndex as Integer) as String
Dim NameStr as String
	NameStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
	NameStr = Trim (Mid(NameStr, 16))
	CalGetNameOfEvent = NameStr
End Function


Function CalGetMonthOfEvent(ByVal ListIndex as Integer) as Integer
Dim MonthStr as String
	MonthStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
	MonthStr = Mid(MonthStr, 5, 3)
	&apos; In chinese Short Monthnames may be only 2 characters long. 
	&apos; In this case the third character is filled up with an empty space
	MonthStr = RTrim(MonthStr)
	CalGetMonthOfEvent = CalGetIntOfShortMonthName(MonthStr)
End Function


Function GetOwnYear()	
	If DlgCalModel.chkEventOnce.State = 1 Then
		GetOwnYear() = DlgCalModel.txtOwnEventYear.Value
	Else
		GetOwnYear() = Year(Now())
	End If
End Function


Sub CheckInsertedDates()
Dim EvYear as Long
Dim EvDay as Long
Dim sEvMonth as String
Dim bDoEnable as Boolean	
	EvYear = GetOwnYear()
	bDoEnable = (EvYear &lt;&gt; 0) And (CurOwnMonth &gt; 0)
	If bDoEnable Then
		DlgCalModel.txtOwnEventDay.ValueMax = CalMaxDayInMonth(EvYear, CurOwnMonth)
		bDoEnable = DlgCalModel.txtOwnEventDay.Value &lt;&gt; 0
		If bDoEnable Then
			bDoEnable = Ubound(DlgCalModel.lstOwnEventMonth.SelectedItems()) &gt; -1
			If bDoEnable Then
				bDoEnable = LTrim(DlgCalModel.txtEvent.Text) &lt;&gt; &quot;&quot;
			End If
		End If
	End If
	DlgCalModel.cmdInsert.Enabled = bDoEnable
End Sub


Sub GetOwnMonth()
Dim EvYear as Integer
	EvYear = GetOwnYear()
	CurOwnMonth = DlgCalModel.lstOwnEventMonth.SelectedItems(0) + 1
	DlgCalModel.txtOwnEventDay.ValueMax = CalMaxDayInMonth(EvYear, CurOwnMonth)
	CheckInsertedDates()
End Sub</script:module>