Page 1 of 1

Entendendo xBrowse

Posted: Sun Aug 04, 2013 7:29 am
by SAOliveira
Senhores, primeiro desculpe pelo tamanho do post e pelo ingles (google tradutor)
Gentlemen, first sorry for the size of the post and the English (google translator)

Estou tentando entender o código abaixo.
I'm trying to understand the code below.

Code: Select all

**----------------------------------------------------------**
    FUNCTION TESTE()
    #include 'fivewin.ch'
**----------------------------------------------------------**
Wid_fornecedor:=2
cCmd:="SELECT c.registro,c.status,c.nota_numero,c.nota_emissao,c.nota_entrada,c.nota_total,c.nota_produto,CONCAT(DATE_FORMAT(c.data_atualizou,'%d/%m/%Y'),' ',uso.fantasia) AS data_atualizou"
cCmd+=" FROM cfe_cabec AS c, usuario_cadastro AS uso"
cCmd+=" WHERE c.id_fornecedor="+Any2Sql(Wid_fornecedor)
cCmd+=" AND c.usuario_atualizou=uso.registro"
aFME:=SQLArray(cCmd,,xBanco)
aEval(aFME,{|_1,_2|aFME[_2,1]:=val(aFME[_2,1]),;
                   aFME[_2,3]:=val(aFME[_2,3]),;
                   aFME[_2,4]:=Transf(StoD(StrTran(aFME[_2,4],'-','')),"@D"),;
                   aFME[_2,5]:=Transf(StoD(StrTran(aFME[_2,5],'-','')),"@D"),;
                   aFME[_2,6]:=val(aFME[_2,6]),;
                   aFME[_2,7]:=val(aFME[_2,7])})

***************************************
aSort(aFME,,,{|x,y|x[4] < y[4]})
***************************************
DEFINE DIALOG oDlgFME RESOURCE "TESTE" OF oWnd
              oDlgFME:cCaption:="..:: Teste de xBrowse/Array ::.."
              oDlgFME:lHelpIcon:=.F.
              oDlgFME:lTransparent:=.f.
              oDlgFME:SetFont(oPub:fNorm11)
              oDlgFME:SetColor(oPub:CorPreto,oPub:CorDlg)

    oBrwFME:=TXBROWSE():NEW(oDlgFME)
        oBrwFME:CreateFromResource(201)
        oBrwFME:SetArray( aFME,.T.,4,{1,2,3,4,5,6,7,8})
        oBrwFME:SetColor( oPub:CorAzul,oPub:CorDlg )
        oBrwFME:SetFont(oPub:fNorm11)
        oBrwFME:l2007               := .F.
        oBrwFME:lKinetic            :=.F.
        oBrwFME:lAllowRowSizing     := .T.
        oBrwFME:lHScroll            := .F.
        oBrwFME:lVScroll            := .T.
        oBrwFME:lRecordSelector     := .T.
        oBrwFME:lAllowColSwapping   := .F.
        oBrwFME:nDataLines          := 1
        oBrwFME:lColDividerComplete := .T.
        oBrwFME:lColDividerComplete := .T.
        oBrwFME:nColDividerStyle    := 4
        oBrwFME:nRowDividerStyle    := 4
        oBrwFME:nMarqueeStyle       := 5
        oBrwFME:nRowHeight          := 25
        oBrwFME:nRecSelColor        := oPub:CorDlg
        oBrwFME:nFreeze             := 8
        oBrwFME:bClrStd             :={||{oPub:CorGet,If(oBrwFME:nArrayAt%2==0,oPub:CorDlg,oPub:CorFundoGet) }}
        oBrwFME:bClrSel             :={||{oPub:CorGet,If(oBrwFME:nArrayAt%2==0,oPub:CorDlg,oPub:CorFundoGet) }}
        oBrwFME:bClrSelFocus        :={||{oPub:CorFundoGet,oPub:CorAzulM}}
        oBrwFME:bClrRowFocus        :={||{oPub:CorFundoGet,oPub:CorAzulM}}

        oBrwFME:lHeader             := .T.
        oBrwFME:bClrHeader          := {|| {oPub:CorPreto,oPub:CorDlg }}

        oBrwFME:aCols[1]:cHeader      :="Registro"
        oBrwFME:aCols[1]:cEditPicture :="@E 999,999"
        oBrwFME:aCols[1]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[1]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[1]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[1]:nWidth       :=60

        oBrwFME:aCols[2]:AddResource("16_LOCK")
        oBrwFME:aCols[2]:cHeader      :="Status"
        oBrwFME:aCols[2]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[2]:nDataStrAlign:=AL_CENTER
        oBrwFME:aCols[2]:bBmpData     :={|| IF(aFME[oBrwFME:nArrayAt,2]=='1',1,2)}
        oBrwFME:aCols[2]:nWidth       :=40

        oBrwFME:aCols[3]:cHeader      :="Nota nº"
        oBrwFME:aCols[3]:cEditPicture :="@E 999,999"
        oBrwFME:aCols[3]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[3]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[3]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[3]:nWidth       :=80

        oBrwFME:aCols[4]:cHeader      :="Emissão"
        oBrwFME:aCols[4]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[4]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[4]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[4]:nWidth       :=90

        oBrwFME:aCols[5]:cHeader      :="Entrada"
        oBrwFME:aCols[5]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[5]:nDataStrAlign:=AL_CENTER
        oBrwFME:aCols[5]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[5]:nWidth       :=90

        oBrwFME:aCols[6]:cHeader      :="Total Nota"
        oBrwFME:aCols[6]:cEditPicture :="@E 999,999.99"
        oBrwFME:aCols[4]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[6]:nDataStrAlign:=AL_RIGHT
        oBrwFME:aCols[6]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[6]:nWidth       :=100

        oBrwFME:aCols[7]:cHeader      :="Total Produto"
        oBrwFME:aCols[7]:cEditPicture :="@E 999,999.99"
        oBrwFME:aCols[7]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[7]:nDataStrAlign:=AL_RIGHT
        oBrwFME:aCols[7]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[7]:nWidth       :=100

        oBrwFME:aCols[8]:cHeader      :="Atualização"
        oBrwFME:aCols[8]:cEditPicture :="@!"
        oBrwFME:aCols[8]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[8]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[8]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[8]:nWidth       :=213

