Problema ao gravar dados na tabela de dados - AdvPl
Olá pessoal,
Estou fazendo um programa de registro de backup e estou tento alguns problemas para gravar os dados na tabela
Vou explicar como funciona:
1 - Menu com 4 opções são elas: [1]Cadastrar, [2]Excluir, [3]Registrar e [4]Movimentar.
2 - Quando for digitada a opção [1], são solicitados o código da fita, data do cadastro(sugerindo a data atual) e Meses de validade. Depois isso é gravado no banco de dados.
3 - Quando for digitada a opção [2], são solicitados o código da fita e uma confirmação de exclusão. Depois o campo D_E_L_E_T_ é marcado com "*".
4 - Quando for digitada a opção [3], são solicitados o código da fita, o programa verifica se a fita foi cadastrada se não tiver sido cadastrada é apresentado um alerta se não é solicitado tipo de backup: [1]Semanal ou [2]Mensal, código da sessão, data do backup, localização, data de retorno pro MSL em semanas, data de retorno pro MSL em DD/MM/AAAA e depois uma tela com as próximas movimentações. Depois os dados são gravados na tabela de dados.
5 - Quando for digitada a opção [4], são solicitados o código da fita e o novo local nas opções de novos locais tem: [1]MSL, [2]Mochila, [3]Cofre e [4]Espera. Se for digitado 1 quer dizer que a fita venceu, então os campos: data da próxima movimentação, data de retorno, data do backup, tipo do backup e código da sessão, são apagados. Se for digitado qualquer uma das outras opções é gravado o novo local na tabela de dados e é encerrado.
Agora vamos aos problemas:
1 - Eu não estou conseguindo fazer com que seja excluido os itens da tabela de dados quando for selecionada a opção [1] na movimentação.
2 - Não estou conseguindo também, alterar somente o LOCAL quando digitado a opção 2 na movimentação.
3 - Não estou conseguindo gravar a data de cadastro e os meses de validade da fita na opção 2 de registro(Mesmo que nessa opção não seja solicitado a data de cadastro e os meses de validade).
Meu código:
User Function MCT016
*************************
Local nTela := 0
Local lExecute := .T.
local cReadAux := " "
Private cOpcMenu := " "
Private cDataCad := " "
Private cTipoBack := " "
Private cLocal := " "
Private cCodSessao := " "
Private cDtretorno := " "
Private cDtBackup := " "
Private cNovoLocal := " "
Private cProxMov := " "
Private cProxsMov := " "
Private cProMov := " "
Private nMesVal := 0
Private nSemRet := 0
While lExecute
nTela := 1
While nTela <= 1
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Escolha uma opcao")
TerSay(01, 00, "[1]Cadastrar")
TerSay(02, 00, "[2]Excluir")
TerSay(03, 00, "[3]Registrar")
TerSay(04, 00, "[4]Movimentar")
TerSay(05, 00, "[ ]")
cOpcMenu := " "
TerGetRead(05, 01, @cOpcMenu,, {|| cOpcMenu == "1" .Or. cOpcMenu == "2" .Or. cOpcMenu == "3" .Or. cOpcMenu == "4"})
If TerEsc()
nTela --
Exit
EndIf
nTela ++
While nTela <= 2
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Leia a fita:")
cIDFita := Space(8)
TerGetRead(01, 00, @cIDFita,, {|| !Empty(cIDFita)})
If TerEsc()
nTela--
Exit
EndIf
TerGetRead(00, 00, @cReadAux,,)
If TerEsc()
nTela --
Exit
EndIf
If cOpcMenu == "1"
TerCls()
TerCBuffer()
TerIsQuit()
ZBF ->(dbSetOrder(1)) //Altera o indice corrente da tebela
If ZBF->(dbSeek(xFilial("ZBF")+cIDFita))//Pesquisa pelo codigo da fita para que depois possa ser feito uma condição
VTAlert("Fita ja cadastrada")
Loop
EndIf
TerSay(00, 00, "Data do cadastro:")
cDataCad := Space(8)
U_TerData(@cDataCad, 01, .T.)
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Meses de validade:")
nMesVal := 36
TerGetRead(01, 00, @nMesVal, "@E 99", {|| !Empty(nMesVal) .And. Positivo(nMesVal)})
If TerEsc()
nTela --
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
RecLock("ZBF", .T.)
ZBF->ZBF_FILIAL := xFilial("ZBF")
ZBF->ZBF_IDFITA := cIDFita
ZBF->ZBF_VALID := nMesVal
ZBF->ZBF_DTCAD := StoD(cDataCad)
ZBF->ZBF_LOCAL := "1"
ZBF->(MsUnLock())
VTAlert("Fita cadastrada", "Cadastrar")
ElseIf cOpcMenu == "2"
ZBF->(dbSetOrder(1))
If ZBF->(dbSeek(xFilial("ZBF")+cIDFita))
If !Empty(ZBF->ZBF_IDSES)
VTAlert("Fita com backup gravado", "Excluir")
Loop
Else
If U_TerYesNo("Excluir fita", "Deseja excluir a fita?", "S")
RecLock("ZBF", .F.)
ZBF->(dbDelete())
ZBF->(MsUnLock())
VTAlert("Fita excluida!", "Excluir")
Else
Loop
EndIf
EndIf
Else
VTAlert("Fita nao cadastrada", "Excluir")
Loop
EndIf
ElseIf cOpcMenu == "3"
ZBF->(dbSetOrder(1))
If ZBF->(dbSeek(xFilial("ZBF")+cIDFita))
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Tipo de backup")
TerSay(01, 00, "[1]Semanal")
TerSay(02, 00, "[2]Mensal")
TerSay(03, 00, "[ ]")
cTipoBack := " "
TerGetRead(03, 01, @cTipoBack,, {|| cTipoBack == "1" .Or. cTipoBack == "2"})
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Codigo da sessao:")
cCodSessao := Space(15)
TerGetRead(01, 00, @cCodSessao,, {|| !Empty(cCodSessao)})
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Data do backup:")
U_TerData2(@cDtBackup, 01, .T., 2, "Subtracao")
If TerEsc()
nTela--
Exit
EndIf
If cTipoBack == "1"
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Localizacao")
TerSay(01, 00, "[1]MSL")
TerSay(02, 00, "[2]Mochila")
TerSay(03, 00, "[3]Cofre")
TerSay(04, 00, "[4]Daniel")
TerSay(05, 00, "[ ]")
cLocal := "2"
TerGetRead(05, 01, @cLocal,, {|| cLocal $ "1234"})
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Data de retorno pro")
Tersay(01, 00, "MSL em SEMANAS:")
nSemRet := 4
TerGetRead(02, 01, @nSemRet,,{|| !Empty(nSemRet)})
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
nSemret := nSemRet * 7
TerSay(00, 00, "Data de retorno pro")
TerSay(01, 00, "MSL em DD/MM/AAAA:")
U_TerData2(@cDtRetorno, 02, .T., nSemRet, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Proxima movimentacao")
TerSay(01, 00, "Para a [2]Mochila.")
TerSay(02, 00, "Do dia:")
U_TerData(@cProxMov, 03, .T.)
If TerEsc()
nTela--
Exit
EndIf
TerSay(04, 00, "Ate o dia:")
U_TerData2(@cProxsMov, 05, .T., 7, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Dps. para o [3]Cofre")
TerSay(01, 00, "Do dia:")
U_TerData2(@cProxsMov, 02, .T., 7, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerSay(03, 00, "Ate o dia:")
U_TerData2(@cProMov, 04, .T., 21, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
VTAlert("Depois, expira e volta para o [1]MSL", "Movimentacoes")
RecLock("ZBF", .T.)
ZBF->ZBF_FILIAL := xFilial("ZBF")
ZBF->ZBF_IDFITA := cIDFita
ZBF->ZBF_LOCAL := cLocal
ZBF->ZBF_DTBKP := StoD(cDtBackup)
ZBF->ZBF_TIPO := cTipoBack
ZBF->ZBF_IDSES := cCodSessao
ZBF->ZBF_DTRET := StoD(cDtRetorno)
ZBF->ZBF_DTPMOV := StoD(cProxMov)
ZBF->ZBF_DTCAD := StoD(cDataCad)
ZBF->ZBF_VALID := nMesVal
ZBF->(MsUnLock())//Destrava o registro
VTAlert("Backup registrado", "Registrar")
ElseIf cTipoBack == "2"
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Localizacao")
TerSay(01, 00, "[1]MSL")
TerSay(02, 00, "[2]Mochila")
TerSay(03, 00, "[3]Cofre")
TerSay(04, 00, "[4]Daniel")
TerSay(05, 00, "[ ]")
cLocal := "2"
TerGetRead(05, 01, @cLocal,, {|| cLocal $ "1234"})
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Data de retorno pro")
TerSaY(01, 00, "MSL em semanas:")
nSemRet := 52
TerGetRead(02, 01, @nSemRet,,{|| !Empty(nSemRet)})
If TerEsc()
nTela--
Exit
EndIf
TeGetRead(00, 00, @cReadAux,,)
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
nSemRet := nSemRet * 7
TerSay(00, 00, "Data de retorno pro")
TerSay(01, 00, "MSL em DD/MM/AAAA:")
U_TerData2(@cDtRetorno, 02, .T., nSemRet, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Proxima movimentacao")
TerSay(01, 00, "Para a [2]Mochila.")
TerSay(02, 00, "Do dia:")
U_TerData(@cProxMov, 03, .T.)
If TerEsc()
nTela--
Exit
EndIf
TerSay(04, 00, "Ate o dia:")
U_TerData2(@cProxsMov, 05, .T., 7, "Soma")
If TerCls()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Dps. para o [3]Cofre")
TerSay(01, 00, "Do dia:")
U_TerData2(@cProxsMov, 02, .T., 7, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerSay(03, 00, "Ate o dia:")
U_TerData2(@cProMov, 04, .T., 210, "Soma")
If TerEsc()
nTela--
Exit
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Dps. para o [4]Daniel")
TerSay(01, 00, "Do dia:")
U_TerData2(@cProMov, 02, .T., 210, "Soma")
If TerCls()
nTela--
Exit
EndIf
TerSay(03, 00, "Ate o dia:")
U_TerData2(@cProMov, 04, .T., 360, "Soma")
If TerEsc()
nTela--
Exit
EndIf
RecLock("ZBF", .T.)
VTAlert("Depois, expira e volta para o [1]MSL", "Movimentacoes")
ZBF->ZBF_FILIAL := xFilial("ZBF")
ZBF->ZBF_IDFITA := cIDFita
ZBF->ZBF_LOCAL := cLocal
ZBF->ZBF_DTBKP := StoD(cDtBackup)
ZBF->ZBF_TIPO := cTipoBack
ZBF->ZBF_IDSES := cCodSessao
ZBF->ZBF_DTRET := StoD(cDtRetorno)
ZBF->ZBF_DTPMOV := StoD(cProxMov)
ZBF->ZBF_DTCAD := StoD(cDataCad)
ZBF->ZBF_VALID := nMesVal
ZBF->(MsUnLock())//Destrava o registro
VTAlert("Backup registrado", "Registrar")
EndIf
Else
VTAlerT("Fita nao cadastrada", "Registro")
EndIf
ElseIf cOpcMenu == "4"
TerCls()
TerCBuffer()
TerIsQuit()
TerSay(00, 00, "Novo local")
TerSay(01, 00, "[1]MSL")
TerSay(02, 00, "[2]Mochila")
TerSay(03, 00, "[3]Cofre")
TerSay(04, 00, "[4]Daniel")
TerSay(05, 00, "[ ]")
cNovoLocal := " "
TerGetRead(05, 01, @cNovoLocal,, {|| cNovoLocal $ "1234"})
If TerEsc()
nTela--
Exit
EndIf
If cNovoLocal == "1"
ZBF(dbSetOrder(1))
If ZBF->(dbSeek(xFilial("ZBF")+cIDFita))
RecLock("ZBF", .F.)
ZBF->(dbDelete())
ZBF->(MsUnLock())
VTAlert("Movimentacao registrada!", "Movimentar")
Else
VTAlert("Fita nao cadastrada", "Movimentar")
Loop
EndIf
ElseIf cNovoLocal # "1"
ZBF->(dbSetOrder(1))
If ZBF->(dbSeek(xFilial("ZBF")+cIDFita))
RecLock("ZBF", .T.)
ZBF->ZBF_FILIAL := xFilial("ZBF")
ZBF->ZBF_LOCAL := cNovoLocal
ZBF->(MsUnLock())
VTAlert("Fita movimentada", "Movimentar")
Else
VTAlert("Fita nao cadastrada", "Movimentar")
Loop
EndIf
EndIf
EndIf
nTela--
Exit
EndDo
EndDo
If nTela <= 0
If U_TerYesNo("Sair da rotina", "Deseja sair da rotina?", "S")
lExecute := .F.
Exit
Else
Loop //Ao contrário do exit, o Loop cancela as próximas verificações que o laço irá fazer e sobe para a primeira linha no While
EndIf
EndIf
TerCls()
TerCBuffer()
TerIsQuit()
EndDo
Return
Qualquer dúvida estarei a disposição. Desde já agradeço.
Discussão (1)
Carregando comentários...