Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CtDays form DBI
Message
From
13/09/2008 07:43:25
 
 
To
04/09/2008 19:02:37
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01344996
Message ID:
01347327
Views:
19
I'm trying to discover how to save the appointments of the schedule plan to a table and how to show the appointment retrived form a table to the schedule plan.
They don't have a sample how to save the info to a database, and to retrive them to the OCX.

Does someone know how to do it?
Just need some sample of code.


Here is the class definition for a sample subclass of ctDays that I used in the sample code for my presentation on activeX controls at Frankfurt last year:

GetAppointment and SaveAppointment are template methods - code is in the instance.
**************************************************
*-- 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
Enddefine
And 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 
ENDWITH
and 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 
Previous
Reply
Map
View

Click here to load this message in the networking platform