Visual Nuevo
-
Upload
yonikyonik -
Category
Documents
-
view
218 -
download
1
description
Transcript of Visual Nuevo
CREATE PROCEDURE SP_INSERTACAMBIAR @PIDIGUALVARCHAR(10), @PNOMIGUALVARCHAR(20), @PDIRIGUAL VARCHAR(20)AS BEGININSERT INTO CAMBIAR(id_proveedor,nombre_prov,direc_prov)VALUES (@PIDIGUAL,@PNOMBIGUAL,@PDIRIGUAL)END
CREATE PROCEDURE SP_LISTACAMBIARASBEGIN SELECT * FROM CAMBIARENDCREATE PROCEDURE SP_BUSCACAMBIAR@PIDIGUAL VARCHAR(10)ASBEGIN SELECT * FROM CAMBIAR WHERE id_CAMBIARr=@PIDIGUALEND
CREATE PROCEDURE SP_ACTUALIZACAMBIAR @PIDIGUALVARCHAR(10), @PNOMIGUALVARCHAR(20), @PDIRIGUAL VARCHAR(20)ASBEGIN UPDATE CAMBIAR SET nombre_CAMBIAR=@PNOMBIGUAL, direc_CAMBIAR=@PDIRIGUAL WHERE id_CAMBIAR=@PIDIGUALEND
CREATE PROCEDURE SP_ELIMINACAMBIAR@PIDIGUALVARCHAR(10)ASBEGIN DELETE FROM CAMBIAR WHERE id_CAMBIAR=@PIDIGUALEND
Paso 4: Iniciar Visual Studio 2010
Paso 5: En el Men Contextual indicar Archivo Nuevo Proyecto Aplicacin de Windows Form Aceptar Para dar nombre y ubicacin al proyecto. Indicar Archivo Guardar todo. Indicar el nombre y ubicacin del proyecto. Luego indicar Guardar.
Paso 6: En el primer formulario (Form1) cambia la propiedad text a MENU y la propiedad name a FormMenu.
Paso 7: De la paleta de Herramientas agregar un control (objeto) MenuStrip en el formulario Menu y escribir las opciones del men.(Si no visualiza el cuadro de herramientas en el men de opciones Ver Cuadro de Herramientas)
Paso 8: En el explorador de soluciones (superior derecha) Marcar ProyectoAlmacen click derecho Agregar WindowsForm Agregue un Windows form (Form1). Cambiar el texto y name de este formulario por el de FormProveedor.
Paso 9: En el FormCAMBIAR incorporar los controles (objetos) que se indican
OBJETOATRIBUTOVALORLabel1TextCODIGOLabel2TextNOMBRESLabel3TextDIRECCIONGroupBox1TextDatos PersonalesGroupBox2TextOperacionesTextBox1NametxtcodigoTextTextBox2NametxtnombresTextTextBox3NametxtdireccionTextDataGridViewNameDGVCAMBIARButton1TextRegistrarNameBtnRegistrarButton2TextActualizarNameBtnActualizarButton3TextEliminarNameBtnEliminarButton4TextBuscarNameBtnBuscarButton5TextLimpiarNameBtnLimpiar
Paso 10: En el Men, en la opcin Proveedor dar doble click y escribir el siguiente cdigo (para el llamado de los formularios desde el Menu Principal).
Private Sub CAMBIARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAMBIARToolStripMenuItem.Click Dim MnuCAMBIAR As New FormCAMBIAR MnuCAMBIAR.Show()End Sub
Paso 11: En el explorador de soluciones (superior derecha) Marcar ProyectoAlmacen click derecho Agregar Clase. Implementar la clase Proveedor con sus correspondientes atributos y mtodos.
Imports System.Data.SqlClientPublic Class CAMBIAR
Private idIGUAL, nombIGUAL, dirIGUAL As String Private conn As SqlConnection Private cmd As SqlCommandPrivate strConn As String = "SERVER=localhost;DATABASE=BDCAMBIARIntegrated Security=SSPI;" Sub New() conn = New SqlConnection(strConn) End Sub
Sub New(ByVal tid As String, ByVal tnombre As String, ByVal tdir As String) Me.idIGUAL = tid Me.nombIGUAL = tnombre Me.dirIGUAL = tdir conn = New SqlConnection(strConn) End Sub
Public Property fidIGUAL() As String Get Return Me.idIGUAL End Get Set(ByVal value As String) Me.idIGUAL= value End Set End Property
Public Property fnombIGUAL() As String Get Return Me.nombIGUAL End Get Set(ByVal value As String) Me.nombIGUAL = value End Set End Property
Public Property fdirIGUAL () As String Get Return Me.dirIGUAL End Get Set(ByVal value As String) Me.dirIGUAL= value End Set End Property
Public Sub RegistrarIGUAL () Try conn.Open() cmd = New SqlCommand("SP_INSERTACAMBIAR", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@pidIGUAL", idIGUAL) cmd.Parameters.AddWithValue("@pnombIGUAL", nombIGUAL) cmd.Parameters.AddWithValue("@pdirIGUAL", dirIGUAL) cmd.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Close() End Try End Sub
Public Sub ActualizarIGUAL() Try conn.Open() cmd = New SqlCommand("SP_ACTUALIZACAMBIAR", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@pidIGUAL", idIGUAL) cmd.Parameters.AddWithValue("@pnombIGUAL", nombIGUAL) cmd.Parameters.AddWithValue("@pdirIGUAL", dirIGUAL) cmd.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Close() End Try End Sub
Public Function EliminarIGUAL () As Integer Dim c As Integer Try conn.Open() cmd = New SqlCommand("SP_ELIMINACAMBIAR", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@pidIGUAL", idIGUAL) c = cmd.ExecuteNonQuery() Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Close() End Try Return c End Function
Public Sub BuscarIGUALxId() Try Dim dr As SqlDataReader conn.Open() cmd = New SqlCommand("SP_BUSCACAMBIAR", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@pidIGUAL", idIGUAL) dr = cmd.ExecuteReader() If Not dr.HasRows Then Throw New Exception("CAMBIAR no encontrado") End If While dr.Read idIGUAL = dr(0) nombIGUAL = dr(1) dirIGUAL = dr(2) End While Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Close() End Try End Sub Public Function ListarIGUAL () As DataTable Try Dim ds As DataSet Dim da As SqlDataAdapter conn.Open() cmd = New SqlCommand("SP_LISTACAMBIAR", conn) cmd.CommandType = CommandType.StoredProcedure ds = New DataSet da = New SqlDataAdapter(cmd) da.Fill(ds) Return ds.Tables(0) Catch ex As Exception Throw New Exception(ex.Message) Finally conn.Close() End Try End FunctionEnd Class
Paso 12: Ubicarse en el formulario Proveedor. Alli dar doble click Codificar los mtodos e incluirlos en el form1 (formulario de empleado)
Private Sub FormCAMBIAR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load FillGrid()End SubPrivate Sub FillGrid() Try Dim objIGUAL As New CAMBIAR With objIGUAL DGVIGUAL.DataSource = .ListarIGUAL End With Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub
Private Sub LimpiarForm() txtcodigo.Text = "" txtnombres.Text = "" txtdireccion.Text = "" txtcodigo.Focus() End Sub
Paso 13: En el formulario Proveedor dar doble clik en los objetos button y codificar.
Private Sub BtnRegistrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRegistrar.Click Try Dim objIGUALAs New CAMBIAR With objIGUAL .fidIGUAL= txtcodigo.Text .fnombIGUAL = txtnombres.Text .fdirIGUAL = txtdireccion.Text .RegistrarIGUAL() End With MsgBox("CAMBIAR Registrado !!!!") LimpiarForm() 'Invocar al mtodo limpiar formulario FillGrid() 'Llenar el Grid Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub
Private Sub BtnActualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnActualizar.Click Try Dim objIGUAL As New CAMBIAR With objIGUAL .fidIGUAL = txtcodigo.Text .fnombIGUAL = txtnombres.Text .fdirIGUAL = txtdireccion.Text .ActualizarIGUALr() End With MsgBox("Datos Actualizados !!!!") LimpiarForm() FillGrid()
Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub
Private Sub BtnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEliminar.Click Try Dim objIGUAL As New CAMBIAR With objIGUAL .fidIGUAL = txtcodigo.Text .EliminarIGUAL() End With MsgBox("Datos Eliminados !!!!") LimpiarForm() FillGrid()
Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub
Private Sub BtnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBuscar.Click Try Dim objIGUALAs New CAMBIAR With objIGUAL .fidIGUAL = txtcodigo.Text .BuscarIGUALxId() txtnombres.Text = .fnombIGUAL txtdireccion.Text = .fdirIGUAL End With Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub
Private Sub BtnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLimpiar.Click Try Dim objIGUAL As New CAMBIAR With objIGUAL txtcodigo.Text = "" txtnombres.Text = "" txtdireccion.Text = "" txtcodigo.Focus() End With MsgBox("Datos Eliminados !!!!") LimpiarForm() FillGrid()
Catch ex As Exception MsgBox("Mensaje: " & ex.Message) End Try End Sub