Perguntas Atualizar Grid em Mvc apos preencher Cabeçalho

Mais
3 anos 2 meses atrás #33147 por Wanderson
Boa Tarde Pessoal,

Tenho uma tela de cadastro em MVC que tem cabeçalho e item mas, usando apenas uma tabela, neste cadastro o cabeçalho tenho 2 campos cCpoNatd e cCpoNatA, após preencher este segundo campo cCpoNatA gostaria que estás informações fossem para a grid de uma forma sequencia, tem como fazer isso?

Exemplo:

cCpoNatd: 000001
cCpoNatA: 000010

Na grid ele vai inserir as 10 linhas conforme a sequencia que o usuário preencher estes 2 campos.

Segue abaixo o fonte caso alguém possa me ajudar nesta dúvida.

#include "protheus.ch"
#include "fwmvcdef.ch"

User Function VSPCADN()
Local oBrowse As Object
Private aRotina := MenuDef()
oBrowse := FWMBrowse():New()
oBrowse:SetAlias("ZB1")
oBrowse:SetDescription("Amarração de Natureza x Contas")
oBrowse:SetMenuDef("GSFAT095")

oBrowse:Activate()

Return NIL

Static Function MenuDef()
Local aRotina As Array

aRotina := {}
ADD OPTION aRotina TITLE "Pesquisar" ACTION "VIEWDEF.VSPCADN" OPERATION 1 ACCESS 0
ADD OPTION aRotina TITLE "Visualizar" ACTION "VIEWDEF.VSPCADN" OPERATION 2 ACCESS 0
ADD OPTION aRotina TITLE "Incluir" ACTION "VIEWDEF.VSPCADN" OPERATION 3 ACCESS 0
ADD OPTION aRotina TITLE "Alterar" ACTION "VIEWDEF.VSPCADN" OPERATION 4 ACCESS 0
ADD OPTION aRotina TITLE "Excluir" ACTION "VIEWDEF.VSPCADN" OPERATION 5 ACCESS 0
ADD OPTION aRotina TITLE "Imprimir" ACTION "VIEWDEF.VSPCADN" OPERATION 8 ACCESS 0
ADD OPTION aRotina TITLE "Copiar" ACTION "VIEWDEF.VSPCADN" OPERATION 9 ACCESS 0

Return (aRotina)

Static Function ModelDef()
Local oMasterZB1 As Object
Local oDetailZB1 As Object
Local oModel As Object

oMasterZB1 := FWFormStruct(1, "ZB1", {|cIdField| VldField(cIdField)})
oDetailZB1 := FWFormStruct(1, "ZB1", {|cIdField| !VldField(cIdField)})

oModel := MPFormModel():New("VSPCADNM", /*bPre*/, /*bPost*/, /*bCommit*/, /*bCancel*/)

oModel:SetDescription("Contas x Natureza")
oModel:AddFields("ZB1MASTER", /*cOwner*/, oMasterZB1)
oModel:SetPrimaryKey({"ZB1_FILIAL", "ZB1_IDSEQ", "ZB1_ITEM"})

oModel:AddGrid("ZB1DETAIL", "ZB1MASTER", oDetailZB1, /*bLinePre*/, /*bLinePost*/, /*bPre*/, /*bLinePost*/, /*bLoad*/)
oModel:SetRelation("ZB1DETAIL", {{"ZB1_FILIAL", "FWxFilial(‘ZB1‘)"}, {"ZB1_IDSEQ", "ZB1_IDSEQ"}}, ZB1->(IndexKey(1)))

oModel:GetModel("ZB1DETAIL"):SetUniqueLine({"ZB1_ITEM"})
oModel:GetModel("ZB1MASTER"):SetDescription("Conta")
oModel:GetModel("ZB1DETAIL"):SetDescription("Naturezas")

Return (oModel)

Static Function ViewDef()
LOCAL oView as Object
LOCAL oModel as Object
LOCAL oMasterZB1 as Object
LOCAL oDetailZB1 as Object

oModel := FWLoadModel("VSPCADN")
oMasterZB1 := FWFormStruct(2, "ZB1", {|cIdField| VldField(cIdField)})
oDetailZB1 := FWFormStruct(2, "ZB1", {|cIdField| !VldField(cIdField)})

