Anda di halaman 1dari 32

Imports System.Data.

SqlClient
Public Class conexion
Protected cnn As New SqlConnection 'creamos una variable para establecer la conexion con la
base de datos
'creamos la funcion para conectar con la base de datos
Public idusuario As Integer
Protected Function conectado()
Try
'creamos la cadena de conexion
cnn = New SqlConnection("data source=(local);initial catalog=sisalmacen;integrated
security=true")
'abrimos la conexion
cnn.Open()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
'creamos la funcion para desconectar con la base de datos
Protected Function desconectado()
Try
'si la conexion esta abierta entonces la cerramos
If cnn.State = ConnectionState.Open Then
cnn.Close()
Return True
Else
'en caso contrario esta cerrada entonces no hacemos nada
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class
Imports System.Data.SqlClient
Public Class fcliente
Inherits conexion
Dim cmd As New SqlCommand
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vcliente) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_cliente")

cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@nombres", dts.gnombres)
cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
cmd.Parameters.AddWithValue("@dni", dts.gdni)
cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
cmd.Parameters.AddWithValue("@sexo", dts.gsexo)
cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
cmd.Parameters.AddWithValue("@email", dts.gemail)
cmd.Parameters.AddWithValue("@observacion", dts.gobservacion)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function editar(ByVal dts As vcliente) As Boolean
Try
conectado()
cmd = New SqlCommand("editar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
cmd.Parameters.AddWithValue("@nombres", dts.gnombres)
cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
cmd.Parameters.AddWithValue("@dni", dts.gdni)
cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
cmd.Parameters.AddWithValue("@sexo", dts.gsexo)
cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
cmd.Parameters.AddWithValue("@email", dts.gemail)
cmd.Parameters.AddWithValue("@observacion", dts.gobservacion)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vcliente) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@idcliente", SqlDbType.NVarChar, 50).Value = dts.gidcliente
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally

desconectado()
End Try
End Function
End Class
Imports System.Data.SqlClient
Public Class fequipo
Inherits conexion
Dim cmd As New SqlCommand
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_equipo")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vequipo) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_equipo")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
cmd.Parameters.AddWithValue("@marca", dts.gmarca)
cmd.Parameters.AddWithValue("@modelo", dts.gmodelo)
cmd.Parameters.AddWithValue("@serie", dts.gserie)
cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
cmd.Parameters.AddWithValue("@problema_desc", dts.gproblema_desc)
cmd.Parameters.AddWithValue("@estado_almacen", dts.gestado_almacen)
cmd.Parameters.AddWithValue("@fecha_ingreso", dts.gfecha_ingreso)
cmd.Parameters.AddWithValue("@estado_pago", dts.gestado_pago)
cmd.Parameters.AddWithValue("@reparacion_desc", dts.greparacion_desc)
cmd.Parameters.AddWithValue("@tipo_doc", dts.gtipo_doc)
cmd.Parameters.AddWithValue("@num_doc", dts.gnum_doc)
cmd.Parameters.AddWithValue("@total_pago", dts.gtotal_pago)
cmd.Parameters.AddWithValue("@fecha_salida", dts.gfecha_salida)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function editar(ByVal dts As vequipo) As Boolean
Try
conectado()

cmd = New SqlCommand("editar_equipo")


cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idequipo", dts.gidequipo)
cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
cmd.Parameters.AddWithValue("@marca", dts.gmarca)
cmd.Parameters.AddWithValue("@modelo", dts.gmodelo)
cmd.Parameters.AddWithValue("@serie", dts.gserie)
cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
cmd.Parameters.AddWithValue("@problema_desc", dts.gproblema_desc)
cmd.Parameters.AddWithValue("@estado_almacen", dts.gestado_almacen)
cmd.Parameters.AddWithValue("@fecha_ingreso", dts.gfecha_ingreso)
cmd.Parameters.AddWithValue("@estado_pago", dts.gestado_pago)
cmd.Parameters.AddWithValue("@reparacion_desc", dts.greparacion_desc)
cmd.Parameters.AddWithValue("@tipo_doc", dts.gtipo_doc)
cmd.Parameters.AddWithValue("@num_doc", dts.gnum_doc)
cmd.Parameters.AddWithValue("@total_pago", dts.gtotal_pago)
cmd.Parameters.AddWithValue("@fecha_salida", dts.gfecha_salida)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vequipo) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_equipo")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@idequipo", SqlDbType.NVarChar, 50).Value = dts.gidequipo
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
End Class
Imports System.Data.SqlClient
Public Class fusuario
Inherits conexion
Dim cmd As New SqlCommand
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_usuario")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt

Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vusuario) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_usuario")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@nombres", dts.gnombres)
cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
cmd.Parameters.AddWithValue("@dni", dts.gdni)
cmd.Parameters.AddWithValue("@fecha_nac", dts.gfecha_nac)
cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
cmd.Parameters.AddWithValue("@sexo", dts.gsexo)
cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
cmd.Parameters.AddWithValue("@email", dts.gemail)
cmd.Parameters.AddWithValue("@login", dts.glogin)
cmd.Parameters.AddWithValue("@password", dts.gpassword)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function editar(ByVal dts As vusuario) As Boolean
Try
conectado()
cmd = New SqlCommand("editar_usuario")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idusuario", dts.gidusuario)
cmd.Parameters.AddWithValue("@nombres", dts.gnombres)
cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
cmd.Parameters.AddWithValue("@dni", dts.gdni)
cmd.Parameters.AddWithValue("@fecha_nac", dts.gfecha_nac)
cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
cmd.Parameters.AddWithValue("@sexo", dts.gsexo)
cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
cmd.Parameters.AddWithValue("@email", dts.gemail)
cmd.Parameters.AddWithValue("@login", dts.glogin)
cmd.Parameters.AddWithValue("@password", dts.gpassword)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally

desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vusuario) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_usuario")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@idusuario", SqlDbType.NVarChar, 50).Value = dts.gidusuario
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function validarusuario(ByVal dts As vusuario)
Try
conectado()
cmd = New SqlCommand("validar_usuario")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@log", dts.glogin)
cmd.Parameters.AddWithValue("@pas", dts.gpassword)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader
If dr.HasRows = True Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function

End Class
Public Class vcliente
Dim idcliente As Integer
Dim nombres, apellidos, dni, telefono, sexo, direccion, email, observacion As String
Public Property gidcliente
Get
Return idcliente
End Get
Set(ByVal value)
idcliente = value
End Set
End Property
Public Property gnombres
Get
Return nombres

End Get
Set(ByVal value)
nombres = value
End Set
End Property
Public Property gapellidos
Get
Return apellidos
End Get
Set(ByVal value)
apellidos = value
End Set
End Property
Public Property gdni
Get
Return dni
End Get
Set(ByVal value)
dni = value
End Set
End Property
Public Property gtelefono
Get
Return telefono
End Get
Set(ByVal value)
telefono = value
End Set
End Property
Public Property gsexo
Get
Return sexo
End Get
Set(ByVal value)
sexo = value
End Set
End Property
Public Property gdireccion
Get
Return direccion
End Get
Set(ByVal value)
direccion = value
End Set
End Property
Public Property gemail
Get
Return email
End Get
Set(ByVal value)
email = value
End Set
End Property
Public Property gobservacion
Get
Return observacion
End Get
Set(ByVal value)
observacion = value
End Set
End Property
Public Sub New()
End Sub

Public Sub New(ByVal idcliente As Integer, ByVal nombres As String, ByVal apellidos As String,
ByVal dni As String, ByVal telefono As String, ByVal sexo As String, ByVal direccion As String, ByVal
email As String, ByVal observacion As String)
gidcliente = idcliente
gnombres = nombres
gapellidos = apellidos
gdni = dni
gtelefono = telefono
gsexo = sexo
gdireccion = direccion
gemail = email
gobservacion = observacion
End Sub
End Class
Public Class vequipo
Dim idequipo, idcliente, idusuario As Integer
Dim nombre, marca, modelo, serie, problema_desc, estado_almacen, estado_pago,
reparacion_desc, tipo_doc, num_doc As String
Dim fecha_ingreso, fecha_salida As Date
Dim total_pago As Double
Public Property gidequipo
Get
Return idequipo
End Get
Set(ByVal value)
idequipo = value
End Set
End Property
Public Property gidcliente
Get
Return idcliente
End Get
Set(ByVal value)
idcliente = value
End Set
End Property
Public Property gidusuario
Get
Return idusuario
End Get
Set(ByVal value)
idusuario = value
End Set
End Property
Public Property gnombre
Get
Return nombre
End Get
Set(ByVal value)
nombre = value
End Set
End Property
Public Property gmarca
Get
Return marca
End Get
Set(ByVal value)
marca = value
End Set
End Property
Public Property gmodelo
Get
Return modelo
End Get
Set(ByVal value)

modelo = value
End Set
End Property
Public Property gserie
Get
Return serie
End Get
Set(ByVal value)
serie = value
End Set
End Property
Public Property gproblema_desc
Get
Return problema_desc
End Get
Set(ByVal value)
problema_desc = value
End Set
End Property
Public Property gestado_almacen
Get
Return estado_almacen
End Get
Set(ByVal value)
estado_almacen = value
End Set
End Property
Public Property gfecha_ingreso
Get
Return fecha_ingreso
End Get
Set(ByVal value)
fecha_ingreso = value
End Set
End Property
Public Property gestado_pago
Get
Return estado_pago
End Get
Set(ByVal value)
estado_pago = value
End Set
End Property
Public Property greparacion_desc
Get
Return reparacion_desc
End Get
Set(ByVal value)
reparacion_desc = value
End Set
End Property
Public Property gtipo_doc
Get
Return tipo_doc
End Get
Set(ByVal value)
tipo_doc = value
End Set
End Property
Public Property gnum_doc
Get
Return num_doc
End Get
Set(ByVal value)
num_doc = value
End Set

End Property
Public Property gtotal_pago
Get
Return total_pago
End Get
Set(ByVal value)
total_pago = value
End Set
End Property
Public Property gfecha_salida
Get
Return fecha_salida
End Get
Set(ByVal value)
fecha_salida = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal idequipo As Integer, ByVal idcliente As Integer, ByVal idusuario As Integer,
ByVal nombre As String, ByVal marca As String, ByVal serie As String, ByVal modelo As String, ByVal
problema_desc As String, ByVal estado_almacen As String, ByVal fecha_ingreso As Date, ByVal
estado_pago As String, ByVal reparacion_desc As String, ByVal tipo_doc As String, ByVal num_doc As
String, ByVal total_pago As Double, ByVal fecha_salida As Date)
gidcliente = idcliente
gidequipo = idequipo
gidusuario = idusuario
gnombre = nombre
gmarca = marca
gmodelo = modelo
gserie = serie
gproblema_desc = problema_desc
gestado_almacen = estado_almacen
gfecha_ingreso = fecha_ingreso
gestado_pago = estado_pago
greparacion_desc = reparacion_desc
gtipo_doc = tipo_doc
gnum_doc = num_doc
gtotal_pago = total_pago
gfecha_salida = fecha_salida
End Sub
End Class
Public Class vusuario
Dim idusuario As Integer
Dim nombres, apellidos, dni, telefono, sexo, direccion, email, login, password As String
Dim fecha_nac As Date
Public Property gidusuario
Get
Return idusuario
End Get
Set(ByVal value)
idusuario = value
End Set
End Property
Public Property gnombres
Get
Return nombres
End Get
Set(ByVal value)
nombres = value
End Set
End Property
Public Property gapellidos
Get

