home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0031 / OwnEvents.xba < prev   
Encoding:
Extensible Markup Language  |  2001-07-20  |  9.0 KB  |  286 lines

  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.  
  5. Sub Main
  6.     Call CalAutopilotTable()
  7. End Sub
  8.  
  9. Sub CalSaveOwnData()
  10.     '    Sichert die Daten, die im lbOwnData Control eingegeben wurden.
  11.     '    Die Datei hei├ƒt Date.Dat und wird ins Unterverzeichnis Konfiguration
  12.     '    des Office3 Verzeichnis geschrieben.
  13. Dim FileName$
  14. Dim FileChannel%
  15.     Dim i as Integer
  16.     FileName$ = GetPathSettings("Config", False)+ GetPathSeparator() + "DATE.DAT"
  17.     '    Falls die Datei neu geschrieben wird, mu├ƒ sie vorher gel├╢scht werden
  18.     If Dir$(FileName$) = "DATE.DAT" Then
  19.         kill(FileName$)
  20.     End If
  21.  
  22.     FileChannel% = FreeFile()
  23.     Open FileName$ For OUTPUT Access WRITE LOCK WRITE As FileChannel%
  24.     
  25.     Write #FileChannel%, "=========================================================="
  26.     Write #FileChannel%, "Don't edit this file,"
  27.     Write #FileChannel%, "Don't edit this file!"
  28.     Write #FileChannel%, "----------------------------------------------------------"
  29.     Write #FileChannel%, "It is not allowed to edit this file! Don't edit this file!"
  30.     Write #FileChannel%, "=========================================================="
  31.     
  32.     For i = 0 To Ubound(DlgCalModel.lstOwnData.StringItemList())
  33.         Write #FileChannel%, DlgCalModel.lstOwnData.StringItemList(i)
  34.     Next
  35.     
  36.     Close #FileChannel%
  37. End Sub
  38.  
  39.  
  40. '    L├ñdt die Daten der pers├╢nlichen Ereignisse und
  41. '    schreibt diese dann in das Control lbOwnData.
  42. Sub CalLoadOwnData()
  43. Dim FileName$, tempStr$
  44. Dim FileChannel%, Count%
  45. Dim i as Integer
  46.     FileName$ = GetPathSettings("Config", False)+ GetPathSeparator() + "DATE.DAT"
  47.  
  48.     If Dir(FileName$) = "DATE.DAT" Then 
  49.         FileChannel% = FreeFile()
  50.         Open FileName$ For INPUT Access READ LOCK READ As FileChannel%
  51.         
  52.         '    Kommentare werden eingelesen
  53.         For Count% = 1 To 6
  54.             Line Input #FileChannel%, tempStr$
  55.         Next
  56.         i = 0
  57.         '    Einf├╝gen nach Reihenfolge sortiert.
  58.         While (not eof(#FileChannel%))
  59.             Input #FileChannel%, tempStr$
  60.             DlgCalModel.lstOwnData.AddItem(tempStr$, i)
  61.             i = i + 1
  62.         Wend        
  63.  
  64.         Close #FileChannel%
  65.     End If    
  66. End Sub
  67.  
  68.  
  69. Function SetFocusToControl(oTextControl as Object)
  70.     If oTextControl.Text = "" Then
  71.         Beep
  72.         oTextControl.DefaultButton = True
  73.         SetFocusToControl = True
  74.     Else
  75.         SetFocusToControl = False    
  76.     End If
  77. End Function
  78.  
  79.  
  80. Function CalCreateDateFromInput() as Date
  81. '    Generiert aus den Eingabedaten der Ereignisseite 
  82. '    ein Datum im Dateserial Format, 
  83. Dim newDate as Date
  84. Dim EvMonth as Integer
  85. Dim EvDay as Integer
  86. Dim EvYear as Integer
  87.     EvMonth = DlgCalModel.lstOwnEventMonth.SelectedItems(0)    
  88.     EvDay = Val(DlgCalModel.txtOwnEventDay.Text)    
  89.     If DlgCalModel.chkEventOnce.State = 1 Then
  90.         EvYear = Val(DlgCalModel.txtOwnEventYear.Text)
  91.         newDate = DateSerial(EvYear, EvMonth, EvDay)
  92.     Else
  93.         newDate = DateSerial(0, EvMonth, EvDay)
  94.     End If
  95.     CalCreateDateFromInput = newDate
  96. End Function
  97.  
  98.  
  99. Function CalCreateDateStrOfInput() as String
  100. Dim DateStr as String
  101. Dim EvMonth as Integer
  102. Dim EvDay as Integer
  103.     EvDay = Val(Trim(DlgCalModel.txtOwnEventDay.Text))
  104.     If EvDay < 10 Then
  105.         DateStr = "0" & EvDay & ". "
  106.     Else
  107.         DateStr = Cstr(EvDay) & ". "
  108.     End If
  109.     DateStr = DateStr & DlgCalendar.GetControl("lstOwnEventMonth").GetSelectedItem()
  110.     
  111.     If DlgCalModel.chkEventOnce.State = 1 And DlgCalModel.txtOwnEventYear.Text <> "" Then
  112.         DateStr = DateStr & "  " + Trim(DlgCalModel.txtOwnEventYear.Text)
  113.     Else
  114.         DateStr = DateStr + "      "
  115.     End If
  116.     DateStr = DateStr  + "  " + Trim(DlgCalModel.txtEvent.Text)
  117.     CalCreateDateStrOfInput = DateStr
  118. End Function
  119.  
  120.  
  121. Function CalGetDateWithoutYear&(ByVal i as Integer)
  122.     CalGetDateWithoutYear& = DateSerial(0, CalGetMonthOfEvent(i), CalGetDayOfEvent(i))
  123. End Function
  124.  
  125.  
  126. Sub CalcmdInsertData()
  127. Dim DateStr as String
  128. Dim LastIndex as Integer
  129. Dim bGetYear as Boolean
  130. Dim NewDate as Date
  131. Dim bInserted as Boolean
  132. Dim bDateDoubled as Boolean
  133. Dim EvYear as Integer
  134. Dim i as Integer
  135. Dim CurEvYear as Integer
  136. Dim CurEvMonth as Integer
  137. Dim CurEvDay as Integer
  138.  
  139.     bGetYear = DlgCalModel.chkEventOnce.State = 1
  140.     LastIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())            
  141.     If bGetYear Then
  142.         EvYear = Val(DlgCalModel.txtOwnEventYear.Text)
  143.         If (EvYear <= 1582) OR (EvYear >= 9957)    Then
  144.             SetFocusToControl(txtOwnEventMonth)
  145.             Exit Sub
  146.         End If
  147.     End If
  148.  
  149.     If DlgCalModel.chkEventOnce.State = 1 Then
  150.         EvYear = Val(DlgCalModel.txtOwnEventYear.Text)
  151.     End If            
  152.     newDate = CalCreateDateFromInput()
  153.     DateStr = CalCreateDateStrOfInput()
  154.     If DateStr = "" Then Exit Sub
  155.  
  156.     '    Es ist noch garnichts vorhanden
  157.     If Ubound(DlgCalModel.lstOwnData.StringItemList()) = -1 Then
  158.         DlgCalendar.GetControl("lstOwnData").AddItem(DateStr, 0 + 1)
  159.         bInserted = True
  160.     Else
  161.         '    gleiche jahre(auch keine Jahre sind gleiche jahre)->alt l├╢schen neu rein
  162.         i = 0
  163.         Do
  164.             CurEvYear = CalGetYearOfEvent(i)
  165.             CurEvMonth = CalGetMonthOfEvent(i)
  166.             CurEvDay = CalGetDayOfEvent(i)
  167.             If DateSerial(CurEvYear, CurEvMonth, CurEvDay) = NewDate Then
  168.                 ' Todo: Abchecken wie das ist mit 'Ereignis einmalig' oder nicht
  169.                 DlgCalModel.GetControl("lstOwnData").RemoveItem(DateStr, i)
  170.                 DlgCalModel.GetControl("lstOwnData").AddItem(DateStr, i)
  171.                 bInserted = True
  172.             End If
  173.             i = i + 1
  174.         Loop Until bInserted Or i > LastIndex
  175.         
  176.         '    Es existiert ein Datum mit Jahreszahl. Es wird dasselbe Datum
  177.         '    ohne Angabe der Jahreszahl angegeben.
  178.         If Not bInserted And Not bGetYear Then
  179.             i = 0
  180.             Do
  181.                 bInserted = CalGetDateWithoutYear(i) = newDate
  182.                 i = i + 1
  183.                 If bInserted Then
  184.                     If CalGetYearOfEvent(i) <> 0 Then
  185.                         DlgCalModel.GetControl("lstOwnData").AddItem(DateStr, i)
  186.                     End If
  187.                 End If    
  188.             Loop Until bInserted Or i > LastIndex
  189.         End If
  190.     
  191.         '    Das einzuf├╝gende Datum besitzt eine Jahreszahl, es gibt bereits
  192.         '    das Datum in der Liste, jedoch ohne Datum.
  193.         If Not bInserted And bGetYear Then
  194.             i = 0
  195.             Do
  196.                 bInserted = CalGetDateWithoutYear(i) = newDate
  197.                 i = i + 1
  198.                 If bInserted Then
  199.                     DlgCalModel.GetControl("lstOwnData").AddItem(DateStr, i)
  200.                 End If
  201.             Loop Until bInserted Or i > LastIndex
  202.         End If
  203.     
  204.         '    Das Datum ist noch nicht vorhanden und wir richtig einsortiert
  205.         If Not bInserted And Not bDateDoubled Then
  206.             i = 0
  207.             Do 
  208.                 bInserted = newDate > CalGetDateWithoutYear(i)
  209.                 i = i + 1
  210.                 If bInserted Then
  211.                     DlgCalendar.GetControl("lstOwnData").AddItem(DateStr, i)
  212.                 End If
  213.             Loop Until bInserted Or i > LastIndex
  214.         End If
  215.     End If
  216.     
  217.     '    Flag zum Speichern der neuen Daten.
  218.     If bInserted = True Then
  219.         bCalOwnDataChanged = True
  220.     End If
  221.     
  222.     Call CalClearInputMask()
  223. End Sub
  224.  
  225.  
  226. Function CalGetYearOfEvent(ByVal ListIndex as Integer) as Integer
  227. Dim YearStr as String
  228.     YearStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
  229.     CalGetYearOfEvent% = Val(Mid(YearStr, 10, 4))
  230. End Function
  231.  
  232.  
  233. Function CalGetDayOfEvent(ByVal ListIndex as Integer) as Integer
  234. Dim DayStr as String
  235.     DayStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
  236.     CalGetDayOfEvent = Val(Left(DayStr,2)) 'Mid(DayStr, 1, 2))
  237. End Function
  238.  
  239.  
  240. Function CalGetNameOfEvent(ByVal ListIndex as Integer) as Integer
  241. Dim NameStr as String
  242.     NameStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
  243.     NameStr = Trim (Mid(NameStr, 16))
  244. '    If Val(NameStr) = 0 Then
  245. '        NameStr = ""
  246. '    End If
  247.     CalGetNameOfEvent = NameStr
  248. End Function
  249.  
  250.  
  251. Function CalGetMonthOfEvent(ByVal ListIndex as Integer) as Integer
  252. Dim MonthStr as String
  253.     MonthStr = DlgCalModel.lstOwnData.StringItemList(ListIndex)
  254.     MonthStr = Mid(MonthStr, 5, 3)
  255.     CalGetMonthOfEvent = CalGetIntOfShortMonthName(MonthStr)
  256. End Function
  257.  
  258.  
  259. Sub CheckInsertedDates()
  260. Dim EvYear as Long
  261. Dim EvMonth as Long
  262. Dim EvDay as Long
  263. Dim sEvMonth as String
  264. Dim bDoEnable as Boolean
  265.     bDoEnable = True
  266.     If DlgCalModel.chkEventOnce.State = 1 Then
  267.         EvYear = Val(DlgCalModel.txtOwnEventYear.Text)
  268.             '(EvYear >= 1582) AND (EvYear <= 9957)
  269.         bDoEnable = EvYear <> 0
  270.     Else
  271.         EvYear = Year(Now())
  272.     End If
  273.     If bDoEnable Then
  274.         EvDay = Val(DlgCalModel.txtOwnEventDay.Text)
  275.         bDoEnable = Ubound(DlgCalModel.lstOwnEventMonth.SelectedItems()) > -1
  276.         If bDoEnable Then
  277.             EvMonth = DlgCalModel.lstOwnEventMonth.SelectedItems(0)
  278.             bDoEnable = (EvDay > 1) AND (EvDay < CalMaxDayInMonth(EvYear, EvMonth))
  279.             If bDoEnable Then
  280.                 bDoEnable = LTrim(DlgCalModel.txtEvent.Text) <> ""    
  281.             End If
  282.         End If
  283.     End If
  284.     DlgCalModel.cmdInsert.Enabled = bDoEnable
  285. End Sub
  286. </script:module>