home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Month_View205275392007.psc / CalendarCtl / cAlarmGroup.cls < prev    next >
Text File  |  2004-02-23  |  8KB  |  197 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cAlarmGroup"
  10. Attribute VB_GlobalNameSpace = True
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Dim m_Collection As Collection
  16. Private Declare Function GetTickCount Lib "kernel32" () As Long
  17.  
  18. Public Function add(dateTime As Date, alarmType As eAlarmType, filename As String, message As String, Optional UID As Double, Optional repeat As Integer, Optional presetMins As Integer = 0, Optional alarmTime As Date) As Long
  19.     Dim newOBJ As New cAlarm
  20.     Dim nCount As Integer
  21.     Dim nInsert As Integer
  22.     
  23.     nInsert = -1
  24.     For nCount = 1 To m_Collection.Count
  25.         If m_Collection(nCount).dateTime > dateTime Then
  26.             nInsert = nCount
  27.             Exit For
  28.         End If
  29.     Next nCount
  30.     
  31.     With newOBJ
  32.         .dateTime = dateTime
  33.         .alarmType = alarmType
  34.         .filename = filename
  35.         .message = message
  36.         .repeat = repeat
  37.         .presetMins = presetMins
  38.         If CDbl(alarmTime) = 0 Then
  39.             .alarmTime = DateAdd("n", -.presetMins, .dateTime)
  40.         Else
  41.             .alarmTime = alarmTime
  42.         End If
  43.         If UID = 0 Then
  44.             .UID = GetTickCount + Int((1000 * Rnd) + 1) / 1000
  45.         Else
  46.             .UID = UID
  47.         End If
  48.     End With
  49.     
  50.     If nInsert = -1 Then
  51.         m_Collection.add newOBJ
  52.     Else
  53.         m_Collection.add newOBJ, , nInsert
  54.     End If
  55.     add = newOBJ.UID
  56.     Set newOBJ = Nothing
  57. End Function
  58. Public Sub DeleteUID(UID As Double)
  59.     Dim nCount As Integer
  60.     
  61.     For nCount = 1 To m_Collection.Count
  62.         If CStr(m_Collection(nCount).UID) = CStr(UID) Then
  63.             m_Collection.Remove (nCount)
  64.             Exit For
  65.         End If
  66.     Next nCount
  67. End Sub
  68. Public Sub Delete(Index As Integer)
  69.     m_Collection.Remove Index
  70. End Sub
  71. Public Function Item(Index As Integer) As cAlarm
  72. Attribute Item.VB_UserMemId = 0
  73.     Set Item = m_Collection(Index)
  74. End Function
  75. Public Function Count() As Integer
  76.     Count = m_Collection.Count
  77. End Function
  78. Private Sub Class_Initialize()
  79.     Set m_Collection = New Collection
  80. End Sub
  81. Public Function FindItem(value As Double) As Integer
  82.     Dim nCount As Integer
  83.     
  84.     For nCount = 1 To m_Collection.Count
  85.         If CStr(m_Collection(nCount).UID) = CStr(value) Then
  86.             FindItem = nCount
  87.             Exit For
  88.         End If
  89.     Next nCount
  90. End Function
  91. Public Sub LoadData(filename As String)
  92.     Dim nLoadFile As Integer
  93.     Dim nextLine As String
  94.     Dim sSplit() As String
  95.     Dim sVersion As String
  96.     
  97.     Set m_Collection = New Collection
  98.     If Dir(filename, vbNormal) <> "" Then
  99.         nLoadFile = FreeFile
  100.         Open filename For Input As #nLoadFile
  101.             Line Input #nLoadFile, nextLine
  102.             sVersion = nextLine
  103.             Do While Not EOF(nLoadFile)
  104.                 Line Input #nLoadFile, nextLine
  105.                 If Trim(nextLine) <> "" Then
  106.                     On Error GoTo e_Next
  107.                     sSplit = Split(nextLine, SPACER_CHAR)
  108.                     If CLng(sVersion) <= 1001004 Then
  109.                         If UBound(sSplit) >= 4 Then
  110.                             If CDate(sSplit(1)) >= DateAdd("n", -1, Now) Then
  111.                                 Call add(CDate(sSplit(1)), CInt(sSplit(2)), "", LoadFormat(sSplit(4)), CDbl(sSplit(0)), CInt(sSplit(3)))
  112.                             End If
  113.                         End If
  114.                     ElseIf CLng(sVersion) <= 1001009 Then
  115.                         If UBound(sSplit) >= 5 Then
  116.                             If CDate(sSplit(1)) >= DateAdd("n", -1, Now) Then
  117.                                 Call add(CDate(sSplit(1)), CInt(sSplit(2)), CStr(sSplit(4)), LoadFormat(sSplit(5)), CDbl(sSplit(0)), CInt(sSplit(3)))
  118.                             End If
  119.                         End If
  120.                     Else
  121.                         If UBound(sSplit) >= 6 Then
  122.                             If CDate(sSplit(1)) >= DateAdd("n", -1, Now) Then
  123.                                 Call add(CDate(sSplit(1)), CInt(sSplit(2)), CStr(sSplit(5)), LoadFormat(sSplit(6)), CDbl(sSplit(0)), CInt(sSplit(3)), CInt(sSplit(4)))
  124.                             End If
  125.                         End If
  126.                     End If
  127. e_Next:
  128.                 End If
  129.             Loop
  130.         Close #nLoadFile
  131.     End If
  132. End Sub
  133. Public Sub SaveData(filename As String)
  134.     Dim nLoadFile As Integer
  135.     Dim nCount As Integer
  136.     
  137.     nLoadFile = FreeFile
  138.     Open filename For Output As #nLoadFile
  139.         Print #nLoadFile, Format(App.Major, "000") & Format(App.Minor, "000") & Format(App.Revision, "0000")
  140.         For nCount = 1 To m_Collection.Count
  141.             Print #nLoadFile, m_Collection(nCount).UID & SPACER_CHAR & m_Collection(nCount).dateTime & SPACER_CHAR & m_Collection(nCount).alarmType & SPACER_CHAR & m_Collection(nCount).repeat & SPACER_CHAR & m_Collection(nCount).presetMins & SPACER_CHAR & m_Collection(nCount).filename & SPACER_CHAR & SaveFormat(m_Collection(nCount).message)
  142.         Next nCount
  143.         Print #nLoadFile, ""
  144.     Close #nLoadFile
  145. End Sub
  146.  
  147. Public Function GetAlarmDays(inputDate As Date) As cAlarmGroup
  148.     Dim nCount As Integer
  149.     Dim dStartDate As Date
  150.     Dim dEndDate As Date
  151.     
  152.     dStartDate = DateAdd("s", -1, Format(inputDate, "m") & "/01/" & Format(inputDate, "yy"))
  153.     dEndDate = DateAdd("m", 1, Format(inputDate, "m") & "/01/" & Format(inputDate, "yy"))
  154.     
  155.     Set GetAlarmDays = New cAlarmGroup
  156.     For nCount = 1 To m_Collection.Count
  157.         With m_Collection(nCount)
  158.             If .dateTime > dStartDate And .dateTime < dEndDate Then
  159.                 GetAlarmDays.add .dateTime, .alarmType, .filename, .message, .UID, .repeat, .presetMins
  160.             End If
  161.         End With
  162.     Next nCount
  163.     
  164. End Function
  165. Public Function GetEvents(inputDate As Date, searchInterval As eUpdate, Optional weekStartsWith As VbDayOfWeek = vbSunday) As cAlarmGroup
  166.     Dim nCount As Integer
  167.     Dim dStartDate As Date
  168.     Dim dEndDate As Date
  169.     Dim dHoldDate As Date
  170.     Dim nDayOfWeek As Integer
  171.     
  172.     If searchInterval = ccDaily Then
  173.         dStartDate = DateAdd("s", -1, inputDate)
  174.         dEndDate = DateAdd("d", 1, inputDate)
  175.     ElseIf searchInterval = ccWeekly Then
  176.         nDayOfWeek = Format(inputDate, "w")
  177.         nDayOfWeek = (nDayOfWeek + 7 - weekStartsWith) Mod 7
  178.         dHoldDate = Format(DateAdd("d", -nDayOfWeek, inputDate), "mm/dd/yy")
  179.         
  180.         dStartDate = DateAdd("s", -1, dHoldDate)
  181.         dEndDate = DateAdd("d", 7, dHoldDate)
  182.     ElseIf searchInterval = ccMonthly Then
  183.         dStartDate = DateAdd("s", -1, Format(inputDate, "m") & "/01/" & Format(inputDate, "yy"))
  184.         dEndDate = DateAdd("m", 1, Format(inputDate, "m") & "/01/" & Format(inputDate, "yy"))
  185.     End If
  186.     
  187.     Set GetEvents = New cAlarmGroup
  188.     For nCount = 1 To m_Collection.Count
  189.         If (m_Collection(nCount).dateTime > dStartDate And m_Collection(nCount).dateTime < dEndDate) Or searchInterval = ccNever Then
  190.             GetEvents.add m_Collection(nCount).dateTime, m_Collection(nCount).alarmType, m_Collection(nCount).filename, m_Collection(nCount).message, m_Collection(nCount).UID, m_Collection(nCount).repeat
  191.         End If
  192.     Next nCount
  193.     
  194. End Function
  195.  
  196.  
  197.