CodigoFelizLombriz
Imports System.Data.SqlClient

Module ModulePerfil
    Public Perfil As String

End Module

Imports Sys...
End If
                  If tipodeusuario = "operario" Then
                      Usuario = TextBoxUsuario.Text
          ...
VehiculosToolStripMenuItem1.Enabled = False
           ReporteClientesToolStripMenuItem2.Enabled = False
           Report...
End Sub

    Private Sub EmpleadosToolStripMenuItem1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Han...
Dim reporte_clientes As New ReporteClientes
       reporte_clientes.Show()

    End Sub

    Private Sub ReporteEmpleadosT...
Imports System.Data
Imports System.Data.SqlClient


Public Class MantenimientoClientes

    Private Sub ButtonVolver_Click...
TextBoxNombre.DataBindings.Add("Text", BindingSource1,
"nom_cli")
             TextBoxCiudad.DataBindings.Add("Text", Bind...
conexion.Open()
             If comando.ExecuteNonQuery > 0 Then
                  MessageBox.Show("Ingreso Exitoso")
    ...
End Sub

    Private Sub ButtonLimpiar_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ButtonLim...
Catch ex As Exception
           MessageBox.Show("ERROR ACTUALIZAR CLIENTES: " & ex.Message)
       End Try
       conexio...
Private Sub ButtonVolver_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ButtonVolver.Click
    ...
Dim conexion As New SqlConnection("Data
Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated
Security=True")
       ...
Upcoming SlideShare
Loading in …5
×

CodigoFelizLombriz

2,273 views
2,218 views

Published on

CodigoFelizLombriz

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,273
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
205
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

CodigoFelizLombriz

  1. 1. CodigoFelizLombriz Imports System.Data.SqlClient Module ModulePerfil Public Perfil As String End Module Imports System.Data.SqlClient Module ModuleUsuario Public Usuario As String End Module Imports System.Data.SqlClient Public Class Login Dim intento As Integer Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() Call Limpiar() End Sub Private Sub Limpiar() TextBoxUsuario.Clear() TextBoxPassword.Clear() TextBoxUsuario.Focus() End Sub Private Sub ButtonEntrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEntrar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("Select nom_usuario, password,tipo from Usuarios where nom_usuario= '" & TextBoxUsuario.Text.Trim & "' and password= '" & TextBoxPassword.Text.Trim & "'", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dsdatos As New DataSet Try conexion.Open() adaptador.Fill(dsdatos, "Usuarios") If dsdatos.Tables("Usuarios").Rows.Count > 0 Then Dim tipodeusuario As String = dsdatos.Tables("Usuarios").Rows(0)("tipo") If tipodeusuario = "administrador" Then Usuario = TextBoxUsuario.Text Perfil = "administrador" Me.Hide() Dim menu As New MenuPrincipal menu.Show()
  2. 2. End If If tipodeusuario = "operario" Then Usuario = TextBoxUsuario.Text Perfil = "operario" Me.Hide() Dim menu As New MenuPrincipal menu.Show() End If If tipodeusuario = "mecanico" Then Usuario = TextBoxUsuario.Text Perfil = "mecanico" Me.Hide() Dim menu As New MenuPrincipal menu.Show() End If Else intento = intento + 1 If intento <= 2 Then MessageBox.Show("Usuario y/o password incorrectos, solo 3 intentos " & intento & " intento") Call Limpiar() End If If intento = 3 Then MessageBox.Show("No hay mas intentos " & intento & " BYEEEEEEEE") Me.Close() End If End If Catch ex As Exception MessageBox.Show("ERROR LOGIN: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() End Sub End Class Imports System.Data.SqlClient Public Class MenuPrincipal Private Sub MenuPrincipal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() LabelUsuario.Text = Usuario If Perfil = "mecanico" Then ClientesToolStripMenuItem.Enabled = False EmpleadosToolStripMenuItem.Enabled = False ClientesToolStripMenuItem1.Enabled = False EmpleadosToolStripMenuItem1.Enabled = False
  3. 3. VehiculosToolStripMenuItem1.Enabled = False ReporteClientesToolStripMenuItem2.Enabled = False ReporteEmpleadosToolStripMenuItem2.Enabled = False FacturaToolStripMenuItem.Enabled = False End If If Perfil = "operario" Then ClientesToolStripMenuItem.Enabled = False EmpleadosToolStripMenuItem.Enabled = False ClientesToolStripMenuItem1.Enabled = False EmpleadosToolStripMenuItem1.Enabled = False ReporteClientesToolStripMenuItem2.Enabled = False ReporteEmpleadosToolStripMenuItem2.Enabled = False FacturaToolStripMenuItem.Enabled = False End If End Sub Private Sub SalirDelSistemaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirDelSistemaToolStripMenuItem.Click Me.Close() End Sub Private Sub ClientesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesToolStripMenuItem.Click Me.Hide() Dim consulta_clientes As New ConsultaClientes consulta_clientes.Show() End Sub Private Sub EmpleadosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmpleadosToolStripMenuItem.Click Me.Hide() Dim consulta_empleados As New ConsultaEmpleados consulta_empleados.Show() End Sub Private Sub VehiculosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VehiculosToolStripMenuItem.Click Me.Hide() Dim consulta_vehiculo As New ConsultaVehiculos consulta_vehiculo.Show() End Sub Private Sub ClientesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesToolStripMenuItem1.Click Me.Hide() Dim mantenimiento_clientes As New MantenimientoClientes mantenimiento_clientes.Show()
  4. 4. End Sub Private Sub EmpleadosToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmpleadosToolStripMenuItem1.Click Me.Hide() Dim mantenimiento_empleados As New MantenimientoEmpleados mantenimiento_empleados.Show() End Sub Private Sub VehiculosToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VehiculosToolStripMenuItem1.Click Me.Hide() Dim mantenimiento_vehiculos As New MantenimientoVehiculos mantenimiento_vehiculos.Show() End Sub Private Sub CambioDeContraseñaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CambioDeContraseñaToolStripMenuItem.Click Me.Hide() Dim cambio_contraseña As New CambioContraseña cambio_contraseña.Show() End Sub Private Sub BlockDeNotasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlockDeNotasToolStripMenuItem.Click System.Diagnostics.Process.Start("notepad.exe") End Sub Private Sub CalculadoraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculadoraToolStripMenuItem.Click System.Diagnostics.Process.Start("calc.exe") End Sub Private Sub CorreoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CorreoToolStripMenuItem.Click System.Diagnostics.Process.Start("msimn.exe") End Sub Private Sub MSNToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MSNToolStripMenuItem.Click System.Diagnostics.Process.Start("msnmsgr.exe") End Sub Private Sub ReporteClientesToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReporteClientesToolStripMenuItem2.Click Me.Hide()
  5. 5. Dim reporte_clientes As New ReporteClientes reporte_clientes.Show() End Sub Private Sub ReporteEmpleadosToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReporteEmpleadosToolStripMenuItem2.Click Me.Hide() Dim reporte_empleados As New ReporteEmpleados reporte_empleados.Show() End Sub Private Sub ReporteVehículosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReporteVehículosToolStripMenuItem.Click Me.Hide() Dim reporte_vehiculos As New ReporteVehiculos reporte_vehiculos.Show() End Sub Private Sub ContenidoDelSistemaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContenidoDelSistemaToolStripMenuItem.Click End Sub Private Sub AcercaDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcercaDeToolStripMenuItem.Click End Sub Private Sub FacturaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FacturaToolStripMenuItem.Click Me.Hide() Dim transaccion_factura As New TransaccionFactura transaccion_factura.Show() End Sub Private Sub AticulosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AticulosToolStripMenuItem.Click Me.Hide() Dim consulta_articulos As New ConsultaArticulos consulta_articulos.Show() End Sub End Class
  6. 6. Imports System.Data Imports System.Data.SqlClient Public Class MantenimientoClientes Private Sub ButtonVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVolver.Click Me.Hide() Dim menu As New MenuPrincipal menu.Show() End Sub Private Sub MantenimientoClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() LabelUsuario.Text = usuario Call Limpiar() Call CargarDatosNavegador() Call CargarDatosDataGrid() End Sub Private Sub Limpiar() TextBoxRut.Clear() TextBoxNombre.Clear() TextBoxEmail.Clear() TextBoxPais.Clear() TextBoxTelefono.Clear() TextBoxEmail.Clear() TextBoxCiudad.Clear() TextBoxSexo.Clear() TextBoxRut.Focus() End Sub Private Sub CargarDatosNavegador() Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("Select * from Clientes", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try conexion.Open() adaptador.Fill(dset, "Clientes") BindingSource1.DataSource = dset 'datasource: obtiene o establece el origen de lo datos con q enlazar el conector BindingSource1.DataMember = dset.Tables(0).ToString 'obtiene o establece ' la lista concreta del origen de los datos con la q esta enlazada en este 'momento BindingNavigator1.BindingSource = BindingSource1 TextBoxRut.DataBindings.Add("Text", BindingSource1, "rut_cli")
  7. 7. TextBoxNombre.DataBindings.Add("Text", BindingSource1, "nom_cli") TextBoxCiudad.DataBindings.Add("Text", BindingSource1, "ciudad_cli") TextBoxTelefono.DataBindings.Add("Text", BindingSource1, "tel_cli") TextBoxSexo.DataBindings.Add("Text", BindingSource1, "sexo_cli") TextBoxPais.DataBindings.Add("Text", BindingSource1, "pais_cli") TextBoxEmail.DataBindings.Add("Text", BindingSource1, "email_cli") Catch ex As Exception MessageBox.Show("ERROR CARGAR NAVEGADOR: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() End Sub Private Sub CargarDatosDataGrid() Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("Select * from Clientes", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try conexion.Open() adaptador.Fill(dset, "Clientes") DataGridView1.DataSource = dset DataGridView1.DataMember = dset.Tables(0).ToString Catch ex As Exception MessageBox.Show("ERROR CARGAR GRID VIEW: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() End Sub Private Sub ButtonIngresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonIngresar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("insert into Clientes values('" & TextBoxRut.Text.Trim & "','" & TextBoxNombre.Text.Trim & "', '" & TextBoxCiudad.Text.Trim & "','" & Integer.Parse(TextBoxTelefono.Text.Trim) & "','" & TextBoxSexo.Text.Trim & "', '" & TextBoxEmail.Text.Trim & "','" & TextBoxPais.Text.Trim & "') ", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try
  8. 8. conexion.Open() If comando.ExecuteNonQuery > 0 Then MessageBox.Show("Ingreso Exitoso") Else MessageBox.Show("Error al Ingresar") End If Catch ex As Exception MessageBox.Show("ERROR INGRESAR CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() Call CargarDatosNavegador() Call CargarDatosDataGrid() Call Limpiar() End Sub Private Sub ButtonBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBuscar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("select * from Clientes where rut_cli = '" & TextBoxRut.Text.Trim & "' ", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Dim dreader As SqlDataReader 'para trabajar de forma conectada con la bd. recibe los registros Try conexion.Open() dreader = comando.ExecuteReader 'se guardan los datos en el dr If dreader.Read = True Then TextBoxNombre.Text = dreader("nom_cli") TextBoxCiudad.Text = dreader("ciudad_cli") TextBoxTelefono.Text = dreader("tel_cli") TextBoxSexo.Text = dreader("sexo_cli") TextBoxEmail.Text = dreader("email_cli") TextBoxPais.Text = dreader("pais_cli") Else MessageBox.Show("Problemas al Buscar") End If Catch ex As Exception MessageBox.Show("ERROR BUSQUEDA CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() Call CargarDatosNavegador() Call CargarDatosDataGrid() Call Limpiar()
  9. 9. End Sub Private Sub ButtonLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLimpiar.Click Call Limpiar() End Sub Private Sub ButtonEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEliminar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("delete from Clientes where rut_cli='" & TextBoxRut.Text.Trim & "' ", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try conexion.Open() If comando.ExecuteNonQuery > 0 Then MessageBox.Show("Eliminacion Exitosa") Else MessageBox.Show("Error al Eliminar") End If Catch ex As Exception MessageBox.Show("ERROR ELIMINAR CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() Call CargarDatosNavegador() Call CargarDatosDataGrid() Call Limpiar() End Sub Private Sub ButtonActualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonActualizar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("update Clientes set nom_cli='" & TextBoxNombre.Text.Trim & "', ciudad_cli='" & TextBoxCiudad.Text.Trim & "',tel_cli='" & Integer.Parse(TextBoxTelefono.Text.Trim) & "',sexo_cli='" & TextBoxSexo.Text.Trim & "', email_cli='" & TextBoxEmail.Text.Trim & "',pais_cli='" & TextBoxPais.Text.Trim & "' where rut_cli= '" & TextBoxRut.Text.Trim & "' ", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try conexion.Open() If comando.ExecuteNonQuery > 0 Then MessageBox.Show("Actualizacion Exitosa") Else MessageBox.Show("Error al Actualizar") End If
  10. 10. Catch ex As Exception MessageBox.Show("ERROR ACTUALIZAR CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() Call CargarDatosNavegador() Call CargarDatosDataGrid() Call Limpiar() End Sub End Class Imports System.Data.SqlClient Public Class ConsultaClientes Dim campo As String Dim nombreCampo As String Private Sub ConsultaClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() Call limpiar() End Sub Private Sub Limpiar() TextBox2.Clear() TextBox2.Focus() End Sub Private Sub ConsultaClientes_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove If radiobuttonRut.Checked = True Then campo = "rut_cli" nombreCampo = "rut" End If If RadiobuttonNombre.Checked = True Then campo = "nom_cli" nombreCampo = "nombre" End If If RadiobuttonCiudad.Checked = True Then campo = "ciudad_cli" nombreCampo = "ciudad" End If If RadiobuttonPais.Checked = True Then campo = "pais_cli" nombreCampo = "pais" End If Label1.Text = "Ingrese " & nombreCampo & " a buscar:" End Sub
  11. 11. Private Sub ButtonVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVolver.Click Me.Hide() Dim menu As New MenuPrincipal menu.Show() End Sub Private Sub ButtonBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBuscar.Click Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("Select * from Clientes where " & campo.Trim & " like '" & TextBox2.Text.Trim & "%'", conexion) Dim adaptador As New SqlDataAdapter(comando) 'representa un conj. de comandos de datos y una conexion a Bd para poder llenar un dataset Dim dset As New DataSet ' representa una tabla virtual Try If TextBox2.Text = "" Then Label1.Text = "Ingrese " & nombreCampo & " a buscar:" TextBox2.Focus() Else conexion.Open() adaptador.Fill(dset, "Clientes") DataGrid1.DataSource = dset DataGrid1.DataMember = dset.Tables(0).ToString End If Catch ex As Exception MessageBox.Show("ERROR CARGAR GRID CONSULTAR CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() End Sub Private Sub ButtonLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLimpiar.Click Call Limpiar() End Sub End Class Imports System.Data.SqlClient Public Class ReporteClientes Private Sub ButtonReporte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReporte.Click
  12. 12. Dim conexion As New SqlConnection("Data Source=(local)SQLEXPRESS;Initial Catalog=Safito;Integrated Security=True") Dim comando As New SqlCommand("select * from Clientes", conexion) Dim adaptador As New SqlDataAdapter(comando) Dim dset As New DataSet Try conexion.Open() adaptador.Fill(dset, "Clientes") Dim reporte As New ReportClientes 'nombre del .rpt reporte.SetDataSource(dset.Tables("Clientes")) CrystalReportViewer1.ReportSource = reporte Catch ex As Exception MessageBox.Show("ERROR REPORTE CLIENTES: " & ex.Message) End Try conexion.Close() comando.Dispose() conexion.Dispose() End Sub Private Sub ReporteClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() LabelUsuario.Text = Usuario End Sub Private Sub ButtonVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVolver.Click Dim menu As New MenuPrincipal Me.Hide() menu.Show() End Sub End Class

×