oMasterZB1:RemoveField("ZB1_LEGEND")
oMasterZB1:RemoveField("ZB1_OK")

oView := FWFormView():New()
oView:SetModel(oModel)

oView:AddField("ZB1MASTER", oMasterZB1)
oView:AddGrid("ZB1DETAIL", oDetailZB1)

oView:AddIncrementField("ZB1DETAIL", "ZB1_ITEM")

oView:CreateHorizontalBox("SUPERIOR", 40)
oView:CreateHorizontalBox("INFERIOR", 60)

oView:SetOwnerView("ZB1MASTER", "SUPERIOR")
oView:SetOwnerView("ZB1DETAIL", "INFERIOR")

Return (oView)

Static Function VldField(cIdField As Char)
Local aHeader As Array
Local lRet As Logical

aHeader := {}
AAdd(aHeader, "ZB1_IDSEQ")
AAdd(aHeader, "ZB1_CONTA")
AAdd(aHeader, "ZB1_FILATI")
AAdd(aHeader, "ZB1_FILBLQ")

lRet := (AScan(aHeader, {|x| (x == RTrim(cIdField))}) > 0)

Return (lRet)



User Function zOpcoes()
Local aArea := GetArea()
Local cOpcoes := ""

//Montando as opções de retorno

cOpcoes += "BARRACAO; "
cOpcoes += "CALL CENTER; "
cOpcoes += "CARRO; "
cOpcoes += "CAVALO; "
cOpcoes += "DESPESAS CHACARA; "
cOpcoes += "DESPESAS RANCHO;"
cOpcoes += "DESPESAS VIAGEM;"
cOpcoes += "EMPRESTIMOS A FAZ;"
cOpcoes += "GASTOS GERAIS;"
cOpcoes += "GREENVILLE;"
cOpcoes += "HUM.CL;"
cOpcoes += "IGREJA;"
cOpcoes += "IMPOSTO MATRIZ;"
cOpcoes += "INVESTIMO HUM;"
cOpcoes += "INVESTIMO LOJA 01;"
cOpcoes += "JUROS DR;"
cOpcoes += "JUROS ZECA;"
cOpcoes += "MARKETING FILIAL 01;"
cOpcoes += "MATRIZ;"
cOpcoes += "QUAY;"
cOpcoes += "REFEITORIO;"
cOpcoes += "RETIRADA CAPITAL;"
cOpcoes += "ROYAL GARDEN;"
cOpcoes += "SALARIO"

RestArea(aArea)
Return cOpcoes

Por favor Acessar ou Registrar para participar da conversa.

Mais
3 anos 2 meses atrás #33151 por Wanderson
Boa Tarde Pessoal já descobrir como fazer porem ainda continuo com uma duvida.
Quando Informo o código no cabeçalho ele monta o array e preenche o grid com as informações deste array porem preciso que, quando eu for digitar a nova sequencia de códigos ele de sequencia no grid e isso que não esta acontecendo agora. Segue abaixo o fonte atualizado caso alguém possa me ajudar.

#include "protheus.ch"
#include "fwmvcdef.ch"

User Function VSPCADN()
Local oBrowse As Object
Private aRotina := MenuDef()
Private aSED := {}
oBrowse := FWMBrowse():New()
oBrowse:SetAlias("ZB1")
oBrowse:SetDescription("Amarração de Natureza x Contas para o Quiken")
oBrowse:SetMenuDef("GSFAT095")
oBrowse:Activate()

Return NIL

Static Function MenuDef()
Local aRotina As Array

