/*
* Demonstrates oRs:EditBaseRecord( [cFieldList], [lAppend], [bEditDlg], [oBrw] )
* Where RowSet contains only some of the fields. this method can be used
* to edit full record of the table with all fields/selected fields
*
*/
#include "fivewin.ch"
#include "dbcombo.ch"
static aStates
//----------------------------------------------------------------------------//
function Main()
local oCn, oRs
local oDlg, oBrw
FWNumFormat( "A", .t. )
oCn := FW_DemoDB()
oCn:LockTimeOut := 1
oCn:lShowErrors := .t.
? oCn:cServerInfo
? oCn:IsMariaDB
? oCn:in_transaction
aStates := oCn:Execute( "SELECT CODE,NAME FROM states" )
oRs := oCn:RowSet( "SELECT ID,FIRST,CITY,SALARY FROM customer" )
DEFINE DIALOG oDlg SIZE 500,600 PIXEL TRUEPIXEL ;
TITLE "EditBaseRecord()"
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oRs AUTOCOLS ;
COLSIZES -4, -20, -20 ;
CELL LINES NOBORDER FOOTERS FASTEDIT
WITH OBJECT oBrw
:nEditTypes := EDIT_GET
:Salary:nFooterType := AGGR_SUM
:MakeTotals()
:CreateFromCode()
END
@ 20, 20 BTNBMP PROMPT "ADD" SIZE 100,30 PIXEL FLAT OF oDlg ;
ACTION oRs:EditBaseRecord( nil, .t., { |oRec| MyEditDlg( oRec ) }, oBrw )
@ 20,130 BTNBMP PROMPT "EDIT" SIZE 100,30 PIXEL FLAT OF oDlg ;
ACTION EditRecord(oRs, oBrw) //oRs:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw, {|oRs|Locked_Problem(oRs)} )
ACTIVATE DIALOG oDlg CENTERED
return nil
function EditRecord(oRs, oBrw)
? oRs, VALTYPE(oRs)
xbrowser oRs slnum title "GO_DETAY"
xbrowser oBrw slnum
oRs:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw, {|oRs|Locked_Problem(oRs)} )
return
FUNCTION Locked_Problem(oRs)
? "Locked_Problem(oRs)", oRs
RETURN
static function MyEditDlg( oRec )
local lNew := ( oRec:RecNo == 0 )
local oDlg, oFont
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
DEFINE DIALOG oDlg SIZE 400,470 PIXEL TRUEPIXEL FONT oFont ;
TITLE If( lNew, "ADD NEW ", "EDIT" ) + " RECORD"
@ 030,020 SAY "ID :" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 060,020 SAY "First" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 090,020 SAY "Last" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 120,020 SAY "Street" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 150,020 SAY "City" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 180,020 SAY "State" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 210,020 SAY "Zip" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 240,020 SAY "HireDate" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 270,020 SAY "Married" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 300,020 SAY "Age" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 330,020 SAY "Salary" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 360,020 SAY "Notes" SIZE 80,20 PIXEL OF oDlg RIGHT
@ 030,120 GET oRec:ID SIZE 100,22 PIXEL OF oDlg READONLY RIGHT
@ 060,120 GET oRec:First SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:First )
@ 090,120 GET oRec:Last SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:Last )
@ 120,120 GET oRec:Street SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:Street )
@ 150,120 GET oRec:City SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:City )
@ 180,120 DBCOMBO oRec:State SIZE 240,300 PIXEL OF oDlg ;
ALIAS aStates ITEMFIELD "1" LISTFIELD "2"
@ 210,120 GET oRec:Zip SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:Zip )
@ 240,120 GET oRec:HireDate SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:HireDate )
@ 270,120 CHECKBOX oRec:Married PROMPT "" SIZE 22,22 PIXEL OF oDlg
@ 300,120 GET oRec:Age SIZE 240,22 PIXEL OF oDlg PICTURE "99" RIGHT VALID ( oRec:Age >= 20 )
@ 330,120 GET oRec:Salary SIZE 240,22 PIXEL OF oDlg PICTURE "999,999.99" RIGHT VALID ( oRec:Salary > 0 )
@ 360,120 GET oRec:Notes SIZE 240,22 PIXEL OF oDlg
@ 420,020 BTNBMP PROMPT "Save" SIZE 150,30 PIXEL FLAT OF oDlg ;
ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()
@ 420,240 BTNBMP PROMPT "Cancel" SIZE 150,30 PIXEL FLAT OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED ;
ON PAINT oDlg:Box( 15, 10, 395, 390 )
return nil