Code: Select all
#include "FiveWin.ch"
#include "RichEdit.ch"
#include "xbrowse.ch"
#include "splitter.ch"
#include "report.ch"
static oWndMain, oWndDbfs
//----------------------------------------------------------------------------//
function Main()
local oBmpTiled , oBar
local hDLL := LoadLibrary( "Riched20.dll" )
SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
DEFINE BITMAP oBmpTiled RESOURCE "background"
DEFINE WINDOW oWndMain TITLE "Reports Builder" MDI ;
MENU BuildMenu()
DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
DEFINE BUTTON OF oBar PROMPT "New" RESOURCE "new" ACTION ReportNew()
DEFINE BUTTON OF oBar PROMPT "Open" RESOURCE "open" ACTION ReportOpen()
DEFINE BUTTON OF oBar PROMPT "DataBases" RESOURCE "database" ACTION Databases() GROUP
DEFINE BUTTON OF oBar PROMPT "Add" RESOURCE "add" ACTION ReportAddColumn() GROUP
DEFINE BUTTON OF oBar PROMPT "Edit" RESOURCE "edit" ACTION ReportEditColumn()
DEFINE BUTTON OF oBar PROMPT "Del" RESOURCE "del" ACTION ReportDelColumn()
DEFINE BUTTON OF oBar PROMPT "Run" RESOURCE "run" GROUP ;
ACTION ReportRun()
DEFINE BUTTON OF oBar PROMPT "Exit" RESOURCE "exit" ;
ACTION oWndMain:End() GROUP
ReportNew()
ACTIVATE WINDOW oWndMain MAXIMIZED ;
VALID MsgYesNo( "Want to end ?" ) ;
ON PAINT DrawTiled( hDC, oWndMain, oBmpTiled )
oBmpTiled:End()
FreeLibrary( hDLL )
return nil
//----------------------------------------------------------------------------//
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "Reports"
MENU
MENUITEM "New" ACTION ReportNew()
ENDMENU
ENDMENU
return oMenu
//----------------------------------------------------------------------------//
function DataBases( cFileName )
local oBar, oBrw, aWorkAreas := GetWorkAreas(), cClrBack
if ! Empty( oWndDbfs )
oWndDbfs:SetFocus()
return nil
endif
DEFINE WINDOW oWndDbfs TITLE "DataBases management" MDICHILD
DEFINE BUTTONBAR oBar OF oWndDbfs 2010 SIZE 70, 70
DEFINE BUTTON OF oBar PROMPT "Add" RESOURCE "add" ;
ACTION ( OpenDataBase(), oBrw:SetArray( GetWorkAreas() ), oBrw:SetFocus() )
DEFINE BUTTON OF oBar PROMPT "Struct" RESOURCE "struct" ;
ACTION ( Alias( oBrw:nArrayAt ) )->( Struct( cFileName, oBrw ) ) GROUP
DEFINE BUTTON OF oBar PROMPT "Exit" RESOURCE "exit" ;
ACTION oWndDbfs:End() GROUP
@ 0, 0 XBROWSE oBrw OF oWndDbfs LINES ;
ARRAY aWorkAreas AUTOCOLS
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:bClrStd = { || If( oBrw:nArrayAt % 2 == 0, ;
{ CLR_BLACK, RGB( 198, 255, 198 ) }, ;
{ CLR_BLACK, RGB( 232, 255, 232 ) } ) }
oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }
cClrBack = Eval( oBrw:bClrSelFocus )[ 2 ]
oBrw:bClrSelFocus = { || { CLR_WHITE, cClrBack } }
oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
oBrw:CreateFromCode()
oBrw:aCols[ 1 ]:cHeader = "Area"
oBrw:aCols[ 1 ]:nWidth = 100
oBrw:aCols[ 1 ]:bStrData = { || If( Len( oBrw:aArrayData ) > 0, oBrw:nArrayAt, "" ) }
if Empty( aWorkAreas )
ADD COLUMN TO oBrw HEADER "Alias" DATA oBrw:nArrayAt WIDTH 150
oBrw:aCols[ 2 ]:bStrData = { || If( Len( oBrw:aArrayData ) > 0, oBrw:aArrayData[ oBrw:nArrayAt, 1 ], "" ) }
ADD COLUMN TO oBrw HEADER "Rdd" DATA oBrw:nArrayAt WIDTH 100
oBrw:aCols[ 3 ]:bStrData = { || If( Len( oBrw:aArrayData ) > 0, oBrw:aArrayData[ oBrw:nArrayAt, 3 ], "" ) }
endif
oWndDbfs:oClient = oBrw
ACTIVATE WINDOW oWndDbfs ;
VALID ( oWndDbfs := nil, .T. )
return nil
//----------------------------------------------------------------------------//
function OpenDataBase( cFileName )
DEFAULT cFileName := cGetFile( "*.dbf", "Please select a DBF" )
if File( cFileName )
USE ( cFileName ) NEW
endif
return nil
//----------------------------------------------------------------------------//
function GetWorkAreas()
local aWorkAreas := {}, n := 1
while ! Empty( Alias( n ) )
AAdd( aWorkAreas, { Alias( n ), Alias( n ), RddName( n++ ) } )
end
return aWorkAreas
//----------------------------------------------------------------------------//
function ReportEditColumn()
local oDlg, oBrw := oWndMain:oWndActive:aControls[ 2 ]
local oCol := oBrw:aCols[ oBrw:nColSel ]
local cHeader := PadR( oCol:cHeader, 100 )
DEFINE DIALOG oDlg TITLE "Column properties" SIZE 400, 300
@ 0.5, 1 SAY "Header:"
@ 0.6, 3.9 GET cHeader SIZE 150, 11
@ 1.5, 1 SAY "Data:"
@ 1.7, 3.9 GET oCol:cExpr SIZE 150, 11 ;
ACTION MsgInfo( "expression builder" )
@ 2.5, 1 SAY "Width:"
@ 2.7, 3.9 GET oBrw:aCols[ oBrw:nColSel ]:nWidth SIZE 70, 4 SPINNER
@ 7, 7 BUTTON "&Ok" OF oDlg SIZE 45, 13 ;
ACTION ( oCol:cHeader := RTrim( cHeader ), oBrw:Refresh(), oDlg:End() )
@ 7, 18 BUTTON "&Cancel" OF oDlg SIZE 45, 13 ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
return nil
//----------------------------------------------------------------------------//
function ReportNew()
local oWndChild, cHeader := "Header", oHeader, oSplit1, oBrw
local cFooter := "Footer", oFooter, oSplit2
DEFINE WINDOW oWndChild TITLE "New report" MDICHILD
@ 0, 0 RICHEDIT oHeader VAR cHeader SIZE oWndChild:nWidth, 70 OF oWndChild
@ 5.3, 0 XBROWSE oBrw ARRAY { Space( 20 ) } OF oWndChild SIZE oWndChild:nWidth, 150
oBrw:CreateFromCode()
oBrw:aCols[ 1 ]:cHeader = "Empty"
oBrw:aCols[ 1 ]:cExpr = "nil"
@ 15.2, 0 RICHEDIT oFooter VAR cFooter SIZE oWndChild:nWidth, 130 OF oWndChild
@ 70,0 SPLITTER oSplit1 ;
HORIZONTAL ;
PREVIOUS CONTROLS oHeader ;
HINDS CONTROLS oBrw ;
TOP MARGIN 30 ;
BOTTOM MARGIN oSplit2:nLast + 50 ;
SIZE 500, 4 PIXEL ;
OF oWndChild ;
STYLE
@ 225,0 SPLITTER oSplit2 ;
HORIZONTAL ;
PREVIOUS CONTROLS oBrw ;
HINDS CONTROLS oFooter ;
TOP MARGIN oSplit1:nFirst + 50 ;
BOTTOM MARGIN 80 ;
SIZE 500, 4 PIXEL ;
OF oWndChild ;
STYLE
ACTIVATE WINDOW oWndChild ;
ON RESIZE ( oSplit1:Adjust( .T., .F., .T., .T. ), oSplit2:Adjust( .F., .T., .T., .T. ) )
return nil
//----------------------------------------------------------------------------//
function ReportOpen()
return nil
//----------------------------------------------------------------------------//
function ReportAddColumn()
local oBrw
if ! Empty( oWndMain:oWndActive )
oBrw = oWndMain:oWndActive:aControls[ 2 ]
ADD COLUMN TO oBrw TITLE "Test" DATA Time() SIZE 150
ATail( oBrw:aCols ):cExpr = "Time()"
if oBrw:aCols[ 1 ]:cHeader == "Empty"
oBrw:DelCol( 1 )
endif
oBrw:Refresh()
endif
return nil
//----------------------------------------------------------------------------//
function ReportDelColumn()
return nil
//----------------------------------------------------------------------------//
function ReportRun()
local oRpt, aControls, oBrw
local oHeader, oFooter, n
if oWndMain:oWndActive != nil
aControls = oWndMain:oWndActive:aControls
oHeader = aControls[ 1 ]
oBrw = aControls[ 2 ]
oFooter = aControls[ Len( aControls ) - 2 ]
REPORT oRpt PREVIEW ;
HEADER oHeader:GetText() ;
FOOTER oFooter:GetText()
for n = 1 to Len( oBrw:aCols )
RptAddColumn( { GetHeader( oBrw, n ) },, { GetValue( oBrw, n ) } )
next
END REPORT
ACTIVATE REPORT oRpt
endif
return nil
//----------------------------------------------------------------------------//
static function GetHeader( oBrw, n )
return { || oBrw:aCols[ n ]:cHeader }
//----------------------------------------------------------------------------//
static function GetValue( oBrw, n )
return { || oBrw:aCols[ n ]:bStrData }
//----------------------------------------------------------------------------//
function Struct( cFileName, oBrwParent )
local oDlg, oBrw, aFields := DbStruct(), n
if Empty( aFields ) .and. ! Empty( oBrwParent:oRS )
for n = 0 to oBrwParent:oRS:Fields:Count - 1
AAdd( aFields, { oBrwParent:oRS:Fields[ n ]:Name,;
oBrwParent:oRS:Fields[ n ]:Type,;
oBrwParent:oRS:Fields[ n ]:DefinedSize,;
oBrwParent:oRS:Fields[ n ]:NumericScale } )
next
endif
DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400
@ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
HEADERS "Name", "Type", "Len", "Dec" ;
COLSIZES 150, 50, 80, 80
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
{ CLR_BLACK, RGB( 198, 255, 198 ) }, ;
{ CLR_BLACK, RGB( 232, 255, 232 ) } ) }
oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }
oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
oBrw:CreateFromCode()
oDlg:oClient = oBrw
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( BuildStructBar( oDlg, oBrw, cFileName ), oDlg:Resize(), oBrw:SetFocus() )
return nil
//----------------------------------------------------------------------------//
function BuildStructBar( oDlg, oBrw, cFileName )
local oBar
DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
DEFINE BUTTON OF oBar PROMPT "Code" RESOURCE "code" ;
ACTION ( TxtStruct(), oBrw:SetFocus() )
DEFINE BUTTON OF oBar PROMPT "Exit" RESOURCE "exit" ;
ACTION oDlg:End() GROUP
return nil
//----------------------------------------------------------------------------//
function TxtStruct()
local cCode := "local aFields := { ", n
for n = 1 to FCount()
if n > 1
cCode += Space( 27 )
endif
cCode += '{ "' + FieldName( n ) + '", "' + ;
FieldType( n ) + '", ' + ;
AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
next
cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }" + CRLF + CRLF
cCode += 'DbCreate( "myfile.dbf", aFields, "' + RddName() + '" )'
MemoEdit( cCode, "Code" )
return nil
//----------------------------------------------------------------------------//