SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
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)
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
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")
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
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
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
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()
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")
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)
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
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
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
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"))
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
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)
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
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
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
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
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
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
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
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
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
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
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

Más contenido relacionado

La actualidad más candente

The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202Mahmoud Samir Fayed
 
Java script frame window
Java script frame windowJava script frame window
Java script frame windowH K
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile servicesAymeric Weinbach
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidRodrigo de Souza Castro
 
The Ring programming language version 1.3 book - Part 20 of 88
The Ring programming language version 1.3 book - Part 20 of 88The Ring programming language version 1.3 book - Part 20 of 88
The Ring programming language version 1.3 book - Part 20 of 88Mahmoud Samir Fayed
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 

La actualidad más candente (19)

The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88The Ring programming language version 1.3 book - Part 34 of 88
The Ring programming language version 1.3 book - Part 34 of 88
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185
 
Punto fijo multivariante
Punto fijo multivariantePunto fijo multivariante
Punto fijo multivariante
 
Codeofdatabase
CodeofdatabaseCodeofdatabase
Codeofdatabase
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
 
resume_Alexey_Zaytsev
resume_Alexey_Zaytsevresume_Alexey_Zaytsev
resume_Alexey_Zaytsev
 
The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202
 
Mobile Web 5.0
Mobile Web 5.0Mobile Web 5.0
Mobile Web 5.0
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
CRUD VB2010
CRUD VB2010CRUD VB2010
CRUD VB2010
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
 
Everyday's JS
Everyday's JSEveryday's JS
Everyday's JS
 
The Ring programming language version 1.3 book - Part 20 of 88
The Ring programming language version 1.3 book - Part 20 of 88The Ring programming language version 1.3 book - Part 20 of 88
The Ring programming language version 1.3 book - Part 20 of 88
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 

Similar a Sistema de ventas

Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduinozadkiel_123
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .netAyuda Universidad
 
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.154.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15Rajes Wari
 
Inventory management
Inventory managementInventory management
Inventory managementRajeev Sharan
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguajeguest6473b8
 
Documento de altas
Documento de altasDocumento de altas
Documento de altasalejandroDFK
 
Membuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaMembuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaYusman Kurniadi
 
VisualBasicExample
VisualBasicExampleVisualBasicExample
VisualBasicExampleBo Dake
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docxAustinaGRPaigey
 
I can't get my code below to work with Option Strict On due to this part of t...
I can't get my code below to work with Option Strict On due to this part of t...I can't get my code below to work with Option Strict On due to this part of t...
I can't get my code below to work with Option Strict On due to this part of t...hwbloom115
 
Student information system
Student information systemStudent information system
Student information systempatrick7772
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletMitchinson
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Netcymbron
 
OOP - PREFINAL ACTIVITY - ACLC
OOP - PREFINAL ACTIVITY - ACLCOOP - PREFINAL ACTIVITY - ACLC
OOP - PREFINAL ACTIVITY - ACLCMarlo Tinio
 

Similar a Sistema de ventas (20)

Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduino
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .net
 
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.154.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
 
Inventory management
Inventory managementInventory management
Inventory management
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguaje
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
 
Documento de altas
Documento de altasDocumento de altas
Documento de altas
 
Membuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaMembuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhana
 
VisualBasicExample
VisualBasicExampleVisualBasicExample
VisualBasicExample
 
Form1.vb
Form1.vbForm1.vb
Form1.vb
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
I can't get my code below to work with Option Strict On due to this part of t...
I can't get my code below to work with Option Strict On due to this part of t...I can't get my code below to work with Option Strict On due to this part of t...
I can't get my code below to work with Option Strict On due to this part of t...
 
Student information system
Student information systemStudent information system
Student information system
 
Training cards implementation
Training cards implementationTraining cards implementation
Training cards implementation
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Net
 
OOP - PREFINAL ACTIVITY - ACLC
OOP - PREFINAL ACTIVITY - ACLCOOP - PREFINAL ACTIVITY - ACLC
OOP - PREFINAL ACTIVITY - ACLC
 
Docimp
DocimpDocimp
Docimp
 
Qtp test
Qtp testQtp test
Qtp test
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
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