ReportManager can also be used in Harbour in another way, via shared libraries. In the next entry i will show you how to do it. The code sample connects to a free online mysql server, browse a customer table and allows to tag/untag the desired records and to print a list of the selected customers.
The result is this :
and the source :
#include "dbinfo.ch"
#include "error.ch"
#include "hbrddsql.ch"
#include "inkey.ch"
REQUEST SDDMY, SQLMIX
ANNOUNCE RDDSYS
MEMVAR aTagList
Function main()
LOCAL cChoice
PRIVATE aTagList := {}
RDDSETDEFAULT("SQLMIX")
? "Connecting to www.freesql.org with user name inforpires, password mypass, database inforpires"
IF RDDINFO(RDDI_CONNECT, {"MYSQL", "www.freesql.org", "inforpires","mypass", "inforpires"}) == 0
? "Unable connect to the server !!! Check Internet and firewall"
RETURN 1
ENDIF
CLS
? "Connected to mysql"
ACCEPT "Drop existing table ? [Y/N]" TO cChoice
IF cChoice == "Y"
RDDINFO(RDDI_EXECUTE, "DROP TABLE customers")
RDDINFO(RDDI_EXECUTE, "CREATE TABLE IF NOT EXISTS customers (CODE int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY, NAME char(50) )")
RDDINFO(RDDI_EXECUTE, "INSERT INTO customers (name) VALUES ('John Doe'),('Moe'),('Bart'),('Homer'),('Lisa'),('Marge'),('Nelson')")
ENDIF
DBUSEAREA( .T.,, "SELECT * FROM customers", "customers" )
@24,0 SAY "SPACE-Tag/Untag ESC-End F2-List by code F3-List by name"
DBEDIT(0,0,20,79,{"IIF(aScan(aTagList,field->code)!=0,'X',' ')",;
"code",;
"name"},"myFunc",,{"Tag","Code","Name"})
DBCLOSEALL()
RETURN 0
// ------------------------------------------------
// Dbedit Key Handle routine
FUNCTION MyFunc(status, fld_ptr)
Local nReturn := 1, nKey, nPos
nKey = LASTKEY()
DO CASE
CASE status == 4
IF nKey == K_SPACE
IF (nPos := aScan(aTagList,field->code)) != 0
ADEL(aTagList,nPos)
ASIZE(aTagList,LEN(aTagList)-1)
ELSE
aadd(aTagList,field->code)
ENDIF
nReturn := 2
ELSEIF nKey == K_ESC
nReturn := 0
ELSEIF nKey == K_F2
doReport(1)
ELSEIF nKey == K_F3
doReport(2)
ENDIF
ENDCASE
RETURN nReturn
// ---------------------------------------------
// Call ReportMan, setup parameters AND preview
PROCEDURE doReport(nOrderMode)
local oRep, cFilter
oRep := oReport():new("custlist.rep")
oRep:setparamvalue("OrderCondition",IF(nOrderMode==1,"code","name"))
oRep:setparamvalue("FilterCondition","select * from customers where code in ("+implode(",",aTagList)+")" +;
" order by " + IF(nOrderMode==1,"code","name") )
oRep:preview()
RETURN
// ---------------------------------------------
// Clone of php implode function for numbers
FUNCTION implode(cDelim,aArray)
LOCAL cStr := "", nLen := LEN(aArray)
AEVAL(aArray,{|x,n| cStr += STR(x) + IF(n != nLen, cDelim, "" ) })
RETURN cStr
On my next post i will post the needed steps and a link to download the source and other files that can be compiled in linux and windows with only minor changes.
Sem comentários:
Enviar um comentário