Vous êtes sur la page 1sur 7

Imports System.Data.

SqlClient
Imports System.Data
Imports System.Windows.Forms

Module biblioteca

Public conexion As New SqlConnection


Private cmb As SqlCommandBuilder
Public ds As DataSet = New DataSet()
Public da As SqlDataAdapter
Public comando As SqlCommand
Public Sub conectar()
Try
conexion.Close()
conexion.ConnectionString = "Data Source=DESKTOP-82G2P5S\ANDRES;Initial
Catalog=bdfut;Integrated Security=True"
conexion.Open()

Catch ex As Exception
MsgBox(ex.Message)

End Try
End Sub
Public Function sqlsel(ByRef sql As String) As DataSet
conectar()
Dim adaptador As New SqlDataAdapter(sql, conexion)
Dim rsdatos As New DataSet
adaptador.Fill(rsdatos, "datos")
Return rsdatos
conexion.Close()

End Function

Function eliminar(ByVal tabla, ByVal condicion)


conectar()

Dim elimina As String = "delete from " + tabla + " where " + condicion
comando = New SqlCommand(elimina, conexion)
Dim i As Integer = comando.ExecuteNonQuery()
conexion.Close()
If (i > 0) Then
Return True
Else
Return False

End If
End Function
Function Actualizar(ByVal tabla, ByVal campos, ByVal condicion)

conectar()
Dim actualiza As String = "update " + tabla + " set " + campos + " where " +
condicion
comando = New SqlCommand(actualiza, conexion)
Dim i As Integer = comando.ExecuteNonQuery()
conexion.Close()
If (i > 0) Then
Return True
Else
Return False

End If
End Function

Public Sub Consulta(ByVal sql As String, ByVal tabla As String)

ds.Tables.Clear()
da = New SqlDataAdapter(sql, conexion)
cmb = New SqlCommandBuilder(da)
da.Fill(ds, tabla)

End Sub

End Module

Valores
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class valores

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles nuevo.Click
Form1.Show()
Form1.TextBox1.Text = Form1.TextBox1.Text + 1

Form1.TextBox2.Clear()
Form1.TextBox3.Clear()
Form1.TextBox4.Clear()
Form1.TextBox5.Clear()
Form1.TextBox6.Clear()

subt.Clear()
desc.Clear()
tot.Clear()

Me.Visible = False

End Sub

Private Sub mstrar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles mstrar.Click
Dim consulta As String = "select * from valor"
DataGridView1.DataSource = sqlsel(consulta).Tables("datos")
conexion.Close()
End Sub

Private Sub insertar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles insertar.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "debe ingresar datos")
ElseIf subt.Text = "" Then
ErrorProvider1.SetError(subt, "debe ingresar datos")
ElseIf desc.Text = "" Then
ErrorProvider1.SetError(desc, "debe ingresar datos")
ElseIf tot.Text = "" Then
ErrorProvider1.SetError(tot, "debe ingresar datos")

Else

Try
Dim conex As New SqlConnection("Data Source=DESKTOP-
82G2P5S\ANDRES;Initial Catalog=bdfut;Integrated Security=True")
Dim cmd As New SqlCommand("insertarvalor", conex)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@id_cliente", SqlDbType.NChar).Value =
TextBox1.Text
cmd.Parameters.Add("@subt", SqlDbType.NChar).Value = subt.Text
cmd.Parameters.Add("@iva", SqlDbType.NChar).Value = desc.Text
cmd.Parameters.Add("@tot", SqlDbType.NChar).Value = tot.Text

conex.Open()
cmd.ExecuteNonQuery()
conex.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles eliminar.Click
If (biblioteca.eliminar("valor", "id_cliente= " + TextBox1.Text)) Then
MessageBox.Show("datos eliminados correctamente")
MostrarDatos()
Else
MessageBox.Show("error al eliminar")

End If

End Sub
Private dv As New DataView

Public Sub MostrarDatos()


biblioteca.Consulta("select * from valor", "valor")
DataGridView1.DataSource = biblioteca.ds.Tables("valor")
End Sub

Private Sub valores_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
biblioteca.conectar()
MostrarDatos()
End Sub

Private Sub finalizar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles finalizar.Click
End

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal


e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick
Dim dgv As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
TextBox1.Text = dgv.Cells(0).Value.ToString()
subt.Text = dgv.Cells(1).Value.ToString()
desc.Text = dgv.Cells(2).Value.ToString()
tot.Text = dgv.Cells(3).Value.ToString()

End Sub

Private Sub modificare_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles modificare.Click
Dim actualizar As String = "subt= '" + subt.Text + "',iva='" + desc.Text +
"',tot='" + tot.Text + "'"
If (biblioteca.Actualizar("valor", actualizar, "id_cliente= " +
TextBox1.Text)) Then
MessageBox.Show("datos actualizados correctamente")
MostrarDatos()
Else
MessageBox.Show("error al actualizar")

End If

End Sub

Private Sub back_Click(sender As System.Object, e As System.EventArgs) Handles


back.Click
Form1.Show()
Me.Visible = False

End Sub
End Class

Form 1
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim consulta As String = "select * from cliente"
DataGridView1.DataSource = sqlsel(consulta).Tables("datos")
conexion.Close()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
biblioteca.conectar()
MostrarDatos()
End Sub
Private dv As New DataView

Public Sub MostrarDatos()


biblioteca.Consulta("select * from cliente", "cliente")
DataGridView1.DataSource = biblioteca.ds.Tables("cliente")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If (biblioteca.eliminar("cliente", "id= " + TextBox1.Text)) Then
MessageBox.Show("datos eliminados correctamente")
MostrarDatos()
TextBox1.Clear() : TextBox2.Clear() : TextBox3.Clear() :
TextBox4.Clear() : TextBox5.Clear() : TextBox6.Clear()

Else
MessageBox.Show("error al eliminar")

End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "debe ingresar datos")
ElseIf TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "debe ingresar datos")
ElseIf TextBox3.Text = "" Then
ErrorProvider1.SetError(TextBox3, "debe ingresar datos")
ElseIf TextBox4.Text = "" Then
ErrorProvider1.SetError(TextBox4, "debe ingresar datos")
ElseIf TextBox5.Text = "" Then
ErrorProvider1.SetError(TextBox5, "debe ingresar datos")
ElseIf TextBox6.Text = "" Then
ErrorProvider1.SetError(TextBox6, "debe ingresar datos")
Else

