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