Novo Exemplo Caderno Agricola OOP MVC - WEBDEV 28
VIDEO EXPLICANDO O PROJETO
https://youtu.be/5rpXbfDnqtI
CODIGOS
IN GLOBAL INIT DO PROJETO
//----------------------------------------
HModifyStructure("*")
HCreationIfNotFound("*")
HOpenConnection(MyConnectionHfsqlCS)
HChangeConnection("*",MyConnectionHfsqlCS)
GLOBAL
gn_ID is 8-byte int
gs_tabela, gs_chave, gs_campo, gs_nomeJanela, gs_plane, gs_tableGrid, gs_col, gs_campo_buscar, gs_Parametros, gs_acao, gs_mensagem is string
//gs_acao = incluir, alterar, excluir, excluir tudo, selecionar, buscar
//minhaconexao is connection
//minhaconexao..Provider = hNativeAccessPostgreSQL
//minhaconexao..User = "adriano"
//minhaconexao..Password = "123456"
//minhaconexao..Server = "184.200.3.5"
//minhaconexao..Database = "clientes"
//
//HOpenConnection(minhaconexao)
//
//HChangeConnection("*",minhaconexao)
//-------------------------------------------------------
GLOBAL DAS JANELAS - INIT
//------------------------------------------------
PROCEDURE MyPage()
gs_tabela = "t001_clientes"
gs_chave = "t001_cliente_id"
gs_nomeJanela = "PAGE_Clientes"
gs_tableGrid = "TABLE_T001_clientes"
gs_col = "COL_T001_cliente_id"
gs_mensagem = "Bom dia!!!!!"
gs_plane = 1
//--------------------------------------------------------
NO CLICK DO TABLE
//---------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
// Evento_Click_Registro ()
//
// Parameters:
// None
// Return value:
// None
//
// Example:
// <Specify a usage example>
//
PROCEDURE Evento_Click_Registro()
IF gs_acao = "alterar" AND gn_ID > 0
ExecuteProcess(FLEX_Main.LAYOUT_Main.CTPL_Alterar.BTN_ALTERAR,trtClick)
END
//------------------------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//Evento_SelectRow_gn_ID ()
//
// Parameters:
// None
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE Evento_SelectRow_gn_ID()
IF TABLE_T001_clientes <> -1 THEN
gn_ID = TABLE_T001_clientes[TABLE_T001_clientes].COL_T001_cliente_id
IF gn_ID > 0 THEN
gs_acao = "alterar"
ELSE
gs_acao = ""
gn_ID = 0
END
ELSE
gs_acao = ""
gn_ID = 0
END
//-----------------------------------------------------------------------------------------------------
//CLASSE OOP
// Summary: <specify the procedure action>
// Syntax:
//evento_alterar (<tabela>, <chave>, <nomeJanela>, <tableGrid>, <ID>)
//
// Parameters:
// tabela: <specify the role of tabela>
// chave: <specify the role of chave>
// nomeJanela: <specify the role of nomeJanela>
// tableGrid: <specify the role of tableGrid>
// ID: <specify the role of ID>
// Example:
// <Specify a usage example>
//
// Return value:
// acao: <specify the role of acao>
PROCEDURE PUBLIC GLOBAL evento_alterar(tabela, chave, nomeJanela, tableGrid, ID)
//Info("alterar",tabela, nomeJanela, tableGrid, acao, ID)
// Verificar se uma linha foi selecionada
// no controle de tela
IF TableSelect(tableGrid) = -1 OR ID = 0
RETURN
ELSE
gs_acao = "alterar"
HReset(tabela)
IF HReadSeek(tabela,chave,ID,hIdentical) = True THEN
FileToPage()
evento_vai_para_plane(nomeJanela,2)
END
END
//------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_buscar (<tabela>)
//
// Parameters:
// tabela: <specify the role of tabela>
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_buscar(tabela, campo_buscar)
Info("buscar",tabela,campo_buscar)
//--------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_excluir (<tabela>, <nomeJanela>, <tableGrid>, <acao>)
//
// Parameters:
// tabela: <specify the role of tabela>
// nomeJanela: <specify the role of nomeJanela>
// tableGrid: <specify the role of tableGrid>
// acao: <specify the role of acao>
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_excluir(tabela, nomeJanela, tableGrid, acao)
Info("excluir",tabela, nomeJanela, tableGrid, acao)
// Verificamos se uma linha foi selecionada
IF TableSelect(tableGrid) = -1 THEN
RETURN
ELSE
//1 : Sim
//2 : Não
SWITCH Dialog("Deseja excluir o registro?")
// Sim
CASE 1
TableDelete(tableGrid)
// Posiciona o controle de tela no registro atual
TableDisplay(tableGrid, taInit)
TableDisplay(tableGrid, taReExecuteQuery)
// Não
CASE 2
END
END
//--------------------------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_gravar (<tabela>, <nomeJanela>, <tableGrid>)
//
// Parameters:
// tabela: <specify the role of tabela>
// nomeJanela: <specify the role of nomeJanela>
// tableGrid: <specify the role of tableGrid>
// Example:
// <Specify a usage example>
//
// Return value:
// acao: <specify the role of acao>
PROCEDURE PUBLIC GLOBAL evento_gravar(tabela, nomeJanela, tableGrid)
// Lê o conteúdo dos controles de tela //pagina
PageToFile()
IF {tabela,indFile}..NewRecord = True THEN
IF gs_acao = "incluir"
IF HAdd(tabela) = True THEN
Info("Gravou com sucesso")
ELSE
Info(HErrorInfo()+ErrorInfo())
END
END
// aqui voce faz os tratamentos
ELSE
// Modifica o registro seleciona
IF gs_acao = "alterar"
IF HModify(tabela) = True THEN
Info("Gravou com sucesso")
ELSE
Info(HErrorInfo()+ErrorInfo())
END
END
END
TableDisplay({tableGrid},taInit)
// Retornar um valor da janela
MyPage.ReturnedValue = True
evento_vai_para_plane(nomeJanela,1)
//-------------------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_incluir (<tabela>, <nomeJanela>, <tableGrid>)
//
// Parameters:
// tabela: <specify the role of tabela>
// nomeJanela: <specify the role of nomeJanela>
// tableGrid: <specify the role of tableGrid>
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_incluir(tabela, nomeJanela, tableGrid, acao, ID)
Info("incluir",tabela, nomeJanela, tableGrid, acao, ID)
// Ao criar um novo registro
acao = "incluir"
gs_acao = "incluir"
// Limpa o buffer do arquivo e carregamos os valores default
HReset(tabela)
//plane
evento_vai_para_plane(nomeJanela,2)
//numero do registro
gn_ID = 0
ID = 0
//-------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_procedure (<tabela>, <nomeJanela>, <tableGrid>, <Parametros>)
//
// Parameters:
// tabela: <specify the role of tabela>
// nomeJanela: <specify the role of nomeJanela>
// tableGrid: <specify the role of tableGrid>
// Parametros: <specify the role of Parametros>
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_procedure(tabela, nomeJanela, tableGrid, Parametros)
Info(tabela, nomeJanela, tableGrid, Parametros)
//-----------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_selecionar ()
//
// Parameters:
// None
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_selecionar()
IF gs_acao = "alterar" AND gn_ID > 0 THEN
BotaoAlterar is string = gs_nomeJanela+".FLEX_Main.LAYOUT_Main.CTPL_Alterar.BTN_ALTERAR"
ExecuteProcess({BotaoAlterar},trtClick)
END
//-----------------------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_vai_para_plane ()
//
// Parameters:
// None
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_vai_para_plane(nomePagina, plane)
{nomePagina,indPage}..Plane = plane // saiba que {} alter value in runtime
//--------------------------------------------------------------------------------------------------------------
// Summary: <specify the procedure action>
// Syntax:
//evento_voltar ()
//
// Parameters:
// None
// Example:
// <Specify a usage example>
//
// Return value:
PROCEDURE PUBLIC GLOBAL evento_voltar(nomePagina, plane)
{nomePagina,indPage}..Plane = plane
//--------------------------------------------------------------------------------------------------------
NOS BOTOES EXEMPLO DO INCLUIR
CODE
Classe_OOP.evento_incluir(gs_tabela, gs_nomeJanela, gs_tableGrid, gs_acao, gn_ID)