+ All Categories
Home > Documents > Pro Yec to Ventas

Pro Yec to Ventas

Date post: 11-Oct-2015
Category:
Upload: manuelrogerchav
View: 74 times
Download: 2 times
Share this document with a friend

of 12

Transcript
  • CLASE CONECCION.VB Imports System.Data.SqlClient 'importar la librera para trabajar cn sql Public Class coneccion Protected cnn As New SqlConnection 'Declarar la variable para establecer cadena de conexin con bd Public idusuario As Integer Protected Function conectado() 'funcin para conectarse con la bd Try 'declara capturador de errores 'Establecer la cadena de conexin si est trabajando en red se pondr direccin ip del servidor, si no se pondr local

    cnn = New SqlConnection("data source=(local);initial catalog=dbventas;integrated security=true") cnn.Open()'Abrir la cadena de coneccion Return True 'function retorna un valor Catch ex As Exception MsgBox(ex.Message) mostrar un error describiendo la excepcin Return False End Try

    End Function

    'funcin para desconectarse con la bd Protected Function desconectado() 'declara capturador de errores Try If cnn.State = ConnectionState.Open Then cnn.Close() 'function retorna un valor Return True Else Return False End If Catch ex As Exception 'mostrar un error decscribiendo la excepcion MsgBox(ex.Message) Return False End Try End Function

    End Class

  • CLASE vcliente.VB Public Class vcliente Dim idcliente As Integer Dim nombre, apellidos, direccion, telefono, dni As String 'get yset leer y escribir datos Public Property gidcliente Get Return idcliente End Get Set(ByVal value) idcliente = value End Set End Property Public Property gnombre Get Return nombre End Get Set(ByVal value) nombre = value End Set End Property Public Property gapellidos Get Return apellidos End Get Set(ByVal value) apellidos = value End Set End Property Public Property gdireccion Get Return direccion End Get Set(ByVal value) direccion = value End Set End Property Public Property gtelefono Get Return telefono End Get Set(ByVal value) telefono = value End Set End Property Public Property gdni Get Return dni End Get Set(ByVal value) dni = value End Set End Property 'crear constructores que reciban datos y se comunica con la carpeta datos y esta la insertar, modificar 'constrtor en blanco

  • Public Sub New() End Sub Public Sub New(ByVal idcliente As Integer, ByVal nombre As String, ByVal apellidos As String, ByVal direccion As String, ByVal telefono As String, ByVal dni As String) gidcliente = idcliente gnombre = nombre gapellidos = apellidos gdireccion = direccion gtelefono = telefono gdni = dni End Sub End Class CLASE FCLIENTE.VB Imports System.Data.SqlClient Public Class fcliente Inherits coneccion 'hereda atributos,propiedades,procedimientos y eventos de la clase coneccion Dim cmd As SqlCommand 'declara variable de tipo procedimiento almacenado 'declarar variable para enviar peticiones a la bdventas Public Function mostrar() As DataTable 'funcin mostrar en modo tabla de datos en memoria en la que contenemos todos los valores de la bdventa a la tabla cliente Try conectado() 'llama al procedimiento conectado de coneccion p' conectarse a la bdventas

    cmd = New SqlCommand("Mostrar_cliente") 'crear una instancia a un procedimiento almacenado mostrar_cliente que se debe encontrar en la bdventas

    cmd.CommandType = CommandType.StoredProcedure 'est llamando a un procedimiento almacenado cmd.Connection = cnn 'establecer al cmd como cadena de conexin a cnn If cmd.ExecuteNonQuery Then Dim dt As New DataTable Dim da As New SqlDataAdapter(cmd) da.Fill(dt) Return dt Else Return Nothing End If Catch ex As Exception MsgBox(ex.Message) 'mostrar un error describiendo la excepcin Return Nothing Finally desconectado() End Try End Function

    Public Function insertar(ByVal dts As vcliente) As Boolean 'funcion para insertar elementos Try

    conectado() 'llama al procedimiento conectado de coneccion p' conectarse a la bdventas 'crear una instancia a un procedimiento almacenado insertar_cliente cmd = New SqlCommand("insertar_cliente") 'esta llamando a un procedimiento almacenado cmd.CommandType = CommandType.StoredProcedure cmd.Connection = cnn 'establecer al cmd como cadena de coneccion a cnn 'enviando todos los valores al procedimiento almacebado insertar_cliente 'se captura mediante geter los siguientes objetos cmd.Parameters.AddWithValue("@nombre", dts.gnombre) cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos) cmd.Parameters.AddWithValue("@direccion", dts.gdireccion) cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)

  • cmd.Parameters.AddWithValue("@dni", dts.gdni) If cmd.ExecuteNonQuery Then Return True Else Return False End If 'capturador de errores Catch ex As Exception 'mostrar un error decscribiendo la excepcion MsgBox(ex.Message) Return False Finally desconectado() End Try End Function Public Function eliminar(ByVal dts As vcliente) As Boolean 'Funcion devuelve un true o false Try conectado() 'llama al procedimiento conectado de coneccion p' conectarse a la bdventas 'crear una instancia a un procedimiento almacenado insertar_cliente que se debe encontrar en la bdventas cmd = New SqlCommand("eliminar_clientes") 'esta llamando a un procedimiento almacenado cmd.CommandType = CommandType.StoredProcedure 'establecer al cmd como cadena de coneccion a cnn cmd.Connection = cnn 'enviando todos los valores al procedimiento almacebado insertar_cliente 'se captura mediante geter los siguientes objetos cmd.Parameters.Add("@idcliente", SqlDbType.NVarChar, 50).Value = dts.gidcliente If cmd.ExecuteNonQuery Then Return True Else Return False End If 'capturador de errores Catch ex As Exception 'mostrar un error decscribiendo la excepcion MsgBox(ex.Message) Return False End Try End Function End Class

  • Public Class frmcliente Private dt As New DataTable Private Sub frmcliente_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load mostrar() End Sub Public Sub Limpiar() btnGuardar.Visible = True btneditar.Visible = False txtnombre.Text = "" txtapellidos.Text = "" txtdireccion.Text = "" txttelefono.Text = "" txtdni.Text = "" txtIdcliente.Text = "" End Sub Private Sub mostrar() Try Dim fun As New fcliente 'declarar una variable para instanciar a la funcion fcliente dt = fun.mostrar datalistado.Columns.Item("Eliminar").Visible = False If dt.Rows.Count 0 Then datalistado.DataSource = dt txtbuscar.Enabled = True datalistado.ColumnHeadersVisible = True inexistente.Visible = False Else datalistado.DataSource = Nothing txtbuscar.Enabled = False datalistado.ColumnHeadersVisible = False inexistente.Visible = True End If btnnuevo.Visible = True btneditar.Visible = False buscar() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub buscar() Try Dim ds As New DataSet ds.Tables.Add(dt.Copy) 'copiar la estructura de la tabla en memoria del dt a la variable ds Dim dv As New DataView(ds.Tables(0)) 'declara variable de tipo vista para enlazar datos a un datatable para filtrado,ordenacion,busqueda dv.RowFilter = cbocampo.Text & "like'" & txtbuscar.Text & "%'" If dv.Count 0 Then inexistente.Visible = False datalistado.DataSource = dv ocultar_columnas() Else inexistente.Visible = True datalistado.DataSource = Nothing End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub

  • Private Sub ocultar_columnas() datalistado.Columns(1).Visible = False End Sub 'validar cada caja de texto en el evento validating para saber si hay datos ingresados Private Sub txtnombre_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtnombre.Validating If DirectCast(sender, TextBox).TextLength > 0 Then Me.ErrorIcono.SetError(sender, "") Else 'En caso no haya datos ingresados emitir un mensaje de error Me.ErrorIcono.SetError(sender, "Ingrese el nombre del cliente, este dato es oblgatorio") End If End Sub Private Sub txtapellidos_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtapellidos.Validating If DirectCast(sender, TextBox).TextLength > 0 Then Me.ErrorIcono.SetError(sender, "") Else Me.ErrorIcono.SetError(sender, "Ingrese el apellido del cliente, este dato es oblgatorio") End If End Sub Private Sub txtdireccion_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtdireccion.Validating If DirectCast(sender, TextBox).TextLength > 0 Then Me.ErrorIcono.SetError(sender, "") Else Me.ErrorIcono.SetError(sender, "Ingrese la direccin del cliente, este dato es oblgatorio") End If End Sub Private Sub txtdni_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtdni.Validating If DirectCast(sender, TextBox).TextLength > 0 Then Me.ErrorIcono.SetError(sender, "") Else Me.ErrorIcono.SetError(sender, "Ingrese el DNI del cliente, este dato es oblgatorio") End If End Sub Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click 'Llamar a los procedimientos limpiar y mostrar Limpiar() mostrar() End Sub

  • Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuardar.Click 'VERIFICAR QUE CAJAS DE TEXTO ESTEN NO VACIAS If Me.ValidateChildren = True And txtnombre.Text "" And txtapellidos.Text "" And txtdireccion.Text "" And txtdni.Text "" Then Try 'declara variables que llame a todos los objetos de la clase vcliente y fcliente que se encuentra en la carpeta lgica y presentacin Dim dts As New vcliente 'Variable para instanciar a las funciones o atributos de clase vcliente Dim func As New fcliente 'Variable para instanciar a las funciones de la clase fcliente dts.gnombre = txtnombre.Text dts.gapellidos = txtapellidos.Text dts.gdireccion = txtdireccion.Text dts.gtelefono = txttelefono.Text dts.gdni = txtdni.Text 'La clave principal idcliente no se coloca porque ese dato es autonumerico y se genera en SQLSERVER If func.insertar(dts) Then 'SI LA FUNCION INSERTAR DEVUELVE UN TRUE MessageBox.Show("Cliente registrado correctamente", "guardando registro", MessageBoxButtons.OK, MessageBoxIcon.Information) mostrar() Limpiar() Else MessageBox.Show("Cliente no fue registrado intente de nuevo ", "guardando registro", MessageBoxButtons.OK, MessageBoxIcon.Error) mostrar() Limpiar() End If Catch ex As Exception MsgBox(ex.Message) End Try Else MessageBox.Show("falta ingresar algunos datos", "guardando registro", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub End Class Private Sub cbeliminar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbeliminar.CheckedChanged If cbeliminar.CheckState = CheckState.Checked Then datalistado.Columns.Item("Eliminar").Visible = True End If End Sub End Class

  • PROCEDIIENTO ALMACENADO PARA INSERTAR_CLIENTE

    Create proc insertar_cliente

    @nombre varchar(50),

    @apellidos varchar(50),

    @direccion varchar(100),

    @telefono varchar(9),

    @dni varchar(8)

    as

    insert into

    cliente(nombre,apellidos,direccion,telefono,dni)values(@nombre,@apellidos,@direcci

    on,@telefono,@dni)

    PROCEDIIENTO ALMACENADO PARA MOSTRAR CLIENTE

    Create proc mostrar_cliente

    as

    select * from cliente

    order by idcliente desc

    PROCEDIIENTO ALMACENADO PARA ELIMINAR CLIENTE

    Create proc eliminar_cliente

    @idcliente integer

    as

    delete from cliente where idcliente=@idcliente


Recommended