Contribua

Doação

terça-feira, 28 de junho de 2016

CRUD com GAMBAS codigo completo Melhorado

CRUD com GAMBAS codigo completo Melhorado
Este um exemplo de CRUD completo e funcional pode ser melhorado, e adaptado para outras aplicaçoes.

CRUD e um acronimo Create Read Update e Delete, se trata de um aplicativo que faz uma interaçao com uma Base de Dados, onde interagimos com o banco suas tabelas e registros, cadastrando, modificando, excluindo ou apenas lendo seus dados.



















CRUD EM GAMBAS ( VISUAL BASIC MELHORADO)

' Gambas class file

'CRUD, LISTVIEW, LISTBOX, COMBOBOS, STREAM, CONEXAO MYSQL
'AUTHOR EDSON PESSOTTI
'JUNHO/2016
''PRAMAÇAO VISUAL GAMBAS3
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
''VARIAVEIS GLOBAIS
'''0-0--------0-0--
Public hFile As File
Public jog As String
Public pos As String
Public cam As Short
Public idx As Short
Public minhaSt As String
Public $cod As String
Public $nome As String
Public resultado As Result
Public Sub _new()

End
'iNICIALIZAÇAO-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
''-0-0-0-
Public Sub Form_Open()
tb1.text = " "
tb2.text = " "
TB3.text = " "
TB4.text = " "
TB5.text = " "
'create the file if it does not exist, otherwise just open it
If Exist(Application.path & "/file.txt") Then
hFile = Open Application.path & "/file.txt" For Write Append
Else
hFile = Open Application.path & "/file.txt" For Write Create
Endif

End
'cARGA DO LISTBOX.
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
Public Sub Button1_Click()
Dim pkey As Short = CInt(TB5.Text)
Dim lista As String
Module1.conex()
Module1.resultado = db.EXEC(" Select * From jogadores where id = &1 ", pkey)

tb1.Text = module1.resultado!jogador
tb2.text = module1.resultado!posicao
TB4.text = module1.resultado!camisa
TB5.text = module1.resultado!id

lista = "id--" & TB5.text & "--Nome--" & TB1.text & "Posição--" & tb2.text & "--camisa--" & TB4.text & "--Time--" & TB3.text
LB1.Add(lista)
Module1.db.Close()

End
'
''MODULO DE NOVA INSERÇAO NO BANCO DE DADOS
Public Sub Button2_Click()
jog = TB1.text
pos = TB2.text
cam = TB4.text
idx = CInt(TB5.text)
Module1.conex()
module1.db.EXEC("insert into jogadores values(&1,&2,&3,&4)", jog, pos, cam, idx)
' Module1.consulta2()
db.Close

End

Public Sub Button3_Click()
Dim tt As Integer = CInt(TB5.Text)
Module1.conex()
Module1.resultado = db.EXEC("delete from jogadores where id=&1", tt)

End
'
''MODULO DE CARGA DO LISTVIEW
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
Public Sub Button5_Click()
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim x As Short
LV1.Clear()
' Dialog.Filter = ["*.lst", "Lists", "*.txt", "Arquivos de texto", "*", "All Files"]
' If Dialog.OpenFile() Then Return
'' Lb1.List = Split(File.Load(Dialog.Path), "\\n")
'Catch
' Message.Info("Não é possível carregar lista:\\n" & Dialog.Path & "\\n" & Error.Text)
Module1.conex()
Module1.resultado = db.EXEC("Select id ,jogador , posicao, camisa from jogadores")
For Each Module1.resultado
a = module1.resultado!jogador
b = module1.resultado!posicao
c = module1.resultado!camisa
d = module1.resultado!id
minhaSt = a & " -- " & b & " -- " & c & " -- " & d
x = x + 1
With LV1
.Add(x, minhaSt)
End With
Next
db.Close
End

Public Sub CB1_Click()

TB3.text = CB1.current.text

End
'
''METODO DE CARGA DOS TEXTBOX COM DADOS DO BANCO DE DADOS.
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0--0-0-0-0-0-
Public Sub Button7_Click()
Dim pkey As Short = CInt(TB5.Text)
tb1.text = " "
tb2.text = " "
TB4.text = " "
Module1.conex()
Module1.resultado = db.EXEC(" Select * From jogadores where id = &1 ", pkey)

tb1.Text = module1.resultado!jogador
tb2.text = module1.resultado!posicao
TB4.text = module1.resultado!camisa
TB5.text = module1.resultado!id

db.Close
End
''METODO DE INSERÇAO
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
''
Public Sub Button8_Click()
Dim tt As Integer = CInt(TB5.Text)
Module1.conex()
Module1.db.EXEC("delete from jogadores where id=&1", tt)
jog = TB1.text
pos = TB2.text
cam = TB4.text
module1.db.EXEC("insert into jogadores values(&1,&2,&3,&4)", jog, pos, cam, tt)

db.Close

End
'
''METODO DE GRAVAÇAO EM ARQUIVO TEXTO.
'''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
Public Sub Button6_Click()
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim x As Short = 1

Dialog.Filter = ["*.lst", "Lists", "*.txt", "Text Files", "*", "All Files"]
If Dialog.SaveFile() Then Return
File.Save(Dialog.Path, Lb1.List.Join("\\n"))
Catch
Message.Info("Cannot save list:\\n" & Dialog.Path & "\\n" & Error.Text)

End
'METODO DE FIMALIZAÇAO DO AP
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
Public Sub Button4_Click()
hFile.Close
module1.db.Close()
FTest.Close

End

Public Sub PB1_MouseDown()


End

-0-0-0-0-0-00-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0=0
-------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------
 MODULO DE CONEXAO

' Gambas module file

'metodo de conexao
'Author Edson Pessotti
''Junho/2016
'''PROGRAMAÇAO VISUAL GAMBAS3
''''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0

Public db As New Connection

Public resultado As Result

Public Function conex() As Boolean

db.CLOSE()

db.Type = "mysql"
db.host = "localhost"
db.Port = "3306"
db.Login = "root"
db.Name = "gambas"
db.password = "edson...9"
db.OPEN()
Return True

Catch
message.error(" Deu PAU na conexao")
Return False
End
'Metodo de seleçao0x0x0x0x0x0x0x0x0
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
Public Sub consulta(query As String)

'
End '
'Metodo de inserçao
''--0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
Public Sub Insere(query As String)
 

Return
End
'Metodo de Deleçao
''-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
Public Sub Deleta(query As String)


End
'Metodo de Atualizaçao
'-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0
Public Sub Atualiza(query As String)
 




Abçs at'e o proximo post.

Nenhum comentário:

Postar um comentário

Programa exempo para consulta em bd Mysql com programa C

#include<stdio.h> #include<mysql/mysql.h> # ...