Ajude o site desativando o bloqueador de anúncio

ASSINE A NEWSLETTER

Cadastrando...
PIX uDesenv pix deposito

ADVPL MVC TLPP

Autor: Eurai Criado: 30/03/2025 Atualizado: 30/03/2025

Salve salve, blzz?

 

 

 

ADVPL MVC NO TLPP, VERSÃO 2410+

Como fazer o MVC funcionar no TLPP

 

Abaixo segue exemplo completo

 

1. Criar tabela ZZA com a coluna ZZA_NOME1 + índice e browser

2. Criar tabela ZZB com a coluna ZZB_NOME + índice e browser

3. Criar fonte: UDMVCTLPPZZA.tlpp

                                                    

#INCLUDE 'TOTVS.CH'
#INCLUDE "FWMVCDEF.CH"

namespace custom.udmvctlppzza

PUBLISH USER MODEL REST NAME custom_udmvctlppzza_fMain SOURCE "custom.udmvctlppzza"


/*/{Protheus.doc} fMain
TESTE ZZA 1

@author       Eurai Rapelli
@since        2025.04.30
/*/
User Function fMain()
Local oBrowse        := Nil

Private aRotina     := custom.udmvctlppzza.U_MenuDef()

oBrowse := FWMBrowse():New()
oBrowse:SetAlias('ZZA')
oBrowse:SetDescription('ZZA TESTE 1')

oBrowse:SetWalkThru(.F.)
oBrowse:SetAmbiente(.F.)
oBrowse:SetUseCursor(.F.)
oBrowse:DisableLocate(.F.)
oBrowse:DisableConfig()
oBrowse:DisableDetails()
oBrowse:Activate()
oBrowse:DeActivate()
oBrowse:Destroy()


Return( Nil )



/*/{Protheus.doc} MenuDef
Monta MENU/aRotina

@author    Eurai Rapelli
@since     2025.04.30
/*/
User Function MenuDef()
Local aRotina := {}

aAdd( aRotina, { 'Visualizar'     , 'ViewDef.custom.udmvctlppzza.fMain', 0, 2, 0, NIL } )
aAdd( aRotina, { 'Incluir'        , 'ViewDef.custom.udmvctlppzza.fMain', 0, 3, 0, NIL } )
aAdd( aRotina, { 'Alterar'        , 'ViewDef.custom.udmvctlppzza.fMain', 0, 4, 0, NIL } )
aAdd( aRotina, { 'Excluir'        , 'ViewDef.custom.udmvctlppzza.fMain', 0, 5, 0, NIL } )
aAdd( aRotina, { 'Alert'          , 'custom.udmvctlppzza.U_alert', 0, 3, 0, NIL } )
aAdd( aRotina, { 'Imprimir'     , 'VIEWDEF.custom.udmvctlppzza.fMain', 0, 8, 0, NIL } )
aAdd( aRotina, { 'Copiar'       , 'VIEWDEF.custom.udmvctlppzza.fMain', 0, 9, 0, NIL } )

Return( aRotina )

/*/{Protheus.doc} ModelDef
Monta o modelo para a view

@author       Eurai Rapelli
@since        2025.04.30
/*/
User Function ModelDef()
Local oModel           := Nil
Local oStructZZA       := FWFormStruct(1, 'ZZA')     

oModel     := MPFormModel():New('MDL_ZZA')

oModel:AddFields('MODEL_ZZA', NIL, oStructZZA)
oModel:SetPrimaryKey({ 'ZZA_NOME1' })

Return( oModel ) 

/*/{Protheus.doc} ViewDef
Visualização do Modelo

@author        Eurai Rapelli
@since         2025.04.30
/*/
User Function ViewDef()
Local oModel           := FWLoadModel("custom.udmvctlppzza.fMain")
Local oView            := FWFormView():New()
Local oStructZZA       := FWFormStruct(2, 'ZZA')

oView:SetModel(oModel)

oView:AddField( 'VIEW_ZZA' , oStructZZA, 'MODEL_ZZA' )

oView:CreateHorizontalBox( 'MASTER' , 100 )

oView:SetOwnerView( 'VIEW_ZZA' , 'MASTER' )
oView:EnableTitleView('VIEW_ZZA' , 'Dados' ) 


Return( oView )

/*/{Protheus.doc} alert
alert teste 

@type        function
@author      Eurai Rapelli
@since       2025.04.30
/*/
User Function alert()

alert('UDMVCTLPPZZA')

Return( Nil )


                                                  

4. Criar fonte: UDMVCTLPPZZB.tlpp

                                                    

#INCLUDE 'TOTVS.CH'
#INCLUDE "FWMVCDEF.CH"

namespace custom.UDMVCTLPPZZB

