Exemplo do Ponto de Entrada OS010BTN.
Exemplo do Ponto de Entrada:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | //Bibliotecas #Include "Protheus.ch" /*--------------------------------------------------------------------------* | P.E.: OS010BTN | | Descr.: Função que adiciona Ações Relacionadas dentro da Tabela de Preço | *--------------------------------------------------------------------------*/ User Function OS010BTN() Local aArea := GetArea() Local aButtons := {} //Adicionando o botão no Ações Relacionadas aAdd(aButtons,{ "* Atualiza Produtos" , {|| u_zAtuGrid()}, "* Atualiza Produtos" }) RestArea(aArea) Return aButtons User Function zAtuGrid() Local aArea := GetArea() Local nJanAltu := 100 Local nJanLarg := 700 Local oFontPad := TFont():New( "Arial" , , -14) Private lNovo := .F. Private oDlgAtu Private cMaskDA1 := PesqPict( 'DA1' , 'DA1_PRCVEN' ) //Carregando os modelos de dados do cabeçalho e grid Private oModelPad := FWModelActive() Private oModelGrid := oModelPad:GetModel( 'DA1DETAIL' ) Private nOperacao := oModelPad:nOperation //Pegando posições do aHeader Private nPosProd := aScan(oModelGrid:aHeader, {|x| AllTrim(x[2]) == AllTrim( "DA1_CODPRO" )}) Private nPosDesc := aScan(oModelGrid:aHeader, {|x| AllTrim(x[2]) == AllTrim( "DA1_DESCRI" )}) Private nPosPrcV := aScan(oModelGrid:aHeader, {|x| AllTrim(x[2]) == AllTrim( "DA1_PRCVEN" )}) //Linha Atual Private nLinAtu := oModelGrid:nLine //Linha encontrada Private nLinEnc := 0 //Gets Private oGetCod, cGetCod := Space(TamSX3( 'B1_COD' )[01]) Private oGetDes, cGetDes := Space(TamSX3( 'B1_DESC' )[01]) Private oGetPrc, nGetPrc := 0 Private oGetMsg, cGetMsg := "" //Montando a janela DEFINE MSDIALOG oDlgAtu TITLE "Atualização Preço" FROM 000, 000 TO nJanAltu, nJanLarg COLORS 0, 16777215 PIXEL //Produto nColAux := 3 @ 007, nColAux SAY oSayCod PROMPT "Produto: " SIZE 050, 007 OF oDlgAtu COLORS 0, 16777215 PIXEL @ 004, nColAux+40 MSGET oGetCod VAR cGetCod SIZE 060, 010 OF oDlgAtu COLORS 0, 16777215 F3 'SB1' VALID (fPesqSB1()) PIXEL //Descrição nColAux += 103 @ 007, nColAux SAY oSayDes PROMPT "Descrição: " SIZE 050, 007 OF oDlgAtu COLORS 0, 16777215 PIXEL @ 004, nColAux+40 MSGET oGetDes VAR cGetDes SIZE 100, 010 OF oDlgAtu COLORS 0, 16777215 PIXEL oGetDes:lActive := .F. //Preço Venda nColAux += 143 @ 007, nColAux SAY oSayPrc PROMPT "Preço Venda: " SIZE 050, 007 OF oDlgAtu COLORS 0, 16777215 PIXEL @ 004, nColAux+40 MSGET oGetPrc VAR nGetPrc SIZE 060, 010 OF oDlgAtu COLORS 0, 16777215 PICTURE cMaskDA1 PIXEL //Get de Log @ 023, 003 MSGET oGetMsg VAR cGetMsg SIZE (nJanLarg/2)-12, 012 OF oDlgAtu COLORS 0, 16777215 NO BORDER FONT oFontPad PIXEL oGetMsg:lActive := .F. oGetMsg:setCSS( "QLineEdit{color:#FF0000; background-color:#FEFEFE;}" ) //Botão confirmar If nOperacao == 3 .Or. nOperacao == 4 @ (nJanAltu/2)-24, (nJanLarg/2)-53 BUTTON oBtnCon PROMPT "Confirmar" SIZE 048, 018 OF oDlgAtu ACTION(fConfirmar() ) PIXEL EndIf ACTIVATE MSDIALOG oDlgAtu CENTERED //Volta pra primeira linha oModelGrid:nLine := 1 RestArea(aArea) Return /*---------------------------------------------------------------------* | Func: fPesqSB1 | | Desc: Função que valida o código do produto digitado | *---------------------------------------------------------------------*/ Static Function fPesqSB1() Local lRet := .T. DbSelectArea( 'SB1' ) SB1->(DbSetOrder(1)) //B1_FILIAL + B1_COD //Se conseguir posicionar no produto If SB1->(DbSeek(FWxFilial( 'SB1' ) + cGetCod)) cGetDes := SB1->B1_DESC lRet := .T. //Busca a linha nLinEnc := aScan(oModelGrid:aCols, {|x| AllTrim(x[nPosProd]) == AllTrim(cGetCod)}) //Caso não encontre If nLinEnc == 0 cGetMsg := "Item Novo" nGetPrc := 0 lNovo := .T. Else cGetMsg := "Item Existente" nGetPrc := oModelGrid:aCols[nLinEnc][nPosPrcV] lNovo := .F. EndIf Else lRet := .F. MsgAlert( "Produto não encontrado!" , "Atenção" ) EndIf Return lRet /*---------------------------------------------------------------------* | Func: fConfirmar | | Desc: Função chamada pelo botão confirmar | *---------------------------------------------------------------------*/ Static Function fConfirmar() Local nLin //Se for novo, adiciona uma nova linha If lNovo oModelGrid:AddLine() nLin := Len(oModelGrid:aCols) //Senão pega a linha encontrada Else nLin := nLinEnc EndIf //Define a linha que será utilizada oModelGrid:nLine := nLin oModelPad:SetValue( 'DA1DETAIL' , 'DA1_CODPRO' , cGetCod) oModelPad:SetValue( 'DA1DETAIL' , 'DA1_DESCRI' , cGetDes) oModelPad:SetValue( 'DA1DETAIL' , 'DA1_PRCVEN' , nGetPrc) //Atualiza os textos cGetCod := Space(TamSX3( 'B1_COD' )[01]) cGetDes := Space(TamSX3( 'B1_DESC' )[01]) nGetPrc := 0 cGetMsg := "" oGetCod:Refresh() oGetDes:Refresh() oGetPrc:Refresh() oGetMsg:Refresh() Return |
Observações:
– Caso tenha dúvidas ou problemas com os exemplos, entre em contato;
– Se tiver sugestões de rotinas, pode entrar em contato;