Sei sulla pagina 1di 7

CANAL

AGREGANDO VALOR AL MUNDO


LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

A CONTINUACIÓN SE DETALLA EL CODIGO VB.NET (Formulario de Proveedores)

Imports CapaDatos
Imports CapaEntidades
Public Class frmProveedores
Dim ObjetodeClase_EProveedores As New EntiProveedores
Dim ObjetodeClase_FProveedores As New FProveedor

' --> Inicio --> Procedimienot para cerrar deshabilitar el botón cerrar de nuestra aplicación
Dim _enabledCerrar As Boolean = False

<System.ComponentModel.DefaultValue(False), System.ComponentModel.Description("Define si se habilita el botón cerrar en el formulario")> _


Public Property EnabledCerrar() As Boolean
Get
Return _enabledCerrar
End Get
Set(ByVal Value As Boolean)
If _enabledCerrar <> Value Then
_enabledCerrar = Value
End If
End Set
End Property
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
If _enabledCerrar = False Then
Const CS_NOCLOSE As Integer = &H200
cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
End If
Return cp
End Get
End Property

Realizado por: Lic. Antonio Ramírez Bogantes Página 1


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

' --> Fin --> Procedimienot para cerrar deshabilitar el botón cerrar de nuestra aplicación
Private Sub frmProveedores_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MetodoLimpiar()
MetodoBotonesInicio()
MetedoDeshabilitarCampos()
End Sub

Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click


Me.Close()
End Sub

Private Sub btnNuevo_Click(sender As Object, e As EventArgs) Handles btnNuevo.Click


MetodoNuevo()
End Sub
Sub MetodoNuevo()
txtNombre.Enabled = True
txtApellidos.Enabled = True
txtCedula.Enabled = True
txtRazon.Enabled = True
txtContacto.Enabled = True
txtDireccion.Enabled = True
txtEmail.Enabled = True
txttelcasa.Enabled = True
txtteloficina.Enabled = True
txttelmovil.Enabled = True
txtSaldo.Enabled = True

cmbBuscar.Enabled = True
txtBuscar.Enabled = True
btnNuevo.Enabled = False
btnGrabar.Enabled = True
btnBuscar.Enabled = False
txtNombre.Focus()
End Sub

Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click


MetodoLimpiar()
MetodoBotonesInicio()
MetedoDeshabilitarCampos()
End Sub

Realizado por: Lic. Antonio Ramírez Bogantes Página 2


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

Sub MetodoLimpiar()
txtNombre.Text = ""
txtApellidos.Text = ""
txtCedula.Text = ""
txtRazon.Text = ""
txtContacto.Text = ""
txtDireccion.Text = ""
txtEmail.Text = ""
txttelcasa.Text = ""
txtteloficina.Text = ""
txttelmovil.Text = ""
cmbBuscar.SelectedIndex = 0
dgvProveedores.DataSource = vbNull
btnNuevo.Enabled = True
btnNuevo.Focus()
End Sub
Sub MetodoBotonesInicio()
btnModificar.Enabled = False
btnEliminar.Enabled = False
btnGrabar.Enabled = False
btnNuevo.Enabled = True
btnBuscar.Enabled = True
End Sub
Sub MetedoDeshabilitarCampos()
txtNombre.Enabled = False
txtApellidos.Enabled = False
txtCedula.Enabled = False
txtRazon.Enabled = False
txtContacto.Enabled = False
txtContacto.Enabled = False
txtDireccion.Enabled = False
txtEmail.Enabled = False
txttelcasa.Enabled = False
txtteloficina.Enabled = False
txttelmovil.Enabled = False
txtSaldo.Enabled = False
cmbBuscar.Enabled = False
txtBuscar.Enabled = False
dgvProveedores.DataSource = vbNull
End Sub

Realizado por: Lic. Antonio Ramírez Bogantes Página 3


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

Private Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click


dgvProveedores.DataSource = ObjetodeClase_FProveedores.ConsultaProveedor
MetodoBuscar()
End Sub
Sub MetodoBuscar()
btnNuevo.Enabled = False
btnModificar.Enabled = False
btnEliminar.Enabled = False
btnBuscar.Enabled = False
btnGrabar.Enabled = False
MetedoDeshabilitarCampos()
cmbBuscar.Enabled = True
txtBuscar.Enabled = True
cmbBuscar.SelectedIndex = 0
txtBuscar.Focus()
End Sub
Private Sub txtBuscar_TextChanged(sender As Object, e As EventArgs) Handles txtBuscar.TextChanged
Dim CopiaTabla As New DataView(ObjetodeClase_FProveedores.ConsultaProveedor)
If cmbBuscar.Text = "Nombre" Then
CopiaTabla.RowFilter = "Nombre Like '%" & txtBuscar.Text & "%'"
dgvProveedores.DataSource = vbNull
dgvProveedores.DataSource = CopiaTabla.ToTable
ElseIf cmbBuscar.Text = "Apellidos" Then
CopiaTabla.RowFilter = "Apellidos Like '%" & txtBuscar.Text & "%'"
dgvProveedores.DataSource = vbNull
dgvProveedores.DataSource = CopiaTabla.ToTable
ElseIf cmbBuscar.Text = "Cédula" Then
CopiaTabla.RowFilter = "Cedula Like '%" & txtBuscar.Text & "%'"
dgvProveedores.DataSource = vbNull
dgvProveedores.DataSource = CopiaTabla.ToTable
ElseIf cmbBuscar.Text = "RazónSocial" Then
CopiaTabla.RowFilter = "RazonSocial Like '%" & txtBuscar.Text & "%'"
dgvProveedores.DataSource = vbNull
dgvProveedores.DataSource = CopiaTabla.ToTable
ElseIf cmbBuscar.Text = "Contacto" Then
CopiaTabla.RowFilter = "Contacto Like '%" & txtBuscar.Text & "%'"
dgvProveedores.DataSource = vbNull
dgvProveedores.DataSource = CopiaTabla.ToTable
End If
End Sub