aRotina := {}
ADD OPTION aRotina TITLE "Pesquisar" ACTION "VIEWDEF.VSPCADN" OPERATION 1 ACCESS 0
ADD OPTION aRotina TITLE "Visualizar" ACTION "VIEWDEF.VSPCADN" OPERATION 2 ACCESS 0
ADD OPTION aRotina TITLE "Incluir" ACTION "VIEWDEF.VSPCADN" OPERATION 3 ACCESS 0
ADD OPTION aRotina TITLE "Alterar" ACTION "VIEWDEF.VSPCADN" OPERATION 4 ACCESS 0
ADD OPTION aRotina TITLE "Excluir" ACTION "VIEWDEF.VSPCADN" OPERATION 5 ACCESS 0
ADD OPTION aRotina TITLE "Imprimir" ACTION "VIEWDEF.VSPCADN" OPERATION 8 ACCESS 0
ADD OPTION aRotina TITLE "Copiar" ACTION "VIEWDEF.VSPCADN" OPERATION 9 ACCESS 0

Return (aRotina)

Static Function ModelDef()
Local oMasterZB1 As Object
Local oDetailZB1 As Object
Local oModel As Object

oMasterZB1 := FWFormStruct(1, "ZB1", {|cIdField| VldField(cIdField)})
oDetailZB1 := FWFormStruct(1, "ZB1", {|cIdField| !VldField(cIdField)})

oModel := MPFormModel():New("VSPCADNM", /*bPre*/, /*bPost*/, /*bCommit*/, /*bCancel*/)

oModel:SetDescription("Contas x Natureza")
oModel:AddFields("ZB1MASTER", /*cOwner*/, oMasterZB1)
oModel:SetPrimaryKey({"ZB1_FILIAL", "ZB1_IDSEQ", "ZB1_ITEM"})

oModel:AddGrid("ZB1DETAIL", "ZB1MASTER", oDetailZB1, /*bLinePre*/, /*bLinePost*/, /*bPre*/, /*bLinePost*/, /*bLoad*/)
oModel:SetRelation("ZB1DETAIL", {{"ZB1_FILIAL", "FWxFilial('ZB1')"}, {"ZB1_IDSEQ", "ZB1_IDSEQ"}}, ZB1->(IndexKey(1)))

oModel:GetModel("ZB1DETAIL"):SetUniqueLine({"ZB1_ITEM"})
oModel:GetModel("ZB1MASTER"):SetDescription("Conta")
oModel:GetModel("ZB1DETAIL"):SetDescription("Naturezas")

Return (oModel)

Static Function ViewDef()
LOCAL oView as Object
LOCAL oModel as Object
LOCAL oMasterZB1 as Object
LOCAL oDetailZB1 as Object

oModel := FWLoadModel("VSPCADN")
oMasterZB1 := FWFormStruct(2, "ZB1", {|cIdField| VldField(cIdField)})
oDetailZB1 := FWFormStruct(2, "ZB1", {|cIdField| !VldField(cIdField)})

//Remove Field da Grid
oMasterZB1:RemoveField("ZB1_LEGEND")
oMasterZB1:RemoveField("ZB1_OK")
oMasterZB1:RemoveField("ZB1_NATD")
oMasterZB1:RemoveField("ZB1_NATA")


oView := FWFormView():New()
oView:SetModel(oModel)

oView:AddField("ZB1MASTER", oMasterZB1)
oView:AddGrid("ZB1DETAIL", oDetailZB1)

oView:AddIncrementField("ZB1DETAIL", "ZB1_ITEM")

oView:CreateHorizontalBox("SUPERIOR", 30)
oView:CreateHorizontalBox("INFERIOR", 70)

oView:SetOwnerView("ZB1MASTER", "SUPERIOR")
oView:SetOwnerView("ZB1DETAIL", "INFERIOR")


&& Gatilho para encrementar o grid
oView:SetFieldAction("ZB1_FILBLQ", {|oView, cIdView, cField, xValue| U_CL073LIN(oView, cIdView, cField, xValue)})
Return (oView)

Static Function VldField(cIdField As Char)
Local aHeader As Array
Local lRet As Logical

aHeader := {}
AAdd(aHeader, "ZB1_IDSEQ")
AAdd(aHeader, "ZB1_CONTA")
AAdd(aHeader, "ZB1_FILATI")
AAdd(aHeader, "ZB1_FILBLQ")
AAdd(aHeader, "ZB1_NATD")
AAdd(aHeader, "ZB1_NATA")

lRet := (AScan(aHeader, {|x| (x == RTrim(cIdField))}) > 0)

Return (lRet)



