Sie sind auf Seite 1von 78

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

-1-

VER como hacer con autenticacion


https://www.youtube.com/user/jcarlosad7
SISTEMA DE VENTAS VISUAL ESTUDIO 2010
Sistema de ventas pequeo de ventas 15 minutos
16 VIDEOS 1.82 GIGABYTES Juan Carlos Arcila Diaz Carlos-Ad.6@hotmail.com

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

SQL SERVER 2008 VISUAL ESTUDIO 2010


3 capas
Datos
Lgica
Presentacin
Sql server 2008
En recursos todos los archivos fuentes En sqlserver poner (local)

Base de datos sisventas


Tabla productos

Crear la tabla producto

-2-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Tabla clientes

TABLA ventas

Detalle de ventas

-3-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Tabla usuario para el acceso de sistema

Categoria

6 tablas
Creando diagrama new database diagrama

-4-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

-5-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

VIDEO 2 16 minutos
Generar el esquema del sistema
Usaremos carpetas

Presentaciones formularios
Resorces imgenes
Lgica las clases
Datos una base para conectar los datos y la funciones
Clase conexin

-6-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Capa lgica usaremos el prefijo b


Aqu van a estar las vistas

Los reportes segn las necesidades de sistema


La carpeta reosurces se genera por defecto
PROGRAMA EL SISTEMA FORMULARIO SIS VENTAS

Con el nombre e datos


Otra carpeta presentacin

-7-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Todos los procedimientos almacenados


En la carpeta se crea nueva clase
Clase conexin
se fuera en red poner el IP de la computadora
pag 7.53
Capa datos
Implementar la clase conexin
Imports System.Data.SqlClient
Public Class conexion
Protected cnn As New SqlConnection
Public idusuario As Integer
Protected Function conectado() As Boolean
Try
cnn = New SqlConnection("data source=(local);initial
catalog=bdventas1;integrated security=true")
cnn.Open()
Return True
Catch ex As Exception

-8-

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

-9-

MsgBox(ex.Message)
Return False
End Try
End Function
Protected Function desconectado() As Boolean
Try
If cnn.State = ConnectionState.Open Then
cnn.Close()
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class
Crear todas las funciones para ese cliente
Clase cliente
Imports System.Data.SqlClient
Public Class fcliente
Inherits conexion
Dim cmd As New SqlCommand ' para peticiones para base de datos
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn ' tiene acceso a la cadena conexion por que hereda
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
' permite crear una tabla en memoria para guardar todos los registros de
' la tabla cliente
Dim da As New SqlDataAdapter(cmd) ' adaptador
da.Fill(dt) ' rellena con la variable dt
Return dt ' retorna dt
Else
Return Nothing ' no retorn nada
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
End Class

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Creacion de procedimientos
Crear procedimiento mostrar cliente en el visual estudio 2012

create proc mostrar_cliente


As
Select * from cliente order by idcliente desc
Grabe el procedimiento
El procedimiento se modifica a

- 10 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 11 -

Elimine el procedimiento

VIDEO 3 21.42 MINUTOS


FORMULARIO FRM CLIENTE EN LA CARPETA PRESENTACION
CLIK EN CARPETA presentacin y agregar Windows form
Frm cliente
Propiedad text listado de cliente
Color de fondo = blanco
Campos de bsqueda
Al data agregar nueva columna
Deshabilitar funciones en data grid
Propiedadad selection mode fullrows select para que seleccione toda la fila
Propiedad text de combobox por dni
EL link label se habilita cuando el datalsit esta en blanco, si esta en blanco el labellink
no aparece
Al data listado se agrega una nueva columna con la propiedad colum

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Agregar como check box

Texto de encabezado eliminar

- 12 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Aparece

Arrancar proyecto con formulario cliente

- 13 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 14 -

Proyecto debe arrancar con formulario cliente

Public Class frmCliente


Private dt As New DataTable ' Para guardar los datos en la memoria
Private Sub frmcliente_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mostrar()
End Sub
Private Sub mostrar()
Try
Dim func As New fcliente ' instancia el objeto func
dt = func.mostrar ' dt llama a la funcion mostrar
datalistado.Columns.Item("Eliminar").Visible = False ' ocultar la columna a
eliminar
If dt.Rows.Count <> 0 Then ' si la tabla de de memoria dt

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 15 -

datalistado.DataSource = dt ' rellenar con lo tenga dt


txtbuscar.Enabled = True ' hay
datalistado.ColumnHeadersVisible = True ' las cabeceras del data listado se
hacen visible
inexistente.Visible = False
Else ' si noh datos
datalistado.DataSource = Nothing
txtbuscar.Enabled = False
datalistado.ColumnHeadersVisible = False ' columnas de data listado
desapareces
inexistente.Visible = True ' visible cuando no hay datos
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True ' aparece
BtnEditar.Visible = False ' desparece
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy) ' copiar los datos que tengo a la variable ds
Dim dv As New DataView(ds.Tables(0)) ' se pasa como parametro lo que se ha
copiado
dv.RowFilter = cboCampo.Text & " like '" & txtbuscar.Text & "%'"
' filtrar por el camo eligido en el combobox y filtra por filas
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else ' no tiene datos
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False 'ocult el id cliente
End Sub
End Class
VIDEO 4 9-35 MINUTOS
Botn inserta y botn editar
Agregar la clase b cliente
Un objeto para cada atributo en la tabla base de datos
Objeto son atributos en la memoria
El boton editar recibe y envia datos se implementa la clase
Agregar vcliente

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Public Class vcliente


Dim idcliente As Integer
Dim nombres, apellidos, direccion, telefono, dni As String
' cada uno de los campos de la tabla clientes
'seeter y getter
Public Property gidcliente
Get
Return idcliente
End Get
Set(ByVal value)
idcliente = value
End Set
End Property
Public Property gnombres
Get
Return nombres
End Get
Set(ByVal value)
nombres = value
End Set
End Property
Public Property gapellidos
Get
Return apellidos
End Get
Set(ByVal value)
apellidos = value
End Set
End Property
Public Property gdireccion
Get
Return direccion
End Get
Set(ByVal value)
direccion = value
End Set
End Property
Public Property gtelefono
Get
Return telefono
End Get
Set(ByVal value)
telefono = value
End Set
End Property
Public Property gdni
Get
Return dni

- 16 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 17 -

End Get
Set(ByVal value)
dni = value
End Set
End Property
'constructores
Public Sub New()
' constructor en blanco
End Sub
Public Sub New(ByVal idcliente As Integer, ByVal nombres As String, ByVal apellidos
As String, ByVal direccion As String, ByVal telefono As String, ByVal dni As String)
gidcliente = idcliente
gnombres = nombres
gapellidos = apellidos
gdireccion = direccion
gtelefono = telefono
gdni = dni
' para guardar los campos en los metodos
End Sub
End Class

Todos los datos de la tabla cliente


Public Class vcliente
Dim idcliente As Integer
Dim nombres, apellidos, direccion, telefono, dni As String
'seeter y getter
Public Property gidcliente
Get
Return idcliente
End Get
Set(ByVal value)
idcliente = value
End Set
End Property
Public Property gnombres
Get
Return nombres
End Get
Set(ByVal value)
nombres = value
End Set
End Property
Public Property gapellidos
Get

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 18 -

Return apellidos
End Get
Set(ByVal value)
apellidos = value
End Set
End Property
Public Property gdireccion
Get
Return direccion
End Get
Set(ByVal value)
direccion = value
End Set
End Property
Public Property gtelefono
Get
Return telefono
End Get
Set(ByVal value)
telefono = value
End Set
End Property
Public Property gdni
Get
Return dni
End Get
Set(ByVal value)
dni = value
End Set
End Property
'constructores
Public Sub New()
End Sub
Public Sub New(ByVal idcliente As Integer, ByVal nombres As String, ByVal apellidos
As String, ByVal direccion As String, ByVal telefono As String, ByVal dni As String)
gidcliente = idcliente
gnombres = nombres
gapellidos = apellidos
gdireccion = direccion
gtelefono = telefono
gdni = dni
End Sub
End Class
Crear procedimientos almacenados en la base de datos que permitan registrar
los datos que envie
Procedimiento almacenado insertar cliente
ALTER proc insertar_cliente
@nombre varchar (50),
@apellidos varchar (50),

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 19 -

@direccion varchar (100),


@telefono varchar (10),
@dni varchar (8)
as
insert into cliente (nombre,apellidos,direccion,telefono,dni) values
(@nombre,@apellidos,@direccion,@telefono,@dni)
VIDEO 5 21 minutos
Se abre fcliente y agregar
Imports System.Data.SqlClient
Public Class fcliente
Inherits conexion
Dim cmd As New SqlCommand ' para peticiones para base de datos
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn ' tiene acceso a la cadena conexion por que hereda
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
' permite crear una tabla en memoria para guardar todos los registros de
' la tabla cliente
Dim da As New SqlDataAdapter(cmd) ' adaptador
da.Fill(dt) ' rellena con la variable dt
Return dt ' retorna dt
Else
Return Nothing ' no retorn nada
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vcliente) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_cliente")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
' los 5 paramtros
cmd.Parameters.AddWithValue("@nombre", dts.gnombres)
cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
cmd.Parameters.AddWithValue("@dni", dts.gdni)
If cmd.ExecuteNonQuery Then
Return True

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 20 -

Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
End Class
Abrir el formulario fcliente
Herrmienta que me permite captura algunos errors error provider

Hace aparecer unicono informatico al costado


Programar caja de texto por caja de texto
Progrmar el botn guardar
Poner uno encima del otro
Me sale el icono en las cajas de texto que se ha validado
Insertar y enviar datos
Public Class frmCliente
Private dt As New DataTable ' Para guardar los datos en la memoria
Private Sub mostrar()
Try
Dim func As New fcliente ' instancia el objeto func
dt = func.mostrar ' dt llama a la funcion mostrar
datalistado.Columns.Item("Eliminar").Visible = False ' ocultar la columna a eliminar
If dt.Rows.Count <> 0 Then ' si la tabla de de memoria dt
datalistado.DataSource = dt ' rellenar con lo tenga dt
txtbuscar.Enabled = True ' hay
datalistado.ColumnHeadersVisible = True ' las cabeceras del data listado se
hacen visible
inexistente.Visible = False
Else ' si noh datos
datalistado.DataSource = Nothing
txtbuscar.Enabled = False
datalistado.ColumnHeadersVisible = False ' columnas de data listado
desapareces
inexistente.Visible = True ' visible cuando no hay datos
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True ' aparece

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 21 -

BtnEditar.Visible = False ' desparece


buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy) ' copiar los datos que tengo a la variable ds
Dim dv As New DataView(ds.Tables(0)) ' se pasa como parametro lo que se ha
copiado
dv.RowFilter = cboCampo.Text & " like '" & txtbuscar.Text & "%'"
' filtrar por el camo eligido en el combobox y filtra por filas
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else ' no tiene datos
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub limpiar()
btnguardar.Visible = True
btneditar.Visible = False
txtnombre.Text = ""
txtapellidos.Text = ""
txtdireccion.Text = ""
txttelefono.Text = ""
txtdni.Text = ""
txtidcliente.Text = ""
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False 'ocult el id cliente
End Sub
Private Sub frmCliente_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
mostrar()
End Sub
Private Sub txtnombre_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.ErrorIcono.SetError(sender, "")
Else ' en caso de error
Me.ErrorIcono.SetError(sender, "Ingrese el nombre del cliente porfavor, este
datos es obligatorio")
End If
End Sub
Private Sub txtapellidos_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TxtApellidos.Validating

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 22 -

If DirectCast(sender, TextBox).Text.Length > 0 Then


Me.ErrorIcono.SetError(sender, "")
Else
Me.ErrorIcono.SetError(sender, "Ingrese los apellidos del cliente porfavor, este
datos es obligatorio")
End If
End Sub
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
If Me.ValidateChildren = True And txtnombre.Text <> "" And txtapellidos.Text <> ""
And txtdireccion.Text <> "" And txttelefono.Text <> "" And txtdni.Text <> "" Then
Try
Dim dts As New vcliente ' instancio al objeto dts
Dim func As New fcliente ' todas las funciones de la clase fcliente
dts.gnombres = txtNombre.Text ' le envio dts.nombres
dts.gapellidos = txtapellidos.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gdni = txtdireccion.Text
If func.insertar(dts) Then
MessageBox.Show("cliente registrado correctamente", "Guardando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("cliente no fue registrado intente de nuevo",
"Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btnNuevo_Click(sender As Object, e As EventArgs) Handles
btnNuevo.Click
limpiar() ' llama al porcedimiento limpiar
mostrar()
End Sub
End Class
VIDEO 6 21- 13 .23 MINUTOS
Cdigo del botn editar
AL hacer clic en data gridviee muestra los datos en una caja de texto
Procedimiento almacenado editar cliente

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 23 -

ALTER proc editar_cliente


@idcliente integer,
@nombre varchar (50),
@apellidos varchar (50),
@direccion varchar (100),
@telefono varchar (9),
@dni varchar (8)
as
update cliente set
nombre=@nombre,apellidos=@apellidos,direccion=@direccion,telefono=@telefono,dni
=@dni
where idcliente=@idcliente
programar cada vez que haga clic en un data grid
CLICK EN las cajas de texto ese registro aparece en la caja de texto

Agregar la funcin editar en la clase fcliente


Botn editar parecido al botn guardar
ELBOTON EDITAR es parecido a guardar

18

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 24 -

VIDEO 7 18 49 EL BOTON eliminar


Procedimiento almacenado elimnar cliente en la base de datos
CREATE proc eliminar_cliente
@idcliente integer
as
delete from cliente where idcliente=@idcliente
el codigo del cliente que se envia del visual estudio
Metodologia
Codificar la opcin para eliminar varios a la vez
Aceptar en la capa datos
Crear funcin eliminar
Funcin en la capa clientes yluego elarin el formulario
ElimnAR VARISO REGIStros a la vez
Chech contex te tex 8.23lta la columna eliminar
Aparfece y se oculta la columna eliminar
Public Class frmCliente
Private dt As New DataTable ' Para guardar los datos en la memoria
Private Sub mostrar()
Try
Dim func As New fcliente ' instancia el objeto func
dt = func.mostrar ' dt llama a la funcion mostrar
datalistado.Columns.Item("Eliminar").Visible = False ' ocultar la columna a
eliminar
If dt.Rows.Count <> 0 Then ' si la tabla de de memoria dt
datalistado.DataSource = dt ' rellenar con lo tenga dt
txtbuscar.Enabled = True ' hay
datalistado.ColumnHeadersVisible = True ' las cabeceras del data listado se
hacen visible
inexistente.Visible = False
Else ' si noh datos
datalistado.DataSource = Nothing
txtbuscar.Enabled = False
datalistado.ColumnHeadersVisible = False ' columnas de data listado
desapareces
inexistente.Visible = True ' visible cuando no hay datos
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True ' aparece
BtnEditar.Visible = False ' desparece
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 25 -

ds.Tables.Add(dt.Copy) ' copiar los datos que tengo a la variable ds


Dim dv As New DataView(ds.Tables(0)) ' se pasa como parametro lo que se ha
copiado
dv.RowFilter = cboCampo.Text & " like '" & txtbuscar.Text & "%'"
' filtrar por el camo eligido en el combobox y filtra por filas
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else ' no tiene datos
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub limpiar()
btnguardar.Visible = True
btneditar.Visible = False
txtnombre.Text = ""
txtapellidos.Text = ""
txtdireccion.Text = ""
txttelefono.Text = ""
txtdni.Text = ""
txtidcliente.Text = ""
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False 'ocult el id cliente
End Sub
Private Sub frmCliente_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
mostrar()
End Sub
Private Sub txtnombre_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.ErrorIcono.SetError(sender, "")
Else ' en caso de error
Me.ErrorIcono.SetError(sender, "Ingrese el nombre del cliente porfavor, este
datos es obligatorio")
End If
End Sub
Private Sub cbeliminar_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then ' comprueba el estado
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 26 -

End Sub
Private Sub datalistado_CellContentClick(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DataGridViewCellEventArgs) Handles
datalistado.CellContentClick
' e variable que recoge el indice
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkcell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
' extrae la fila d ela columna elimanr
chkcell.Value = Not chkcell.Value
End If
End Sub
Private Sub txtapellidos_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TxtApellidos.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.ErrorIcono.SetError(sender, "")
Else
Me.ErrorIcono.SetError(sender, "Ingrese los apellidos del cliente porfavor, este
datos es obligatorio")
End If
End Sub
Private Sub btneditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnEditar.Click
Dim result As DialogResult ' resultado de un dialogo
result = MessageBox.Show("Realmente desea editar los datos del cliente?",
"MOdificando registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then
If Me.ValidateChildren = True And txtnombre.Text <> "" And txtapellidos.Text <>
"" And txtdireccion.Text <> "" And txttelefono.Text <> "" And txtdni.Text <> "" And
txtidcliente.Text <> "" Then
Try
Dim dts As New vcliente
Dim func As New fcliente
dts.gidcliente = txtidcliente.Text
dts.gnombres = txtnombre.Text
dts.gapellidos = txtapellidos.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gdni = txtdireccion.Text
If func.editar(dts) Then ' envia los datos del cliente al objeto vcliente
MessageBox.Show("cliente correctamente", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("cliente no fue modifcado intente de nuevo",
"MOdificando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 27 -

Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End Sub
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
If Me.ValidateChildren = True And txtnombre.Text <> "" And txtapellidos.Text <> ""
And txtdireccion.Text <> "" And txttelefono.Text <> "" And txtdni.Text <> "" Then
Try
Dim dts As New vcliente ' instancio al objeto dts
Dim func As New fcliente ' todas las funciones de la clase fcliente
dts.gnombres = txtNombre.Text ' le envio dts.nombres
dts.gapellidos = txtapellidos.Text
dts.gdireccion = txtdireccion.Text
dts.gtelefono = txttelefono.Text
dts.gdni = txtdireccion.Text
If func.insertar(dts) Then
MessageBox.Show("cliente registrado correctamente", "Guardando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("cliente no fue registrado intente de nuevo",
"Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub datalistado_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles datalistado.CellClick
txtidcliente.Text = datalistado.SelectedCells.Item(1).Value
txtnombre.Text = datalistado.SelectedCells.Item(2).Value
txtapellidos.Text = datalistado.SelectedCells.Item(3).Value
txtdireccion.Text = datalistado.SelectedCells.Item(4).Value
txttelefono.Text = datalistado.SelectedCells.Item(5).Value
txtdni.Text = datalistado.SelectedCells.Item(6).Value
BtnEditar.Visible = True ' oculta y muestra los botones
btnguardar.Visible = False
End Sub

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 28 -

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


btnNuevo.Click
limpiar() ' llama al porcedimiento limpiar
mostrar()
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminar.Click
Dim result As DialogResult
result = MessageBox.Show("Realmente desea eliminar los clientes
seleccionados?", "Eliminando registros", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)
If result = DialogResult.OK Then
Try
For Each row As DataGridViewRow In datalistado.Rows
Dim marcado As Boolean =
Convert.ToBoolean(row.Cells("Eliminar").Value)
If marcado Then ' guarda lo que se ha seleccionado el check boxk del
data listado
Dim onekey As Integer = Convert.ToInt32(row.Cells("idcliente").Value)
Dim vdb As New vcliente
Dim func As New fcliente
vdb.gidcliente = onekey
If func.eliminar(vdb) Then
Else
MessageBox.Show("Cliente no fue eliminado", "Eliminando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacin de registros", "Eliminando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
Call limpiar()
End Sub
End Class

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

8 REPASO DE MATENIMIENTO DE TABLAS 20 46 IMIET


Para registrar un producto y registrar una venta
Necesariamente se debe registrar por categora
.25 MATENIa de la tabla caegorias modelaimiento endtifdad relacin
Producto ordenados por categorias
Mantenimiento de la tabla categoria
1.37 proc almacenados parostrar registrar, elimnar y modificar categoras
CREATE proc editar_categoria
@idcategoria integer,
@nombre_categoria varchar(50)
as
update categoria set nombre_categoria=@nombre_categoria
where idcategoria=@idcategoria
CREATE proc eliminar_categoria
@idcategoria integer
as
delete from categoria where idcategoria=@idcategoria
CREATE proc insertar_categoria
@nombre_categoria varchar(50)
as
insert into categoria (nombre_categoria) values (@nombre_categoria)
create proc mostrar_categoria
as
select * from categoria order by idcategoria desc

- 29 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 30 -

crear objetos y metodos para la table categoria


NUEVA clase b Categoria
7.11 CoNSTRUCTOR en blanco y otro con todos los datos
Crear clase fcategoras
Parte formulario 11.36
1456 categorias parecido a clientes
201 4 dos categoras

Public Class frmCategoria


'declaramos una variable que haga una instancia a la clase datatable
'datatable me permite representar una tabla en memoria ram
Private dt As New DataTable
'en el evento load del formulario ingresamos el siguiente cdigo
Private Sub frmcategoria_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mostrar()
End Sub
'declaramos el procedimiento limpiar que me permitir limpiar la caja de texto,
olcultar el botn editar y visualizar el botn guardar
Public Sub limpiar()
btnGuardar.Visible = True
BtnEditar.Visible = False
txtNombre.Text = ""
txtidcategora.Text = ""
End Sub
'declaramos el botn mostrar
Private Sub mostrar()
Try
Dim func As New fcategoria
dt = func.mostrar

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 31 -

datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False
Else
datalistado.DataSource = Nothing
txtbuscar.Enabled = False
datalistado.ColumnHeadersVisible = False
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True
BtnEditar.Visible = False
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = cboCampo.Text & " like '" & txtbuscar.Text & "%'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
End Sub
Private Sub txtnombre_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el nombre de la categora porfavor,
este datos es obligatorio")
End If
End Sub

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 32 -

Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNuevo.Click
limpiar()
mostrar()
End Sub
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
If Me.ValidateChildren = True And txtNombre.Text <> "" Then
Try
Dim dts As New vcategoria
Dim func As New fcategoria
dts.gnombre_categoria = txtNombre.Text
If func.insertar(dts) Then
MessageBox.Show("categora registrada correctamente", "Guardando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("categora no fue registrada intente de nuevo",
"Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub datalistado_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles datalistado.CellClick
txtidcategora.Text = datalistado.SelectedCells.Item(1).Value
txtNombre.Text = datalistado.SelectedCells.Item(2).Value
BtnEditar.Visible = True
btnGuardar.Visible = False
End Sub
Private Sub datalistado_CellContentClick(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DataGridViewCellEventArgs) Handles
datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkcell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkcell.Value = Not chkcell.Value
End If
End Sub

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 33 -

Private Sub btneditar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BtnEditar.Click
Dim result As DialogResult
result = MessageBox.Show("Realmente desea editar los datos de la categora?",
"MOdificando registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then
If Me.ValidateChildren = True And txtNombre.Text <> "" And txtidcategora.Text
<> "" Then
Try
Dim dts As New vcategoria
Dim func As New fcategoria
dts.gidcategoria = txtidcategora.Text
dts.gnombre_categoria = txtNombre.Text
If func.editar(dts) Then
MessageBox.Show("categora MOdificada correctamente", "MOdificando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("categora no fue modifcada intente de nuevo",
"MOdificando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "MOdificando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End Sub
Private Sub cbeliminar_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEliminar.Click
Dim result As DialogResult
result = MessageBox.Show("Realmente desea eliminar las categoras
seleccionadas?", "Eliminando registros", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)
If result = DialogResult.OK Then
Try
For Each row As DataGridViewRow In datalistado.Rows

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 34 -

Dim marcado As Boolean =


Convert.ToBoolean(row.Cells("Eliminar").Value)
If marcado Then
Dim onekey As Integer = Convert.ToInt32(row.Cells("idcategoria").Value)
Dim vdb As New vcategoria
Dim func As New fcategoria
vdb.gidcategoria = onekey
If func.eliminar(vdb) Then
Else
MessageBox.Show("Categora no fue eliminada", "Eliminando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacin de registros", "Eliminando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
Call limpiar()
End Sub
Private Sub txtbuscar_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbuscar.TextChanged
buscar()
End Sub
End Class
VIDEO 9 24 MINUTOS
Para un producto debe haber categoras
Mantenimiento de la tabla productos
Para poder realizar la tabla de ventas detalle
0.49 llave primaria y llave fornea
Columnas se debe tener imgenes
La tabla productos esta relacionada
Catalogo de productos es con imgenes
Aadir un nuevo campo llamado Imagen
En modo diseo no se puede
Sentencia sql para agregar un campo
Alter table producto add imagen image
Procedimiento almacenado para manenimiento de productos
CREATE proc editar_producto
@idproducto integer,
@idcategoria integer,
@nombre varchar (50),

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 35 -

@descripcion varchar (50),


@stock decimal (18,2),
@precio_compra decimal (18,2),
@precio_venta decimal (18,2),
@fecha_vencimiento date,
@imagen image
as
update producto set
idcategoria=@idcategoria,nombre=@nombre,descripcion=@descripcion,
stock=@stock,precio_compra=@precio_compra,precio_venta=@precio_venta,fecha_v
encimiento=@fecha_vencimiento,
imagen=@imagen
where idproducto=@idproducto
create proc eliminar_producto
@idproducto integer
as
delete from producto where idproducto=@idproducto
CREATE proc insertar_producto
@idcategoria integer,
@nombre varchar (50),
@descripcion varchar (50),
@stock decimal (18,2),
@precio_compra decimal (18,2),
@precio_venta decimal (18,2),
@fecha_vencimiento date,
@imagen image
as
insert into producto
(idcategoria,nombre,descripcion,stock,precio_compra,precio_venta,fecha_vencimiento,i
magen)
values
(@idcategoria,@nombre,@descripcion,@stock,@precio_compra,@precio_venta,@fec
ha_vencimiento,@imagen)
CREATE proc mostrar_producto
as
select
producto.idproducto,producto.idcategoria,categoria.nombre_categoria,producto.nombre
,
producto.descripcion,producto.stock,producto.precio_compra,producto.precio_venta,pro
ducto.fecha_vencimiento,
producto.imagen
from producto inner join categoria on producto.idcategoria=categoria.idcategoria
order by producto.idproducto desc
CODIGO DEL FORMULARIO frmproducto
Imports System.Data.SqlClient
' parecido al fcliente

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 36 -

Public Class fproducto


Inherits conexion
Dim cmd As New SqlCommand
Public Function mostrar() As DataTable
Try
conectado()
cmd = New SqlCommand("mostrar_producto")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vproducto) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_producto")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idcategoria", dts.gidcategoria)
cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
cmd.Parameters.AddWithValue("@descripcion", dts.gdescripcion)
cmd.Parameters.AddWithValue("@stock", dts.gstock)
cmd.Parameters.AddWithValue("@precio_compra", dts.gprecio_compra)
cmd.Parameters.AddWithValue("@precio_venta", dts.gprecio_venta)
cmd.Parameters.AddWithValue("@fecha_vencimiento",
dts.gfecha_vencimiento)
cmd.Parameters.AddWithValue("@imagen", dts.gimagen)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 37 -

Public Function editar(ByVal dts As vproducto) As Boolean


Try
conectado()
cmd = New SqlCommand("editar_producto")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idproducto", dts.gidproducto) ' llave primaria
cmd.Parameters.AddWithValue("@idcategoria", dts.gidcategoria)
cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
cmd.Parameters.AddWithValue("@descripcion", dts.gdescripcion)
cmd.Parameters.AddWithValue("@stock", dts.gstock)
cmd.Parameters.AddWithValue("@precio_compra", dts.gprecio_compra)
cmd.Parameters.AddWithValue("@precio_venta", dts.gprecio_venta)
cmd.Parameters.AddWithValue("@fecha_vencimiento",
dts.gfecha_vencimiento)
cmd.Parameters.AddWithValue("@imagen", dts.gimagen)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vproducto) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_producto")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@idproducto", SqlDbType.NVarChar, 50).Value =
dts.gidproducto
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class
Video 10 34 .31 minutos
Interface grafico para dar mantenimiento a la tabla productos

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Llave fornea calculo de utilidad


Interfaza grafica, picture box
Agegar Windows rpodcuto
Listado de catalogo de porductos
Copiarlos los controles control c a control v copiar y pegar
3.13 copiar
Image picture box
Imagen transparente

btnBuscar Categoria 3.37 referencia a otro formulario


date time picker 6.27
9.20 imagen trnsparente propiedad
Varios picturesbox pequeos
Imgenes que funcionan como botones
Clase bitmaps guarda mapas de bits
Btn cargar
Imagen trnasparente file 1602
Oculto dos columnas 17.59
20 38 io . memory string crea una secuencia cuyo almcen de memoria
Rawformat 21.52
Editar datos del producto 23.45
Llave primaria 24
Data listado 24.56
Picture box que se llama imagene
Array de tipo byte
28.28 image demomry string

Elijo la categora en los tre puntitos


VIDEO 11 31.18

- 38 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 39 -

Tabla ventas y detalle de ventas


Detalle de ventas todas las ventas
.45 detalle de ventas capa datos y la capa lgica para la tabla ventas 1.15
2.02 procedimientos almacenados para la tabla ventas
3.55 procedmiento alamcenado editar ventas
Procedimiento alamcenado eliminar 5.27
CREATE proc insertar_venta
@idcliente as integer,
@fecha_venta as date,
@tipo_documento as varchar (50),
@num_documento as varchar (50)
as
insert into venta (idcliente,fecha_venta,tipo_documento,num_documento)
values (@idcliente,@fecha_venta,@tipo_documento,@num_documento)
CREATE proc [dbo].[mostrar_venta]
as
SELECT dbo.venta.idventa, dbo.venta.idcliente, dbo.cliente.apellidos, dbo.cliente.dni,
dbo.venta.fecha_venta, dbo.venta.tipo_documento, dbo.venta.num_documento
FROM
dbo.cliente INNER JOIN
dbo.venta ON dbo.cliente.idcliente = dbo.venta.idcliente
order by dbo.venta.idventa desc

CREATE proc editar_venta


@idventa as integer,
@idcliente as integer,
@fecha_venta as date,
@tipo_documento as varchar (50),
@num_documento as varchar (50)
as

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 40 -

update venta set


idcliente=@idcliente,fecha_venta=@fecha_venta,tipo_documento=@tipo_documento,n
um_documento=@num_documento
where idventa=@idventa
CREATE proc eliminar_venta
@idventa as integer
as
delete from venta where idventa=@idventa
procedimiento almacenados para detalles de ventas
CREATE proc insertar_detalle_venta
@idventa as integer,
@idproducto as integer,
@cantidad as decimal (18,2),
@precio_unitario as decimal (18,2)
as
insert into detalle_venta (idventa,idproducto,cantidad,precio_unitario)
values (@idventa,@idproducto,@cantidad,@precio_unitario)
CREATE proc editar_detalle_venta
@iddetalle_venta as integer,
@idventa as integer,
@idproducto as integer,
@cantidad as decimal (18,2),
@precio_unitario as decimal (18,2)
as
update detalle_venta set
idventa=@idventa,idproducto=@idproducto,cantidad=@cantidad,precio_unitario=@pre
cio_unitario
where idddetalle_venta=@iddetalle_venta
CREATE proc eliminar_detalle_venta
@iddetalle_venta as integer
as
delete from detalle_venta where idddetalle_venta=@iddetalle_venta
CREATE proc [dbo].[mostrar_detalle_venta]
as
SELECT dbo.detalle_venta.idddetalle_venta, dbo.detalle_venta.idventa,
dbo.detalle_venta.idproducto, dbo.producto.nombre, dbo.detalle_venta.cantidad,
dbo.detalle_venta.precio_unitario
FROM
dbo.detalle_venta INNER JOIN
dbo.producto ON dbo.detalle_venta.idproducto = dbo.producto.idproducto
order by dbo.detalle_venta.idddetalle_venta desc

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

12.3 aumentar stcok de la tabla productos


CREATE proc aumentar_stock
@idproducto as integer,
@cantidad as decimal (18,2)
as
update producto set stock=stock+@cantidad where idproducto=@idproducto
CREATE proc disminuir_stock
@idproducto as integer,
@cantidad as decimal (18,2)
as
update producto set stock=stock-@cantidad where idproducto=@idproducto
Capa lgica con todolos objetos
Clase venta
Construtor en blanco
Constructor con todos los campos 1740
Clasedetalle de venta
Capas de datos 23.34 dos clases
Fventa
Fdetalleventas 26.51
Sistema de ventas de ventas
Public Class vventa
Dim idventa, idcliente As Integer
Dim fecha_venta As Date
Dim tipo_documento, num_documento As String
Public Property gidventa
Get
Return idventa
End Get
Set(ByVal value)
idventa = value
End Set
End Property
Public Property gidcliente
Get
Return idcliente
End Get
Set(ByVal value)
idcliente = value
End Set
End Property
Public Property gfecha_venta
Get
Return fecha_venta
End Get
Set(ByVal value)

- 41 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 42 -

fecha_venta = value
End Set
End Property
Public Property gtipo_documento
Get
Return tipo_documento
End Get
Set(ByVal value)
tipo_documento = value
End Set
End Property
Public Property gnum_documento
Get
Return num_documento
End Get
Set(ByVal value)
num_documento = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal idventa As Integer, ByVal idcliente As Integer, ByVal
fecha_venta As Date, ByVal tipo_documento As String, ByVal num_documento As
String)
gidventa = idventa
gidcliente = idcliente
gfecha_venta = fecha_venta
gtipo_documento = tipo_documento
gnum_documento = num_documento
End Sub
End Class
CLASE DETALLE VENTA
Public Class vdetalle_venta
Dim iddetalle_venta, idventa, idproducto As Integer
Dim cantidad, precio_unitario As Double
Public Property giddetalle_venta
Get
Return iddetalle_venta
End Get
Set(ByVal value)
iddetalle_venta = value
End Set
End Property
Public Property gidventa
Get

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 43 -

Return idventa
End Get
Set(ByVal value)
idventa = value
End Set
End Property
Public Property gidproducto
Get
Return idproducto
End Get
Set(ByVal value)
idproducto = value
End Set
End Property
Public Property gcantidad
Get
Return cantidad
End Get
Set(ByVal value)
cantidad = value
End Set
End Property
Public Property gprecio_unitario
Get
Return precio_unitario
End Get
Set(ByVal value)
precio_unitario = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal iddetalle_venta As Integer, ByVal idventa As Integer, ByVal
idproducto As Integer, ByVal cantidad As Double, ByVal precio_unitario As Double)
giddetalle_venta = iddetalle_venta
gidventa = idventa
gidproducto = idproducto
gcantidad = cantidad
gprecio_unitario = precio_unitario
End Sub
End Class
CLASE FVENTA parecido a fcliente
Imports System.Data.SqlClient
Public Class fventa
Inherits conexion
Dim cmd As New SqlCommand
Public Function mostrar() As DataTable
Try
conectado()

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 44 -

cmd = New SqlCommand("mostrar_venta")


cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vventa) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
cmd.Parameters.AddWithValue("@fecha_venta", dts.gfecha_venta)
cmd.Parameters.AddWithValue("@tipo_documento", dts.gtipo_documento)
cmd.Parameters.AddWithValue("@num_documento", dts.gnum_documento)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function

Public Function editar(ByVal dts As vventa) As Boolean


Try

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 45 -

conectado()
cmd = New SqlCommand("editar_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idventa", dts.gidventa)
cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
cmd.Parameters.AddWithValue("@fecha_venta", dts.gfecha_venta)
cmd.Parameters.AddWithValue("@tipo_documento", dts.gtipo_documento)
cmd.Parameters.AddWithValue("@num_documento", dts.gnum_documento)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vventa) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@idventa", SqlDbType.NVarChar, 50).Value =
dts.gidventa
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
End Class
FDETALLE VENTA
Imports System.Data.SqlClient
Public Class fdetalle_venta
Inherits conexion
Dim cmd As New SqlCommand

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 46 -

Public Function mostrar() As DataTable


Try
conectado()
cmd = New SqlCommand("mostrar_detalle_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
desconectado()
End Try
End Function
Public Function insertar(ByVal dts As vdetalle_venta) As Boolean
Try
conectado()
cmd = New SqlCommand("insertar_detalle_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idventa", dts.gidventa)
cmd.Parameters.AddWithValue("@idproducto", dts.gidproducto)
cmd.Parameters.AddWithValue("@cantidad", dts.gcantidad)
cmd.Parameters.AddWithValue("@precio_unitario", dts.gprecio_unitario)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function editar(ByVal dts As vdetalle_venta) As Boolean
Try
conectado()
cmd = New SqlCommand("editar_detalle_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@iddetalle_venta", dts.giddetalle_venta)
cmd.Parameters.AddWithValue("@idventa", dts.gidventa)

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 47 -

cmd.Parameters.AddWithValue("@idproducto", dts.gidproducto)
cmd.Parameters.AddWithValue("@cantidad", dts.gcantidad)
cmd.Parameters.AddWithValue("@precio_unitario", dts.gprecio_unitario)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
Public Function eliminar(ByVal dts As vdetalle_venta) As Boolean
Try
conectado()
cmd = New SqlCommand("eliminar_detalle_venta")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.Add("@iddetalle_venta", SqlDbType.NVarChar, 50).Value =
dts.giddetalle_venta
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Public Function aumentar_stock(ByVal dts As vdetalle_venta) As Boolean
Try
conectado()
cmd = New SqlCommand("aumentar_stock")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idproducto", dts.gidproducto)
cmd.Parameters.AddWithValue("@cantidad", dts.gcantidad)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 48 -

End Function
Public Function disminuir_stock(ByVal dts As vdetalle_venta) As Boolean
Try
conectado()
cmd = New SqlCommand("disminuir_stock")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = cnn
cmd.Parameters.AddWithValue("@idproducto", dts.gidproducto)
cmd.Parameters.AddWithValue("@cantidad", dts.gcantidad)
If cmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
desconectado()
End Try
End Function
End Class
Video 12 46.59 minutos
Mantenimiento a la tabla venta y tabla detalle de venta
Parte grafica modificar proemiento r mostrar ventas
DETALLE de venta Frm detalle venta 12.55
Agrema frm venta
Copiamos el diseo para frmventa del frm cliente
Son tablas relacionadas
9.14 no se puede eliminar directamente una ventas primero hay que elimnar los
detalles de la venta por lo tanto se suprime el boton eliminar

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

CODIGO DE FRMVENTA
Public Class frmventa
Private dt As New DataTable
Private Sub frmventa_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mostrar()
End Sub
Public Sub limpiar()
btnguardar.Visible = True
btneditar.Visible = False
txtidventa.Text = ""
txtidcliente.Text = ""
txtnum_documento.Text = ""
txtnum_documento.Text = ""
txtidventa.Text = ""
End Sub
Private Sub mostrar()
Try
Dim func As New fventa
dt = func.mostrar
datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
txtbuscar.Enabled = True
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False
Else
datalistado.DataSource = Nothing
txtbuscar.Enabled = False
datalistado.ColumnHeadersVisible = False
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True
BtnEditar.Visible = False
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = cboCampo.Text & " like '" & txtbuscar.Text & "%'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else

- 49 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 50 -

inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
datalistado.Columns(2).Visible = False
End Sub
Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNuevo.Click
limpiar()
mostrar()
End Sub
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
If Me.ValidateChildren = True And txtidventa.Text <> "" And txtidcliente.Text <> ""
And txtNum_Documento.Text <> "" Then
Try
Dim dts As New vventa
Dim func As New fventa
dts.gidcliente = txtidventa.Text
dts.gfecha_venta = txtfecha.Text
dts.gtipo_documento = cbtipo_documento.Text
dts.gnum_documento = txtNum_Documento.Text
If func.insertar(dts) Then
MessageBox.Show("Venta registrada correctamente vamos aadir
productos", "Guardando registros", MessageBoxButtons.OK,
MessageBoxIcon.Information)
mostrar()
limpiar()
cargar_detalle()
Else
MessageBox.Show("venta no fue registrada intente de nuevo",
"Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub datalistado_CellClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles datalistado.CellClick
txtidventa.Text = datalistado.SelectedCells.Item(1).Value

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 51 -

txtidventa.Text = datalistado.SelectedCells.Item(2).Value
txtidcliente.Text = datalistado.SelectedCells.Item(3).Value
txtfecha.Text = datalistado.SelectedCells.Item(5).Value
cbtipo_documento.Text = datalistado.SelectedCells.Item(6).Value
txtnum_documento.Text = datalistado.SelectedCells.Item(7).Value
btneditar.Visible = True
btnguardar.Visible = False
End Sub
Private Sub datalistado_CellContentClick(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DataGridViewCellEventArgs) Handles
datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkcell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkcell.Value = Not chkcell.Value
End If
End Sub
Private Sub btneditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnEditar.Click
Dim result As DialogResult
result = MessageBox.Show("Realmente desea editar los datos de la venta?",
"MOdificando registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then
If Me.ValidateChildren = True And txtidcliente.Text <> "" And
txtNum_Documento.Text <> "" And txtidventa.Text <> "" Then
Try
Dim dts As New vventa
Dim func As New fventa
dts.gidventa = txtidventa.Text
dts.gidcliente = txtidventa.Text
dts.gfecha_venta = txtfecha.Text
dts.gtipo_documento = cbtipo_documento.Text
dts.gnum_documento = txtNum_Documento.Text
If func.editar(dts) Then
MessageBox.Show("venta MOdificada correctamente", "MOdificando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Venta no fue modifcada intente de nuevo",
"MOdificando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 52 -

MessageBox.Show("Falta ingresar algunos datos", "MOdificando registros",


MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End Sub
Private Sub cbeliminar_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub
Private Sub txtbuscar_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtbuscar.TextChanged
buscar()
End Sub
Private Sub cargar_detalle()
frmdetalle_venta.txtidventa.Text = datalistado.SelectedCells.Item(1).Value
frmdetalle_venta.txtidcliente.Text = datalistado.SelectedCells.Item(2).Value
frmdetalle_venta.txtidcliente.Text = datalistado.SelectedCells.Item(3).Value
frmdetalle_venta.txtfecha.Text = datalistado.SelectedCells.Item(5).Value
frmdetalle_venta.cbtipo_documento.Text = datalistado.SelectedCells.Item(6).Value
frmdetalle_venta.txtNum_Documento.Text =
datalistado.SelectedCells.Item(7).Value
frmdetalle_venta.ShowDialog()
End Sub
Private Sub datalistado_CellDoubleClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
datalistado.CellDoubleClick
cargar_detalle()
End Sub
Private Sub btnbuscar_cliente_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnbuscar_cliente.Click
frmcliente.txtflag.Text = "1"
frmcliente.ShowDialog()
End Sub
Private Sub txtidcliente_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtidventa.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Seleccione el cliente de la venta, este dato es
obligatorio")
End If
End Sub
Private Sub txtnum_documento_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtnum_documento.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 53 -

Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese el nmero de comprobante, este dato
es obligatorio")
End If
End Sub
End Class
FORMULARIO DETALLE VENTAS

Public Class frmdetalle_venta


Private dt As New DataTable
Private Sub frmdetalle_venta_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mostrar()
End Sub
Public Sub limpiar()
btnGuardar.Visible = True
txtidproducto.Text = ""
txtnombre_producto.Text = ""
txtprecio_unitario.Text = ""
txtcantidad.Value = 0
txtstock.Value = 1
End Sub
Private Sub mostrar()
Try
Dim func As New fdetalle_venta
dt = func.mostrar
datalistado.Columns.Item("Eliminar").Visible = False
If dt.Rows.Count <> 0 Then
datalistado.DataSource = dt
datalistado.ColumnHeadersVisible = True
inexistente.Visible = False

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 54 -

Else
datalistado.DataSource = Nothing
datalistado.ColumnHeadersVisible = False
inexistente.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnNuevo.Visible = True
buscar()
End Sub
Private Sub buscar()
Try
Dim ds As New DataSet
ds.Tables.Add(dt.Copy)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "idventa='" & txtidventa.Text & "'"
If dv.Count <> 0 Then
inexistente.Visible = False
datalistado.DataSource = dv
ocultar_columnas()
Else
inexistente.Visible = True
datalistado.DataSource = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ocultar_columnas()
datalistado.Columns(1).Visible = False
datalistado.Columns(2).Visible = False
datalistado.Columns(3).Visible = False
End Sub
Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
limpiar()
mostrar()
End Sub
Private Sub txtbuscar_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
buscar()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim result As DialogResult
result = MessageBox.Show("Realmente desea quitar los artculos de la venta?",
"Eliminando registros", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 55 -

If result = DialogResult.OK Then


Try
For Each row As DataGridViewRow In datalistado.Rows
Dim marcado As Boolean =
Convert.ToBoolean(row.Cells("Eliminar").Value)
If marcado Then
Dim onekey As Integer =
Convert.ToInt32(row.Cells("idddetalle_venta").Value)
Dim vdb As New vdetalle_venta
Dim func As New fdetalle_venta
vdb.giddetalle_venta = onekey
vdb.gidproducto = datalistado.SelectedCells.Item(3).Value
vdb.gidventa = datalistado.SelectedCells.Item(2).Value
vdb.gcantidad = datalistado.SelectedCells.Item(5).Value
If func.eliminar(vdb) Then
If func.aumentar_stock(vdb) Then
End If
Else
MessageBox.Show("Artculo fue quitado de la venta", "Eliminando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Next
Call mostrar()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Cancelando eliminacin de registros", "Eliminando
registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call mostrar()
End If
Call limpiar()
End Sub
Private Sub btnbuscar_producto_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnbuscar_producto.Click
frmproducto.txtflag.Text = "1"
frmproducto.ShowDialog()
End Sub
Private Sub txtcantidad_ValueChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtcantidad.ValueChanged
Dim cant As Double
cant = txtcantidad.Value
If txtcantidad.Value > txtstock.Value Then
MessageBox.Show("La cantidad que intenta vender supera stock", "Error al
vender el producto", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnGuardar.Visible = 0
txtcantidad.Value = txtstock.Value
Else
btnGuardar.Visible = 1

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 56 -

End If
If txtcantidad.Value = 0 Then
btnGuardar.Visible = 0
Else
btnGuardar.Visible = 1
End If
End Sub
Private Sub btnguardar_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGuardar.Click
If Me.ValidateChildren = True And txtidproducto.Text <> "" And txtcantidad.Text <>
"" And txtprecio_unitario.Text <> "" Then
Try
Dim dts As New vdetalle_venta
Dim func As New fdetalle_venta
dts.gidventa = txtidventa.Text
dts.gidproducto = txtidproducto.Text
dts.gcantidad = txtcantidad.Text
dts.gprecio_unitario = txtprecio_unitario.Text
If func.insertar(dts) Then
If func.disminuir_stock(dts) Then
End If
MessageBox.Show("Artculo fue aadido correctamente a la venta",
"Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
mostrar()
limpiar()
Else
MessageBox.Show("Artculo fue aadido correctamente a la venta intente
de nuevo", "Guardando registros", MessageBoxButtons.OK, MessageBoxIcon.Error)
mostrar()
limpiar()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("Falta ingresar algunos datos", "Guardando registros",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub cbeliminar_CheckedChanged_1(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles cbeliminar.CheckedChanged
If cbeliminar.CheckState = CheckState.Checked Then
datalistado.Columns.Item("Eliminar").Visible = True
Else
datalistado.Columns.Item("Eliminar").Visible = False
End If
End Sub

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 57 -

Private Sub datalistado_CellContentClick(ByVal sender As System.Object, ByVal e


As System.Windows.Forms.DataGridViewCellEventArgs) Handles
datalistado.CellContentClick
If e.ColumnIndex = Me.datalistado.Columns.Item("Eliminar").Index Then
Dim chkcell As DataGridViewCheckBoxCell =
Me.datalistado.Rows(e.RowIndex).Cells("Eliminar")
chkcell.Value = Not chkcell.Value
End If
End Sub
Private Sub txtidproducto_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtidproducto.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Seleccione el producto para aadir a la venta,
este dato es obligatorio")
End If
End Sub
Private Sub txtprecio_unitario_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtprecio_unitario.Validating
If DirectCast(sender, TextBox).Text.Length > 0 Then
Me.erroricono.SetError(sender, "")
Else
Me.erroricono.SetError(sender, "Ingrese precio unitario de la venta, este dato es
obligatorio")
End If
End Sub
Private Sub btnimprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnimprimir.Click
frmreportecomprobante.txtidventa.Text = Me.txtidventa.Text
frmreportecomprobante.ShowDialog()
End Sub
End Class
VIDEO 13 26 04
Comprobante de venta
Generar nueva vista 0.43
Vista nueva vista 1
3.22 procedimiento almacenado generar comprobante
CREATE PROC generar_comprobante
@idventa int
as
SELECT dbo.venta.idventa, dbo.cliente.nombre, dbo.cliente.apellidos,
dbo.cliente.dni, dbo.venta.fecha_venta, dbo.venta.tipo_documento,
dbo.venta.num_documento,

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 58 -

dbo.producto.nombre AS Descripcion, dbo.detalle_venta.cantidad,


dbo.detalle_venta.precio_unitario,
dbo.detalle_venta.cantidad * dbo.detalle_venta.precio_unitario AS
Total_Parcial
FROM
dbo.venta INNER JOIN
dbo.detalle_venta ON dbo.venta.idventa = dbo.detalle_venta.idventa
INNER JOIN
dbo.producto ON dbo.detalle_venta.idproducto = dbo.producto.idproducto
INNER JOIN
dbo.cliente ON dbo.venta.idcliente = dbo.cliente.idcliente
where dbo.venta.idventa=@idventa
AGREGAR un botn para generar ese comprobante 4.34
Agregar reporte
Asistente para informe 5.37
5.29 agregar nuevo elemento reporte
Eligir reporte
Generar vista

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Aparece el asistente para infomes

- 59 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 60 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 61 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 62 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Idventa va ser grupo primario 11


15 dos ventas
Un formulario que llame a ese diseo
Organizar campos

- 63 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 64 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Suprimir para hacer nueva tabla


Id venta grupo primario

frmComporbante
reporte productos

- 65 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

15.56 reporte comprobante


Report newere

UN NUEVO informe para los productos 21.38


Rpt productos
Report viewer
VIDEO 14 33.15

- 66 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 67 -

Parte del men del sistema


Formulario mDI
Modificar men strip
Restringir el acdeso so lo a los usarios
Procedimiento validar en sql server el usuario ( para eso es necesario es sql server
7.14 validar usuario
Clase para el objeto usario
Clase vusuario
Dos constructores 13.10
Blanco
Y otros que reciba todos los valores
Clase f usuario 16-09
Importar librera de sql server
Objeto validadr usario prcediiento almacenado
Crear usuario 3120
VIDEO 15 backup de la base de datos
15.24
Procedimietno almacendado para realizar el backup de la base de datos
Espacio de discon para que lo copie
Archivo .bak
La ruta del backup

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Clase fbackup

Procedimiento almacenado
Backup de base de datos

Mover al disco local C


Windows r notewad
Dbventas.back
En herramientas generar backup

- 68 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

HERRAmientas
New query nueva consulta
Video 16 10 minutos
Instalador de visual basic

Resutaruar la bse de datos y restaurarlo

Backup completo
Descargar el sql sever 2008 1946
Restaurar .3.40 con sqlserver
Cambiar base de datos con la nueva base de datos
6.23 instalador de sitema de ventas

- 69 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 70 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

Em el directorio se muestra el backup

Restaurar la base de datos 3.33

- 71 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 72 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 73 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 74 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

La base de datos restaurada

Configuracin para reportes


Generar instalador de sistema de ventas
Crear instalador

- 75 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

- 76 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

https://www.youtube.com/user/jcarlosad7

- 77 -

Sistema de ventas en visual estudio 2010\ Ismael Vliz Vilca

mircoles 24 de junio del 2015


Repaso de los videos
Video 1 15 23 es crear la base de datos hasta las relaciones
Video 2 16.52 las 5 carpetas de presentacin define la clase cliente
Video 3 21.42 frmcliente
Viedo 4 9.35 minutos hasta insertar clientes
Video 5 21.52 listado clientes
Video 6 13.23 listado de copalientes
Video 7 18 49 clientes eliminar
Video 8 10.08 categoria
Video 9 24 02 producto
Video 10 34.31 porducto con imgenes y categora
Video 11 31.18 venta detalle venta
Video 12 46.59 frm producto
Video 13 26-4 reporte a la vetna reporte
Video 14 3315
Video 15 15.24
Video 16 1000 instalador de visual estudio
Control doble buffering

- 78 -

Das könnte Ihnen auch gefallen