ACTIVATE DIALOG oDlgFME CENTERED
RETURN(NIL)
Legal como na imagem
Cool like the image
Image

Agora se eu simplesmente inverter a ordem : aSort(aFME,,,{|x,y|x[4] > y[4]})
Now if I just reverse the order: asort (AFME,,, {| x, y | x [4] > y [4]})

Muda a apresentação do xBrowse, como na imagem
Changes the presentation of xBrowse, as in the picture
Image

Mas se eu fizer assim:
But if I do this:code=fw

Code: Select all

 **----------------------------------------------------------**
    FUNCTION TESTE()
    #include 'fivewin.ch'
**----------------------------------------------------------**
Wid_fornecedor:=2 ; aFME:={} ; AAdd(aFME,{,,,,,,,})

DEFINE DIALOG oDlgFME RESOURCE "TESTE" OF oWnd
              oDlgFME:cCaption:="..:: Teste de xBrowse/Array ::.."
              oDlgFME:lHelpIcon:=.F.
              oDlgFME:lTransparent:=.f.
              oDlgFME:SetFont(oPub:fNorm11)
              oDlgFME:SetColor(oPub:CorPreto,oPub:CorDlg)

    oBrwFME:=TXBROWSE():NEW(oDlgFME)
        oBrwFME:CreateFromResource(201)
        oBrwFME:SetArray( aFME,.T.,4,{1,2,3,4,5,6,7,8})
        oBrwFME:SetColor( oPub:CorAzul,oPub:CorDlg )
        oBrwFME:SetFont(oPub:fNorm11)
        oBrwFME:l2007               := .F.
        oBrwFME:lKinetic            :=.F.
        oBrwFME:lAllowRowSizing     := .T.
        oBrwFME:lHScroll            := .F.
        oBrwFME:lVScroll            := .T.
        oBrwFME:lRecordSelector     := .T.
        oBrwFME:lAllowColSwapping   := .F.
        oBrwFME:nDataLines          := 1
        oBrwFME:lColDividerComplete := .T.
        oBrwFME:lColDividerComplete := .T.
        oBrwFME:nColDividerStyle    := 4
        oBrwFME:nRowDividerStyle    := 4
        oBrwFME:nMarqueeStyle       := 5
        oBrwFME:nRowHeight          := 25
        oBrwFME:nRecSelColor        := oPub:CorDlg
        oBrwFME:nFreeze             := 8
        oBrwFME:bClrStd             :={||{oPub:CorGet,If(oBrwFME:nArrayAt%2==0,oPub:CorDlg,oPub:CorFundoGet) }}
        oBrwFME:bClrSel             :={||{oPub:CorGet,If(oBrwFME:nArrayAt%2==0,oPub:CorDlg,oPub:CorFundoGet) }}
        oBrwFME:bClrSelFocus        :={||{oPub:CorFundoGet,oPub:CorAzulM}}
        oBrwFME:bClrRowFocus        :={||{oPub:CorFundoGet,oPub:CorAzulM}}

        oBrwFME:lHeader             := .T.
        oBrwFME:bClrHeader          := {|| {oPub:CorPreto,oPub:CorDlg }}

        oBrwFME:aCols[1]:cHeader      :="Registro"
        oBrwFME:aCols[1]:cEditPicture :="@E 999,999"
        oBrwFME:aCols[1]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[1]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[1]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[1]:nWidth       :=60

        oBrwFME:aCols[2]:AddResource("16_LOCK")
        oBrwFME:aCols[2]:cHeader      :="Status"
        oBrwFME:aCols[2]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[2]:nDataStrAlign:=AL_CENTER
        oBrwFME:aCols[2]:bBmpData     :={|| IF(aFME[oBrwFME:nArrayAt,2]=='1',1,2)}
        oBrwFME:aCols[2]:nWidth       :=40

        oBrwFME:aCols[3]:cHeader      :="Nota nº"
        oBrwFME:aCols[3]:cEditPicture :="@E 999,999"
        oBrwFME:aCols[3]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[3]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[3]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[3]:nWidth       :=80

        oBrwFME:aCols[4]:cHeader      :="Emissão"
        oBrwFME:aCols[4]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[4]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[4]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[4]:nWidth       :=90

        oBrwFME:aCols[5]:cHeader      :="Entrada"
        oBrwFME:aCols[5]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[5]:nDataStrAlign:=AL_CENTER
        oBrwFME:aCols[5]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[5]:nWidth       :=90

        oBrwFME:aCols[6]:cHeader      :="Total Nota"
        oBrwFME:aCols[6]:cEditPicture :="@E 999,999.99"
        oBrwFME:aCols[4]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[6]:nDataStrAlign:=AL_RIGHT
        oBrwFME:aCols[6]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[6]:nWidth       :=100

        oBrwFME:aCols[7]:cHeader      :="Total Produto"
        oBrwFME:aCols[7]:cEditPicture :="@E 999,999.99"
        oBrwFME:aCols[7]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[7]:nDataStrAlign:=AL_RIGHT
        oBrwFME:aCols[7]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[7]:nWidth       :=100

        oBrwFME:aCols[8]:cHeader      :="Atualização"
        oBrwFME:aCols[8]:cEditPicture :="@!"
        oBrwFME:aCols[8]:nHeadStrAlign:=AL_CENTER
        oBrwFME:aCols[8]:nDataStrAlign:=AL_LEFT
        oBrwFME:aCols[8]:oDataFont    :=oPub:fBCour13
        oBrwFME:aCols[8]:nWidth       :=213
