You are on page 1of 6

Imports System.Data Imports System.Data.SqlClient Imports System.Data.

OleDb Public Class MARCliente Const CS As String = "Data Source=ZHD264;Initial Catalog=BDD-BolkInk;Integra ted Security=True" 'Instancia del componente BindingSource ' Private bindingsource1 As Windows.Forms.BindingSource = New BindingSource Enum OPFiltro NoFiltro = 0 IDCliente = 1 RFC = 2 Nombre = 3 End Enum Private Sub MARCliente_FormClosing(ByVal sender As Object, ByVal e As System .Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MsgBox("No Guardar Ningun Registro de Cliente. Desea Continuar", MsgBo xStyle.YesNo) = MsgBoxResult.Yes Then End Else Resume End If End Sub Private Sub MARCliente_Load(ByVal sender As System.Object, ByVal e As System .EventArgs) Handles MyBase.Load Dim Conexion As New SqlConnection("Data Source=ZHD264;Initial Catalog=BD D-BolkInk;Integrated Security=True") Dim DA As New SqlDataAdapter("Select * From Cliente", Conexion) Dim DT As New DataTable Try Conexion.Open() DA.Fill(DT) BindingSource1.DataSource = DT With (CmBxTBusqueda) ' opciones al combobox CmBxTBusqueda.Items.Add("No Filtrar") CmBxTBusqueda.Items.Add("ID. Cliente") CmBxTBusqueda.Items.Add("R.F.C") CmBxTBusqueda.Items.Add("N. Cliente") CmBxTBusqueda.DropDownStyle = ComboBoxStyle.DropDownList CmBxTBusqueda.SelectedIndex = 1 End With Catch ex As Exception MsgBox(ex.Message.ToString) End Try End Sub Function Filtrado_DGV1(ByVal Columna As String, ByVal texto As String, ByVal BindingSource As BindingSource, ByVal DataGridView As DataGridView, Optional By

Val Opcion_Filtro As OPFiltro = Nothing) As Integer ' verificar que el DataSource no est vacio If BindingSource1.DataSource Is Nothing Then Return 0 End If Try Dim Filtrado As String = String.Empty ' Seleccionar la opcin Select Case Opcion_Filtro Case OPFiltro.IDCliente Filtrado = "like '" & texto.Trim & "%'" Case OPFiltro.RFC Filtrado = "Not like '" & texto.Trim & "%'" Case OPFiltro.Nombre Filtrado = "Not like '%" & texto.Trim & "%'" End Select If Opcion_Filtro = OPFiltro.NoFiltro Then Filtrado = String.Empty End If If Filtrado <> String.Empty Then Filtrado = "[" & Columna & "]" End If BindingSource.Filter = Filtrado DataGridView.DataSource = BindingSource.DataSource Return BindingSource.Count Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Critical) End Try Return 0 End Function Private Sub Filtrado_Busqueda() ' filtrar por el campo Cliente '''''''''''''''''''''''''''''''''''''''''''''''''''' Dim SLC As Integer = Filtrado_DGV1("Producto", TxBxBusqueda.Text.Trim, B indingSource1, DGV1, CType(CmBxTBusqueda.SelectedIndex, OPFiltro)) If SLC = 0 Then ' si no hay registros cambiar el color del txtbox TxBxBusqueda.BackColor = Color.Red Else TxBxBusqueda.BackColor = Color.White End If ' visualizar la cantidad de registros Me.Text = SLC & " Registros encontrados" End Sub

Private Sub TxBxBusqueda_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxBxBusqueda.TextChanged Call Filtrado_Busqueda() ' Using Conexion As New SqlConnection("Data Source=ZHD264;Initial Ca talog=BDD-BolkInk;Integrated Security=True") 'Dim SQL As String = "Select * From Cliente WHERE TxbxBusqueda.text LIKE '%@Param%'" ' Dim CMD As New SqlCommand(SQL, Conexion) ' Dim DA As New SqlDataAdapter(CMD) ' Dim DT As New DataTable ' Dim DS As DataSet ' ' ' ' ' ' ' ' ' Conexion.Open() BindingSource1 = New BindingSource

CMD.Parameters.AddWithValue("@Param", TxBxBusqueda.Text) CMD = New SqlCommand(SQL, Conexion) CMD.CommandType = CommandType.Text CMD.ExecuteNonQuery() DA.Fill(DT) DGV1.DataSource = DT BindingSource1.Filter = "concat(ID_Cliente, RFC, Nombre, Telefono)" Like "%" & TxBxBusqueda.Text & "%" ' Conexion.Close() ' End Using ' Using Conexion As New SqlConnection("Data Source=ZHD264;Initial Cata log=BDD-BolkInk;Integrated Security=True") 'Dim SLC As String = 'BindingSource1 = New BindingSource 'CMD.Parameters.AddWithValue("@Cliente", TxBxBusqueda.Text) 'TxBxBusqueda.DataBindings.Add(New System.Windows.Forms.Binding("Text", BindingSource1, "@Cliente", True)) 'DS.Clear() 'DA.Fill(DS, "Cliente") 'DGV1.DataSource = DS 'DGV1.DataMember = "Cliente" ' Conexion.Close( 'End Using End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' If Not CheckBox1.Checked = True Then 'TxBxBusqueda.Enabled = True 'TxBxBusqueda.Text = "" 'Else 'TxBxBusqueda.Text = "" 'TxBxBusqueda.Enabled = False 'End If End Sub Private Sub BBuscar_click(ByVal sender As System.Object, ByVal e As System.E

ventArgs) Handles BBuscar.Click Dim Conexion As New SqlConnection("Data Source=ZHD264;Initial Catalog=BD D-BolkInk;Integrated Security=True") Dim CMD As New SqlCommand Dim DA As SqlDataAdapter Dim DT As DataTable Dim SQL As String Conexion.Open() SQL = "Select * From Cliente Order By ID_Cliente" CMD = New SqlCommand(SQL, Conexion) CMD.CommandType = CommandType.Text CMD.ExecuteNonQuery() DA = New SqlDataAdapter(CMD) DT = New DataTable DA.Fill(DT) DGV1.DataSource = DT Conexion.Close() End Sub Private Sub BRegresar_Click(ByVal sender As System.Object, ByVal e As System .EventArgs) Handles BRegresar.Click MRNCliente.Show() Me.Hide() End Sub Private Sub BActualizar_Click(ByVal sender As System.Object, ByVal e As Syst em.EventArgs) Handles BActualizar.Click ' Conexion.Open() ' ' Dim ACT As String ' Dim comando = New OleDb.OleDbCommand(" 'UPDATE Cliente SET ID_Client e=' " & TxbxIDCliente.Text & " ', RFC=' " & TxbxNClienteRFC.Text & " ', Nombre=' " & TxbxNClienteNombre.Text & " ', Telefono=' " & TxbxNClienteTelefono.Text & " ', Direccion=' " & TxbxNClienteDireccion.Text & " ' WHERE ID_Cliente=' " & Txbx IDCliente.Text & "'") ' ' Try 'DA.Fill(DT) ' DR = DT.NewRow() ' CMD.ExecuteNonQuery() ' DT.AcceptChanges() ' Conexion.Close() ' ' Catch ex As Exception 'MessageBox.Show(ex.Message) ' MsgBox(ex.ToString) ' End Try ' ' Me.Validate() ' Me.BindingSource1.EndEdit() ' Me.TableAdapterManager.UpdateAll(Me.Secretaria_PlaneacionDataSet)

' Try

'Dim SQL As String = "UPDATE Cliente SET ID_Cliente=@ID_Cliente, NOMBRE= @NOMBRE WHERE RFC=@RFC" ' Dim CMD As New SqlCommand(SQL, Conexion) ' CMD.Parameters.Add("@ID_Cliente", SqlDbType.VarChar, 7).Value = Me.T xbxIDCliente.Text ' CMD.Parameters.Add("@RFC", SqlDbType.VarChar, 14).Value = Me.TxbxN ClienteRFC.Text ' CMD.Parameters.Add("@Nombre", SqlDbType.VarChar, 70).Value = Me.Txb xNClienteNombre.Text ' CMD.Parameters.Add("@Telefono", SqlDbType.Int).Value = CInt(TxbxNCl ienteTelefono.Text) ' CMD.Parameters.Add("@Direccion", SqlDbType.Text).Value = Me.TxbxNCl ienteDireccion ' ' Conexion.Open() ' Dim i As Integer = CMD.ExecuteNonQuery ' If i = 1 Then 'Label4.Visible = False ' MsgBox("---------- Modifcado ", MsgBoxStyle.Exclamation, "Insercion ") ' Else ' Label4.Visible = True ' End If ' Catch ex As Exception ' Finally ' Conexion.Close() ' End Try End Sub Private Sub BBorrar_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles BBorrar.Click End Sub Private Sub BEliminar_Click(ByVal sender As System.Object, ByVal e As System .EventArgs) Handles BEliminar.Click End Sub ' Try ' If _BDD_BolkInkDataSet1.HasChanges Then ' MsgBox("Datos de Clientes Actualizados") ' End If ' SqlDataAdapter1.Update(DS, "Cliente") ' Catch ex As Exception ' MsgBox("No se Actuzalizo el registro de Cliente") ' End Try ' End Sub ' If RB1.Checked = True Then ' 'LlamarDatos("Select * From Cliente Where [ID. Cliente] '%'") '& TxBxBus queda .Text &' "Like" '& SLC &' "Order by [ID. Cliente]" ' DT = New DataTable ' DA.Fill(DT) 'DGV1.DataSource = DT 'End If

'If RB2.Checked = True Then ' LlamarDatos("Select * From Cliente Where [R.F.C] '%'") '& TxBxBusqueda .Text &' "Like" '& SLC &' "Order by [R.F.C]" ' DT = New DataTable ' DA.Fill(DT) 'DGV1.DataSource = DT ' End If 'If RB3.Checked = True Then 'LlamarDatos("Select * From Cliente Where [N. Cliente] '%'") '& TxBxBusqueda .Text &' "Like" '& SLC &' "Order by [N. Cliente]" 'DT = New DataTable 'DA.Fill(DT) 'DGV1.DataSource = DT 'End If Private Sub DGV1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellContentClick End Sub Private Sub CmBxTBusqueda_SelectedIndexChanged(ByVal sender As System.Object , ByVal e As System.EventArgs) Handles CmBxTBusqueda.SelectedIndexChanged End Sub End Class