For my example, I'll use states.dbf and customer.dbf.
I have the need to have multiple (x4) Dbcombos, all using states dbf. to fill the customer.dbf (state, state1...etc.) fields.
I would add extra state field(s) in the customer.dbf (state1, etc).
I have prepared a sample below to illustrate ( along with a function to produce the Cust_2.dbf with the extra state1 field).
The sample is a modified version of Xbr_edit.prg supplied by Mr. Nages earlier.
Any help appreciated.
Bruce S.
- Code: Select all Expand view
#include "FiveWin.ch"
#include "dbcombo.ch"
static oWnd
static cPath_seg := 'c:\fwh\samples'
function Main()
local oBrush, oBar, oBmp
REQUEST DBFCDX
rddsetdefault("DBFCDX")
SET EPOCH TO 2000
SET DATE TO AMERICAN
SET _3DLOOK ON // Microsoft 3D Look
//-------------------------------------------------
SkinButtons()
DEFINE WINDOW oWnd FROM 3, 38 TO 30, 110 ;
TITLE " - Multiple state DBcombobox "
DEFINE BUTTONBAR oBar OF oWnd
DEFINE BUTTON FILENAME cPath_seg + "Exit.bmp" OF oBar ;
ACTION If( MsgYesNo( "Bye.. Bye", " Select" ), oWnd:End(), ) ;
MESSAGE " End this session" ;
TOOLTIP " Exit "
DEFINE BUTTON FILENAME cPath_seg + "File.bmp" OF oBar ;
MESSAGE " Xbrowse" ACTION xbrAddEdit() ;
TOOLTIP " XbrAddEdit "
DEFINE BUTTON FILENAME cPath_seg + "File.bmp" OF oBar ;
MESSAGE " Make dbf" ACTION mkdbf() ;
TOOLTIP " Make dbf "
@ 22.5, 25 SAY space(3) + cPath_seg + space(3)
@ 23.0, 40 SAY space(3) + FWVERSION + space(3)
ACTIVATE WINDOW oWnd
return nil
//----------------------------------------------------------------------
function XbrAddEdit() //From : Nages Xbr_edit 03/08/15 10:22am
local oCust
local oStates, aStates
local oStates1, aStates1
local oWnd, oBar, oBrw, oFont
RddSetDefault( "DBFCDX" )
SET DELETED ON
oStates := TDataBase():New()
oStates := TDataBase():Open( nil, ( cPath_seg + "states.dbf") )
aStates := ( oStates:nArea )->( FW_DbfToArray() )
oStates:Close()
// I have also tried copying states.dbf to states1.dbf
// and using states1.dbf here
oStates1 := TDataBase():New()
oStates1 := TDataBase():Open( nil, ( cPath_seg + "states.dbf" ) )
aStates1 := ( oStates1:nArea )->( FW_DbfToArray() )
oStates1:Close()
oCust := TDataBase():Open( nil, (cPath_seg + "customer.dbf" ) )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE WINDOW oWnd
oWnd:SetFont( oFont )
DEFINE BUTTONBAR oBar OF oWnd SIZE 90,32 2007
DEFINE BUTTON OF oBar PROMPT "Add" CENTER ACTION oBrw:EditSource( .t. )
DEFINE BUTTON OF oBar PROMPT "Edit" CENTER ACTION oBrw:EditSource()
DEFINE BUTTON OF oBar PROMPT "Delete" CENTER ACTION oBrw:Delete()
@ 0,0 XBROWSE oBrw OF oWnd DATASOURCE oCust ;
COLUMNS "FIRST","LAST","STREET","CITY","STATE","STATE1","ZIP","HIREDATE","MARRIED","AGE","SALARY","NOTES" ;
CELL LINES NOBORDER
WITH OBJECT oBrw
:SetChecks()
:nEditTypes := EDIT_GET
:bEdit := { |oRec| EditDlg( oRec ) }
WITH OBJECT oBrw:oCol( "STATE" )
:nEditType := EDIT_LISTBOX
:aEditListTxt := aStates
END
WITH OBJECT oBrw:oCol( "STATE1" )
:nEditType := EDIT_LISTBOX
:aEditListTxt := aStates1
END
:brclicked := { || EditDlg() }
//
:CreateFromCode()
END
oWnd:oClient := oBrw
ACTIVATE WINDOW oWnd MAXIMIZED
RELEASE FONT oFont
oCust:Close()
return nil
//--------------------------------------------------------------
static function EditDlg( oRec )
local oDlg, oGrp, oBtn
local oStates
local oStates1
local lSave := .f.
oStates := TDataBase():New()
oStates := TDataBase():Open( , "STATES" )
oStates1 := TDataBase():New()
oStates1 := TDataBase():Open( , "STATES" )
DEFINE DIALOG oDlg SIZE 820,380 PIXEL FONT oRec:oBrw:oFont ;
TITLE If( oRec:RecNo == 0, "ADD ", "EDIT " ) + "CUSTOMER"
@ 0, 4 GROUP oGrp TO 168, 405 OF oDlg PIXEL
@ 12, 10 SAY "First:" OF oDlg SIZE 15, 8 PIXEL
@ 10, 44 GET oRec:First OF oDlg SIZE 105, 12 PIXEL UPDATE
@ 26, 10 SAY "Last:" OF oDlg SIZE 15, 8 PIXEL
@ 24, 44 GET oRec:Last OF oDlg SIZE 105, 12 PIXEL UPDATE
@ 40, 10 SAY "Street:" OF oDlg SIZE 21, 8 PIXEL
@ 38, 44 GET oRec:Street OF oDlg SIZE 155, 12 PIXEL UPDATE
@ 54, 10 SAY "City:" OF oDlg SIZE 13, 8 PIXEL
@ 52, 44 GET oRec:City OF oDlg SIZE 155, 12 PIXEL UPDATE
@ 68, 10 SAY "State:" OF oDlg SIZE 19, 8 PIXEL
@ 66, 44 DBCOMBO oRec:State SIZE 100,100 PIXEL OF oDlg UPDATE ;
ALIAS oStates:cAlias ITEMFIELD "CODE" LISTFIELD "NAME"
@ 82, 10 SAY "State1:" OF oDlg SIZE 19, 8 PIXEL
@ 80, 44 DBCOMBO oRec:State1 SIZE 100,100 PIXEL OF oDlg UPDATE ;
ALIAS oStates1:cAlias ITEMFIELD "CODE" LISTFIELD "NAME"
@ 96, 10 SAY "Zip:" OF oDlg SIZE 12, 8 PIXEL
@ 94, 44 GET oRec:Zip OF oDlg SIZE 55, 12 PIXEL UPDATE
@ 108, 10 SAY "Hiredate:" OF oDlg SIZE 29, 8 PIXEL
@ 106, 44 GET oRec:Hiredate OF oDlg SIZE 44, 12 PIXEL
@ 108, 44 CHECKBOX oRec:Married PROMPT "&Married:" OF oDlg SIZE 43, 12 PIXEL UPDATE
@ 122, 10 SAY "Age:" OF oDlg SIZE 15, 8 PIXEL
@ 120, 44 GET oRec:Age OF oDlg SIZE 12, 12 PIXEL PICTURE "99"
@ 136, 10 SAY "Salary:" OF oDlg SIZE 21, 8 PIXEL
@ 134, 44 GET oRec:Salary OF oDlg SIZE 40, 12 PIXEL PICTURE "999,999.99" UPDATE
@ 150, 10 SAY "Notes:" OF oDlg SIZE 21, 8 PIXEL
@ 148, 44 GET oRec:Notes OF oDlg SIZE 355, 12 PIXEL UPDATE
@ 172, 275 BUTTON oBtn PROMPT "&Undo" OF oDlg SIZE 42, 14 PIXEL ;
WHEN oRec:Modified() ;
ACTION ( oRec:Undo(), oDlg:Update() )
@ 172, 319 BUTTON oBtn PROMPT "&Save" OF oDlg SIZE 42, 14 PIXEL ;
WHEN oRec:Modified() ;
ACTION (oDlg:End(), lSave := .T.)
@ 172, 363 BUTTON oBtn PROMPT "&Cancel" OF oDlg SIZE 42, 14 PIXEL CANCEL ACTION (oDlg:End())
ACTIVATE DIALOG oDlg CENTERED
if lSave
oRec:Save()
oRec:oBrw:SetFocus()
endif
oStates:Close()
return nil
//--------------------------------------------------------------------------------
Func mkdbf() // Date : 04/07/15
// Update : 04/07/15
// Purpose: Build CUST_2.dbf file
local cFile := 'CUST_2.DBF '
dbcloseall()
If !file(cPath_seg + cFile)
// safeguard - create file ONLY if it does NOT exist
// CUST_2.DBF
DbCreate(cPath_seg + cFile,;
{;
{"FIRST" , "C", 20, 0 } ,;
{"LAST" , "C", 20, 0 } ,;
{"STREET" , "C", 30, 0 } ,;
{"CITY" , "C", 30, 0 } ,;
{"STATE" , "C", 02, 0 } ,;
{"STATE2" , "C", 02, 0 } ,;
{"ZIP " , "C", 10, 0 } ,;
{"HIREDATE", "D", 08, 0 } ,;
{"MARRIED" , "L", 01, 0 } ,;
{"AGE" , "N", 02, 0 } ,;
{"SALARY" , "N", 09, 2 } ,;
{"NOTES" , "C", 70, 0 } ;
};
)
// safeguard - append to empty file ONLY
USE (cPath_seg + "CUST_2.DBF")
APPEND FROM (cPath_seg + "CUSTOMER.DBF" )
ELSE
msgInfo( cFile + " already exists" )
Endif
msginfo(trans(lastrec(),'99999') + " Records imported OK" )
DBCLOSEALL()
return nil
//---------------------------------------------