User Function zOpcoes()
Local aArea := GetArea()
Local cOpcoes := ""

//Montando as opções de retorno

cOpcoes += "BARRACAO; "
cOpcoes += "CALL CENTER; "
cOpcoes += "CARRO; "
cOpcoes += "CAVALO; "
cOpcoes += "DESPESAS CHACARA; "
cOpcoes += "DESPESAS RANCHO;"
cOpcoes += "DESPESAS VIAGEM;"
cOpcoes += "EMPRESTIMOS A FAZ;"
cOpcoes += "GASTOS GERAIS;"
cOpcoes += "GREENVILLE;"
cOpcoes += "HUM.CL;"
cOpcoes += "IGREJA;"
cOpcoes += "IMPOSTO MATRIZ;"
cOpcoes += "INVESTIMO HUM;"
cOpcoes += "INVESTIMO LOJA 01;"
cOpcoes += "JUROS DR;"
cOpcoes += "JUROS ZECA;"
cOpcoes += "MARKETING FILIAL 01;"
cOpcoes += "MATRIZ;"
cOpcoes += "QUAY;"
cOpcoes += "REFEITORIO;"
cOpcoes += "RETIRADA CAPITAL;"
cOpcoes += "ROYAL GARDEN;"
cOpcoes += "SALARIO"

RestArea(aArea)
Return cOpcoes

//Função para le Cadastro de Natureza

Static Function fSED()
BeginSql alias 'TEMPSED'
SELECT
SED.ED_CODIGO
, SED.ED_DESCRIC
FROM
SED010 SED
WHERE
SED.ED_CODIGO BETWEEN '231300' AND '231305'
AND SED.D_E_L_E_T_=''
ORDER BY SED.ED_CODIGO
EndSql

DbSelectArea('TEMPSED')
While ! TEMPSED->( EOF() )

aAdd(aSED,{TEMPSED->ED_CODIGO,TEMPSED->ED_DESCRIC})

TEMPSED->( dbSkip())

Enddo

Return


USER FUNCTION CL073LIN(oView, cIdView, cField, xValue)

LOCAL nOperation := 0
LOCAL nI := 0
LOCAL nNroBras := xValue
LOCAL aProdscan := {}
LOCAL aEstrut := {}
Local i := 0
LOCAL lAprodscan := .T.
LOCAL oModel := oView:GetModel()
Local cCodigo := Space(15)
Private aProdutos := {}
Private cCodPai := oModel:GetValue("ZB1MASTER", "ZB1_NATA")

FSED()

nOperation := oModel:GetOperation()
IF nOperation == MODEL_OPERATION_INSERT
IF oModel:GetModel("ZB1DETAIL"):CanClearData()
oModel:GetModel("ZB1DETAIL"):ClearData()

if Len(aSED) <> 0
For i:=1 to Len(aSED)
IF oModel:GetModel("ZB1DETAIL"):AddLine() == ++nI
oModel:GetModel("ZB1DETAIL"):GoLine(nI)
oModel:GetModel("ZB1DETAIL"):SetValue("ZB1_ITEM" , STRZERO(nI, 4)) && ITEM
oModel:GetModel("ZB1DETAIL"):SetValue("ZB1_CODNAT" , aSED[i,1]) && Codigo da Natureza
oModel:GetModel("ZB1DETAIL"):SetValue("ZB1_NOMNAT" , aSED[i,2]) && Descrição da Natureza
oModel:GetModel("ZB1DETAIL"):SetValue("ZB1_STATUS" , "A") && Status

ENDIF
oView:Refresh()

next i
oModel:GetModel("ZB1DETAIL"):GoLine(1)
ENDIF
oModel:GetModel("ZB1DETAIL"):GoLine(1)
ENDIF
ENDIF
TEMPSED->( dbCloseArea() )
RETURN (nil)

Por favor Acessar ou Registrar para participar da conversa.

Mais
3 anos 2 meses atrás #33152 por Wanderson
Boa Tarde Pessoal,

Já consegui resolver obrigado.

Por favor Acessar ou Registrar para participar da conversa.

Tempo para a criação da página:0.075 segundos
Joomla templates by a4joomla