************************************************** *-- Class: acxdays *-- ParentClass: olecontrol *-- BaseClass: olecontrol *-- Time Stamp: 10/03/07 02:26:03 PM *-- OLEObject = D:\DBICON~1\STUDIO~1\COMCON~1\ctDays.ocx * Define Class acxdays As OleControl Height = 600 Width = 800 Name = "acxdays" *-- Populates the day view with all the appointments for that day Procedure getappointments4day Lparameters tdDate Endproc *-- Saves the sata to the appointments table Procedure saveappointment Lparameters tnIndex Endproc *-- Converts the number of minutes past midnigh to a time() string Procedure convertminutes2time Lparameters tnMinutes Local lcHours, lcMinutes, lcTime lcHours = Padl( Int( tnMinutes/60 ), 2, [0] ) lcMinutes = Padl( tnMinutes % 60, 2, [0] ) lcTime = lcHours + [:] + lcMinutes Return lcTime Endproc *-- Converts a time() string to a number of minutes past midnight Procedure converttime2minutes Lparameters tdDate, tcTime Local ltStart, ltAppt, lnMinutes ltStart = Datetime( Year( tdDate ), ; MONTH( tdDate ), ; DAY( tdDate ), ; 0, 0, 0 ) ltAppt = Datetime( Year( tdDate ), ; MONTH( tdDate ), ; DAY( tdDate ), ; VAL( Getwordnum( tcTime, 1, [:] ) ), ; VAL( Getwordnum( tcTime, 2, [:] ) ), ; 0 ) lnMinutes = Int( ( ltAppt - ltStart ) / 60 ) Return lnMinutes Endproc Procedure AppUnSelect *** ActiveX Control Event *** Lparameters nindex This.saveappointment( nindex ) Endproc EnddefineAnd here is the code for the GetAppointment:
LPARAMETERS tdDate LOCAL lnNewItem AS Integer WITH This .ClearAppointments() .SetTopTime = .PrimeTimeStart IF SEEK( tdDate, [Appointments], [Appt_date] ) SELECT Appointments SCAN WHILE Appt_date = tdDate AND NOT EOF() lnNewItem = .AddKeyAppointment( .ConvertTime2Minutes( tdDate, Start_Time ), ; .ConvertTime2Minutes( tdDate, End_Time ), ; ALLTRIM( appt_text ), ; Appt_id ) ENDSCAN *** Now set the top time in the control to *** show the first appointment for the day SELECT MIN( start_time ) as start_time ; FROM Appointments INTO CURSOR qTmp IF NOT EMPTY( qTmp.Start_Time ) .SetTopTime = .ConvertTime2Minutes( tdDate, qTmp.Start_Time ) ENDIF ENDIF ENDWITHand SaveAppointment methods:
LPARAMETERS tnIndex LOCAL ldDate, lnKey *** See if we are adding or editing an appointment *** if we are adding one, its key value will be null WITH This ldDate = Thisform.txtCurrentDate.Value lnKey = VAL( NVL( .AppointKeyID( tnIndex), 0 ) ) IF lnKey = 0 *** make sure we do not enter empty appointments IF NOT EMPTY( .AppointText( tnIndex ) ) INSERT INTO Appointments ( appt_text, appt_date, start_time, end_time ) ; VALUES ( ; .AppointText( tnIndex ), ; Thisform.txtCurrentDate.Value, ; .ConvertMinutes2Time( .AppointTimeStart( tnIndex ) ), ; .ConvertMinutes2Time( .AppointTimeEnd( tnIndex ) ) ) *** And update the KeyID for the newly added appointment .AppointKeyID( tnIndex ) = Appointments.Appt_id ENDIF ELSE IF SEEK( lnKey, [Appointments], [appt_id] ) *** If the text is empty, we can safely assume ; *** that we want to delete this appointment IF EMPTY( .AppointmentText( tnIndex ) ) DELETE IN Appointments ELSE REPLACE appt_text WITH .AppointText( tnIndex ), ; appt_date WITH Thisform.txtCurrentDate.Value, ; start_time WITH .ConvertMinutes2Time( .AppointTimeStart( tnIndex ) ), ; end_time WITH .ConvertMinutes2Time( .AppointTimeEnd( tnIndex ) ) IN Appointments ENDIF ENDIF ENDIF IF TABLEUPDATE( 0, .F., [Appointments] ) ELSE MESSAGEBOX( [Unable to save appointment to the table!], 48, [Major WAAAHHHHHH!] ) ENDIF ENDWITH