CODIFICACION EN SQL PARA CLIENTE

CREATE PROCEDURE SP_INSERTACLIENTE @PCODIGO VARCHAR(10), @PAPELLIDOS VARCHAR(20), @PNOMBRES VARCHAR(20), @PDIRECCION VARCHAR(20), @PTELEFONO VARCHAR(20) AS BEGIN INSERT INTO cliente(codigo,apellidos,nombres,direccion,telefono) VALUES (@PCODIGO,@PAPELLIDOS,@PNOMBRES,@PDIRECCION,@PTELEFONO) END CREATE PROCEDURE SP_LISTACLIENTE AS BEGIN SELECT * FROM cliente END CREATE PROCEDURE SP_BUSCACLIENTE @PCODIGO VARCHAR(10) AS BEGIN SELECT * FROM cliente WHERE codigo=@PCODIGO END CREATE PROCEDURE SP_ACTUALIZACLIENTE @PCODIGO VARCHAR(10), @PAPELLIDOS VARCHAR(20), @PNOMBRES VARCHAR(20),@PDIRECCION VARCHAR(20),@PTELEFONO VARCHAR(20) AS BEGIN UPDATE cliente SET apellidos=@PAPELLIDOS,nombres=@PNOMBRES, direccion=@PDIRECCION, telefono=@PTELEFONO WHERE codigo=@PCODIGO END

ENLACE
Private Sub CLIENTEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CLIENTEToolStripMenuItem.Click Dim MnuCLIENTE As New CLIENTE MnuCLIENTE.Show() End Sub

APELLIDOS = value End Set End Property Public Property fNOMBRES() As String Get Return Me.NOMBRES = tNOMBRES Me.NOMBRES = value End Set End Property . ByVal tNOMBRES As String.CLASE Imports System. DIRECCION.Data.CODIGO = value End Set End Property Public Property fAPELLIDOS() As String Get Return Me. APELLIDOS.APELLIDOS = tAPELLIDOS Me. TELEFONO As String Private conn As SqlConnection Private cmd As SqlCommand Private strConn As String = "SERVER=localhost.Integrated Security=SSPI.DATABASE=EJEMPLO. NOMBRES." Sub New() conn = New SqlConnection(strConn) End Sub Sub New(ByVal tCODIGO As String. ByVal tAPELLIDOS As String.TELEFONO = tTELEFONO conn = New SqlConnection(strConn) End Sub Public Property fCODIGO() As String Get Return Me. ByVal tTELEFONO As String) Me.APELLIDOS End Get Set(ByVal value As String) Me. ByVal tDIRECCION As String.DIRECCION = tDIRECCION Me.SqlClient Public Class CLIENTES Private CODIGO.CODIGO End Get Set(ByVal value As String) Me.CODIGO = tCODIGO Me.NOMBRES End Get Set(ByVal value As String) Me.

