You are on page 1of 8

CANAL

AGREGANDO VALOR AL MUNDO


LIC. ANTONIO RAMIREZ BOGANTES

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

A CONTINUACIÓN SE DETALLA EL CODIGO VB.NET (Formulario de Clientes) 13-04-2017

Imports​ CapaDatos
Imports​ CapaEntidades
Public​ ​Class​ ​frmClientes
​Dim​ ObjetodeClase_EClientes ​As​ ​New​ ​EntiClientes
​Dim​ ObjetodeClase_FClientes ​As​ ​New​ ​FClientes

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

<System.ComponentModel.​DefaultValue​(F ​ alse​), 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
​' --> Fin --> Procedimienot para cerrar deshabilitar el botón cerrar de nuestra aplicación

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

​Private​ ​Sub​ btnSalir_Click(sender ​As​ ​Object​, e A


​ s​ ​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()
​ nd​ ​Sub
E

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


MetodoLimpiar()
MetodoBotonesInicio()
MetedoDeshabilitarCampos()
​End​ ​Sub
​Sub​ MetodoLimpiar()
txtNombre.Text = ​""
txtApellidos.Text = ​""

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

txtCedula.Text = ​""
txtRazon.Text = ​""
txtContacto.Text = ​""
txtDireccion.Text = ​""
txtEmail.Text = ​""
txttelcasa.Text = ​""
txtteloficina.Text = ​""
txttelmovil.Text = ​""
cmbBuscar.SelectedIndex = 0
dgvClientes.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
dgvClientes.DataSource = vbNull
​End​ ​Sub

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

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


dgvClientes.DataSource = ObjetodeClase_FClientes.ConsultaCliente
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_FClientes.ConsultaCliente)
​If​ cmbBuscar.Text = ​"Nombre"​ ​Then
CopiaTabla.RowFilter = ​"Nombre Like '%"​ & txtBuscar.Text & ​"%'"
dgvClientes.DataSource = vbNull
dgvClientes.DataSource = CopiaTabla.ToTable
​ElseIf​ cmbBuscar.Text = ​"Apellidos"​ ​Then
CopiaTabla.RowFilter = ​"Apellidos Like '%"​ & txtBuscar.Text & ​"%'"
dgvClientes.DataSource = vbNull
dgvClientes.DataSource = CopiaTabla.ToTable
​ElseIf​ cmbBuscar.Text = ​"Cédula"​ ​Then
CopiaTabla.RowFilter = ​"Cedula Like '%"​ & txtBuscar.Text & ​"%'"
dgvClientes.DataSource = vbNull
dgvClientes.DataSource = CopiaTabla.ToTable
​ElseIf​ cmbBuscar.Text = ​"RazónSocial"​ ​Then
CopiaTabla.RowFilter = ​"RazonSocial Like '%"​ & txtBuscar.Text & ​"%'"
dgvClientes.DataSource = vbNull
dgvClientes.DataSource = CopiaTabla.ToTable
​ElseIf​ cmbBuscar.Text = ​"Contacto"​ ​Then

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

CopiaTabla.RowFilter = ​"Contacto Like '%"​ & txtBuscar.Text & ​"%'"


dgvClientes.DataSource = vbNull
dgvClientes.DataSource = CopiaTabla.ToTable
​End​ ​If
​ nd​ ​Sub
E

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


MetodoLlenaClase()
​If​ ObjetodeClase_EClientes.Nombre <> ​""​ ​And​ ObjetodeClase_EClientes.Apellidos <> ​""​ ​Then
​If​ ObjetodeClase_FClientes.AgregarCliente(ObjetodeClase_EClientes) ​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_EClientes.Nombre = txtNombre.Text
ObjetodeClase_EClientes.Apellidos = txtApellidos.Text
ObjetodeClase_EClientes.Cedula = txtCedula.Text
ObjetodeClase_EClientes.Razonsocial = txtRazon.Text
ObjetodeClase_EClientes.Contacto = txtContacto.Text
ObjetodeClase_EClientes.Direccion = txtDireccion.Text
ObjetodeClase_EClientes.Email = txtEmail.Text
ObjetodeClase_EClientes.TelCasa = txttelcasa.Text
ObjetodeClase_EClientes.TelMovil = txttelmovil.Text
ObjetodeClase_EClientes.TelOficina = txtteloficina.Text
ObjetodeClase_EClientes.saldo = txtSaldo.Text
​End​ ​Sub

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

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


​If​ dgvClientes(0, dgvClientes.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
txttelcasa.Enabled = ​True
txtteloficina.Enabled = ​True
txttelmovil.Enabled = ​True
txtSaldo.Enabled = ​True
txtNombre.Text = dgvClientes(1, dgvClientes.CurrentRow.Index).Value
txtApellidos.Text = dgvClientes(2, dgvClientes.CurrentRow.Index).Value
txtCedula.Text = dgvClientes(3, dgvClientes.CurrentRow.Index).Value
txtRazon.Text = dgvClientes(4, dgvClientes.CurrentRow.Index).Value
txtContacto.Text = dgvClientes(5, dgvClientes.CurrentRow.Index).Value
txtDireccion.Text = dgvClientes(6, dgvClientes.CurrentRow.Index).Value
txtEmail.Text = dgvClientes(7, dgvClientes.CurrentRow.Index).Value
txttelcasa.Text = dgvClientes(8, dgvClientes.CurrentRow.Index).Value
txtteloficina.Text = dgvClientes(9, dgvClientes.CurrentRow.Index).Value
txttelmovil.Text = dgvClientes(10, dgvClientes.CurrentRow.Index).Value
txtSaldo.Text = dgvClientes(11, dgvClientes.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_EClientes.IdCliente = dgvClientes(0, dgvClientes.CurrentRow.Index).Value
​If​ ObjetodeClase_EClientes.Nombre <> ​""​ ​And​ ObjetodeClase_EClientes.Apellidos <> ​""​ ​Then

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

​If​ ObjetodeClase_FClientes.ModificarClientes(ObjetodeClase_EClientes) ​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
​ nd​ ​Sub
E

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


ObjetodeClase_EClientes.IdCliente = dgvClientes(0, dgvClientes.CurrentRow.Index).Value
ObjetodeClase_EClientes.Nombre = dgvClientes(1, dgvClientes.CurrentRow.Index).Value
​If​ ​MessageBox​.Show(​"¿Realmente desea eliminar el registro: ["​ & ObjetodeClase_EClientes.Nombre & ​"]?"​, ​"Mensajes del Sistema"​, ​MessageBoxButtons​.YesNo,
MessageBoxIcon​.Question) ​Then
​If​ ObjetodeClase_FClientes.EliminarClientes(ObjetodeClase_EClientes) ​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

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


MetodoLimpiar()
MetodoBotonesInicio()
MetedoDeshabilitarCampos()
​End​ ​Sub

End​ ​Class

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


CANAL
AGREGANDO VALOR AL MUNDO
LIC. ANTONIO RAMIREZ BOGANTES

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

Realizado por: Lic. Antonio Ramírez BogantesPágina 8

You might also like