Try
Dim conex As New SqlConnection("Data Source=DESKTOP-
82G2P5S\ANDRES;Initial Catalog=bdfut;Integrated Security=True")
Dim cmd As New SqlCommand("insertarcliente", conex)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@id", SqlDbType.NChar).Value = TextBox1.Text
cmd.Parameters.Add("@Nombre", SqlDbType.VarChar).Value =
TextBox2.Text
cmd.Parameters.Add("@cedula", SqlDbType.VarChar).Value =
TextBox3.Text
cmd.Parameters.Add("@num_asien", SqlDbType.VarChar).Value =
TextBox4.Text
cmd.Parameters.Add("@localidad", SqlDbType.VarChar).Value =
TextBox5.Text
cmd.Parameters.Add("@valor", SqlDbType.VarChar).Value =
TextBox6.Text
conex.Open()
cmd.ExecuteNonQuery()
conex.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles RadioButton1.CheckedChanged
TextBox6.Text = 5
TextBox5.Text = "General"

End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles RadioButton2.CheckedChanged
TextBox6.Text = 10
TextBox5.Text = "Tribuna"

End Sub

Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles RadioButton3.CheckedChanged
TextBox6.Text = 45
TextBox5.Text = "Suite"

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
Dim myForm As New valores()
valores.Show()
Me.Visible = False

valores.subt.Text = Val(TextBox4.Text) * Val(TextBox6.Text)


valores.desc.Text = Val(valores.subt.Text) * 0.14

valores.tot.Text = Format(CType(valores.desc.Text, Decimal) +


CType(valores.subt.Text, Decimal), "#,##0.00")
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
valores.TextBox1.Text = TextBox1.Text

End Sub

Private Sub sigte_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles sigte.Click
Me.Visible = False
valores.Show()

End Sub
Private Sub nuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles nuevo.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal


e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick
Dim dgv As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
TextBox1.Text = dgv.Cells(0).Value.ToString()
TextBox2.Text = dgv.Cells(1).Value.ToString()
TextBox3.Text = dgv.Cells(2).Value.ToString()
TextBox4.Text = dgv.Cells(3).Value.ToString()
TextBox5.Text = dgv.Cells(4).Value.ToString()
TextBox6.Text = dgv.Cells(5).Value.ToString()
End Sub

Private Sub modificare_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles modificare.Click
Dim actualizar As String = "nombre ='" + TextBox2.Text + "',cedula= '" +
TextBox3.Text + "',num_asien='" + TextBox4.Text + "',localidad='" + TextBox5.Text +
"',valor='" + TextBox6.Text + "'"
If (biblioteca.Actualizar("cliente", actualizar, "id= " + TextBox1.Text))
Then
MessageBox.Show("datos actualizados correctamente")
MostrarDatos()
Else
MessageBox.Show("error al actualizar")

End If
End Sub

Private Sub game_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles game.Click
playet.Show()
Me.Visible = False

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
End

End Sub
Private Sub bdac_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bdac.Click
resultado.Show()
Me.Visible = False

End Sub
End Clas

Vous aimerez peut-être aussi