#include "fivewin.ch"
#include "constant.ch"
function Matrix()
local oDlg, oBrw, oFont, oBold, oFontGet
local nBottom := 33
local nRight := 80
local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
local nHeight := nBottom * DLG_CHARPIX_H
local oPanelTitle
local oGrp:=array(3)
local aGet:=array(10)
local oBtnClose,oBtnSave,oBtnPrint
local oBtnReset,oBtnInsert
local aData := {{ 0,0,0}} //{{ 1,2,3 } } //, { 4,5,6 } {}
local nRows := Len( aData )
local nCols := Len( aData[ 1 ] )
local nNumbers :=10
local nGuarantee:= 1
local nPoints := 1
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-10
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
DEFINE FONT oFontGet NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE nWidth, nHeight ;
PIXEL TRUEPIXEL FONT oFont RESIZABLE ; //RESIZABLE
TiTle "Manage Matrix"
@ 70, 180 XBROWSE oBrw SIZE 395,300 PIXEL OF oDlg ;
DATASOURCE aData AUTOCOLS CELL LINES NOBORDER FASTEDIT
SetupBrowseMatrix(oBrw)
oBrw:RecSelShowKeyNo()
oBrw:CreateFromCode()
@ 70,10 SAY "Total quantity of numbers" SIZE 150,24 PIXEL OF oDlg FONT oFont
@ 160,10 SAY "Development (nr. for column)" SIZE 150,24 PIXEL OF oDlg FONT oFont
@ 230,10 SAY "Combinations" SIZE 150,24 PIXEL OF oDlg FONT oFont
@ 340,7 SAY "Guarantee" SIZE 150,24 PIXEL OF oDlg FONT oFont
@ 340,130 SAY "points" SIZE 30,24 PIXEL OF oDlg FONT oFont
@ 375,7 SAY "width" SIZE 150,24 PIXEL OF oDlg FONT oFont
@ 375,130 SAY "numbers" SIZE 35,24 PIXEL OF oDlg FONT oFont
@ 90,10 GET aget[1] VAR nNumbers SIZE 100,24 PIXEL;
SPINNER MIN 5 MAX 90 OF oDlg ;
PICTURE "99" FONT oFontGet
@ 250 ,10 GET aget[2] VAR nRows SIZE 100,24 PIXEL OF oDlg SPINNER MIN 1 MAX 100 ;
PICTURE "99" ON CHANGE ResizeArray( oBrw, nRows, nCols, aGet ) FONT oFontGet UPDATE
@ 180,10 GET aget[3] VAR nCols SIZE 100,24 PIXEL OF oDlg SPINNER MIN 3 MAX 10 ;
PICTURE "99" ON CHANGE ResizeArray( oBrw, nRows, nCols, aGet ) FONT oFontGet UPDATE
@ 335 ,55 GET nGuarantee SIZE 50,24 PIXEL;
SPINNER MIN 1 MAX 10 OF oDlg ;
PICTURE "99" FONT oFontGet
@ 370 ,55 GET nPoints SIZE 50,24 PIXEL;
SPINNER MIN 1 MAX 10 OF oDlg ;
PICTURE "99" FONT oFontGet
@ 50,175 GROUP oGrp[1] To 410,oDlg:nWidth-20 Label "Matrix" TRANSPARENT PIXEL OF oDlg
@ 50,2 GROUP oGrp[2] To 300,170 Label "Reduced System" TRANSPARENT PIXEL OF oDlg
@ 310,2 GROUP oGrp[3] To 410,170 Label "Guarantee" TRANSPARENT PIXEL OF oDlg
@ 100,10 BUTTON oBtnReset PROMPT "Reset" of oDlg SIZE 80,22 ACTION SetZeros( oBrw )
@ 100,10 BUTTON oBtnInsert PROMPT "Insert" of oDlg SIZE 80,22 ACTION NewData( oBrw, nil , aGet)
@ 100,10 BUTTON oBtnPrint PROMPT "Print" of oDlg SIZE 80,22 ACTION oBrw:Report()
@ 100,10 BUTTON oBtnClose PROMPT "Close" of oDlg SIZE 80,22 ACTION oDlg:End()
@ 100,10 BUTTON oBtnSave PROMPT "Save" of oDlg SIZE 80,22 ACTION NIL
oDlg:bResized := <||
local oRect := oDlg:GetCliRect()
oBtnPrint:nLeft := oRect:nRight - 200
oBtnPrint:nTop := oRect:nBottom - 45
oBtnClose:nLeft := oRect:nRight - 100
oBtnClose:nTop := oRect:nBottom - 45
oBtnSave:nLeft := oRect:nRight - 300
oBtnSave:nTop := oRect:nBottom - 45
oBtnReset:nLeft := oRect:nLeft+10
oBtnReset:nTop := oRect:nBottom - 45
oBtnInsert:nLeft := oRect:nLeft+100
oBtnInsert:nTop := oRect:nBottom - 45
oBrw:nWidth := oRect:nWidth - 210
oPanelTitle:nTop := oRect:ntop
oPanelTitle:nLeft := oRect:nleft+2
oPanelTitle:nwidth := oRect:nRight
RETURN NIL
>
ACTIVATE DIALOG oDlg CENTERED;
ON INIT (oPanelTitle:=Paneltitle(oDlg),;
SayTexttitle(oPanelTitle,oFont) ,;
Eval(oDlg:bResized))
RELEASE FONT oFont, oBold, oFontGet
XBROWSER aData
return nil
static function ResizeArray( oBrw, nRows, nCols, oControls )
local aData := oBrw:aArrayData
local iRows, iCols, n
iCols := Len( oBrw:aCols )
if ( iRows := oBrw:nLen ) != nRows .or. iCols != nCols
ASize( aData, nRows )
if nCols != iCols
AEval( aData, { |a| ASize( a, nCols ), ;
If( nCols > iCols, AFill( a, 0, iCols + 1 ), nil ) }, 1, Min( iRows, nRows ) )
endif
for n := iRows + 1 to nRows
aData[ n ] := Array( nCols )
AFill( aData[ n ], 0 )
next
//
oBrw:SetArray( aData, .f., 0, .t. )
SetupBrowseMatrix( oBrw )
endif
oControls[2]:SetText( Len( aData ) )
oControls[3]:SetText(Len( aData[ 1 ] ) )
oControls[2]:refresh()
oControls[3]:refresh()
return nil
//----------------------------------------------------------------------------//
static function SetupBrowseMatrix( oBrw )
WITH OBJECT oBrw
// :RecSelShowKeyNo()
AEval( :aCols, { |o,i| o:cHeader := LTrim( Str( i, 2 ) ) } )
:nEditTypes := EDIT_GET
:nWidths := 30
:lHscroll := .f.
:lVscroll := .t.
:l2007 := .f.
:l2015 := .f.
:lAllowRowSizing := .f.
:lAllowColSwapping := .f.
:lAllowColHiding := .f.
// NEW
:lAllowSizings := .f.
:lAutoSaves := .t.
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:bRecSelHeader := { || " " }
:SetStyle( 2018 )
// :CreateFromCode()
END
return nil
//---------------------------------------------------------------------------------------------------------//
static function Paneltitle(oDlg)
local oPanel,oBrush
Local aGrad:= { RGB(173,216,230),RGB(255,255,255)}
DEFINE BRUSH oBrush GRADIENT aGrad
oPanel:=Tpanel():New( 45, 2, 88, oDlg:nWidth-20, oDlg)
oPanel:SetBrush( oBrush )
// oPanel:bPainted := { || oPanel:Box( 1,1,oPanel:nHeight-1,oPanel:nWidth-1 ) }
return oPanel
//---------------------------------------------------------------------------------------------------------//
static function SayTexttitle(oPanelTitle,oFont)
@ 10,10 SAY "Creation Reduced Matrix" SIZE 150,24 PIXEL OF oPanelTitle FONT oFont TRANSPARENT
RETURN NIL
//----------------------------------------------------------------------------//
static function SetZeros( oBrw )
AEval( oBrw:aArrayData, { |aRow| AFill( aRow, 0 ) } )
oBrw:Refresh()
return nil
//----------------------------------------------------------------------------//
static function NewData( oBrw, cData, oControls )
local aNewData,cFile
local n
DEFAULT cData := ;
"1,2,3,4,5" + CRLF + ;
"5,4,6,7,8" + CRLF + ;
"5,3,6,2,1"
cFile := cGetFile( "TEXT (*.txt)| *.Txt|" + ;
"All Files (*.*)| *.*" ;
,"Please select a text file", 4 )
cData := HB_MEMOREAD( cFile )
cData := StrTran( cData, CRLF, CHR(10) )
aNewData := HB_ATokens( cData, CHR(10) )
AEval( aNewData, { |c,i| aNewData[ i ] := HB_ATokens( c, "," ) } )
for n := 1 to Len( aNewData )
AEval( aNewData[ n ], { |c,i| aNewData[ n, i ] := Val( c ) } )
next
ResizeArray( oBrw, Len( aNewData ), Len( aNewData[ 1 ] ),oControls )
for n := 1 to Len( aNewData )
oBrw:aArrayData[ n ] := aNewData[ n ]
next
SetupBrowseMatrix( oBrw )
return nil
----------------------------------------------------------------------------/