PUBLISH USER MODEL REST NAME custom_udmvctlppzzb_fMain SOURCE "custom.udmvctlppzzb" /*/{Protheus.doc} fMain TESTE ZZB 1 @author Eurai Rapelli @since 2025.04.30 /*/ User Function fMain() Local oBrowse := Nil // Private aRotina := custom.udmvctlppzzb.U_MenuDef() oBrowse := FWLoadBrw("custom.udmvctlppzzb.fMain") oBrowse:Activate() oBrowse:DeActivate() oBrowse:Destroy() Return( Nil ) /*/{Protheus.doc} MenuDef BrowseDef @author Eurai Rapelli @since 2025.04.30 /*/ User Function BrowseDef() as object local oBrowse as object oBrowse := FWMBrowse():New() oBrowse:SetAlias('ZZB') oBrowse:SetDescription('ZZB TESTE 1') oBrowse:SetWalkThru(.F.) oBrowse:SetAmbiente(.F.) oBrowse:SetUseCursor(.F.) oBrowse:DisableLocate(.F.) oBrowse:DisableConfig() oBrowse:DisableDetails() Return( oBrowse ) /*/{Protheus.doc} MenuDef Monta MENU/aRotina @author Eurai Rapelli @since 2025.04.30 /*/ User Function MenuDef() Local aRotina := {} aAdd( aRotina, { 'Visualizar' , 'ViewDef.custom.udmvctlppzzb.fMain', 0, 2, 0, NIL } ) aAdd( aRotina, { 'Incluir' , 'ViewDef.custom.udmvctlppzzb.fMain', 0, 3, 0, NIL } ) aAdd( aRotina, { 'Alterar' , 'ViewDef.custom.udmvctlppzzb.fMain', 0, 4, 0, NIL } ) aAdd( aRotina, { 'Excluir' , 'ViewDef.custom.udmvctlppzzb.fMain', 0, 5, 0, NIL } ) aAdd( aRotina, { 'Alert' , 'custom.udmvctlppzzb.U_alert', 0, 3, 0, NIL } ) //aAdd( aRotina, { 'Imprimir' , 'VIEWDEF.custom.udmvctlppzzb.fMain', 0, 8, 0, NIL } ) aAdd( aRotina, { 'Copiar' , 'VIEWDEF.custom.udmvctlppzzb.fMain', 0, 9, 0, NIL } ) Return( aRotina ) /*/{Protheus.doc} ModelDef Monta o modelo para a view @author Eurai Rapelli @since 2025.04.30 /*/ User Function ModelDef() Local oModel := Nil Local oStructZZB := FWFormStruct(1, 'ZZB') oModel := MPFormModel():New('MODEL_ZZB') oModel:AddFields('MODEL_ZZB', NIL, oStructZZB) oModel:SetPrimaryKey({ 'ZZB_NOME' }) Return( oModel ) /*/{Protheus.doc} ViewDef Visualização do Modelo @author Eurai Rapelli @since 2025.04.30 /*/ User Function ViewDef() Local oModel := FWLoadModel("custom.UDMVCTLPPZZB.fMain") Local oView := FWFormView():New() Local oStructZZB := FWFormStruct(2, 'ZZB') oView:SetModel(oModel) oView:AddField( 'VIEW_ZZB' , oStructZZB, 'MDL_ZZB' ) oView:CreateHorizontalBox( 'MASTER' , 100 ) oView:SetOwnerView( 'VIEW_ZZB' , 'MASTER' ) oView:EnableTitleView('VIEW_ZZB' , 'Dados' ) Return( oView ) /*/{Protheus.doc} alert alert teste @type function @author Eurai Rapelli @since 2025.04.30 /*/ User Function alert() alert('UDMVCTLPPZZB') Return( Nil )

5. Adicionar no MENU a rotina custom.UDMVCTLPPZZA.fMain com nome MVC ZZA

6. Adicionar no MENU a rotina custom.UDMVCTLPPZZB.fMain com nome MVC ZZB

 

Utilizar e testes.

Fiz de duas formas as chamadas do MENUDEF (fonte ZZA e ZZB)

Também coloquei a mesma user function alert em namespace diferente, uma não interfere na outra

 

 

 

 

 

 

ADVPL MVC REST NO TLPP, VERSÃO 2410+

 

1. Publicar o modelo, com o comando abaixo:

PUBLISH USER MODEL REST NAME custom_udmvctlppzza_fMain SOURCE "custom.udmvctlppzza.fMain"

2. Criar servidor rest

 

[ONSTART]

JOBS=HTTPJOB

REFRESHRATE=120

 

[HTTPJOB]

MAIN=HTTP_START

ENVIRONMENT=Protheus12_1.2410_REST

 

[HTTPV11]

Enable=1

Sockets=HTTPREST

 

[HTTPREST] 

Port=40001

URIs=HTTPURI

Security=0

 

 

[HTTPURI]

URL=/rest

PrepareIn=ALL

Instances=1,1

 

3. Utilizar no postman.

 

 

 

 

 

 

 

Gostou? Compartilhe com seus amigos e deixe um comentário! 😎

Um abraço, e até a próxima