Sunday, July 23, 2017

Simple Multi user Programming Techniques in Visual Foxpro




MULTIUSER

* Set Environment
SET DELETED ON
SET EXCLUSIVE OFF
SET MULTILOCKS ON

* Open & Shared Data
OPEN DATABASE (HOME(2) + 'data\testdata') SHARED
IF NOT OpenTable('Customer')
   = MESSAGEBOX("Operation NOT successful!",0,"Operation Status")
ENDIF

FUNCTION OpenTable()
LPARAMETERS myTable
STORE .F. TO lSuccess
* Open Table and Set buffering mode and store logical result
IF NOT USED([myTable])
            USE (myTable) IN 0 Shared
            lSuccess=CURSORSETPROP("Buffering", 5, (myTable))
ENDIF
RETURN lSuccess

PROCEDURE SAVERECORD
WITH THISFORM
            REPLACE Customer.Cust_ID WITH .Text1.Value, ;
                   Customer.Company WITH .Text2.Value IN THISFORM.ParentTable
           
            IF NOT TABLEUPDATE(.T., .F., THISFORM.ParentTable)
                        IF MESSAGEBOX([Another user has modified this data] + CHR(13)+;
                           [Do you wish to save anyway], (4+16+256), [Update Failed]) = 6
                          
                           TABLEUPDATE(.T.,.T.,THISFORM.ParentTable)
                        ENDIF
            ENDIF
ENDWITH
ENDPROC

No comments:

Post a Comment