Imports System.Data
Imports System.Data.OleDb
Public Class frmInventario
Dim Referencia As Integer
Dim Acciones As Integer = 0
Dim BaseDeDatos As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & My.Application.Info.DirectoryPath & "\Brayalux1030.accdb")
Private Sub cmdNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNuevo.Click
CajasDeTextos(False)
Botones(False, True)
txtCodigoDelProducto.Focus()
Acciones = 1
End Sub
Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
If MsgBox("¿Desea salir?", vbYesNo, "AVISO") = vbYes Then
Me.Close()
End If
End Sub
Private Sub frmInventario_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MostrarDatosEnGrilla()
CajasDeTextos(True)
Botones(True, False)
End Sub
'Habilitar y Deshabilitar Cajas de Textos
Public Sub CajasDeTextos(ByVal Estado As Boolean)
txtCodigoDelProducto.ReadOnly = Estado
txtConceptoDescripcion.ReadOnly = Estado
txtPrecioUnitario.ReadOnly = Estado
txtExitencia.ReadOnly = Estado
End Sub
'Habilitar y Deshabilitar Botones
Public Sub Botones(ByVal Habilitar As Boolean, ByVal Deshabilitar As Boolean)
cmdNuevo.Enabled = Habilitar
cmdModificar.Enabled = Habilitar
'Boton Grabar Deshabilitado
cmdGrabar.Enabled = Deshabilitar
cmdEliminar.Enabled = Habilitar
'Boton Cancelar Deshabilitado
cmdCancelar.Enabled = Deshabilitar
'Boton Buscar Habilitado
cmdBuscar.Enabled = Habilitar
End Sub
Public Sub LimpiarCajasDeTextos()
txtCodigoDelProducto.Text = ""
txtConceptoDescripcion.Text = ""
txtPrecioUnitario.Text = ""
txtExitencia.Text = ""
txtCodigoDelProducto.Focus()
End Sub
Private Sub cmdCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelar.Click
If MsgBox("¿Esta seguro que desea cancelar?", vbYesNo, "AVISO") = vbYes Then
Botones(True, False)
LimpiarCajasDeTextos()
CajasDeTextos(True)
End If
End Sub
Private Sub cmdGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGrabar.Click
'Validamos las cajas de textos
If txtCodigoDelProducto.Text = "" Then MsgBox("No has ingresado RIF/C.I", vbInformation, "Ingrese RIF/C.I") : txtCodigoDelProducto().Focus() : Exit Sub
If txtConceptoDescripcion.Text = "" Then MsgBox("No has ingresado Razón Social", vbInformation, "Ingrese Razón Social") : txtConceptoDescripcion.Focus() : Exit Sub
If txtPrecioUnitario.Text = "" Then MsgBox("No has ingresado Domicilio Fiscal", vbInformation, "Ingrese Domicilio Fiscal") : txtPrecioUnitario.Focus() : Exit Sub
If txtExitencia.Text = "" Then MsgBox("No has el número de teléfono", vbInformation, "Ingrese número teléfonico") : txtExitencia.Focus() : Exit Sub
'Grabamos
If Acciones = 1 Then
Nuevo()
ElseIf Acciones = 2 Then
Modificar()
End If
CajasDeTextos(True)
Botones(True, False)
LimpiarCajasDeTextos()
End Sub
Private Sub cmdModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdModificar.Click
CajasDeTextos(False)
Botones(False, True)
Acciones = 2
End Sub
Public Sub MostrarDatosEnGrilla()
Dim Datos As New OleDb.OleDbDataAdapter("SELECT * FROM Inventario", BaseDeDatos)
Dim MemoriaInterna As New DataSet
Datos.Fill(MemoriaInterna, "Inventario")
GrillaInventario.DataSource = MemoriaInterna.Tables("Inventario")
'Ocultar campo
GrillaInventario.Columns(0).Width = 0
End Sub
Public Sub Nuevo()
Dim Insertar As New OleDb.OleDbCommand("INSERT INTO Inventario(CodigoDelProducto, ConceptoDescripcion, PrecioUnitario, Existencia) VALUES('" & txtCodigoDelProducto.Text & "','" & txtConceptoDescripcion.Text & "','" & txtPrecioUnitario.Text & "','" & txtExitencia.Text & "')", BaseDeDatos)
BaseDeDatos.Open()
Insertar.ExecuteNonQuery()
BaseDeDatos.Close()
MostrarDatosEnGrilla()
MsgBox("Se ha registrado satisfactoriamente", vbInformation, "El registro tuvo éxito")
End Sub
Public Sub Modificar()
Dim Modificar As New OleDb.OleDbCommand("UPDATE Inventario SET CodigoDelProducto='" & txtCodigoDelProducto.Text & "',ConceptoDescripcion='" & txtConceptoDescripcion.Text & "',PrecioUnitario='" & txtPrecioUnitario.Text & "',Existencia='" & txtExitencia.Text & "' WHERE Referencia='" & Trim(Referencia) & "'", BaseDeDatos)
BaseDeDatos.Open()
Modificar.ExecuteNonQuery()
BaseDeDatos.Close()
MostrarDatosEnGrilla()
MsgBox("Se ha modificado satisfactoriamente", vbInformation, "Se ha actualizado la información")
End Sub
Private Sub GrillaInventario_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GrillaInventario.CellContentClick
Referencia = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
txtReferencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
txtCodigoDelProducto.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(1).Value()
txtConceptoDescripcion.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(2).Value()
txtPrecioUnitario.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(3).Value()
txtExitencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(4).Value()
End Sub
End Class