Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. #INCLUDE 'PROTHEUS.CH'
  2. #INCLUDE 'FWMVCDEF.CH'
  3.  
  4. //-------------------------------------------------------------------
  5. /*/{Protheus.doc} COMP027_MVC
  6. Exemplo de montagem da modelo e interface para uma estrutura
  7. pai/filho/neto em MVC usando TREE
  8.  
  9. @author Ernani Forastieri e Rodrigo Antonio Godinho
  10. @since 05/10/2009
  11. @version P10
  12. /*/
  13. //-------------------------------------------------------------------
  14. User Function COMP027_MVC()
  15. Local oBrowse
  16.  
  17. oBrowse := FWmBrowse():New()
  18. oBrowse:SetAlias( 'ZA3' )
  19. oBrowse:SetDescription( 'Albuns' )
  20. oBrowse:Activate()
  21.  
  22. Return NIL
  23.  
  24.  
  25. //-------------------------------------------------------------------
  26. Static Function MenuDef()
  27. Local aRotina := {}
  28.  
  29. ADD OPTION aRotina Title 'Visualizar' Action 'VIEWDEF.COMP027_MVC' OPERATION 2 ACCESS 0
  30. ADD OPTION aRotina Title 'Incluir' Action 'VIEWDEF.COMP027_MVC' OPERATION 3 ACCESS 0
  31. ADD OPTION aRotina Title 'Alterar' Action 'VIEWDEF.COMP027_MVC' OPERATION 4 ACCESS 0
  32. ADD OPTION aRotina Title 'Excluir' Action 'VIEWDEF.COMP027_MVC' OPERATION 5 ACCESS 0
  33. ADD OPTION aRotina Title 'Imprimir' Action 'VIEWDEF.COMP027_MVC' OPERATION 8 ACCESS 0
  34. ADD OPTION aRotina Title 'Copiar' Action 'VIEWDEF.COMP027_MVC' OPERATION 9 ACCESS 0
  35.  
  36. Return aRotina
  37.  
  38.  
  39. //-------------------------------------------------------------------
  40. Static Function ViewDef()
  41. Local aTreeInfo:={}
  42. // Cria a estrutura a ser usada na View
  43. Local oStruZA3 := FWFormStruct( 2, 'ZA3' )
  44. Local oStruZA4 := FWFormStruct( 2, 'ZA4' )
  45. Local oStruZA5 := FWFormStruct( 2, 'ZA5' )
  46. // Cria um objeto de Modelo de Dados baseado no ModelDef do fonte informado
  47. Local oModel := FWLoadModel( 'COMP023_MVC' )
  48. Local oView
  49.  
  50. // Remove campos da estrutura
  51. oStruZA4:RemoveField( 'ZA4_ALBUM' )
  52. oStruZA5:RemoveField( 'ZA5_ALBUM' )
  53. oStruZA5:RemoveField( 'ZA5_MUSICA' )
  54.  
  55. // Cria o objeto de View
  56. oView := FWFormView():New()
  57.  
  58. // Define qual o Modelo de dados será utilizado
  59. oView:SetModel( oModel )
  60.  
  61. //Adiciona no nosso View um controle do tipo FormFields
  62. oView:AddField( 'VIEW_ZA3', oStruZA3, 'ZA3MASTER' )
  63. //oView:AddGrid( 'VIEW_ZA4', oStruZA4, "ZA4DETAIL" )
  64. //oView:AddGrid( 'VIEW_ZA5', oStruZA5, "ZA5DETAIL" )
  65.  
  66. // Cria a estrutura das grids em formato de árvore
  67. // [1] ID do Model
  68. // [2] Array de 1 dimensão com os IDs dos campos que iram aparecer no tree.
  69. // [3] Objeto do tipo FWViewStruct com a Estruturas dos campos
  70. aAdd( aTreeInfo, { "ZA4DETAIL", { "ZA4_MUSICA", "ZA4_TITULO" }, oStruZA4 } )
  71. aAdd( aTreeInfo, { "ZA5DETAIL", { "ZA5_INTER" } , oStruZA5 } )
  72.  
  73. // oView:AddTreeGrid( IDTree, Grids em Tree, IDDetail )
  74. oView:AddTreeGrid( "TREE", aTreeInfo, "DETAIL_TREE" )
  75.  
  76. // Criar "box" horizontal para receber algum elemento da view
  77. oView:CreateHorizontalBox( 'EMCIMA' , 20 )
  78. oView:CreateHorizontalBox( 'EMBAIXO', 80 )
  79.  
  80. // Criar "box" vertical para receber algum elemento da view
  81. oView:CreateVerticalBox( 'EMBAIXOESQ', 30, 'EMBAIXO' )
  82. oView:CreateVerticalBox( 'EMBAIXODIR', 70, 'EMBAIXO' )
  83.  
  84. // Relaciona o ID da View com o "box" para exibicao
  85. oView:SetOwnerView( 'VIEW_ZA3' , 'EMCIMA' )
  86. oView:SetOwnerView( 'TREE' , 'EMBAIXOESQ' )
  87. oView:SetOwnerView( 'DETAIL_TREE', 'EMBAIXODIR' )
  88.  
  89. Return oView
  90.  
  91.  
  92. //-------------------------------------------------------------------
  93. Static Function COMP23BUT( oPanel )
  94. Local lOk := .F.
  95.  
  96. @ 10, 10 Button 'Estatistica' Size 36, 13 Message 'Contagem da FormGrid' Pixel Action COMP23ACAO( 'ZA4DETAIL', 'Existem na Grid de Musicas' ) of oPanel
  97. @ 30, 10 Button 'Autor/Inter.' Size 36, 13 Message 'Inclui Autor/Interprete' Pixel Action FWExecView('Inclusao por FWExecView','COMP011_MVC', MODEL_OPERATION_INSERT, , { || .T. } ) of oPanel
  98. Return NIL
  99.  
  100.  
  101. //-------------------------------------------------------------------
  102. Static Function COMP23ACAO( cIdGrid, cMsg )
  103. Local oModel := FWModelActive()
  104. Local oModelFilho := oModel:GetModel( cIdGrid )
  105. Local nI := 0
  106. Local nCtInc := 0
  107. Local nCtAlt := 0
  108. Local nCtDel := 0
  109. Local aSaveLines := FWSaveRows()
  110.  
  111. For nI := 1 To oModelFilho:Length()
  112. oModelFilho:GoLine( nI )
  113.  
  114. If oModelFilho:IsDeleted()
  115. nCtDel++
  116. ElseIf oModelFilho:IsInserted()
  117. nCtInc++
  118. ElseIf oModelFilho:IsUpdated()
  119. nCtAlt++
  120. EndIf
  121.  
  122. Next
  123.  
  124.  
  125. Help( ,, 'HELP',, cMsg + CRLF + ;
  126. Alltrim( Str( nCtInc ) ) + ' linhas incluidas' + CRLF + ;
  127. Alltrim( Str( nCtAlt ) ) + ' linhas alteradas' + CRLF + ;
  128. Alltrim( Str( nCtDel ) ) + ' linhas deletadas' + CRLF ;
  129. , 1, 0)
  130.  
  131. FWRestRows( aSaveLines )
  132.  
  133. Return NIL
  134.  
  135.  
  136. //-------------------------------------------------------------------
  137. Static Function COMP027LPRE( oModelGrid, nLinha, cAcao, cCampo )
  138. Local lRet := .T.
  139. Local oModel := oModelGrid:GetModel()
  140. Local nOperation := oModel:GetOperation()
  141.  
  142. // Valida se pode ou nao deletar uma linha do Grid
  143. If cAcao == 'DELETE' .AND. nOperation == MODEL_OPERATION_UPDATE
  144. lRet := .F.
  145. Help( ,, 'Help',, 'Nao permitido apagar linhas na alteracao.' + CRLF + ;
  146. 'Voce esta na linha ' + Alltrim( Str( nLinha ) ), 1, 0 )
  147. EndIf
  148.  
  149. Return lRet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement