0% found this document useful (0 votes)
123 views8 pages

Formulario Principal

This document contains code for four forms in Visual Basic for a sales application. Form1 contains code for the main form and navigation between other forms. Form2 contains code for registering customers. Form3 contains code for registering products. Form4 contains code for sales transactions, including adding products to an order, calculating totals, and connecting to a database.

Uploaded by

Richi GL
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views8 pages

Formulario Principal

This document contains code for four forms in Visual Basic for a sales application. Form1 contains code for the main form and navigation between other forms. Form2 contains code for registering customers. Form3 contains code for registering products. Form4 contains code for sales transactions, including adding products to an order, calculating totals, and connecting to a database.

Uploaded by

Richi GL
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

FORMULARIO PRINCIPAL

Public Class Form1 Private Sub ToolStripButton10_Click(sender As Object, e As EventArgs) Handles ToolStripButton10.Click Dim r As Integer r = MsgBox("Desea Salir del Sistema.........?", MsgBoxStyle.YesNo, "Sistema de Ventas") If (r = 6) Then End End If End Sub Private Sub AltasToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AltasToolStripMenuItem.Click Form2.Show() End Sub Private Sub AcercaDeToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles AcercaDeToolStripMenuItem1.Click Acercade.Show() End Sub Private Sub AltasToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles AltasToolStripMenuItem1.Click Form3.Show() End Sub

Private Sub AltasToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles AltasToolStripMenuItem2.Click Form4.Show() End Sub End Class

FORMULARIO REGISTRO CLIENTES

