Creating a multi user 4D Agenda
To demonstrate the use of 4D Agenda in a multi user environment we will build a simple demonstration 4D app. Nothing fancy, just to give you some directions to go.
Lets start off with the first table for the users
Table name: [USERS]
Field name Type Options
UserID Longint Indexed/unique
UserName Alpha[80]
Password Alpha[80]
And an event table
Table name: [EVENTS]
Field name Type Options
EventID Longint Indexed/Unique
UserID Longint Indexed
StartDate Date Indexed
EndDate Date
StartTime Time Indexed
EndTime Time Indexed
Description Text
Now create in the Database startup routine the following code
C_LONGINT(<>SYS_USERID)
All Records([USERS])
If(Records in selection([USERS])=0)
USER_CreateSomeUsers
End if
<>SYS_USERID:=USER_Login
Now create the method: USER_CreateSomeUsers
CREATE RECORD([USERS])
[USERS]UserID:=Sequence Number([USERS])
[USERS]UserName:=Chris
[USERS]Password:=Smit
SAVE RECORD([USERS])
CREATE RECORD([USERS])
[USERS]UserID:=Sequence Number([USERS])
[USERS]UserName:=Hans
[USERS]Password:=Apple
SAVE RECORD([USERS])
UNLOAD RECORD([USERS])
Now lets build some simple login dialog box in the [USERS] table. I leave the design of the dialog box to your own creativity, it should include two text variables, vs_Name and vs_Password and an ACCEPT-button.
The simple login method,
C_LONGINT($Window)
C_LONINT($0)
$Window:=open window(10;40;310;340;8;;)
DIALOG([USERS];LoginDialog)
CLOSE WINDOW
If(OK=1)
QUERY([USERS];[USERS]Name=vsName)
$0:=[USERS]UserID
Else
$0:=0
End if
As I said before nothing fancy, no error checking or password checking stuff, just to get you started in one of the many possibilitys to create a multi-user agenda.
Now the 4D Agenda dialog box, this one can best be used from the 4D Agenda demo app.
The Form method should look something like this:
C_DATE(vDate)
C_INTEGER(vStart;vEnd)
C_LONGINT(err)
Case of
: (Form event= On Load )
vStart:=7
vEnd:=22
vDate:=Current date
err:= AG SET EVENT TABLE NUM (vAgenda ; Table(->[Events]))
err:= AG SET START DATE FIELD NUM (vAgenda ; Field(->[Events]StartDate))
err:= AG SET END DATE FIELD NUM (vAgenda ; Field(->[Events]EndDate))
err:= AG SET START TIME FIELD NUM (vAgenda ; Field(->[Events]StartTime))
err:= AG SET END TIME FIELD NUM (vAgenda ; Field(->[Events]EndTime))
err:= AG SET DESCRIPTION FIELD NUM (vAgenda ; Field(->[Events]Description))
`Set the UserID field
err:= AG SET USERID FIELD NUM (vAgenda ; Field(->[Events]UserID))
err:= AG SET EVENTID FIELD NUM (vAgenda ; Field(->[Events]EventID))
err:= AG SET AGENDA START HOUR (vAgenda ; vStart)
err:= AG SET AGENDA END HOUR (vAgenda ; vEnd)
err:= AG AGENDA EVENT HANDLER (vAgenda ; "AG_EventHandler")
` Set the current User ID to the ID of the user who has just logged-in
err:= AG CURRENT USER ID (vAgenda ; <>SYS_USERID)
End case
4D Agenda will keep track of a single Agenda per user this way. To create an easy way to switch to the
Agenda of an other user, create a pop-up menu on the 4D Agenda dialog box with the following
method attached to it:
If (pop_Users # 0)
vUserID:=arr_UserID{pop_Users}
err:= AG CURRENT USER ID (vAgenda ; vUserID)
` And to prevent any changes to the Agenda
err:= AG SET EVENT DRAG LOCK (vAgenda ; AG_True)
err:= AG SET EVENT EDIT LOCK (vAgenda ; AG_True)
Else `Switch back to the current user
$A:=Find in Array (arr_UserID ; <>SYS_USERID)
pop_Users:=$A
err:= AG CURRENT USER ID (vAgenda ; vUserID)
err:= AG SET EVENT DRAG LOCK (vAgenda ; AG_False)
err:= AG SET EVENT EDIT LOCK (vAgenda ; AG_False)
End if
err:=AG REDRAW (vAgenda ; AG_Reload)
|