Realizado por: Lic. Antonio Ramírez Bogantes Página 4


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles btnGrabar.Click


MetodoLlenaClase()
If ObjetodeClase_EProveedores.Nombre <> "" And ObjetodeClase_EProveedores.Apellidos <> "" Then
If ObjetodeClase_FProveedores.AgregarProveedor(ObjetodeClase_EProveedores) Then
MessageBox.Show("Registro grabado correctamente, gracias....", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Error al grabar el registro, contacte con su administrador de sistema....", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else
MessageBox.Show("No puede grabar el registro, favor ingresar al menos el nombre y los apellidos", "Mensaje del sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtNombre.Focus()
End If
MetodoLimpiar()
MetodoBotonesInicio()
End Sub
Sub MetodoLlenaClase()
ObjetodeClase_EProveedores.Nombre = txtNombre.Text
ObjetodeClase_EProveedores.Apellidos = txtApellidos.Text
ObjetodeClase_EProveedores.Cedula = txtCedula.Text
ObjetodeClase_EProveedores.Razonsocial = txtRazon.Text
ObjetodeClase_EProveedores.Contacto = txtContacto.Text
ObjetodeClase_EProveedores.Direccion = txtDireccion.Text
ObjetodeClase_EProveedores.Email = txtEmail.Text
ObjetodeClase_EProveedores.TelCasa = txttelcasa.Text
ObjetodeClase_EProveedores.TelMovil = txttelmovil.Text
ObjetodeClase_EProveedores.TelOficina = txtteloficina.Text
ObjetodeClase_EProveedores.saldo = txtSaldo.Text
End Sub

Private Sub dgvProveedores_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvProveedores.CellDoubleClick


If dgvProveedores(0, dgvProveedores.CurrentRow.Index).Value <> 0 Then
' encender las cajas de texto
txtNombre.Enabled = True
txtApellidos.Enabled = True
txtCedula.Enabled = True
txtRazon.Enabled = True
txtContacto.Enabled = True
txtDireccion.Enabled = True
txtEmail.Enabled = True

Realizado por: Lic. Antonio Ramírez Bogantes Página 5


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

txttelcasa.Enabled = True
txtteloficina.Enabled = True
txttelmovil.Enabled = True
txtSaldo.Enabled = True
txtNombre.Text = dgvProveedores(1, dgvProveedores.CurrentRow.Index).Value
txtApellidos.Text = dgvProveedores(2, dgvProveedores.CurrentRow.Index).Value
txtCedula.Text = dgvProveedores(3, dgvProveedores.CurrentRow.Index).Value
txtRazon.Text = dgvProveedores(4, dgvProveedores.CurrentRow.Index).Value
txtContacto.Text = dgvProveedores(5, dgvProveedores.CurrentRow.Index).Value
txtDireccion.Text = dgvProveedores(6, dgvProveedores.CurrentRow.Index).Value
txtEmail.Text = dgvProveedores(7, dgvProveedores.CurrentRow.Index).Value
txttelcasa.Text = dgvProveedores(8, dgvProveedores.CurrentRow.Index).Value
txtteloficina.Text = dgvProveedores(9, dgvProveedores.CurrentRow.Index).Value
txttelmovil.Text = dgvProveedores(10, dgvProveedores.CurrentRow.Index).Value
txtSaldo.Text = dgvProveedores(11, dgvProveedores.CurrentRow.Index).Value
btnEliminar.Enabled = True
btnModificar.Enabled = True
btnBuscar.Enabled = False
cmbBuscar.Enabled = False
txtBuscar.Enabled = False
End If
End Sub

Private Sub btnModificar_Click(sender As Object, e As EventArgs) Handles btnModificar.Click


MetodoLlenaClase()
ObjetodeClase_EProveedores.IdProveedor = dgvProveedores(0, dgvProveedores.CurrentRow.Index).Value
If ObjetodeClase_EProveedores.Nombre <> "" And ObjetodeClase_EProveedores.Apellidos <> "" Then
If ObjetodeClase_FProveedores.ModificarProveedor(ObjetodeClase_EProveedores) Then
MessageBox.Show("Registro fue modificado correctamente, gracias....", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Error al Modificar el registro, contacte con su administrador de sistema....", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else
MessageBox.Show("No puede Modificar el registro, consultar con su administrador de sistema...", "Mensaje del sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtNombre.Focus()
End If
End Sub

Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click


ObjetodeClase_EProveedores.IdProveedor = dgvProveedores(0, dgvProveedores.CurrentRow.Index).Value
ObjetodeClase_EProveedores.Nombre = dgvProveedores(1, dgvProveedores.CurrentRow.Index).Value

Realizado por: Lic. Antonio Ramírez Bogantes Página 6


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

COSTA RICA
CÓDIGO VISUAL BASIC .NET
Formulario de Proveedores

If MessageBox.Show("¿Realmente desea eliminar el registro: [" & ObjetodeClase_EProveedores.Nombre & "]?", "Mensajes del Sistema", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Then
If ObjetodeClase_FProveedores.EliminarProveedor(ObjetodeClase_EProveedores) Then
MessageBox.Show("el registro fue eliminado correctamente", "Mensajes del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
MessageBox.Show("El registro no ha sido eliminado", "Mensajes del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning)
MetodoLimpiar()
MetedoDeshabilitarCampos()
MetodoLimpiar()
MetodoBotonesInicio()
End If
End Sub
End Class

Realizado por: Lic. Antonio Ramírez Bogantes Página 7

Potrebbero piacerti anche