You are on page 1of 4

Imports System.Data.

SqlClient
Imports System.Data
Public Class FRMClientes
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.
Click
If TextBox1.Text.Trim.Length = 0 Then
MessageBox.Show("INGRESE RUC....", "MENSAJE",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text.Trim.Length = 0 Then
MessageBox.Show("INGRESE NOMBRES....", "MENSAJE",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox2.Focus()
Exit Sub
End If
Dim COMANDO As New SqlCommand("INSERT INTO CLIENTES VALUES(@RUC,@NOMBRES
,@DIRECCION,@DEPARTAMENTO,@PROVINCIA,@TELEFONO,@CELULAR,@EMAIL) ", BDCONEXION.CO
NEXION)
COMANDO.CommandType = CommandType.Text
COMANDO.Parameters.AddWithValue("@RUC", TextBox1.Text)
COMANDO.Parameters.AddWithValue("@NOMBRES", TextBox2.Text)
COMANDO.Parameters.AddWithValue("@DIRECCION", TextBox3.Text)
COMANDO.Parameters.AddWithValue("@DEPARTAMENTO", ComboBox1.SelectedValue
)
COMANDO.Parameters.AddWithValue("@PROVINCIA", ComboBox2.SelectedValue)
COMANDO.Parameters.AddWithValue("@TELEFONO", TextBox4.Text)
COMANDO.Parameters.AddWithValue("@CELULAR", TextBox5.Text)
COMANDO.Parameters.AddWithValue("@EMAIL", TextBox6.Text)
BDCONEXION.CONEXION.Open()
COMANDO.ExecuteNonQuery()
BDCONEXION.CONEXION.Close()
MessageBox.Show("DATOS GRABADOS", "MENSAJE",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
'////////////////////////////////////////////////////////////// CONSULTA
CLIENTES
Dim CONSULTACLI As New _
SqlDataAdapter("SELECT RUC,NOMBRES,DIRECCION,(SELECT DEPARTAMENT
O FROM DEPARTAMENTOS WHERE DEPARTAMENTOS.CODDEPART=CLIENTES.CODDEPART) AS DEPART
AMENTO,(SELECT PROVINCIA FROM PROVINCIA WHERE PROVINCIA.CODPROV=CLIENTES.CODPROV
) AS PROVINCIA,TELEFONO,CELULAR,EMAIL FROM CLIENTES",
BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
DataGridView1.DataSource = TABLACLI
End Sub
Private Sub FRMClientes_Load(sender As Object, e As EventArgs) Handles MyBas
e.Load
Dim CONSULTADEPAR As New _
SqlDataAdapter("SELECT * FROM DEPARTAMENTOS",
BDCONEXION.CONEXION)
CONSULTADEPAR.SelectCommand.CommandType = CommandType.Text
Dim TABLA As New DataTable
CONSULTADEPAR.Fill(TABLA)
ComboBox1.DataSource = TABLA
ComboBox1.DisplayMember = "DEPARTAMENTO"
ComboBox1.ValueMember = "CODDEPART"

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Dim CONSULTAPROV As New _
SqlDataAdapter("SELECT * FROM PROVINCIA WHERE CODDEPART=@CODDEPART",
BDCONEXION.CONEXION)
CONSULTAPROV.SelectCommand.CommandType = CommandType.Text
CONSULTAPROV.SelectCommand.Parameters.
AddWithValue("@CODDEPART", ComboBox1.SelectedValue)
Dim TABLAP As New DataTable
CONSULTAPROV.Fill(TABLAP)
ComboBox2.DataSource = TABLAP
ComboBox2.DisplayMember = "PROVINCIA"
ComboBox2.ValueMember = "CODPROV"
ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
'////////////////////////////////////////////////////////////// CONSULTA
CLIENTES
Dim CONSULTACLI As New _
SqlDataAdapter("SELECT RUC,NOMBRES,DIRECCION,(SELECT DEPARTAMENTO FROM D
EPARTAMENTOS WHERE DEPARTAMENTOS.CODDEPART=CLIENTES.CODDEPART) AS DEPARTAMENTO,(
SELECT PROVINCIA FROM PROVINCIA WHERE PROVINCIA.CODPROV=CLIENTES.CODPROV) AS PRO
VINCIA,TELEFONO,CELULAR,EMAIL FROM CLIENTES",
BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
DataGridView1.DataSource = TABLACLI
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedValue.ToString <> "System.Data.DataRowView" Then
Dim CONSULTAPROV As New _
SqlDataAdapter("SELECT * FROM PROVINCIA WHERE CODDEPART=@CODDEPART
",
BDCONEXION.CONEXION)
CONSULTAPROV.SelectCommand.CommandType = CommandType.Text
CONSULTAPROV.SelectCommand.Parameters.
AddWithValue("@CODDEPART", ComboBox1.SelectedValue)
Dim TABLAP As New DataTable
CONSULTAPROV.Fill(TABLAP)
ComboBox2.DataSource = TABLAP
ComboBox2.DisplayMember = "PROVINCIA"
ComboBox2.ValueMember = "CODPROV"
ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
End If
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox
1.Leave
Dim CONSULTACLI As New _
SqlDataAdapter("SELECT * FROM CLIENTES WHERE RUC=@RUC",
BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
CONSULTACLI.SelectCommand.Parameters.
AddWithValue("@RUC", TextBox1.Text)
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
If TABLACLI.Rows.Count > 0 Then
MessageBox.Show("EL RUC YA EXISTE", "MENSAJE",
MessageBoxButtons.OK, MessageBoxIcon.Warning)

TextBox1.SelectAll()
TextBox1.Focus()
End If
End Sub
'NUEVO
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.
Click
For Each C As Control In Me.Controls
If TypeOf C Is TextBox Then
C.Text = ""
End If
Next
End Sub
Private Sub DataGridView1_RowHeaderMouseDoubleClick(sender As Object, e As D
ataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseDoubleClick
TextBox1.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(0).Value
TextBox2.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(1).Value
TextBox3.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(2).Value
ComboBox1.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cell
s(3).Value
ComboBox2.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cell
s(4).Value
TextBox4.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(5).Value
TextBox5.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(6).Value
TextBox6.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells
(7).Value
End Sub
'BOTON ELIMINAR
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.
Click
If MessageBox.Show("Desea eliminar..", "Mensaje",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
Dim COMANDO As New _
SqlCommand("DELETE FROM CLIENTES WHERE RUC=@RUC",
BDCONEXION.CONEXION)
COMANDO.CommandType = CommandType.Text
COMANDO.Parameters.AddWithValue("@RUC", TextBox1.Text)
BDCONEXION.CONEXION.Open()
COMANDO.ExecuteNonQuery()
BDCONEXION.CONEXION.Close()
'///////////////////////////////////////////////////////ACTUALIZA EL
DATAGRIDVIEW
Dim CONSULTACLI As New _
SqlDataAdapter("SELECT RUC,NOMBRES,DIRECCION,(SELECT DEPARTAMENTO FROM DE
PARTAMENTOS WHERE DEPARTAMENTOS.CODDEPART=CLIENTES.CODDEPART) AS DEPARTAMENTO,(S
ELECT PROVINCIA FROM PROVINCIA WHERE PROVINCIA.CODPROV=CLIENTES.CODPROV) AS PROV
INCIA,TELEFONO,CELULAR,EMAIL FROM CLIENTES",
BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
DataGridView1.DataSource = TABLACLI
End If

End Sub
End Class

You might also like