Bom dia pessoal, preciso montar uma rotina em MVC modelo 3 (com dois grids) ou seja serão três tabelas e ambas as tabelas são tabelas temporárias. Quando é somente Filds eu já consegui mas com grid estou com dificuldades, a rotina apresenta o seguinte error.log
THREAD ERROR ([3900], fabricio, rocknet) 28/09/2021 09:16:54 variable is not an object on FWFORMVIEW:GETMODELSTRUCT(FWFORMVIEW.PRW) 30/08/2021 18:16:28 line : 1102
Abaixo segue meu modeldef e viewdef e em anexo o fonte completo, se alguém puder me dar uma luz.
/*
|_| |Programa - ModelDef Autor Fabricio Antunes Data 22/11/2020 | |_| |Descricao|Modelo de dados MVC para edicao da tabela temporaria | | | | |_|_| |Uso | Coopervap | |_|_| |_| */ Static Function ModelDef()
Local oModel := Nil Local osCabec := FWFormModelStruct():New() Local osGrd1 := FWFormModelStruct():New() Local osGrd2 := FWFormModelStruct():New() Local nX Local lCopy:=.F. Local bLoad1 := {|osGrd1, lCopy| loadGrd1(osGrd1, lCopy)} Local bLoad2 := {|osGrd2, lCopy| loadGrd2(osGrd2, lCopy)}
//User nome real da tebela no banco //cTableCab, cTableGr1, cTableGr2
For nX:=1 to Len(aBrows) aBrows[nX,6]=.F. Next osCabec:AddTable(cAlisCab, {"ID"}, "Concilicao Financeira")
For nX:=1 to Len(aGrd1) aadd(aGrd1[nX],.F.) Next osGrd1:AddTable(cAlisGr1, {"ID","ITEM"}, "Contabilidade")
For nX:=1 to Len(aGrd2) aadd(aGrd2[nX],.F.) Next osGrd2:AddTable(cAlisGr2, {"ID","ITEM"}, "Financeiro")
/*---------------------------------------------------------------------- Estratuda do array para montagem dos campos usados na funcao MntStrut 1 - Descricao 2 - Nome do Campo 3 - Tipo do campo 4 - Tamanho do campo 5 - Decimal
6 - Se campo e editavel
*/
MntStrut(@osCabec,cAlisCab,aBrows) MntStrut(@osGrd1,cAlisGr1,aGrd1) MntStrut(@osGrd2,cAlisGr2,aGrd2)
oModel := MPFormModel():New("mdMCON001",/bPre/, /bPos/,/bCommit/,/bCancel/)
oModel:AddFields("ID_M_FLD",/cOwner/,osCabec) oModel:AddGrid( 'ID_M_GRD1', 'ID_M_FLD', osGrd1, /bLinePre/, /{|oModelZA2| ValLinha(oModelZA2)}/, /bPreVal/,/{|oModel| ValLinha(oModel)}/, bLoad1) oModel:AddGrid( 'ID_M_GRD2', 'ID_M_FLD', osGrd2, /bLinePre/, /{|oModelZA2| ValLinha(oModelZA2)}/, /bPreVal/,/{|oModel| ValLinha(oModel)}/, bLoad2)
oModel:SetRelation( 'ID_M_GRD1', {{'ID','ID'}}, (cAlisGr1)->(IndexKey(1))) oModel:SetRelation( 'ID_M_GRD2', {{'ID','ID'}}, (cAlisGr2)->(IndexKey(1)))
oModel:GetModel( 'ID_M_GRD1' ):SetUniqueLine( { 'ITEM'} ) oModel:GetModel( 'ID_M_GRD2' ):SetUniqueLine( { 'ITEM'} ) oModel:SetPrimaryKey({ 'ID' })
oModel:AddCalc( 'TOTAL', 'ID_M_FLD', 'ID_M_GRD1', 'SALDO' , '_nVlrOcor', 'SUM' , ,,'Total Saldo',/{ |oModel| AGL300H( oModel)} / ) oModel:AddCalc( 'TOTAL2', 'ID_M_FLD', 'ID_M_GRD2', 'SALDO' , '_nVlrOco2', 'SUM' , ,,'Total Saldo',/{ |oModel| AGL300H( oModel)} / )
oModel:SetDescription( 'Conciliacao Financeiro' ) oModel:GetModel( 'ID_M_GRD1' ):SetDescription( 'Contabilidade' ) oModel:GetModel( 'ID_M_GRD1' ):SetDescription( 'Financeiro' )
Return oModel
Static Function loadGrd1(oGridModel, lCopy) Local aLoad := {}
aAdd(aLoad,{0,{'000001','000001', "01/10/2021", "00000000", "HISTORICO",0,0,0}})
Return aLoad
Static Function loadGrd2(oGridModel, lCopy) Local aLoad := {}
aAdd(aLoad,{0,{'000001','000001', "01/10/2021", "00000000", "HISTORICO",0,0,0}})
Return aLoad /*
|_| |Programa - ViewDef Autor Fabricio Antunes Data 21/09/2021 | |_| |Descricao|Visao de dados MVC para montagem da tela da tabela temporaria | | | | |_|_| |Uso | Coopervap | |_|_| |_| */
Static Function ViewDef() Local oModel := FWLoadModel("MCON001") Local osCabec := FWFormViewStruct():New() Local osGrd1 := FWFormViewStruct():New() Local osGrd2 := FWFormViewStruct():New() Local oView := Nil Local nX Local aDadCab :={} Local aDadGr1 :={} Local aDadGr2 :={} Local oStruTOT1 := FWCalcStruct( oModel:GetModel('TOTAL') ) Local oStruTOT2 := FWCalcStruct( oModel:GetModel('TOTAL2') )
/*---------------------------------------------------------------------- Estratuda do array para montagem dos campos usados na funcao MntView 1 - Nome do Campo 2 - Ordem 3 - Titulo do campo 4 - Tipo do campo 5 - Picture
6 - Se campo e editavel
*/
For nX:=1 to Len(aBrows) IF aBrows[nX,3] = "C" cPict:="@!" ElseIF aBrows[nX,3] = "N" cPict:="@E 9,999,999.99" Else cPict:="" EnDIF aADD(aDadCab,{aBrows[nX,2],StrZero(nX,2),aBrows[nX,1],aBrows[nX,3],cPict,.F.})
Next
For nX:=1 to Len(aGrd1) IF aGrd1[nX,3] = "C" cPict:="@!" ElseIF aGrd1[nX,3] = "N" cPict:="@E 9,999,999.99" Else cPict:="" EnDIF aADD(aDadGr1,{aGrd1[nX,2],StrZero(nX,2),aGrd1[nX,1],aGrd1[nX,3],cPict,.F.})
Next
For nX:=1 to Len(aGrd2) IF aGrd2[nX,3] = "C" cPict:="@!" ElseIF aGrd2[nX,3] = "N" cPict:="@E 9,999,999.99" Else cPict:="" EnDIF aADD(aDadGr2,{aGrd2[nX,2],StrZero(nX,2),aGrd2[nX,1],aGrd2[nX,3],cPict,.F.})
Next
MntView(@osCabec,aDadCab) MntView(@osGrd1,aDadGr1) MntView(@osGrd2,aDadGr2)
oView := FWFormView():New() oView:SetModel(oModel)
oView:AddField("ID_V_FLD", osCabec, "ID_M_FLD") oView:AddGrid("ID_V_GRD1", osGrd1, "ID_M_GRD1") oView:AddGrid("ID_V_GRD2", osGrd2, "ID_M_GRD2")
// Adiciona objeto totais. oView:AddField( 'ID_V_GRD1', oStruTOT1, 'TOTAL1' ) oView:AddField( 'ID_V_GRD2', oStruTOT2, 'TOTAL2' )
oView:CreateHorizontalBox("SUPERIOR",30) oView:CreateHorizontalBox("INFERIOR",70) oView:CreateVerticalBox('ESQUERDA', 50 , 'INFERIOR') oView:CreateVerticalBox("DIREITA", 50 , 'INFERIOR')
oView:SetOwnerView( 'ID_V_FLD' , 'SUPERIOR' ) oView:SetOwnerView( 'ID_V_GRD1' , 'ESQUERDA' ) oView:SetOwnerView( 'ID_V_GRD2' , 'DIREITA' )
//Colocando título do formulário oView:EnableTitleView('ID_V_FLD', 'Conciliacao Financeiro' ) oView:EnableTitleView('ID_V_GRD1', 'Contabilidade' ) oView:EnableTitleView('ID_V_GRD2', 'Financeiro' )
oView:SetCloseOnOk({||.T.})
Return oView