Imports System.Data.OleDb Public Class Form2 Dim strConexion As New OleDbConnection With {.ConnectionString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" & Application.StartupPath & "/PRODUCTOS.accdb;"} Dim strSQL As New OleDbCommand Dim oData As OleDbDataReader Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click Me.Close() End Sub Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click txtNombre.Text = "" txtAP.Text = ""

txtAM.Text = "" txtDireccion.Text = "" txtTel.Text = "" txtRFC.Text = "" fn.Text = Now txtNombre.Focus() End Sub Private Sub btnGuardar_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click If (Trim(txtNombre.Text) = "") Then MsgBox("Inserte el nombre del Cliente") txtNombre.Focus() ElseIf (Trim(txtAP.Text) = "") Then MsgBox("Inserte el Apellido Paterno") txtAP.Focus() ElseIf (Trim(txtAM.Text) = "") Then MsgBox("Inserte el Apellido materno") txtAM.Focus() ElseIf (Trim(txtDireccion.Text) = "") Then MsgBox("Inserte la direccion del Cliente") txtDireccion.Focus() ElseIf (Trim(txtRFC.Text) = "") Then MsgBox("Inserte el RFC del Cliente") txtRFC.Focus() Else Try strConexion.Open() 'Abre base de datos strSQL.CommandText = "INSERT INTO CLIENTES(APELLIDOPATERNO, APELLIDOMATERNO, NOMBRE, FNACIMIENTO,DIRECCION,TELEFONO,RFC) VALUES ('" & txtAP.Text & "','" & txtAM.Text & "', '" & txtNombre.Text & "','" & FN.Text & "', '" & txtDireccion.Text & "','" & txtTel.Text & "', '" & txtRFC.Text & "')" strSQL.Connection = strConexion 'Asigna la conexion al comando de la consulta oData = strSQL.ExecuteReader() 'Ejecuta la consulta SQL strConexion.Close() 'Cierra la conexion a la base de datos btnLimpiar_Click(sender, e) rellenar() Catch ex As Exception MsgBox("Ha ocurrido un Error") strConexion.Close() End Try End If End Sub Private Sub rellenar() Dim da As New OleDbDataAdapter("SELECT * FROM CLIENTES", strConexion) Dim ds As New DataSet da.Fill(ds) DataGridView1.DataSource = ds.Tables(0) End Sub Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load rellenar() End Sub End Class

FORMULARIO REGISTRO PRODUCTOS

Imports System.Data.OleDb Public Class Form3 Dim strConexion As New OleDbConnection With {.ConnectionString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" & Application.StartupPath & "/PRODUCTOS.accdb;"} Dim strSQL As New OleDbCommand Dim oData As OleDbDataReader Private Sub rellenar() Dim da As New OleDbDataAdapter("SELECT * FROM PRODUCTOS", strConexion) Dim ds As New DataSet da.Fill(ds) DataGridView1.DataSource = ds.Tables(0) End Sub Private Sub btnGuardar_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click If (Trim(txtCodigo.Text) = "") Then MsgBox("Inserte el Codigo del Producto.........!") txtCodigo.Focus() ElseIf (Trim(txtProducto.Text) = "") Then MsgBox("Inserte el Nombre del Producto.........!") txtProducto.Focus() ElseIf (Val(txtPrecio.Text) < 0) Then MsgBox("Inserte el Precio del Producto.........!") txtPrecio.Focus()

ElseIf (Trim(FC.Text) = "") Then MsgBox("Inserte la Fecha de Caducidad..........!") FC.Focus() ElseIf (Val(txtCantidad.Text) < 0) Then MsgBox("Inserte la Cantidad de Existencia del Producto......!") txtCantidad.Focus() Else Try strConexion.Open() 'Abre base de datos strSQL.CommandText = "INSERT INTO PRODUCTOS VALUES ('" & txtCodigo.Text & "','" & txtProducto.Text & "', '" & Val(txtPrecio.Text) & "','" & FC.Text & "', '" & Val(txtCantidad.Text) & "')" strSQL.Connection = strConexion 'Asigna la conexion al comando de la consulta oData = strSQL.ExecuteReader() 'Ejecuta la consulta SQL strConexion.Close() 'Cierra la conexion a la base de datos btnLimpiar_Click(sender, e) rellenar() Catch ex As Exception MsgBox("Ha ocurrido un Error") strConexion.Close() End Try End If End Sub Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click txtCodigo.Text = "" txtProducto.Text = "" txtPrecio.Text = "" txtCantidad.Text = "" FC.Text = Now txtCodigo.Focus() End Sub Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click Me.Close() End Sub Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load rellenar() End Sub End Class

FORMULARIO DE VENTAS

Imports System.Data.OleDb Public Class Form4 Dim strConexion As New OleDbConnection With {.ConnectionString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" & Application.StartupPath & "/PRODUCTOS.accdb;"} Dim strSQL As New OleDbCommand Dim oData As OleDbDataReader Dim NVenta As Integer Dim NC As String Dim NUEVO As Integer Private Sub cmdCancelar_Click(sender As Object, e As EventArgs) Handles cmdCancelar.Click txtCodigo.Text = "" txtCantidad.Text = "" txtSubtotal.Text = "" FV.Text = Now txtCodigo.Focus() End Sub Private Sub cmdAgregar_Click(sender As Object, e As EventArgs) Handles cmdAgregar.Click Dim TV As Double Try If (NVenta = 0) Then strConexion.Open()

strSQL.CommandText = "INSERT INTO VENTAS(FECHAVENTA, TOTALVENTA, IDCLIENTE) VALUES ('" & FV.Text & "'," & Val(txtTotal.Text) & ", " & 1 & ")" strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Close() strConexion.Close() strConexion.Open() strSQL.CommandText = "SELECT MAX(NVENTA) FROM VENTAS" strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Read() NVenta = oData(0) oData.Close() strConexion.Close() End If strConexion.Open() strSQL.CommandText = "SELECT TOTALVENTA FROM VENTAS WHERE NVENTA=" & NVenta strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Read() TV = oData(0) oData.Close() strConexion.Close() strConexion.Open() strSQL.CommandText = "INSERT INTO VENTAS_DETALLES VALUES (" & NVenta & ",'" & txtCodigo.Text & "', " & Val(txtCantidad.Text) & "," & Val(txtSubtotal.Text) & ")" strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Close() strConexion.Close() TV = TV + Val(txtSubtotal.Text) strConexion.Open() strSQL.CommandText = "UPDATE VENTAS SET TOTALVENTA=" & TV & " WHERE NVENTA=" & NVenta strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Close() strConexion.Close() cmdCancelar_Click(sender, e) txtTotal.Text = TV rellenar() Catch ex As Exception MsgBox("Ha ocurrido un Error") strConexion.Close() End Try 'End If End Sub Private Sub rellenar() Dim da As New OleDbDataAdapter("SELECT * FROM VENTAS_DETALLES WHERE NVENTA=" & NVenta, strConexion) Dim ds As New DataSet da.Fill(ds) DataGridView1.DataSource = ds.Tables(0) End Sub Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load NVenta = 0 clientes() End Sub

Private Sub clientes() Try strConexion.Open() strSQL.CommandText = "SELECT * FROM CLIENTES" strSQL.Connection = strConexion oData = strSQL.ExecuteReader() While oData.Read() NC = oData(1) & " " & oData(2) & " " & oData(3) cboCliente.Items.Add(NC) End While oData.Close() strConexion.Close() Catch ex As Exception MsgBox("Ha ocurrido un Error") strConexion.Close() End Try End Sub Private Sub cmdSalir_Click(sender As Object, e As EventArgs) Handles cmdSalir.Click Me.Close() End Sub Private Sub txtCodigo_LostFocus(sender As Object, e As EventArgs) Handles txtCodigo.LostFocus Dim codigoP As String codigoP = Trim(txtCodigo.Text) strConexion.Open() strSQL.CommandText = "SELECT * FROM PRODUCTOS WHERE CODIGO='" & codigoP & "'" strSQL.Connection = strConexion oData = strSQL.ExecuteReader() oData.Read() txtProducto.Text = oData(1) txtPrecio.Text = oData(2) oData.Close() strConexion.Close() End Sub Private Sub txtCantidad_TextChanged(sender As Object, e As EventArgs) Handles txtCantidad.TextChanged Dim pr As Double Dim ca As Integer pr = Val(txtPrecio.Text) ca = Val(txtCantidad.Text) txtSubtotal.Text = pr * ca End Sub End Class

Cualquier duda me pueden escribir al [email protected]

You might also like