This document contains code for a sales system application in Visual Basic. It includes code for forms to manage clients, products, invoices and users. It allows adding, editing, deleting and searching records in databases. It also includes code to launch other applications like Word, Excel and Calculator from the main form.
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Sistema de ventas
1. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Sistema de Ventas
Form1.vb
Public Class Form1
Private Sub MantenimientoDeClientesToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MantenimientoDeClientesToolStripMenuItem.Click
Dim frm As New FRMCLIENTES
frm.MdiParent = Me
frm.Show()
End Sub
Private Sub MantenimientoDeProdutosToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MantenimientoDeProdutosToolStripMenuItem.Click
Dim frm As New frmPoductos
frm.MdiParent = Me
frm.Show()
End Sub
Private Sub CascadaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CascadaToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub MosaicoHorizontalToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MosaicoHorizontalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub MosaicoVerticalToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MosaicoVerticalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileVertical)
2. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
End Sub
Private Sub AcercaDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AcercaDeToolStripMenuItem.Click
Dim frm As New Acercade
frm.MdiParent = Me
frm.Show()
End Sub
Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SalirToolStripMenuItem.Click
If MessageBox.Show("¿Desea Salir de la aplicación?", "Systms Test",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes
Then
Me.Close()
End If
End Sub
Private Sub MantenimientoDeBoletasToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MantenimientoDeBoletasToolStripMenuItem.Click
Dim frm As New frmBoleta
frm.MdiParent = Me
frm.Show()
End Sub
Private Sub CalculadoraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CalculadoraToolStripMenuItem.Click
Dim proceso As New Process
proceso.StartInfo.FileName = "calc.exe"
proceso.StartInfo.Arguments = ""
proceso.Start()
End Sub
Private Sub WordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles WordToolStripMenuItem.Click
Dim proceso As New Process
proceso.StartInfo.FileName = "winword.exe"
proceso.StartInfo.Arguments = ""
proceso.Start()
End Sub
Private Sub EcxelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles EcxelToolStripMenuItem.Click
Dim proceso As New Process
proceso.StartInfo.FileName = "excel.exe"
proceso.StartInfo.Arguments = ""
proceso.Start()
End Sub
Private Sub UsuariosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles UsuariosToolStripMenuItem.Click
Dim frm As New frmUsuarios
frm.MdiParent = Me
frm.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim myfrm As New frmAcceso
myfrm.ShowDialog()
End Sub
Private Sub ApellidoClienteToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ApellidoClienteToolStripMenuItem.Click
Dim frm As New frmBoletas_Clientes
frm.MdiParent = Me
3. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
frm.Show()
End Sub
Private Sub FechasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FechasToolStripMenuItem.Click
Dim frm As New frmBuscarxfecha
frm.MdiParent = Me
frm.Show()
End Sub
End Class
Frmclientes.vb
Imports System.Data.SqlClient
Public Class FRMCLIENTES
Private oDataAdapter As SqlDataAdapter
Private oDataTable As DataTable
Private oConnection As SqlConnection
Private oDataRow As DataRow
Private oCommandBuilder As SqlCommandBuilder
Private PosFilaAct As Integer
Private vNuevo As Boolean
Private Sub Activa_Desactiva(ByVal sw As Boolean)
gbdatos.Enabled = Not sw
Me.btnGuardar.Enabled = Not sw
Me.btnNuevo.Enabled = sw
Me.btnEditar.Enabled = sw
Me.btnEliminar.Enabled = sw
Me.btnImprimir.Enabled = sw
Me.dtgclientes.Enabled = sw
End Sub
Private Sub CargarDatos()
Try
Me.oDataRow = Me.oDataTable.Rows(Me.PosFilaAct)
Me.txtid.Text = oDataRow("ID_CLIENTE")
Me.txtnom.Text = oDataRow("NOM_CLIENTE")
Me.txtape.Text = oDataRow("APE_CIENTE")
4. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Me.txtdni.Text = oDataRow("DNI_CLIENTE")
Me.txtruc.Text = oDataRow("RUC_CLIENTE")
Me.txttele.Text = oDataRow("TELEFONO_CLIENTE")
Me.txtdomicilio.Text = oDataRow("DOMICILIO_CLIENTE")
Catch ex As Exception
MessageBox.Show("Error" & Chr(13) & "No existen registros", "Cargar datos",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub FRMCLIENTES_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
oConnection = New
SqlConnection("server=.SQLEXPRESS;database=DB_VENTAS;integrated security=yes")
oCommandBuilder = New SqlCommandBuilder(Me.oDataAdapter)
oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES", oConnection)
oDataTable = New DataTable
oDataAdapter.Fill(oDataTable)
dtgclientes.DataSource = oDataTable
Me.dtgclientes.AllowUserToAddRows = False
Me.dtgclientes.AllowUserToDeleteRows = False
Me.CargarDatos()
Me.Activa_Desactiva(True)
End Sub
Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNuevo.Click
For Each objControl As Control In Me.gbdatos.Controls
If TypeOf objControl Is TextBox Then
objControl.Text = ""
End If
Next
vNuevo = True
Activa_Desactiva(False)
Me.txtnom.Focus()
End Sub
Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
Try
For Each objControl As Control In Me.gbdatos.Controls
If (TypeOf objControl Is TextBox) And objControl.Text = "" _
And Not objControl.Name = "txtid" Then
MessageBox.Show("Error faltan datos en" & Chr(13) & _
objControl.Name, "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Exit Sub
End If
Next
If MessageBox.Show("¿Desea guardar registro actual?", "Guardar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If vNuevo Then
oDataRow = Me.oDataTable.NewRow
End If
'oDataRow("ID_CLIENTE") = Me.txtid.Text
oDataRow("NOM_CLIENTE") = Me.txtnom.Text
oDataRow("APE_CIENTE") = Me.txtape.Text
oDataRow("DNI_CLIENTE") = Me.txtdni.Text
oDataRow("RUC_CLIENTE") = Me.txtruc.Text
oDataRow("TELEFONO_CLIENTE") = Me.txttele.Text
oDataRow("DOMICILIO_CLIENTE") = Me.txtdomicilio.Text
5. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
If vNuevo Then
Me.oDataTable.Rows.Add(Me.oDataRow)
Me.PosFilaAct = (Me.oDataTable.Rows.Count - 1)
End If
oCommandBuilder.DataAdapter = Me.oDataAdapter
Me.oDataAdapter.Update(Me.oDataTable)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
MessageBox.Show("Datos Guardados", "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("No se guardó el registro", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Activa_Desactiva(True)
Me.CargarDatos()
Catch ex As Exception
MessageBox.Show("Error al intentar guardar registro" & Chr(13) & ex.Message,
"Guardar", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditar.Click
MessageBox.Show("Proceda con la edición del registro actual", "Edición",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Activa_Desactiva(False)
vNuevo = False
Me.txtnom.Focus()
End Sub
Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminar.Click
Try
If Me.oDataTable.Rows.Count > 0 Then
If MessageBox.Show("¿Desea eliminar registro actual?", "Eliminar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim strDeleteSQL As String
Dim oSQLCommand As New SqlCommand
strDeleteSQL = "Delete From TB_CLIENTES where ID_CLIENTE =" &
CInt(Me.txtid.Text)
Me.oConnection.Open()
oSQLCommand.Connection = Me.oConnection
oSQLCommand.CommandText = strDeleteSQL
oSQLCommand.ExecuteNonQuery()
Me.oConnection.Close()
Me.PosFilaAct = IIf(Me.PosFilaAct > 0, Me.PosFilaAct - 1, 0)
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES",
Me.oConnection)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
Me.CargarDatos()
End If
Else
MessageBox.Show("No existen registros para eliminar", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show("Error para eliminar", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Try
End Sub
6. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub dtgclientes_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgclientes.CellClick
If Not Me.dtgclientes.Item(0, Me.dtgclientes.CurrentRow.Index).Value Is
DBNull.Value Then
Me.PosFilaAct = Me.dtgclientes.CurrentRow.Index
Me.CargarDatos()
End If
End Sub
Private Sub txtnom_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtnom.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.txtape.Focus()
End If
End Sub
Private Sub txtape_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtape.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.txtdni.Focus()
End If
End Sub
Private Sub txtdni_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtdni.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.txtruc.Focus()
End If
End Sub
Private Sub txtruc_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtruc.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.txttele.Focus()
End If
End Sub
Private Sub txttele_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txttele.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.txtdomicilio.Focus()
End If
End Sub
Private Sub txtdomicilio_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtdomicilio.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.btnGuardar.Focus()
End If
End Sub
Private Sub txtbape_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbape.KeyPress
sololetras(e)
End Sub
Private Sub txtbape_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbape.TextChanged
Try
Me.oDataTable.Clear()
If txtbape.Text <> "" Then
7. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES where
APE_CIENTE like'" _
& txtbape.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
Private Sub txtbruc_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbruc.KeyPress
solonumeros(e)
End Sub
Private Sub txtbruc_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbruc.TextChanged
Try
Me.oDataTable.Clear()
If txtbruc.Text <> "" Then
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES where
RUC_CLIENTE like'" _
& txtbruc.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
Private Sub txtbdni_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbdni.KeyPress
solonumeros(e)
End Sub
Private Sub txtbdni_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbdni.TextChanged
Try
Me.oDataTable.Clear()
If txtbdni.Text <> "" Then
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES where
DNI_CLIENTE like'" _
& txtbdni.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_CLIENTES",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImprimir.Click
Dim myreport As New rtpclientes
myreport.SetDataSource(Me.oDataTable)
Dim myfrom As New frm_Reporte_clientes
myfrom.crvclientes.ReportSource = myreport
myfrom.WindowState = FormWindowState.Maximized
myfrom.ShowDialog()
8. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
End Sub
End Class
Frmproductos.vb
Imports System.Data.SqlClient
Public Class frmPoductos
Private oDataAdapter As SqlDataAdapter
Private oDataTable As DataTable
Private oConnection As SqlConnection
Private oDataRow As DataRow
Private oCommandBuilder As SqlCommandBuilder
Private PosFilaAct As Integer
Private vNuevo As Boolean
Private Sub Activa_Desactiva(ByVal sw As Boolean)
gbDatos.Enabled = Not sw
Me.btnGuardar.Enabled = Not sw
Me.btnNuevo.Enabled = sw
Me.btnEditar.Enabled = sw
Me.btnEliminar.Enabled = sw
Me.btnImprimir.Enabled = sw
Me.dtgprductos.Enabled = sw
End Sub
Private Sub CargarDatos()
Try
Me.oDataRow = Me.oDataTable.Rows(Me.PosFilaAct)
Me.txtid.Text = oDataRow("ID_PRODUCTO")
Me.txtnom.Text = oDataRow("NOM_PRODUCTO")
Me.txtpc.Text = oDataRow("PRE_COMPRA_PRODUCTO")
Me.txtpv.Text = oDataRow("PRE_VENTA_PRODUCTO")
Me.txtstock.Text = oDataRow("STOCK_PRDUCTO")
Me.dtpfa.Text = oDataRow("FECHA_ACTUALIZACION_PRODUCTO")
9. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Catch ex As Exception
MessageBox.Show("Error" & Chr(13) & "No existen registros", "Cargar datos",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub frmPoductos_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
oConnection = New
SqlConnection("server=.SQLEXPRESS;database=DB_VENTAS;integrated security=yes")
oCommandBuilder = New SqlCommandBuilder(Me.oDataAdapter)
oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS", oConnection)
oDataTable = New DataTable
oDataAdapter.Fill(oDataTable)
dtgprductos.DataSource = oDataTable
Me.dtgprductos.AllowUserToAddRows = False
Me.dtgprductos.AllowUserToDeleteRows = False
Me.CargarDatos()
Me.Activa_Desactiva(True)
End Sub
Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNuevo.Click
For Each objControl As Control In Me.gbdatos.Controls
If TypeOf objControl Is TextBox Then
objControl.Text = ""
End If
Next
vNuevo = True
Activa_Desactiva(False)
Me.txtnom.Focus()
End Sub
Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
Try
For Each objControl As Control In Me.gbdatos.Controls
If (TypeOf objControl Is TextBox) And objControl.Text = "" _
And Not objControl.Name = "txtid" Then
MessageBox.Show("Error faltan datos en" & Chr(13) & _
objControl.Name, "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Exit Sub
End If
Next
If MessageBox.Show("¿Desea guardar registro actual?", "Guardar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If vNuevo Then
oDataRow = Me.oDataTable.NewRow
End If
'oDataRow("ID_PRODUCTO") = Me.txtid.Text
oDataRow("NOM_PRODUCTO") = Me.txtnom.Text
oDataRow("PRE_COMPRA_PRODUCTO") = Me.txtpc.Text
oDataRow("PRE_VENTA_PRODUCTO") = Me.txtpv.Text
oDataRow("STOCK_PRDUCTO") = Me.txtstock.Text
oDataRow("FECHA_ACTUALIZACION_PRODUCTO") = Me.dtpfa.Text
If vNuevo Then
Me.oDataTable.Rows.Add(Me.oDataRow)
Me.PosFilaAct = (Me.oDataTable.Rows.Count - 1)
10. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
End If
oCommandBuilder.DataAdapter = Me.oDataAdapter
Me.oDataAdapter.Update(Me.oDataTable)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
MessageBox.Show("Datos Guardados", "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("No se guardó el registro", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Activa_Desactiva(True)
Me.CargarDatos()
Catch ex As Exception
MessageBox.Show("Error al intentar guardar registro" & Chr(13) & ex.Message,
"Guardar", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditar.Click
MessageBox.Show("Proceda con la edición del registro actual", "Edición",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Activa_Desactiva(False)
vNuevo = False
Me.txtnom.Focus()
End Sub
Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminar.Click
Try
If Me.oDataTable.Rows.Count > 0 Then
If MessageBox.Show("¿Desea eliminar registro actual?", "Eliminar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim strDeleteSQL As String
Dim oSQLCommand As New SqlCommand
strDeleteSQL = "Delete From TB_PRODUCTOS where ID_PRODUCTO =" &
CInt(Me.txtid.Text)
Me.oConnection.Open()
oSQLCommand.Connection = Me.oConnection
oSQLCommand.CommandText = strDeleteSQL
oSQLCommand.ExecuteNonQuery()
Me.oConnection.Close()
Me.PosFilaAct = IIf(Me.PosFilaAct > 0, Me.PosFilaAct - 1, 0)
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS",
Me.oConnection)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
Me.CargarDatos()
End If
Else
MessageBox.Show("No existen registros para eliminar", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show("Error para eliminar", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Try
End Sub
Private Sub dtgprductos_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgprductos.CellClick
If Not Me.dtgprductos.Item(0, Me.dtgprductos.CurrentRow.Index).Value Is
DBNull.Value Then
Me.PosFilaAct = Me.dtgprductos.CurrentRow.Index
11. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Me.CargarDatos()
End If
End Sub
Private Sub txtbnom_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbnom.KeyPress
sololetras(e)
End Sub
Private Sub txtbnom_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbnom.TextChanged
Try
Me.oDataTable.Clear()
If txtbnom.Text <> "" Then
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS where
NOM_PRODUCTO like'" _
& txtbnom.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
Private Sub txtbstock_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbstock.KeyPress
solonumeros(e)
End Sub
Private Sub txtbstock_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbstock.TextChanged
Try
Me.oDataTable.Clear()
If txtbstock.Text <> "" Then
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS where
STOCK_PRDUCTO like'" _
& txtbstock.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_PRODUCTOS",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
Private Sub txtnom_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtnom.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.txtpc.Focus()
End If
End Sub
Private Sub txtpc_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtpc.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.txtpv.Focus()
End If
End Sub
12. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub txtpv_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtpv.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.txtstock.Focus()
End If
End Sub
Private Sub txtstock_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtstock.KeyPress
solonumeros(e)
If e.KeyChar() = Chr(13) Then
Me.dtpfa.Focus()
End If
End Sub
Private Sub dtpfa_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles dtpfa.KeyPress
If e.KeyChar() = Chr(13) Then
Me.btnGuardar.Focus()
End If
End Sub
Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImprimir.Click
Dim myreport As New rptproductos
myreport.SetDataSource(Me.oDataTable)
Dim myfrom As New frmReporte_Productos
myfrom.cvproductos.ReportSource = myreport
myfrom.WindowState = FormWindowState.Maximized
myfrom.ShowDialog()
End Sub
End Class
acercade.vb
Public NotInheritable Class Acercade
13. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OKButton.Click
Me.Close()
End Sub
End Class
frmBoleta.vb
Imports System.Data.SqlClient
Public Class frmBoleta
Private oconnection As SqlConnection
Private oDTDBtmp As DataTable 'tabla temporal para manejar items
Private Sub Activar_Desactivar(ByVal sw As Boolean)
Me.btnBCliente.Enabled = sw
Me.btnAgregarItem.Enabled = sw
Me.btnEliminarItem.Enabled = sw
Me.btnGuardarBoleta.Enabled = sw
Me.btnImprimir.Enabled = sw
Me.btnNBoleta.Enabled = Not sw
End Sub
Private Sub Crear_Tabla_temporal()
oDTDBtmp = New DataTable("tbDetalle_Boleta_Temporal") 'crear tabla temporal
Me.dtgDetalle_Boleta.DataSource = oDTDBtmp 'asignar el datasource del tdgddetalle
With oDTDBtmp.Columns
.Add("ID_Producto", Type.GetType("System.Int32"))
.Add("Cantidad", Type.GetType("System.Int32"))
.Add("Descripcion", Type.GetType("System.String"))
14. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
.Add("Precio", Type.GetType("System.Single"))
.Add("Importe", Type.GetType("System.Single"))
End With
Me.dtgDetalle_Boleta.Columns(0).Visible = False
oDTDBtmp.PrimaryKey = New DataColumn() {oDTDBtmp.Columns("ID_Producto")}
End Sub
Private Sub frmBoleta_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Me.oconnection = New
SqlConnection("server=.sqlexpress;database=DB_VENTAS;Integrated security=true")
Me.Crear_Tabla_temporal()
Me.dtpfecha.Value = Now
Activar_Desactivar(False)
Catch ex As Exception
MessageBox.Show("Error al cargar datos" & Chr(13) & ex.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.Activar_Desactivar(False)
End Sub
Private Sub btnBCliente_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBCliente.Click
Dim myfrm As New frmAgregar_Clientes
Dim respuesta As Windows.Forms.DialogResult = myfrm.ShowDialog
If respuesta = Windows.Forms.DialogResult.OK Then
If myfrm.dtgClientes.RowCount > 0 Then
Dim filaAct As Integer = myfrm.dtgClientes.CurrentRow.Index
Me.txtid.Text = myfrm.dtgClientes.Item(0, filaAct).Value
Me.txtnom.Text = myfrm.dtgClientes.Item(1, filaAct).Value
Me.txtape.Text = myfrm.dtgClientes.Item(2, filaAct).Value
Me.txtdomicilio.Text = myfrm.dtgClientes.Item(6, filaAct).Value
Me.txtdni.Text = myfrm.dtgClientes.Item(5, filaAct).Value
Else
MessageBox.Show("No existe Cliente Seleccionado", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
Dim objcontrol As Control
Dim txttexbox As TextBox
' for each para que no puedan cambiar sus datos que sea solo lectura
For Each objcontrol In Me.gbCliente.Controls
If TypeOf objcontrol Is TextBox Then
txttexbox = objcontrol
txttexbox.ReadOnly = True
End If
Next objcontrol
End Sub
Private Sub Calcular_Totales()
'actualizar totales
Dim vtotal As Single
vtotal = IIf(oDTDBtmp.Compute("Sum(Importe)", Nothing) Is DBNull.Value, 0,
oDTDBtmp.Compute("Sum(Importe)", Nothing))
Me.txtTotal_Boleta.Text = Format(vtotal, "###0.00")
Me.txtSon.Text = Letras(Val(Me.txtTotal_Boleta.Text)).ToUpper
End Sub
Private Sub btnNBoleta_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNBoleta.Click
Dim oDTBoleta As DataTable
Dim oDABoleta As SqlDataAdapter
15. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Activar_Desactivar(True)
Dim objcontrol As Control
For Each objcontrol In Me.gbCliente.Controls
If TypeOf objcontrol Is TextBox Then
objcontrol.Text = ""
End If
Next
Me.txtidboleta.Text = ""
Me.txtTotal_Boleta.Text = ""
Me.txtSon.Text = ""
Me.Crear_Tabla_temporal()
oDTBoleta = New DataTable("TB_BOLETAS")
oDABoleta = New SqlDataAdapter("select * from TB_BOLETAS", oconnection)
oDABoleta.Fill(oDTBoleta)
Dim N_Boleta As String
If oDTBoleta.Rows.Count > 0 Then
Dim oDatarow = oDTBoleta.Rows(oDTBoleta.Rows.Count - 1)
N_Boleta = oDatarow(0)
Else
N_Boleta = 0
End If
Me.txtidboleta.Text = Format(CInt(N_Boleta) + 1, "0000000000")
End Sub
Private Sub btnAgregarItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAgregarItem.Click
Dim myform As New frmAgregar_Producto
Dim respuesta As Windows.Forms.DialogResult = myform.ShowDialog
Try
If respuesta = Windows.Forms.DialogResult.OK Then
Dim odatarow As DataRow
odatarow = oDTDBtmp.NewRow
odatarow(0) = myform.txtId_Producto.Text
odatarow(1) = myform.nudCantidad.Text
odatarow(2) = myform.txtDescripcion_Pro.Text
odatarow(3) = myform.txtPrecio.Text
odatarow(4) = myform.txtImporte.Text
oDTDBtmp.Rows.Add(odatarow)
oDTDBtmp.AcceptChanges()
Me.Calcular_Totales()
End If
Catch ex As Exception
MessageBox.Show("Error al agregar item" & ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
myform.Dispose()
Dim objcontrol As Control
Dim txttexbox As TextBox
' for each para que no puedan cambiar sus datos que sea solo lectura
For Each objcontrol In Me.Panel2.Controls
If TypeOf objcontrol Is TextBox Then
txttexbox = objcontrol
txttexbox.ReadOnly = True
End If
Next objcontrol
End Sub
Private Sub btnEliminarItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminarItem.Click
Try
If oDTDBtmp.Rows.Count > 0 Then
Dim oDataRow As DataRow
oDataRow = oDTDBtmp.Rows(Me.dtgDetalle_Boleta.CurrentRow.Index)
oDTDBtmp.Rows.Remove(oDataRow)
16. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Me.Calcular_Totales()
Else
MessageBox.Show("No existen items ", "error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show("error al eliminar item " & Chr(13) & ex.Message, "error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnGuardarBoleta_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardarBoleta.Click
Dim oDADetalleBoleta, oDABoleta As SqlDataAdapter
Dim oDTDetalleBoleta, oDTBoleta As DataTable
Dim oCommandBuilder As New SqlCommandBuilder
If MessageBox.Show("¿Desea guardar registro actual ?", "guardar ",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'----------------------------------------------------------------------------
--------------------
If Me.txtid.Text = "" Then
MessageBox.Show("Debe seleccionar un cliente ", "error",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.btnBCliente_Click(Nothing, Nothing)
Exit Sub
End If
If Me.oDTDBtmp.Rows.Count <= 0 Then
MessageBox.Show("no se agregaron productos", "Guardar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.btnAgregarItem_Click(Nothing, Nothing)
Exit Sub
End If
oDTBoleta = New DataTable("TB_BOLETAS")
oDABoleta = New SqlDataAdapter("Select * from TB_BOLETAS", Me.oconnection)
oDABoleta.Fill(oDTBoleta)
Dim oDataRowBoleta As DataRow
oDataRowBoleta = oDTBoleta.NewRow
oDataRowBoleta("ID_BOLETA") = Me.txtidboleta.Text
oDataRowBoleta("ID_CLIENTE") = CInt(Me.txtid.Text)
oDataRowBoleta("FECHA_BOLETA") = Now
oDataRowBoleta("TOTAL_BOLETA") = Me.txtTotal_Boleta.Text
oDTBoleta.Rows.Add(oDataRowBoleta)
Dim oDataRowDetalleBoleta As DataRow
oDTDetalleBoleta = New DataTable("TB_DT_BOLETAS")
oDADetalleBoleta = New SqlDataAdapter("select * FROM TB_DT_BOLETAS",
oconnection)
oDADetalleBoleta.Fill(oDTDetalleBoleta)
If Me.dtgDetalle_Boleta.RowCount > 0 Then
Dim i As Integer
For i = 0 To Me.dtgDetalle_Boleta.RowCount - 1
oDataRowDetalleBoleta = oDTDetalleBoleta.NewRow
oDataRowDetalleBoleta("ID_BOLETA") = Me.txtidboleta.Text
oDataRowDetalleBoleta("ID_PRODUCTO") = Me.dtgDetalle_Boleta.Item(0,
i).Value
oDataRowDetalleBoleta("PRECIO_DT_BOLETA") =
Me.dtgDetalle_Boleta.Item(1, i).Value
oDataRowDetalleBoleta("CANTIDAD_DT_BOLETA") =
Me.dtgDetalle_Boleta.Item(3, i).Value
oDataRowDetalleBoleta("REPORTE_DT_BOLETA") =
Me.dtgDetalle_Boleta.Item(4, i).Value
oDTDetalleBoleta.Rows.Add(oDataRowDetalleBoleta)
Next
17. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Try
oCommandBuilder.DataAdapter = oDABoleta
oDABoleta.Update(oDTBoleta)
oCommandBuilder.DataAdapter = oDADetalleBoleta
oDADetalleBoleta.Update(oDTDetalleBoleta)
MessageBox.Show("Registro Guardado", "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("Error al guardar" & Chr(13) & ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.btnNBoleta_Click(Nothing, Nothing)
Exit Sub
Finally
Me.oDTDBtmp.Dispose()
End Try
End If
Else
MessageBox.Show("Registro no guardado", "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Me.btnNBoleta_Click(Nothing, Nothing)
End If
Activar_Desactivar(False)
End Sub
Private Sub dtgDetalle_Boleta_CellValueChanged(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
dtgDetalle_Boleta.CellValueChanged
Dim vFilaActual As Integer = Me.dtgDetalle_Boleta.CurrentRow.Index
With Me.dtgDetalle_Boleta
.Item(4, vFilaActual).Value = .Item(1, vFilaActual).Value * .Item(3,
vFilaActual).Value
End With
Me.Calcular_Totales()
End Sub
End Class
18. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
frmUsuarios.vb
Imports System.Data.SqlClient
Public Class frmUsuarios
Private oDataAdapter As SqlDataAdapter
Private oDataTable As DataTable
Private oConnection As SqlConnection
Private oDataRow As DataRow
Private oCommandBuilder As SqlCommandBuilder
Private PosFilaAct As Integer
Private vNuevo As Boolean
Private Sub Activa_Desactiva(ByVal sw As Boolean)
gbdatos.Enabled = Not sw
Me.btnGuardar.Enabled = Not sw
Me.btnNuevo.Enabled = sw
Me.btnEditar.Enabled = sw
Me.btnEliminar.Enabled = sw
Me.btnImprimir.Enabled = sw
Me.dtgusuarios.Enabled = sw
End Sub
19. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub CargarDatos()
Try
Me.oDataRow = Me.oDataTable.Rows(Me.PosFilaAct)
Me.txtId.Text = oDataRow("cod_usuario")
Me.txtnom.Text = oDataRow("Nom_usuario")
Me.txtcont.Text = "***************"
Me.txtconfir.Text = "***************"
Catch ex As Exception
MessageBox.Show("Error" & Chr(13) & "No existen registros", "Cargar datos",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub frmUsuarios_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
oConnection = New
SqlConnection("server=.SQLEXPRESS;database=DB_VENTAS;integrated security=yes")
oCommandBuilder = New SqlCommandBuilder(Me.oDataAdapter)
oDataAdapter = New SqlDataAdapter("Select * From TB_USUARIOS", oConnection)
oDataTable = New DataTable
oDataAdapter.Fill(oDataTable)
dtgusuarios.DataSource = oDataTable
Me.CargarDatos()
Me.Activa_Desactiva(True)
End Sub
Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNuevo.Click
For Each objControl As Control In Me.gbdatos.Controls
If TypeOf objControl Is TextBox Then
objControl.Text = ""
End If
Next
Activa_Desactiva(False)
MessageBox.Show("Ingrese datos", "Nuevo", MessageBoxButtons.OK,
MessageBoxIcon.Information)
vNuevo = True
Me.txtnom.Focus()
End Sub
Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
Try
For Each objControl As Control In Me.gbdatos.Controls
If (TypeOf objControl Is TextBox) And objControl.Text = "" _
And Not objControl.Name = "txtId" Then
MessageBox.Show("Error faltan datos en" & Chr(13) & _
objControl.Name, "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Exit Sub
End If
Next
If Me.txtcont.Text <> Me.txtconfir.Text Then
MessageBox.Show("Contraseña no coincide", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
If MessageBox.Show("¿Desea guardar registro actual?", "Guardar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If vNuevo Then
oDataRow = Me.oDataTable.NewRow
End If
'oDataRow("cod_usuario") = Me.txtId.Text
oDataRow("Nom_usuario") = Me.txtnom.Text
20. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
oDataRow("contraseña_usuario") = ENCRIPTAR(Me.txtcont.Text)
If vNuevo Then
Me.oDataTable.Rows.Add(Me.oDataRow)
Me.PosFilaAct = (Me.oDataTable.Rows.Count - 1)
End If
oCommandBuilder.DataAdapter = Me.oDataAdapter
Me.oDataAdapter.Update(Me.oDataTable)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
MessageBox.Show("Datos Guardados", "Guardar", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("No se guardó el registro", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Activa_Desactiva(True)
Me.CargarDatos()
Catch ex As Exception
MessageBox.Show("Error al intentar guardar registro" & Chr(13) & ex.Message,
"Guardar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.CargarDatos()
Activa_Desactiva(True)
End Try
End Sub
Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditar.Click
MessageBox.Show("Proceda con la edición del registro actual", "Edición",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Activa_Desactiva(False)
vNuevo = False
Me.txtnom.Focus()
End Sub
Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminar.Click
Try
If Me.oDataTable.Rows.Count > 0 Then
If MessageBox.Show("¿Desea eliminar registro actual?", "Eliminar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim strDeleteSQL As String
Dim oSQLCommand As New SqlCommand
strDeleteSQL = "Delete From TB_USUARIOS where cod_usuario =" &
CInt(Me.txtId.Text)
Me.oConnection.Open()
oSQLCommand.Connection = Me.oConnection
oSQLCommand.CommandText = strDeleteSQL
oSQLCommand.ExecuteNonQuery()
Me.oConnection.Close()
Me.PosFilaAct = IIf(Me.PosFilaAct > 0, Me.PosFilaAct - 1, 0)
Me.oDataAdapter = New SqlDataAdapter("Select * TB_USUARIOS",
Me.oConnection)
Me.oDataTable.Clear()
Me.oDataAdapter.Fill(Me.oDataTable)
Me.CargarDatos()
End If
Else
MessageBox.Show("No existen registros para eliminar", "Eliminar",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show("Error para eliminar", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Try
End Sub
21. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImprimir.Click
Dim myreport As New rptUsuarios
myreport.SetDataSource(Me.oDataTable)
Dim myfrom As New frmReporte_Usuarios
myfrom.crvUsuarios.ReportSource = myreport
myfrom.WindowState = FormWindowState.Maximized
myfrom.ShowDialog()
End Sub
Private Sub dtgusuarios_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgusuarios.CellClick
If Not Me.dtgusuarios.Item(0, Me.dtgusuarios.CurrentRow.Index).Value Is
DBNull.Value Then
Me.PosFilaAct = Me.dtgusuarios.CurrentRow.Index
Me.CargarDatos()
End If
End Sub
Private Sub txtnom_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtnom.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.txtcont.Focus()
End If
End Sub
Private Sub txtcont_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtcont.KeyPress
If e.KeyChar() = Chr(13) Then
Me.txtconfir.Focus()
End If
End Sub
Private Sub txtconfir_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtconfir.KeyPress
sololetras(e)
If e.KeyChar() = Chr(13) Then
Me.btnGuardar.Focus()
End If
End Sub
Private Sub txtbUsuario_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtbUsuario.KeyPress
sololetras(e)
End Sub
Private Sub txtbUsuario_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbUsuario.TextChanged
Try
Me.oDataTable.Clear()
If txtbUsuario.Text <> "" Then
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_USUARIOS where
Nom_usuario like'" _
& txtbUsuario.Text & "%'", Me.oConnection)
Else
Me.oDataAdapter = New SqlDataAdapter("Select * From TB_USUARIOS",
Me.oConnection)
End If
Me.oDataAdapter.Fill(Me.oDataTable)
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
End Class
22. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
frmAcceso.vb
Imports System.Data.SqlClient
Public Class frmAcceso
Private oDAUsiario As SqlDataAdapter
Private oDTUsuario As DataTable
Private oCN As SqlConnection
Private oDRUsuario As DataRow
Private vAcceso As Boolean
Private Sub frmAcceso_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If Not Me.vAcceso Then
Me.Dispose()
Application.Exit()
End If
End Sub
Private Sub frmAcceso_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.oCN = New SqlConnection
Me.oCN.ConnectionString = "server=.SQLEXPRESS;database=DB_VENTAS;integrated
security=yes"
Me.oDAUsiario = New SqlDataAdapter("select * from TB_USUARIOS", Me.oCN)
Me.oDTUsuario = New DataTable
Me.oDAUsiario.Fill(Me.oDTUsuario)
Me.cbousuario.DataSource = Me.oDTUsuario
Me.cbousuario.DisplayMember = "Nom_usuario"
Me.cbousuario.ValueMember = "cod_usuario"
Me.txtcontraseña.Focus()
End Sub
Private Sub btnaceptar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnaceptar.Click
If cbousuario.Text.Length = 0 Then
MessageBox.Show("Debe seleccionar el usuario")
cbousuario.Focus()
Exit Sub
End If
If txtcontraseña.Text.Length = 0 Then
MessageBox.Show("Debe ingresar contraseña")
txtcontraseña.Focus()
Exit Sub
End If
Dim odatarow = Me.oDTUsuario.Rows(Me.cbousuario.SelectedIndex)
If ENCRIPTAR(Me.txtcontraseña.Text) = odatarow("contraseña_usuario") Then
23. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
MessageBox.Show("Bienvenido Administrador", "Systems Test",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
Me.vAcceso = True
Else
MessageBox.Show("Verifique su cuenta", "Systems Test", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End Sub
Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancelar.Click
Dim x As Integer
x = MessageBox.Show("Desea detener la aplicación", "Mensaje",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If x = 6 Then
Me.Close()
End If
End Sub
Private Sub txtcontraseña_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtcontraseña.KeyPress
If e.KeyChar() = Chr(13) Then
Me.btnaceptar.Focus()
End If
End Sub
End Class
frmBoletas_Clientes.vb
Imports System.Data.SqlClient
Public Class frmBoletas_Clientes
Dim oCN As SqlConnection
Dim oDT As DataTable
Dim oDA As SqlDataAdapter
Dim Cadena_Sql As String
24. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
Private Sub frmBoletas_Clientes_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Cadena_Sql = "SELECT TB_BOLETAS.ID_BOLETA, TB_CLIENTES.ID_CLIENTE,
TB_CLIENTES.NOM_CLIENTE, TB_CLIENTES.APE_CIENTE, TB_BOLETAS.FECHA_BOLETA,
TB_BOLETAS.TOTAL_BOLETA FROM TB_BOLETAS INNER JOIN TB_CLIENTES ON TB_BOLETAS.ID_CLIENTE
= TB_CLIENTES.ID_CLIENTE "
Me.oCN = New SqlConnection("server=.sqlexpress;Database=DB_VENTAS;Integrated
security=true")
oDT = New DataTable
oDA = New SqlDataAdapter(Cadena_Sql, oCN)
oDA.Fill(oDT)
Me.dtgBoletas.DataSource = oDT
Me.txtBuscar_cliente_TextChanged(Nothing, Nothing)
Catch ex As Exception
MessageBox.Show("Error al Conectar" & Chr(13) & ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub txtBuscar_cliente_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtBuscar_cliente.TextChanged
Try
Dim Vtotal As Single
Dim filter As String = "APE_CIENTE like'" & _
Me.txtBuscar_cliente.Text & "%'"
Me.oDT.DefaultView.RowFilter = filter
'================================================
Vtotal = IIf(oDT.Compute("Sum(TOTAL_BOLETA)", filter) Is DBNull.Value, 0,
oDT.Compute("Sum(TOTAL_BOLETA)", filter))
Me.txtTotal.Text = Format(Vtotal, "###0.00")
'=================================================
txtBuscar_cliente.Focus()
Catch ex As Exception
MessageBox.Show("Error al buscar" & Chr(13) & ex.Message)
End Try
End Sub
End Class
25. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
frmBuscarFecha.vb
Imports System.Data.SqlClient
Public Class frmBuscarxfecha
Dim oDT As DataTable
Dim oDA As SqlDataAdapter
Dim oCN As SqlConnection
Dim cadena_Sql As String
Private Sub frmBuscarxfecha_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
cadena_Sql = "SELECT TB_BOLETAS.ID_BOLETA, TB_CLIENTES.ID_CLIENTE,
TB_CLIENTES.NOM_CLIENTE, TB_CLIENTES.APE_CIENTE, TB_BOLETAS.FECHA_BOLETA,
TB_BOLETAS.TOTAL_BOLETA FROM TB_BOLETAS INNER JOIN TB_CLIENTES ON TB_BOLETAS.ID_CLIENTE
= TB_CLIENTES.ID_CLIENTE"
Me.oCN = New SqlConnection("server=.sqlexpress;Database=DB_VENTAS;Integrated
security=true")
oDT = New DataTable
oDA = New SqlDataAdapter(cadena_Sql, oCN)
oDA.Fill(oDT)
Me.dtgboletas.DataSource = oDT
Me.btnC_Click(Nothing, Nothing)
Catch ex As Exception
End Try
End Sub
Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnC.Click
'Dim fecha As Date
'Dim feini As String
' Dim fefin As String
'Dim filter As String = "TOTAL_BOLETA = 13/01/2010"
'feini = Me.dtpF1.Value.Date.ToString
26. Computación e Informática V Ciclo – Willeams Medina – acreditación_ies@hotmail.com – tlf. 972893759
'fefin = Me.dtpF2.Value.Date.ToString
'filter = fecha.Day & "/" & fecha.Month & "/" & fecha.Year
'Dim vTotal As Single
'filter = "TOTAL_BOLETA >= 13/01/2001 and TOTAL_BOLETA <= 14/01/2001"
'vTotal = IIf(oDT.Compute("Sum(TOTAL_BOLETA)", filter) Is DBNull.Value, 0,
oDT.Compute("Sum(TOTAL_BOLETA)", filter))
'Me.txttotal.Text = Format(vTotal, "###0.00")
Try
Dim vTotal As Single
'Dim filtro As String = "WHERE Fecha like '" &
Trim(dtpDesde.Value.Date.ToString.Substring(0, 10)) & "'"
Dim filtro As String = "fecha_BOLETA >= '" &
Trim(dtpF1.Value.Date.ToString.Substring(0, 10)) & "' and " & "fecha_BOLETA <= '" &
Trim(dtpF2.Value.Date.ToString.Substring(0, 10)) & "'"
Me.oDT.DefaultView.RowFilter = filtro
vTotal = IIf(oDT.Compute("SUM(TOTAL_BOLETA)", filtro) Is _
DBNull.Value, 0, oDT.Compute("SUM(TOTAL_BOLETA)", filtro))
Me.txttotal.Text = Format(vTotal, "###0.00")
Catch ex As Exception
MessageBox.Show("error al buscar" & Chr(13) & ex.Message, _
"error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnS.Click
If MessageBox.Show("¿Desea salir?", "Sistema", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End Sub
Private Sub btnI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnI.Click
Dim myreport As New rptBoletas_Fechas
myreport.SetDataSource(Me.oDT.DefaultView)
Dim myfrom As New frmReporte_BoletasxFechas
myfrom.crvBoletas_Fechas.ReportSource = myreport
myfrom.WindowState = FormWindowState.Maximized
myfrom.ShowDialog()
End Sub
End Class