StoredProcedure cmd.Parameters.CommandType = CommandType.Close() End Try End Sub Public Sub Actualizarcliente() Try conn. NOMBRES) cmd. conn) cmd. CODIGO) cmd.Close() End Try End Sub Public Sub BuscarCLIENTExId() Try Dim dr As SqlDataReader conn. conn) cmd.Parameters.AddWithValue("@pTELEFONO".Open() cmd = New SqlCommand("SP_ACTUALIZACLIENTE".Message) Finally conn.AddWithValue("@pTELEFONO".Parameters.CommandType = CommandType.Parameters. DIRECCION) cmd.AddWithValue("@pCODIGO".AddWithValue("@pDIRECCION".Parameters.Public Property fDIRECCION() As String Get Return Me. APELLIDOS) cmd.StoredProcedure cmd.TELEFONO = value End Set End Property Public Sub RegistrarCLIENTE() Try conn.Parameters.Parameters.Parameters.TELEFONO End Get Set(ByVal value As String) Me.DIRECCION End Get Set(ByVal value As String) Me.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.AddWithValue("@pNOMBRES". TELEFONO) cmd.Parameters.CommandType = CommandType.AddWithValue("@pAPELLIDOS".Message) Finally conn. TELEFONO) cmd.HasRows Then . CODIGO) cmd.AddWithValue("@pAPELLIDOS". CODIGO) dr = cmd.Parameters.AddWithValue("@pNOMBRES".Open() cmd = New SqlCommand("SP_BUSCACLIENTE".DIRECCION = value End Set End Property Public Property fTELEFONO() As String Get Return Me. APELLIDOS) cmd. conn) cmd.AddWithValue("@pDIRECCION".Open() cmd = New SqlCommand("SP_INSERTACLIENTE".AddWithValue("@pCODIGO". NOMBRES) cmd.ExecuteReader() If Not dr. DIRECCION) cmd.StoredProcedure cmd.AddWithValue("@pCODIGO".Parameters.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.

CommandType = CommandType.Object. ByVal e As System.EventArgs) Handles MyBase.Close() End Try End Function End Class Private Sub Formcliente_Load(ByVal sender As System.Close() End Try End Sub Public Function ListarCLIENTES() As DataTable Try Dim ds As DataSet Dim da As SqlDataAdapter conn. conn) cmd.StoredProcedure ds = New DataSet da = New SqlDataAdapter(cmd) da.Message) Finally conn.Fill(ds) Return ds.Tables(0) Catch ex As Exception Throw New Exception(ex.Load FillGrid() End Sub Private Sub FillGrid() Try Dim objcliente As New CLIENTE .Read CODIGO = dr(0) APELLIDOS = dr(1) NOMBRES = DR(2) DIRECCION = dr(3) TELEFONO = DR(4) End While Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Open() cmd = New SqlCommand(" SP_LISTACLIENTE()".Throw New Exception("Proveedor no encontrado") End If While dr.

Text .EventArgs) Handles ButtonREGISTRAR.DataSource = .Text = "" TextNOMBRES.Text .fDIRECCION = TextDIRECCION.Text = "" TextDIRECCION.Listarcliente End With Catch ex As Exception MsgBox("Mensaje: " & ex.fCODIGO = TextCODIGO.Message) End Try End Sub Private Sub LimpiarForm() TextCODIGO.Text .fAPELLIDOS = TextAPELLIDOS.With objcliente DGVCLIENTE.Message) End Try End Sub .Click Try Dim objcliente As New CLIENTE With objcliente .fTELEFONO = TextTELEFONO.Text .fNOMBRES = TextNOMBRES. ByVal e As System.Text .Focus() End Sub BUTTON Private Sub BtnRegistrar_Click(ByVal sender As System.fCODIGO = TextCODIGO.fNOMBRES = TextNOMBRES.Message) End Try End Sub Private Sub BtnActualizar_Click(ByVal sender As System.Actualizarcliente() End With MsgBox("Datos Actualizados !!!!") LimpiarForm() FillGrid() Catch ex As Exception MsgBox("Mensaje: " & ex.Text = "" TextTELEFONO.RegistrarCLIENTE() End With MsgBox("Porveedor Registrado !!!!") LimpiarForm() 'Invocar al método limpiar formulario FillGrid() 'Llenar el Grid Catch ex As Exception MsgBox("Mensaje: " & ex.Click Try Dim objCLIENTE As New CLIENTE With objCLIENTE .Text .fDIRECCION = TextDIRECCION.Text .EventArgs) Handles ButtonACTUALIZAR.Text .fAPELLIDOS = TextAPELLIDOS.Text = "" TextAPELLIDOS.fTELEFONO = TextTELEFONO.Object.Text . ByVal e As System.Object.Text .Text = "" TextCODIGO.

@PNOMBRE.fAPELLIDOS TextNOMBRES.@PPRECIO FLOAT AS BEGIN UPDATE producto SET nombre=@PNOMBRE.EventArgs) Handles ButtonBUSCAR.@PDESCRIPCION. @PPRECIO FLOAT AS BEGIN INSERT INTO producto(id_producto.fTELEFONO End With Catch ex As Exception MsgBox("Mensaje: " & ex.Text .fNOMBRES TextDIRECCION.Text = .Private Sub BtnBuscar_Click(ByVal sender As System.BuscarCLIENTExId() TextAPELLIDOS. @PDESCRIPCION VARCHAR(20).Text = .descripcion=@PDESCRIPCION.fCODIGO = TextCODIGO. ByVal e As System.@PNOMBRE VARCHAR(20). @PNOMBRE VARCHAR(20).precio) VALUES (@PID_PRODUCTO.descripcion.@PPRECIO) END CREATE PROCEDURE SP_LISTAPRODUCTO AS BEGIN SELECT * FROM producto END CREATE PROCEDURE SP_BUSCAPRODUCTO @PID_PRODUCTO VARCHAR(10) AS BEGIN SELECT * FROM producto WHERE id_producto=@PID_PRODUCTO END CREATE PROCEDURE SP_ACTUALIZAPRODUCTO @PID_PRODUCTO VARCHAR(10). precio=@PPRECIO WHERE id_producto=@PID_PRODUCTO END .Message) End Try End Sub End Class CODIFICACION EN SQL PARA PRODUCTO CREATE PROCEDURE SP_INSERTAPRODUCTO @PID_PRODUCTO VARCHAR(10).nombre.fDIRECCION TextTELEFONO.@PDESCRIPCION VARCHAR(20).Text = .Object.Text = .Click Try Dim objcliente As New CLIENTE With objcliente .

ID_PRDUCTO End Get . ByVal tDESCRIPCION As String.Data." Sub New() conn = New SqlConnection(strConn) End Sub Sub New(ByVal tID_PRODUCTO As String.SqlClient Public Class PRODUCTO Private ID_PRDUCTO.Integrated Security=SSPI.ENLACE Private Sub PRODUCTOToolStripMenuItem_Click(ByVal sender As System. ByVal tNOMBRE As String.Show() End Sub End Class CLASE Imports System. NOMBRE.PRECIO = tPRECIO conn = New SqlConnection(strConn) End Sub Public Property fID_PRODUCTO() As String Get Return Me.ID_PRDUCTO = tID_PRODUCTO Me.Click Dim Mnuproducto As New formPRODUCTO Mnuproducto.Object. DESCRIPCION As String Private PRECIO As String Private conn As SqlConnection Private cmd As SqlCommand Private strConn As String = "SERVER=localhost. ByVal tPRECIO As Char) Me.DESCRIPCION = tDESCRIPCION Me.NOMBRE = tNOMBRE Me.DATABASE=EJEMPLO. ByVal e As System.EventArgs) Handles PRODUCTOToolStripMenuItem.