Return apellidos
End Get
Set(ByVal value)
apellidos = value
End Set
End Property
Public Property gdni
Get
Return dni
End Get
Set(ByVal value)
dni = value
End Set
End Property
Public Property gfecha_nac
Get
Return fecha_nac
End Get
Set(ByVal value)
fecha_nac = value
End Set
End Property
Public Property gtelefono
Get
Return telefono
End Get
Set(ByVal value)
telefono = value
End Set
End Property
Public Property gsexo
Get
Return sexo
End Get
Set(ByVal value)
sexo = value
End Set
End Property
Public Property gdireccion
Get
Return direccion
End Get
Set(ByVal value)
direccion = value
End Set
End Property
Public Property gemail
Get
Return email
End Get
Set(ByVal value)
email = value
End Set
End Property
Public Property glogin
Get
Return login
End Get
Set(ByVal value)
login = value
End Set
End Property
Public Property gpassword
Get
Return password

End Get
Set(ByVal value)
password = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal idusuario As Integer, ByVal nombres As String, ByVal apellidos As String,
ByVal dni As String, ByVal telefono As String, ByVal sexo As String, ByVal fecha_nac As Date, ByVal
direccion As String, ByVal email As String, ByVal login As String, ByVal password As String)
gidusuario = idusuario
gnombres = nombres
gapellidos = apellidos
gdni = dni
gtelefono = telefono
gsexo = sexo
gfecha_nac = fecha_nac
gdireccion = direccion
gemail = email
glogin = login
gpassword = password
End Sub
End Class
Public Class Form1
Private Sub btningresar_Click(sender As Object, e As EventArgs) Handles btningresar.Click
Try
Dim dts As New vusuario
Dim func As New fusuario
dts.glogin = txtlogin.Text
dts.gpassword = txtpassword.Text
If func.validarusuario(dts) = True Then
Dim forinicio As New Form2
Form2.Show()
Me.Hide()
Else
MessageBox.Show("Login o Password incorrecto, Usted no tiene acceso", "Acceso
denegado - Sistema de Almacn", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtpassword.Clear()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Btncancelar_Click(sender As Object, e As EventArgs) Handles Btncancelar.Click
If MsgBox("Deseas salir de la aplicacin?", MsgBoxStyle.YesNo, "MANTENIMIENTO") =
MsgBoxResult.Yes Then
End If
Application.Exit()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
lbltime.Text = TimeOfDay
End Sub
Private Sub PictureBox3_MouseHover(sender As Object, e As EventArgs) Handles
PictureBox3.MouseHover
ttmensaje.SetToolTip(PictureBox3, "Usted debe tener una cuenta de usuario y un password
para acceder al sistema")
ttmensaje.ToolTipTitle = "Ingreso Al Sistema"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


MessageBox.Show("Bienvenido!!,..por favor Ingrese su Usuario y Contrasea", "Bienvenidos A
mi pequea aplicacion", MessageBoxButtons.OK, MessageBoxIcon.Information)
lbltime.Text = TimeOfDay
End Sub
End Class
Imports System.Windows.Forms
Public Class Form2
Private Sub ToolBarToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
ToolBarToolStripMenuItem.Click
ToolStrip.Visible = ToolBarToolStripMenuItem.Checked
End Sub
Private Sub StatusBarToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
StatusBarToolStripMenuItem.Click
StatusStrip.Visible = StatusBarToolStripMenuItem.Checked
End Sub
Private Sub EquiposToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
EquiposToolStripMenuItem.Click
Form3.MdiParent = Me
Form3.Show()
End Sub
Private Sub ClientesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
ClientesToolStripMenuItem.Click
Form4.MdiParent = Me
Form4.Show()
End Sub
Private Sub UsuariosToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
UsuariosToolStripMenuItem.Click
Form5.MdiParent = Me
Form5.Show()
End Sub
Private Sub VistaclienteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
VistaclienteToolStripMenuItem.Click
Form6.MdiParent = Me
Form6.Show()
End Sub
Private Sub MsWordToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
MsWordToolStripMenuItem.Click
Shell("C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE",
AppWinStyle.MaximizedFocus)
End Sub
Private Sub MsExcelToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
MsExcelToolStripMenuItem.Click
Shell("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE",
AppWinStyle.MaximizedFocus)
End Sub
Protected Overrides Sub Finalize()
End Sub
End Class
Public Class Form3
Private dt As New DataTable
Private Sub mostrar()
Try

Dim func As New fequipo


dt = func.mostrar
datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False
Else
datalistado.DataSource = Nothing
datalistado.ColumnHeadersVisible = False
cbeliminar.CheckState = CheckState.Unchecked
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnnuevo.Visible = True
btnguardar.Visible = False
btneditar.Visible = False
cbeliminar.Checked = False
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = cbocampo.Text & " like '" & txtbuscar.Text & "%'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
lbltotal.Text = "Total Registros: " & dv.Count
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub limpiar()
txtcodigo.Text = ""
txtidcliente.Text = ""
txtnombrecliente.Text = ""
txtnombre.Text = ""
txtmarca.Text = ""
txtnumdoc.Text = ""
txtfecha_ingreso.Text = ""
txtreparacion_desc.Text = ""
txtproblema.Text = ""
txtnumdoc.Text = ""
txtreparacion_desc.Text = ""
btnguardar.Visible = False
btneditar.Visible = False
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
datalistado.Columns(2).Visible = False
datalistado.Columns(6).Visible = False
datalistado.Columns(7).Visible = False
datalistado.Columns(12).Visible = False
End Sub

Private Sub btneliminar_Click(sender As Object, e As EventArgs) Handles btneliminar.Click


Dim result As DialogResult 'declaramos la variable que recogera el valor resultante(true o false)
de la pregunta de confirmacion de eliminar o no registros?
result = MessageBox.Show("Realmente desea eliminar los Equipos?", "Eliminando registros",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si hace click en ok entonces eliminamos
Try
For Each row As DataGridViewRow In datalistado.Rows
Dim marcado As Boolean = Convert.ToBoolean(row.Cells("Eliminar").Value) 'marcado es
la variable que guarda la fila que se selecciono
If marcado Then
Dim oneKey As Integer = Convert.ToInt32(row.Cells("idequipo").Value) 'enviamos el
campo de la llave principal para eliminarlo
Dim vbd As New vequipo 'instanciamos la clase de las variables
Dim func As New fequipo 'instanciamos la clase de las funciones
vbd.gidequipo = oneKey
If func.eliminar(vbd) Then
Else
MessageBox.Show("Error al eliminar los equipos", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacion de registros", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
limpiar()
End Sub
Private Sub txtbuscar_TextChanged(sender As Object, e As EventArgs) Handles
txtbuscar.TextChanged
buscar()
End Sub
Private Sub datalistado_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles
datalistado.CellClick
txtcodigo.Text = datalistado.SelectedCells.Item(1).Value
txtnombre.Text = datalistado.SelectedCells.Item(2).Value
txtmarca.Text = datalistado.SelectedCells.Item(3).Value
txtmodelo.Text = datalistado.SelectedCells.Item(4).Value
txtserie.Text = datalistado.SelectedCells.Item(5).Value
txtidcliente.Text = datalistado.SelectedCells.Item(6).Value
txtnombrecliente.Text = datalistado.SelectedCells.Item(7).Value
txtproblema.Text = datalistado.SelectedCells.Item(8).Value
cboestadoalmacen.Text = datalistado.SelectedCells.Item(9).Value
txtfecha_ingreso.Text = datalistado.SelectedCells.Item(10).Value
cboestado_pago.Text = datalistado.SelectedCells.Item(11).Value
txtreparacion_desc.Text = datalistado.SelectedCells.Item(12).Value
cbotipo_doc.Text = datalistado.SelectedCells.Item(13).Value
txtnumdoc.Text = datalistado.SelectedCells.Item(14).Value
txttotalpago.Text = datalistado.SelectedCells.Item(15).Value
txtfecha_salida.Text = datalistado.SelectedCells.Item(16).Value
btnguardar.Visible = False
btneditar.Visible = True
End Sub
Private Sub datalistado_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
Handles datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then

Dim chkCell As DataGridViewCheckBoxCell =


Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkCell.Value = Not chkCell.Value
End If
End Sub
Private Sub cbeliminar_CheckedChanged(sender As Object, e As EventArgs) Handles
cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub
Private Sub btnnuevo_Click(sender As Object, e As EventArgs) Handles btnnuevo.Click
limpiar()
btnguardar.Visible = True
End Sub
Private Sub btneditar_Click(sender As Object, e As EventArgs) Handles btneditar.Click
Dim result As DialogResult
'preguntamos si esta seguro de editar o no los datos
result = MessageBox.Show("Realmente desea modificar los datos del equipo?", "MOdificando
registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si esta seguro de modificar
'verficamos que todos los campos no esten vacios
If Me.ValidateChildren = True And txtcodigo.Text <> "" And txtnombre.Text <> "" And
txtmarca.Text <> "" And txtserie.Text <> "" And txtmodelo.Text <> "" And txtidcliente.Text <> ""
And txtproblema.Text <> "" And txtreparacion_desc.Text <> "" And txtnumdoc.Text <> "" And
txttotalpago.Text <> "" Then
Try
Dim dts As New vequipo 'instanciamos a la clase de variables de la tabla trabajador
Dim func As New fequipo 'instanciamos a la clase de funciones de la tabla trabajador
'enviamos los datos
dts.gidequipo = txtcodigo.Text
dts.gnombre = txtnombre.Text
dts.gmarca = txtmarca.Text
dts.gmodelo = txtmodelo.Text
dts.gserie = txtserie.Text
dts.gidcliente = txtidcliente.Text
dts.gproblema_desc = txtproblema.Text
dts.gestado_almacen = cboestadoalmacen.Text
dts.gfecha_ingreso = txtfecha_ingreso.Text
dts.gestado_pago = cboestado_pago.Text
dts.greparacion_desc = txtreparacion_desc.Text
dts.gtipo_doc = cbotipo_doc.Text
dts.gnum_doc = txtnumdoc.Text
dts.gtotal_pago = txttotalpago.Text
dts.gfecha_salida = txtfecha_salida.Text
'llamamos a la funcion mostrar del objeto func
If func.editar(dts) Then
MessageBox.Show("Equipo Modificado Correctamente", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Modificar el Equipo", "MOdificanco registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'mostramos el mensaje en caso algunos de los campos esten vacios
MessageBox.Show("Falta ingresar algunos datos", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
'mostramos un mensaje en caso se cancele la modificacion
MessageBox.Show("NO se ha modificado el equipo", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
End Sub
Private Sub btnguardar_Click(sender As Object, e As EventArgs) Handles btnguardar.Click
If Me.ValidateChildren = True And txtnombre.Text <> "" And txtmarca.Text <> "" And
txtserie.Text <> "" And txtmodelo.Text <> "" And txtidcliente.Text <> "" And txtproblema.Text <> ""
And txtreparacion_desc.Text <> "" And txtnumdoc.Text <> "" And txttotalpago.Text <> "" Then
Try
Dim dts As New vequipo 'instanciamos a la clase atributos de la tabla trabajador
Dim func As New fequipo 'instanciamos a la clase funciones de la tabla trabajador
'enviamos los datos
dts.gnombre = txtnombre.Text
dts.gmarca = txtmarca.Text
dts.gmodelo = txtmodelo.Text
dts.gserie = txtserie.Text
dts.gidcliente = txtidcliente.Text
dts.gproblema_desc = txtproblema.Text
dts.gestado_almacen = cboestadoalmacen.Text
dts.gfecha_ingreso = txtfecha_ingreso.Text
dts.gestado_pago = cboestado_pago.Text
dts.greparacion_desc = txtreparacion_desc.Text
dts.gtipo_doc = cbotipo_doc.Text
dts.gnum_doc = txtnumdoc.Text
dts.gtotal_pago = txttotalpago.Text
dts.gfecha_salida = txtfecha_salida.Text
If func.insertar(dts) Then
MessageBox.Show("equipo Guardado Correctamente", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Guardar equipo", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'mostramos un mensaje en caso falten datos
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub

Private Sub btncancelar_Click(sender As Object, e As EventArgs) Handles btncancelar.Click


limpiar()
End Sub
Private Sub btnsalir_Click(sender As Object, e As EventArgs) Handles btnsalir.Click
Close()
End Sub
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mostrar()
End Sub
Private Sub txtproblema_MouseHover(sender As Object, e As EventArgs) Handles
txtproblema.MouseHover
ttmensaje.SetToolTip(txtproblema, "Ingrese los problemas que presenta el equipo")
ttmensaje.ToolTipTitle = "Fallas del equipo"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub txtnombre_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtnombre.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el nombre del equipo, este dato es obligatorio")
End If
End Sub
Private Sub txtmarca_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtmarca.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la marca del equipo, este dato es obligatorio")
End If
End Sub
Private Sub txtmodelo_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtmodelo.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el modelo del equipo, este dato es obligatorio")
End If
End Sub
Private Sub txtserie_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
Handles txtserie.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la serie del equipo, este dato es obligatorio")
End If
End Sub
Private Sub txtidcliente_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtidcliente.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Seleccione un cliente, este dato es obligatorio")

End If
End Sub
Private Sub txtproblema_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtproblema.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la problematica del equipo, este dato es obligatorio")
End If
End Sub
Private Sub cboestadoalmacen_MouseHover(sender As Object, e As EventArgs) Handles
cboestadoalmacen.MouseHover
ttmensaje.SetToolTip(cboestadoalmacen, "Seleccione el estado del equipo, si esta o no en
almacen")
ttmensaje.ToolTipTitle = "Estado en Almacen"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub txtfecha_ingreso_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtfecha_ingreso.Validating
If DirectCast(sender, DateTimePicker).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la fecha de ingreso a almacen, este dato es
obligatorio")
End If
End Sub
Private Sub txtreparacion_desc_MouseHover(sender As Object, e As EventArgs) Handles
txtreparacion_desc.MouseHover
ttmensaje.SetToolTip(txtreparacion_desc, "Ingrese la reparacion que se ha realizado con el
equipo")
ttmensaje.ToolTipTitle = "Detalle de reparacion"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub txtreparacion_desc_Validated(sender As Object, e As EventArgs) Handles
txtreparacion_desc.Validated
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la descripcion de la reparacion, este dato es
obligatorio")
End If
End Sub
Private Sub txtnumdoc_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtnumdoc.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el numero de documento de ingreso de caja, este
dato es obligatorio")
End If
End Sub
Private Sub txttotalpago_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txttotalpago.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then

Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el total a cancelar, este dato es obligatorio")
End If
End Sub
Private Sub btnhorario_Click(sender As Object, e As EventArgs) Handles btnhorario.Click
Form6.ShowDialog()
End Sub
End Class
Public Class Form4
Private dt As New DataTable
Private Sub mostrar()
Try
Dim func As New fcliente
dt = func.mostrar
datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False
Else
datalistado.DataSource = Nothing
datalistado.ColumnHeadersVisible = False
cbeliminar.CheckState = CheckState.Unchecked
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnnuevo.Visible = True
btnguardar.Visible = False
btneditar.Visible = False
cbeliminar.Checked = False
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = cbocampo.Text & " like '" & txtbuscar.Text & "%'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
lbltotal.Text = "Total Registros: " & dv.Count
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub limpiar()
txtcodigo.Text = ""
txtnombres.Text = ""
txtapellidos.Text = ""
txtdni.Text = ""
txtdireccion.Text = ""

txttelefono.Text = ""
txtemail.Text = ""
cbosexo.Text = ""
txtobservacion.Text = ""
btnguardar.Visible = False
btneditar.Visible = False
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
End Sub
Private Sub btneliminar_Click(sender As Object, e As EventArgs) Handles btneliminar.Click
Dim result As DialogResult 'declaramos la variable que recogera el valor resultante(true o false)
de la pregunta de confirmacion de eliminar o no registros?
result = MessageBox.Show("Realmente desea eliminar los trabajadores?", "Eliminando
registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si hace click en ok entonces eliminamos
Try
For Each row As DataGridViewRow In datalistado.Rows
Dim marcado As Boolean = Convert.ToBoolean(row.Cells("Eliminar").Value) 'marcado es
la variable que guarda la fila que se selecciono
If marcado Then
Dim oneKey As Integer = Convert.ToInt32(row.Cells("idcliente").Value) 'enviamos el
campo de la llave principal para eliminarlo
Dim vbd As New vcliente 'instanciamos la clase de las variables
Dim func As New fcliente 'instanciamos la clase de las funciones
vbd.gidcliente = oneKey
If func.eliminar(vbd) Then
Else
MessageBox.Show("Error al eliminar los trabajadores", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacion de registros", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
limpiar()
End Sub
Private Sub txtbuscar_TextChanged(sender As Object, e As EventArgs) Handles
txtbuscar.TextChanged
buscar()
End Sub
Private Sub datalistado_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles
datalistado.CellClick
txtcodigo.Text = datalistado.SelectedCells.Item(1).Value
txtnombres.Text = datalistado.SelectedCells.Item(2).Value
txtapellidos.Text = datalistado.SelectedCells.Item(3).Value
txtdni.Text = datalistado.SelectedCells.Item(4).Value
txttelefono.Text = datalistado.SelectedCells.Item(5).Value
cbosexo.Text = datalistado.SelectedCells.Item(6).Value
txtdireccion.Text = datalistado.SelectedCells.Item(7).Value
txtemail.Text = datalistado.SelectedCells.Item(8).Value
txtobservacion.Text = datalistado.SelectedCells.Item(9).Value
btnguardar.Visible = False
btneditar.Visible = True
End Sub

Private Sub datalistado_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)


Handles datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkCell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkCell.Value = Not chkCell.Value
End If
End Sub
Private Sub cbeliminar_CheckedChanged(sender As Object, e As EventArgs) Handles
cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub
Private Sub txtdni_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtdni.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub txttelefono_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
txttelefono.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub btnnuevo_Click(sender As Object, e As EventArgs) Handles btnnuevo.Click
limpiar()
btnguardar.Visible = True
End Sub
Private Sub btneditar_Click(sender As Object, e As EventArgs) Handles btneditar.Click
Dim result As DialogResult
'preguntamos si esta seguro de editar o no los datos
result = MessageBox.Show("Realmente desea modificar los datos del trabajador?",
"MOdificando registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si esta seguro de modificar
'verficamos que todos los campos no esten vacios
If Me.ValidateChildren = True And txtcodigo.Text <> "" And txtnombres.Text <> "" And
txtapellidos.Text <> "" And txtdni.Text <> "" And txttelefono.Text <> "" And txtdireccion.Text <> ""
And cbosexo.Text <> "" And txtemail.Text <> "" And txtobservacion.Text <> "" Then
Try
Dim dts As New vcliente 'instanciamos a la clase de variables de la tabla trabajador
Dim func As New fcliente 'instanciamos a la clase de funciones de la tabla trabajador
'enviamos los datos
dts.gidcliente = txtcodigo.Text
dts.gnombres = StrConv((txtnombres.Text), VbStrConv.ProperCase) 'convertimos la
primera letra a mayusculas
dts.gapellidos = StrConv((txtapellidos.Text), VbStrConv.ProperCase)
dts.gdni = txtdni.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text

dts.gsexo = cbosexo.Text
dts.gemail = txtemail.Text
dts.gobservacion = txtobservacion.Text
'llamamos a la funcion mostrar del objeto func
If func.editar(dts) Then
MessageBox.Show("Cliente Modificado Correctamente", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Modificar Cliente", "MOdificanco registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'mostramos el mensaje en caso algunos de los campos esten vacios
MessageBox.Show("Falta ingresar algunos datos", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
'mostramos un mensaje en caso se cancele la modificacion
MessageBox.Show("NO se ha modificado el Cliente", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
End Sub
Private Sub btnguardar_Click(sender As Object, e As EventArgs) Handles btnguardar.Click
If Me.ValidateChildren = True And txtnombres.Text <> "" And txtapellidos.Text <> "" And
txtdni.Text <> "" And txttelefono.Text <> "" And txtdireccion.Text <> "" And cbosexo.Text <> "" And
txtemail.Text <> "" And txtobservacion.Text <> "" Then
Try
Dim dts As New vcliente 'instanciamos a la clase atributos de la tabla trabajador
Dim func As New fcliente 'instanciamos a la clase funciones de la tabla trabajador
'enviamos los datos
dts.gnombres = StrConv((txtnombres.Text), VbStrConv.ProperCase) 'convertimos la
primera letra a mayusculas
dts.gapellidos = StrConv((txtapellidos.Text), VbStrConv.ProperCase)
dts.gdni = txtdni.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gsexo = cbosexo.Text
dts.gemail = txtemail.Text
dts.gobservacion = txtobservacion.Text
If func.insertar(dts) Then
MessageBox.Show("Cliente Guardado Correctamente", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Guardar Cliente", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'mostramos un mensaje en caso falten datos
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub txtobservacion_MouseHover(sender As Object, e As EventArgs) Handles
txtobservacion.MouseHover
ttmensaje.SetToolTip(txtobservacion, "Ingrese una observacin del Cliente, algunas referencias
etc.")
ttmensaje.ToolTipTitle = "Observacin"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub btncancelar_Click(sender As Object, e As EventArgs) Handles btncancelar.Click
limpiar()
End Sub
Private Sub btnsalir_Click(sender As Object, e As EventArgs) Handles btnsalir.Click
Close()
End Sub
Private Sub txtnombres_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtnombres.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el nombre del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub txtapellidos_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtapellidos.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese los Apellidos del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub txtdni_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
Handles txtdni.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el Dni del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub txtdireccion_MouseHover(sender As Object, e As EventArgs) Handles
txtdireccion.MouseHover
ttmensaje.SetToolTip(txtdireccion, "Ingrese la direccin del Cliente, calle y numero-distritoprovincicia-region")
ttmensaje.ToolTipTitle = "Direccin"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub

Private Sub txtdireccion_Validating(sender As Object, e As


System.ComponentModel.CancelEventArgs) Handles txtdireccion.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la direccin del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub Label1_MouseHover(sender As Object, e As EventArgs) Handles Label1.MouseHover
ttmensaje.SetToolTip(Label1, "Este cdigo es autogenerado por el sistema")
ttmensaje.ToolTipTitle = "Cdigo Trabajador"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub txtobservacion_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtobservacion.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese una observacin del Cliente, este dato es
obligatorio")
End If
End Sub
Private Sub cbosexo_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles cbosexo.Validating
If DirectCast(sender, ComboBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Seleccione el sexo del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub txttelefono_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txttelefono.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el telfono del Cliente, este dato es obligatorio")
End If
End Sub
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mostrar()
End Sub
End Class
Public Class Form5
Private dt As New DataTable
Private Sub mostrar()
Try
Dim func As New fusuario
dt = func.mostrar
datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False

Else
datalistado.DataSource = Nothing
datalistado.ColumnHeadersVisible = False
cbeliminar.CheckState = CheckState.Unchecked
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnnuevo.Visible = True
btnguardar.Visible = False
btneditar.Visible = False
cbeliminar.Checked = False
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = cbocampo.Text & " like '" & txtbuscar.Text & "%'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
lbltotal.Text = "Total Registros: " & dv.Count
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub limpiar()
txtidusuario.Text = ""
txtnombres.Text = ""
txtapellidos.Text = ""
txtdni.Text = ""
txtfecha_nac.Text = ""
txtdireccion.Text = ""
txttelefono.Text = ""
txtemail.Text = ""
txtlogin.Text = ""
txtpassword.Text = ""
btnguardar.Visible = False
btneditar.Visible = False
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
End Sub
Private Sub btneliminar_Click(sender As Object, e As EventArgs) Handles btneliminar.Click
Dim result As DialogResult 'declaramos la variable que recogera el valor resultante(true o false)
de la pregunta de confirmacion de eliminar o no registros?
result = MessageBox.Show("Realmente desea eliminar los Usuarios?", "Eliminando registros",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si hace click en ok entonces eliminamos
Try
For Each row As DataGridViewRow In datalistado.Rows
Dim marcado As Boolean = Convert.ToBoolean(row.Cells("Eliminar").Value) 'marcado es
la variable que guarda la fila que se selecciono
If marcado Then
Dim oneKey As Integer = Convert.ToInt32(row.Cells("idusuario").Value) 'enviamos el
campo de la llave principal para eliminarlo

Dim vbd As New vusuario 'instanciamos la clase de las variables


Dim func As New fusuario 'instanciamos la clase de las funciones
vbd.gidusuario = oneKey
If func.eliminar(vbd) Then
Else
MessageBox.Show("Error al eliminar los Usuario", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacion de registros", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
limpiar()
End Sub
Private Sub txtbuscar_TextChanged(sender As Object, e As EventArgs) Handles
txtbuscar.TextChanged
buscar()
End Sub
Private Sub datalistado_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles
datalistado.CellClick
txtidusuario.Text = datalistado.SelectedCells.Item(1).Value
txtnombres.Text = datalistado.SelectedCells.Item(2).Value
txtapellidos.Text = datalistado.SelectedCells.Item(3).Value
txtdni.Text = datalistado.SelectedCells.Item(4).Value
txtfecha_nac.Text = datalistado.SelectedCells.Item(5).Value
cbosexo.Text = datalistado.SelectedCells.Item(6).Value
txttelefono.Text = datalistado.SelectedCells.Item(7).Value
txtdireccion.Text = datalistado.SelectedCells.Item(8).Value
txtemail.Text = datalistado.SelectedCells.Item(9).Value
txtlogin.Text = datalistado.SelectedCells.Item(10).Value
txtpassword.Text = datalistado.SelectedCells.Item(11).Value
btnguardar.Visible = False
btneditar.Visible = True
End Sub
Private Sub datalistado_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
Handles datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkCell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkCell.Value = Not chkCell.Value
End If
End Sub
Private Sub cbeliminar_CheckedChanged(sender As Object, e As EventArgs) Handles
cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub
Private Sub txtdni_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtdni.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False

ElseIf Char.IsControl(e.KeyChar) Then


e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub txttelefono_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
txttelefono.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub btnnuevo_Click(sender As Object, e As EventArgs) Handles btnnuevo.Click
limpiar()
btnguardar.Visible = True
End Sub
Private Sub btneditar_Click(sender As Object, e As EventArgs) Handles btneditar.Click
Dim result As DialogResult
'preguntamos si esta seguro de editar o no los datos
result = MessageBox.Show("Realmente desea modificar los datos del usuario?", "MOdificando
registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then 'si esta seguro de modificar
'verficamos que todos los campos no esten vacios
If Me.ValidateChildren = True And txtidusuario.Text <> "" And txtnombres.Text <> "" And
txtapellidos.Text <> "" And txtdni.Text <> "" And txtfecha_nac.Text <> "" And txttelefono.Text <> ""
And txtdireccion.Text <> "" And cbosexo.Text <> "" And txtemail.Text <> "" And txtlogin.Text <> ""
And txtpassword.Text <> "" Then
Try
Dim dts As New vusuario 'instanciamos a la clase de variables de la tabla trabajador
Dim func As New fusuario 'instanciamos a la clase de funciones de la tabla trabajador
'enviamos los datos
dts.gidusuario = txtidusuario.Text
dts.gnombres = StrConv((txtnombres.Text), VbStrConv.ProperCase) 'convertimos la
primera letra a mayusculas
dts.gapellidos = StrConv((txtapellidos.Text), VbStrConv.ProperCase)
dts.gdni = txtdni.Text
dts.gfecha_nac = txtfecha_nac.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gsexo = cbosexo.Text
dts.gemail = StrConv((txtemail.Text), VbStrConv.ProperCase)
dts.glogin = txtlogin.Text
dts.gpassword = txtpassword.Text
'llamamos a la funcion mostrar del objeto func
If func.editar(dts) Then
MessageBox.Show("Usuario Modificado Correctamente", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Modificar Usuario", "MOdificanco registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception

MsgBox(ex.Message)
End Try
Else
'mostramos el mensaje en caso algunos de los campos esten vacios
MessageBox.Show("Falta ingresar algunos datos", "Modificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
'mostramos un mensaje en caso se cancele la modificacion
MessageBox.Show("NO se ha modificado el Usuario", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
End Sub
Private Sub btnguardar_Click(sender As Object, e As EventArgs) Handles btnguardar.Click
If Me.ValidateChildren = True And txtnombres.Text <> "" And txtapellidos.Text <> "" And
txtdni.Text <> "" And txtfecha_nac.Text <> "" And txttelefono.Text <> "" And txtdireccion.Text <>
"" And cbosexo.Text <> "" And txtemail.Text <> "" And txtlogin.Text <> "" And txtpassword.Text <>
"" Then
Try
Dim dts As New vusuario 'instanciamos a la clase atributos de la tabla trabajador
Dim func As New fusuario 'instanciamos a la clase funciones de la tabla trabajador
'enviamos los datos
dts.gnombres = StrConv((txtnombres.Text), VbStrConv.ProperCase) 'convertimos la
primera letra a mayusculas
dts.gapellidos = StrConv((txtapellidos.Text), VbStrConv.ProperCase)
dts.gdni = txtdni.Text
dts.gfecha_nac = txtfecha_nac.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gsexo = cbosexo.Text
dts.gemail = StrConv((txtemail.Text), VbStrConv.ProperCase)
dts.glogin = txtlogin.Text
dts.gpassword = txtpassword.Text
If func.insertar(dts) Then
MessageBox.Show("Usuario Guardado Correctamente", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Error al intentar Guardar Usuario", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
'mostramos un mensaje en caso falten datos
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btncancelar_Click(sender As Object, e As EventArgs) Handles btncancelar.Click
limpiar()
End Sub

Private Sub btnsalir_Click(sender As Object, e As EventArgs) Handles btnsalir.Click


Close()
End Sub
Private Sub txtnombres_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtnombres.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el nombre del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtapellidos_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtapellidos.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese los Apellidos del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtdni_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
Handles txtdni.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el Dni del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtdireccion_MouseHover(sender As Object, e As EventArgs) Handles
txtdireccion.MouseHover
ttmensaje.SetToolTip(txtdireccion, "Ingrese la direccin del Usuario, calle y numero-distritoprovincicia-region")
ttmensaje.ToolTipTitle = "Direccin"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub txtdireccion_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtdireccion.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese la direccin del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub Label1_MouseHover(sender As Object, e As EventArgs) Handles Label1.MouseHover
ttmensaje.SetToolTip(Label1, "Este cdigo es autogenerado por el sistema")
ttmensaje.ToolTipTitle = "Cdigo Usuario"
ttmensaje.ToolTipIcon = ToolTipIcon.Info
End Sub
Private Sub cbosexo_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles cbosexo.Validating
If DirectCast(sender, ComboBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Seleccione el sexo del Usuario, este dato es obligatorio")
End If
End Sub

Private Sub txttelefono_Validating(sender As Object, e As


System.ComponentModel.CancelEventArgs) Handles txttelefono.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el telfono del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtlogin_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
Handles txtlogin.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el login del usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtpassword_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtpassword.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el password del Usuario, este dato es obligatorio")
End If
End Sub
Private Sub txtemail_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles txtemail.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el email del usuario, este dato es obligatorio")
End If
End Sub
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mostrar()
End Sub
End Class
Public Class Form6
Private dt As New DataTable
Private Sub mostrar()
Try
'instanciamos la clase fhorario y llamamos a la funcion mostrar
Dim func As New fcliente
dt = func.mostrar
'si hay registros entonces llenamos la lista con los registros, mostramos las columas del
datagridview datalistado
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False
'si no hay registros entonces no mostramos nada y mostramos el mensaje de datos
inexistentes y ocultamos las columas
Else
datalistado.DataSource = Nothing
datalistado.ColumnHeadersVisible = False
inexistente.Visible = True
End If
Catch ex As Exception

MsgBox(ex.Message)
End Try
buscar()
End Sub
Private Sub buscar()
Try
'creamos un objeto dataset que me permite recoger los datos de la fuente de datos y
traerlos a nuestra aplicacion
Dim ds As New DataSet
'copiamos a la variable ds todo los registros que contiene la variable dt que es datatable
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
'filtramos los datos por el campo elegido el combobox cbocampo y que inicien con la cadena
escrita en el txtbusccar
dv.RowFilter = cbocampo.Text & " like '" & txtbuscar.Text & "%'"
'si la cantidad de registros es mayor que cero entonces mostramos los registros filtrados
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
'en caso no obtengamos registros no mostramos nada y mostramos el mensaje del label
inexistente "datos inexistentes"
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
lbltotal.Text = "Total Registros: " & dv.Count
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ocultar_columnas()
'ocultamos las columnas
datalistado.Columns(0).Visible = False
End Sub
Private Sub datalistado_CellContentDoubleClick(sender As Object, e As
DataGridViewCellEventArgs) Handles datalistado.CellContentDoubleClick
Form3.txtidcliente.Text = datalistado.SelectedCells.Item(0).Value
Form3.txtnombrecliente.Text = datalistado.SelectedCells.Item(2).Value
Close()
End Sub
Private Sub txtbuscar_TextChanged(sender As Object, e As EventArgs) Handles
txtbuscar.TextChanged
buscar()
End Sub
Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mostrar()
End Sub
End Class

Anda mungkin juga menyukai