ACTIVATE DIALOG oDlgFME CENTERED ON INIT(MostraArray())
RETURN(NIL)
**----------------------------------------------------------**
    STATIC FUNCTION MostraArray()
**----------------------------------------------------------**
    cCmd:="SELECT c.registro,c.status,c.nota_numero,c.nota_emissao,c.nota_entrada,c.nota_total,c.nota_produto,CONCAT(DATE_FORMAT(c.data_atualizou,'%d/%m/%Y'),' ',uso.fantasia) AS data_atualizou"
    cCmd+=" FROM cfe_cabec AS c, usuario_cadastro AS uso"
    cCmd+=" WHERE c.id_fornecedor="+Any2Sql(Wid_fornecedor)
    cCmd+=" AND c.usuario_atualizou=uso.registro"
    aFME:=SQLArray(cCmd,,xBanco)
    aEval(aFME,{|_1,_2|aFME[_2,1]:=val(aFME[_2,1]),;
                   aFME[_2,3]:=val(aFME[_2,3]),;
                   aFME[_2,4]:=StoD(StrTran(aFME[_2,4],'-','')),;
                   aFME[_2,5]:=StoD(StrTran(aFME[_2,5],'-','')),;
                   aFME[_2,6]:=val(aFME[_2,6]),;
                   aFME[_2,7]:=val(aFME[_2,7])})
    aSort(aFME,,,{|x,y|x[4] > y[4]})
    oBrwFME:SetArray( aFME,.T.,4,{1,2,3,4,5,6,7,8})
    RETURN(.T.)
Funciona normal, como na imagem
Operate normally, as in the Picture
Image

Alguma explicação ?
Some explanation?