home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Lotus / LOTUS / SMASTERS / APPROACH / SCHEDULE.MPR / SCRIPT / ApproachDoc / Reservation / Body / btnDone.s (.txt) < prev    next >
Encoding:
Null Bytes Alternating  |  1997-01-09  |  13.5 KB  |  148 lines

  1. '++LotusScript Development Environment:2:5:(Options):0:66
  2.  
  3. '++LotusScript Development Environment:2:5:(Forward):0:1
  4. Declare Sub Click(Source As Button, X As Long, Y As Long, Flags As Long)
  5.  
  6. '++LotusScript Development Environment:2:5:(Declarations):0:2
  7.  
  8. '++LotusScript Development Environment:2:2:BindEvents:1:129
  9. Private Sub BindEvents(Byval Objectname_ As String)
  10.     Static Source As BUTTON
  11.     Set Source = Bind(Objectname_)
  12.     On Event Click From Source Call Click
  13. End Sub
  14.  
  15. '++LotusScript Development Environment:2:2:Click:1:12
  16. Sub Click(Source As Button, X As Long, Y As Long, Flags As Long)
  17. ' Click event for the btnDone button object on the Reservation view
  18. ' This script checks to see if there is a complete reservation in the
  19. ' boxes in the view, checks the label of the btnDone on the view to
  20. ' see what to do with the reservation (Reserve or Remove), and then
  21. ' add the reservation to the schedule database or removes the
  22. ' reservation. Prompts are given to the user if there are errors at
  23. ' various stages in the process.
  24.     
  25.     Dim dateReserved As String    ' Reservation date as entered in the view
  26.     Dim ReservedBy As String        ' Reservation owner as entered in the view
  27.     Dim StartTime As String            ' Start time for the reservation
  28.     Dim FinishTime As String        ' End time for the reservation
  29.     Dim roomName As String        ' Room being reserved
  30.     Dim note As String                ' Comments as entered in the view
  31.     
  32.     Dim start As Double                ' Holds unformatted start time
  33.     Dim finish As Double                ' Holds unformatted end time
  34.     Dim OK As Integer                ' Flag to indicate if the reservation is completed
  35.     Dim msg As String                ' Store error message text
  36.     
  37.     ' Initialize the flag as 'Reservation is not complete'
  38.     OK = False
  39.     
  40.     ' Store the values entered in the view
  41.     dateReserved = source.fbxDate.text
  42.     ReservedBy = source.fbxReservedBy.text
  43.     StartTime = source.ddbStart.text
  44.     FinishTime = source.ddbEnd.text    
  45.     roomName = source.ddbRoom.text
  46.     note = source.fbxNotes.text
  47.     
  48.     ' Check to see if the required parts of the reservation exist in the view 
  49.     ' and set the OK flag appropriately
  50.     If (ReservedBy <>"") And (dateReserved <> "") And (roomName <> "") And (StartTime <> "") And (FinishTime <> "")Then
  51.         OK = True
  52.     Else        ' If the reservation is missing required data, then
  53.         OK = False
  54.         Messagebox "Invalid request.  Be sure the entire reservation form is complete."
  55.     End If        ' If the reservation is complete
  56.     
  57.     ' With a complete reservation, determine what operation to perform and perform it.
  58.     ' This view can create a reservation (Reserve) or delete a reservation (Remove) 
  59.     If OK Then        ' If the reservation is complete, then
  60.         
  61.         ' Remove the formatting from the start and end time strings
  62.         start = Timevalue(Trim(source.ddbStart.text)) *  24
  63.         finish = Timevalue(Trim(source.ddbEnd.text)) * 24
  64.         
  65.         ' Check to see that the start and end times are in the correct order
  66.         If start < finish Then        ' If the start time comes before the end time, then
  67.             
  68.             ' Refer to the text from btnDone to determine the action to perform.
  69.             ' This text is set by the subs that switch to the Reservation view
  70.             Select Case source.text        ' Text from btnDone
  71.                 
  72.             ' If the button label reads "Reserve", compare the reservation information
  73.             ' to the schedule database and update the schedule if there are no conflicts.
  74.             ' Then switch back to the Schedule Display view, clear the existing reservation
  75.             ' information, and display the new information for the date on the new reservation.
  76.             Case "Reserve"
  77.                 ' If the new reservation has no conflicts and is recorded successfully, then
  78.                 If modifySchedule(dateReserved, roomName, ReservedBy, start, finish, note, 1) Then
  79.                     
  80.                     ' Switch from the current view to Schedule Display. Because
  81.                     ' the current view was displayed as a dialog box, it can be treated
  82.                     ' as the current window, using the global variable CurrentWindow
  83.                     currentwindow.close
  84.                     'Doevents returns control back to operating system so that pending 
  85.                     'actions can be performed
  86.                     Doevents
  87.                     
  88.                     ' Remove existing reservation information from the view
  89.                     Call clearDisplay()
  90.                     
  91.                     ' Display reservation information for the date that the new reservation was
  92.                     ' made for
  93.                     Call readBlock (dateReserved)
  94.                     
  95.                     ' Display the date of the reservation information in the field box on the
  96.                     ' top left of the view
  97.                     currentview.body.fbxDateDisplay.text = dateReserved
  98.                     
  99.                 Else        ' If there is a conflicting schedule in the schedule database, then
  100.                     
  101.                     ' Tell the user that the reservation failed to be added because of a conflict
  102.                     msg = "Room " + roomName + " is not available from " +source.ddbStart.text+" to " + source.ddbEnd.text + " on " + dateReserved + "."
  103.                     Messagebox msg, MB_OK,"Schedule Conflict"
  104.                 End If        ' Does the new reservation conflict with an existing one?
  105.                 
  106.             ' If the button label reads "Remove", compare the reservation information
  107.             ' to the schedule database and remove any matching reservation.
  108.             ' Then switch back to the Schedule Display view, clear the existing reservation
  109.             ' information, and display the new information for the date of the removed reservation.                
  110.             Case "Remove"
  111.                 ' If the reservation to be removed exists in the database and is removed successfully, then
  112.                 If modifySchedule(dateReserved, roomName, "", start, finish, "", -1) Then
  113.                     
  114.                     ' Switch from the current view to Schedule Display. Because
  115.                     ' the current view was displayed as a dialog box, it can be treated
  116.                     ' as the current window, using the global variable CurrentWindow
  117.                     currentwindow.close
  118.                     'Doevents returns control back to operating system so that pending 
  119.                     'actions can be performed
  120.                     Doevents
  121.                     ' Remove existing reservation information from the view 
  122.                     Call clearDisplay()
  123.                     
  124.                     ' Display reservation information for the date that the reservation was removed from                
  125.                     Call readBlock (dateReserved)
  126.                     
  127.                     ' Display the date of the reservation information in the field box on the
  128.                     ' top left of the view
  129.                     currentview.body.fbxDateDisplay.text = dateReserved
  130.                 Else        ' If the reservation did not match an existing reservation, then
  131.                     
  132.                     ' Tell the user that the reservation failed to be added because of a conflict
  133.                     msg = "Room " + roomName + " is not scheduled from " + source.ddbStart.text+" to " + source.ddbEnd.text + " on " + dateReserved + "."
  134.                     Messagebox msg, MB_OK, "Room Not Scheduled"
  135.                 End If            ' If the reservation exists and was removed successfully
  136.                 
  137.             End Select        ' Choose from Reserve and Remove
  138.             
  139.         Else        ' If start is after finish, then
  140.             
  141.             ' Prompt the user to correct the times
  142.             msg = "End time must be greater than Start time."
  143.             Messagebox msg , MB_OK, "Invalid Times Entered"
  144.         End If        ' If start is before finish
  145.         
  146.     End If            ' If the reservation is complete in the view
  147.     
  148. End Sub        ' Click event for the btnDone on the Reservation view