ID_PRDUCTO) cmd.Open() cmd = New SqlCommand("SP_ACTUALIZAPRODUCTO".Open() cmd = New SqlCommand("SP_INSERTAPRODUCTO".DESCRIPCION = value End Set End Property Public Property fPRECIO() As String Get Return Me.Parameters.StoredProcedure cmd.Parameters.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.DESCRIPCION End Get Set(ByVal value As String) Me. DESCRIPCION) cmd.PRECIO = value End Set End Property Public Sub RegistrarPRODUCTO() Try conn.Message) Finally conn.Parameters. NOMBRE) cmd.Parameters.PRECIO End Get Set(ByVal value As String) Me.Parameters.NOMBRE End Get Set(ByVal value As String) Me. NOMBRE) cmd.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.Message) Finally conn.CommandType = CommandType.Close() .AddWithValue("@pDESCRIPCION".Parameters.Set(ByVal value As String) Me.NOMBRE = value End Set End Property Public Property fDESCRIPCION() As String Get Return Me.AddWithValue("@pID_PRODUCTO". DESCRIPCION) cmd.AddWithValue("@pID_PRODUCTO".Close() End Try End Sub Public Sub ActualizarPRODUCTO() Try conn. conn) cmd. conn) cmd.Parameters.AddWithValue("@pPRECIO".AddWithValue("@pPRECIO". ID_PRDUCTO) cmd.AddWithValue("@pNOMBRE". PRECIO) cmd.ID_PRDUCTO = value End Set End Property Public Property fNOMBRE() As String Get Return Me. PRECIO) cmd.AddWithValue("@pDESCRIPCION".AddWithValue("@pNOMBRE".CommandType = CommandType.Parameters.StoredProcedure cmd.

HasRows Then Throw New Exception("Proveedor no encontrado") End If While dr. conn) cmd.CommandType = CommandType.Open() cmd = New SqlCommand("SP_LISTAproducto".CommandType = CommandType.Message) Finally conn.Message) Finally conn.StoredProcedure ds = New DataSet da = New SqlDataAdapter(cmd) da.Fill(ds) Return ds.Open() cmd = New SqlCommand("SP_BUSCAPRODUCTO".End Try End Sub Public Sub BuscarPRODUCTOxId() Try Dim dr As SqlDataReader conn.Parameters.AddWithValue("@pID_PRODUCTO".ExecuteReader() If Not dr.Close() End Try End Sub Public Function ListarProducto() As DataTable Try Dim ds As DataSet Dim da As SqlDataAdapter conn.Tables(0) Catch ex As Exception Throw New Exception(ex.Read ID_PRDUCTO = dr(0) NOMBRE = dr(1) DESCRIPCION = dr(2) PRECIO = dr(3) End While Catch ex As Exception Throw New Exception(ex.StoredProcedure cmd.Close() End Try End Function End Class . conn) cmd. ID_PRDUCTO) dr = cmd.

EventArgs) Handles ButtonACTUALIZAR.fPRECIO = TextPRECIO.fID_PRODUCTO = TextID_PRODUCTO.Focus() End Sub BUTTON Private Sub ButtonREGISTAR_Click(ByVal sender As System.DataSource = .Text .Text = "" TextDESCRIPCION.EventArgs) Handles MyBase.fdESCRIPCION = TextDESCRIPCION. ByVal e As System.Text = "" TextNOMBRE. ByVal e As System.FPRECIO = TextPRECIO.RegistrarPRODUCTO() End With MsgBox("PRODUCTO Registrado !!!!") LimpiarForm() 'Invocar al método limpiar formulario FillGrid() 'Llenar el Grid Catch ex As Exception MsgBox("Mensaje: " & ex.Text = "" TextPRECIO.Object.Load FillGrid() End Sub Private Sub FillGrid() Try Dim objProducto As New PRODUCTO With objProducto DGVPRODUCTO.Text .ListarProducto End With Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub Private Sub LimpiarForm() TextID_PRODUCTO.Text .Click Try Dim objPRODUCTO As New PRODUCTO With objPRODUCTO .fNOMBRE = TextNOMBRE.Click Try Dim objproducto As New PRODUCTO With objproducto .Text .Message) End Try End Sub Private Sub BtnActualizar_Click(ByVal sender As System.ActualizarPRODUCTO() End With MsgBox("Datos Actualizados !!!!") .Text = "" TextID_PRODUCTO.Public Class formPRODUCTO Private Sub FormProducto_Load(ByVal sender As System. ByVal e As System.Text .Text .Object.fnombre = TextNOMBRE.fID_PRODUCTO = TextID_PRODUCTO.Text .Object.EventArgs) Handles ButtonREGISTAR.Text .fDESCRIPCION = TextDESCRIPCION.

Text .Windows.fDESCRIPCION = TextDESCRIPCION.CellContentClick End Sub .Text . ByVal e As System.Text End With Catch ex As Exception MsgBox("Mensaje: " & ex.fNOMBRE = TextNOMBRE.fPRECIO = TextPRECIO.DataGridViewCellEventArgs) Handles DGVPRODUCTO.LimpiarForm() FillGrid() Catch ex As Exception MsgBox("Mensaje: " & ex.fID_PRODUCTO = TextID_PRODUCTO.Message) End Try End Sub Private Sub DGVPRODUCTO_CellContentClick(ByVal sender As System.Message) End Try End Sub Private Sub BtnBuscar_Click(ByVal sender As System.Object.EventArgs) Handles ButtonBUSCAR.BuscarPRODUCTOxId() .Forms.Object.Text .Click Try Dim objProducto As New PRODUCTO With objProducto . ByVal e As System.

Sign up to vote on this title
UsefulNot useful