#Include 'Protheus.ch' User Function AdcCompSc() Local oCom := CriaVar("C1_CODCOMP") Local nNumSc := SC1->C1_NUM Local lRet := .T. Local aComp := {'GEORGES.AZAR','ALESSANDRO.SANTOS','THIAGO.OLIVEIRA','SAULO','gustavo'} If aScan(aComp,cUserName) = 0 lRet := .F. Aviso('Sem perm.','Usuário sem permissão para executar essa rotina.',{'Voltar'},1) Return Else lRet := .T. Define MSDialog oDlg Title ' Inclusão de Comprador ' From 0,0 To 225,370 Pixel @ 002,003 SAY "Digite o código do comprador no campo abaixo" @ 004,001 SAY "Código do Comprador" @ 004,010 MSGET oCom F3 CpoRetF3("C1_CODCOMP") Picture PesqPict("SC1","C1_CODCOMP") valid VLDCOMPSC(oCom) // @ 005,001 Say 'E-mail do comprador' // @ 005,010 MSGET oget size 092,11 Picture '@!' Of oDlg When .F. define sButton oBtOk from 090,010 type 1 action (GravComp(oCom, nNumSc), oDlg:End()) enable of oDlg pixel define sButton oBtCan from 090,040 type 2 action (oDlg:End()) enable of oDlg pixel ACTIVATE MSDIALOG oDlg CENTERED EndIf Return lRet //----------------------------------------------// //Função para gravar o cod do comprador na Sc. // //----------------------------------------------// Static Function GravComp(oCom, nNumSc/*,cEmail*/) local nCont:= 1 DbSelectArea('SY1') SY1->( DbSetOrder(1) ) SY1->( DbGoTop() ) If !SY1->( DbSeek(xFilial('SY1') + oCom) ) Aviso('[ERRORCOM]', 'Não foi encontrado comprador cadastrado com esse código', { 'Voltar' }, 1) Return() Else DbSelectArea('SC1') SC1->( DbSetOrder(1) ) //Verifica se está posicionado If DbSeek(xFilial('SC1') + nNumSc) //Altera todos os ítens da S.C While !SC1->( Eof()) .and. SC1->C1_FILIAL == xFilial('SC1') .and. SC1->C1_NUM == nNumSc RecLock('SC1', .F.) SC1->C1_CODCOMP:= oCom nCont ++ SC1->(DbSkip() ) SC1->(MsUnlock()) EndDo EndIf EndIf Return Static Function VLDCOMPSC(oCom, nNumSc) DbSelectArea('SY1') SY1->( DbSetOrder(1) ) SY1->( DbGoTop() ) If !SY1->( DbSeek(xFilial('SY1') + oCom) ) AVISO('[ERRORCOM]', 'Não foi encontrado comprador cadastrado com esse código', { 'Voltar' }, 1) Return() EndIf Return Static Function Tst190215(oCom, nNumSc) Local aAreaSY1 := SY1->(GetArea()),; aAreaSC1 := SC1->(GetArea()) Local nComp := SY1->Y1_NOME DbSelectArea('SC1') SC1->(DbSetOrder(1)) SC1->(DbGoTop()) If SC1->(DbSeek(xFilial('SC1')+ cNumSc + oCom)) DbSelectArea('SY1') SY1->(DbSetOrder(1)) SY1->(DbGoTop()) If SY1->(DbSeek(xFilial('SY1')+ SY1->Y1_COD + SY1->Y1_NOME)) While SY1->(!EoF()) .And. SY1->Y1_FILIAL == xFilial .And. SY1->Y1_COD == nComp RecLock('SC1',.F.) SC1->C1_XCOMP := Y1_NOME SC1->(MsUnlock()) SY1->(DbSkip()) EndDo EndIf EndIf SY1->(RestArea(aAreaSY1)) SC1->(RestArea(aAreaSC1)) Return