|
Exemplo CRUD MVC OOP Indirection
DOCUMENTACAO.PDF / para outras versoes antigas
VIDEO EXPLICANDO O PROJETO https://youtu.be/cTO3dG1P79Y
// Summary: <specify the procedure action> // Syntax: //evento_alterar (<tabela>, <chave>, <tableGrid>) // // Parameters: // tabela: <specify the role of tabela> // chave: <specify the role of chave> // tableGrid: <specify the role of tableGrid> // Example: // <Specify a usage example> // // Return value: // acao: <specify the role of acao> // nomeJanela: <specify the role of nomeJanela> // ID: <specify the role of ID> PROCEDURE PUBLIC GLOBAL evento_alterar(tabela, chave, tableGrid)
//Info("alterar",tabela, nomeJanela, tableGrid, acao, ID)
// Verificar se uma linha foi selecionada
IF tabela = "" THEN RETURN END
IF chave = "" THEN RETURN END
IF tableGrid = "" THEN RETURN END
// no controle de tela IF TableSelect(tableGrid) = -1 OR gn_ID = 0 gn_ID = 0 gs_acao = "" gb_Status = False RETURN ELSE gb_Status = True gs_acao = "alterar" HReset(tabela) IF HReadSeek(tabela,chave,gn_ID,hIdentical) = True THEN FileToScreen() evento_go_plane(gs_nomeJanela,2) gb_Status = True ELSE gn_ID = 0 gs_acao = "" gb_Status = False RETURN END
END
//----------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //evento_excluir () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: // nomeJanela: <specify the role of nomeJanela> // acao: <specify the role of acao> // tabela: <specify the role of tabela> // campo: <specify the role of campo> // tableGrid: <specify the role of tableGrid> PROCEDURE PUBLIC GLOBAL evento_excluir()
//Info("excluir",tabela, nomeJanela, tableGrid, acao)
tabela is string = gs_TableFile campo is string = gs_CampoChave tableGrid is string = gs_TableGrid
// Verificamos se uma linha foi selecionada IF TableSelect(tableGrid) = -1 THEN gn_ID = 0 RETURN ELSE //1 : Sim //2 : Não SWITCH Dialog("Deseja excluir o registro?") // Sim CASE 1 // Posiciona o controle de tela no registro atual HReset(tabela) IF HReadSeek(tabela,campo,gn_ID,hIdentical) = True IF HDelete(tabela) = True TableDisplay(tableGrid, taInit) TableDisplay(tableGrid, taReExecuteQuery) END END // Não CASE 2 gn_ID = 0 END END
//-----------------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //Evento_Filtrar () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: PROCEDURE PUBLIC GLOBAL Evento_Filtrar()
CampoFiltro is string = gs_nomeJanela + ".EDT_JANUSGRID"
gs_JanusGrid = {CampoFiltro}..Value
IF gs_TipoBusca = 0 THEN RETURN END
IF gs_JanusGrid = "" THEN RETURN END
gs_JanusGrid = Replace(gs_JanusGrid,CRLF," ")
gs_JanusGrid = Replace(gs_JanusGrid,CR," ")
IF gs_Debug = True Info(gs_JanusGrid) END
IF gs_TipoBusca = 1 //gs_JanusGrid Order by Evento_Filtrar_OrderBy() ELSE IF gs_TipoBusca = 2 //gs_JanusGrid SQL Evento_Filtrar_SQL() ELSE Info("Selecione um Tipo de Busca") END
//---------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //Evento_Filtrar_OrderBy () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: PROCEDURE PUBLIC GLOBAL Evento_Filtrar_OrderBy()
IF gs_JanusGrid = "" THEN RETURN END
sqlcodigo is string = [ select * from @tabela@ order by @orderby@ ]
sqlcodigo = Replace(sqlcodigo,"@tabela@",gs_TableFile,IgnoreCase) sqlcodigo = Replace(sqlcodigo,"@orderby@",gs_JanusGrid,IgnoreCase)
dsQuery is Data Source
IF HExecuteSQLQuery(dsQuery,hQueryDefault,sqlcodigo) = True THEN FOR EACH dsQuery //.... END END
//--------------------------------------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: // Evento_Filtrar_SQL () // // Parameters: // None // Return value: // None // // Example: // <Specify a usage example> // PROCEDURE PUBLIC GLOBAL Evento_Filtrar_SQL()
IF gs_JanusGrid = "" THEN RETURN END
sqlcodigo is string = [ select * from @tabela@ where @filtros@ ]
sqlcodigo = Replace(sqlcodigo,"@tabela@",gs_TableFile,IgnoreCase) sqlcodigo = Replace(sqlcodigo,"@filtros@",gs_JanusGrid,IgnoreCase)
dsQuery is Data Source
IF HExecuteSQLQuery(dsQuery,hQueryDefault,sqlcodigo) = True THEN FOR EACH dsQuery //.... END END
//------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //evento_go_plane (<nomePagina>, <plane>) // // Parameters: // nomePagina: <specify the role of nomePagina> // plane: <specify the role of plane> // Example: // <Specify a usage example> // // Return value: PROCEDURE PUBLIC GLOBAL evento_go_plane(nomePagina, plane)
IF nomePagina = "" THEN RETURN END
IF plane = 0 THEN RETURN END
{nomePagina,indWindow}..Plane = plane // saiba que {} alter value in runtime
//--------------------------------------------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //evento_gravar (<tabela>, <nomeJanela>, <tableGrid>, <plano>) // // Parameters: // tabela: <specify the role of tabela> // nomeJanela: <specify the role of nomeJanela> // tableGrid: <specify the role of tableGrid> // plano: <specify the role of plano> // Example: // <Specify a usage example> // // Return value: // acao: <specify the role of acao> PROCEDURE PUBLIC GLOBAL evento_gravar(tabela, nomeJanela, tableGrid, plano)
IF tabela = "" THEN RETURN END
IF nomeJanela = "" THEN RETURN END
IF tableGrid = "" THEN RETURN END
IF plano = 0 THEN RETURN END
gb_Status = False
// Lê o conteúdo dos controles de tela //pagina ScreenToFile()
IF {tabela,indFile}..NewRecord = True THEN IF gs_acao = "incluir" IF HAdd(tabela) = True THEN gb_Status = True Info("Gravou com sucesso") ELSE gb_Status = False Info(HErrorInfo()+ErrorInfo()) END END // aqui voce faz os tratamentos ELSE // Modifica o registro seleciona IF gs_acao = "alterar" IF HModify(tabela) = True THEN gb_Status = True Info("Gravou com sucesso") ELSE gb_Status = False Info(HErrorInfo()+ErrorInfo()) END END END
TableDisplay({tableGrid},taInit)
TableDisplay({tableGrid},taReExecuteQuery)
// Retornar um valor da janela MyWindow.ReturnedValue = True
evento_go_plane(nomeJanela,plano)
//--------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //evento_incluir (<tabela>, <GrupoCampos>) // // Parameters: // tabela: <specify the role of tabela> // GrupoCampos: <specify the role of GrupoCampos> // Example: // <Specify a usage example> // // Return value: // ID: <specify the role of tableGrid> // nomeJanela: <specify the role of nomeJanela> PROCEDURE PUBLIC GLOBAL evento_incluir(tabela, GrupoCampos)
//Info("incluir",tabela, nomeJanela, tableGrid, acao, ID)
IF tabela = "" THEN RETURN END
IF GrupoCampos = "" THEN RETURN END
IF gs_nomeJanela = "" THEN RETURN END
// Ao criar um novo registro gs_acao = "incluir"
//Limpar variaveis gn_ID = 0
{GrupoCampos} = ""
// Limpa o buffer do arquivo e carregamos os valores default HReset(tabela) //plane evento_go_plane(gs_nomeJanela,2)
//-----------------------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //[ <Result> = ] evento_selecionar () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: // TableGrid: <specify the role of TableGrid> // Col_ID: <specify the role of Col_ID> PROCEDURE PUBLIC GLOBAL evento_selecionar()
IF gs_TableGrid = "" RETURN END
IF gs_TableGrid_ColunaID = 0 THEN RETURN END
gn_ID = 0
TableGrid is string = gs_TableGrid
Col_ID is string = gs_TableGrid_ColunaID
nx is 8-byte int = TableInfoXY({TableGrid},tiLineNumber,MouseXPos(),MouseYPos())
IF nx > 0 AND Col_ID <> "" Indirection is string = TableGrid+"["+nx+"]."+Col_ID IF nx > 0 AND TableGrid <> "" AND Col_ID <> "" gn_ID = {Indirection} ELSE gn_ID = 0 END ELSE gn_ID = 0 END
//-------------------------------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //[ <Result> = ] evento_selecionar_abrir () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: // TableGrid: <specify the role of TableGrid> // Col_ID: <specify the role of Col_ID> // BotaoAlterar: <specify the role of BotaoAlterar> PROCEDURE PUBLIC GLOBAL evento_selecionar_abrir()
IF gs_TableGrid = "" RETURN END
IF gs_BotaoAlterar = "" THEN RETURN END
IF gs_TableGrid_ColunaID = 0 THEN RETURN END
gn_ID = 0
TableGrid is string = gs_TableGrid
Col_ID is string = gs_TableGrid_ColunaID
nx is 8-byte int = TableInfoXY({TableGrid},tiLineNumber,MouseXPos(),MouseYPos())
IF nx > 0 AND Col_ID <> "" Indirection is string = TableGrid+"["+nx+"]."+Col_ID IF nx > 0 AND TableGrid <> "" AND Col_ID <> "" gn_ID = {Indirection} IF gn_ID > 0 AND nx > 0 ExecuteProcess({gs_BotaoAlterar},trtClick) ELSE gn_ID = 0 END ELSE gn_ID = 0 END ELSE gn_ID = 0 END
//--------------------------------------------------------------------------
// Summary: <specify the procedure action> // Syntax: //evento_voltar () // // Parameters: // None // Example: // <Specify a usage example> // // Return value: PROCEDURE PUBLIC GLOBAL evento_voltar(nomePagina, plane)
IF nomePagina = "" THEN RETURN END
IF plane = 0 THEN RETURN END
{nomePagina,indWindow}..Plane = plane
//-------------------------------------------------------------------------
|
| |
| |
| Illustrations, copies d'écran |
|
| |
(Pour noter la ressource, cliquez sur Ecrire un avis) |
| |
pour pouvoir poster un avis |
| | |
| | |
Aucun avis ou commentaire ? Soyez le premier ! |
https://hostimage.webdev.info/images/bloqueioregistroconcorrente_57525a61a9b3ad55f7d667c8296fada3.jpg
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/4070-bloqueando-segunda-estacao-num-registro-edicao-paulo-viana/read.awp |
| BLOQUEANDO A SEGUNDA ESTACAO NUM REGISTRO EM EDIÇÃO if edt_lock = "s" if cbox_write = false if not readseekfirst(tabela, chave, busca) return end
if hinfolock(tabela, nrecnum(tabela)) <> "" hreset(tabela) infowithtimeout(2s,"registro bloqueado por outro usuario-aguarde!") return end
glo_lock_salvar(mywindow..alias, tabela, hrecnum({tabela})) gbTemLock = true
else
if not hreadseekfirst(tabela, chave, busca) return end
if hinfolock(tabela, hrecnum(tabela)) = "" // realiza o lock if not hlockrecnum(tabela, hrecnumcurrent, hlockwrite) return end
glo_lock_salvar(mywidow..alias, tabela, hrecnum({tabela}))
gbTemLock = true
else
//nao realiza o lock infowithtimeout(2s, "Registro bloqueado por um outro usuario - apenas consulta btn_salvar..state = grayed
end
else
if no readseekfirst(tabela, chave, busca) return end
end
filetoscreen() |
| | |
|