Você está na página 1de 10

CODIGOS PROGRAMACION DISTRIBUIDA

1) Clase Conexión
Imports System.Data
Imports System.Data.SqlClient
Public Class ClsConexion
Public Conexion As New SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename=D:\PracticaMantenimiento\tienda.mdf;Integrated Security=True;Connect
Timeout=30;User Instance=True")
Dim Cmd As SqlCommand
Dim Adap As SqlDataAdapter
Dim Dset As DataSet
Public xCampo(20) As String
Public xValor(20) As String
Public Sub Procedimiento(ByVal NomProc, ByVal NumParam)
Try
Conexion.Open()
Cmd = New SqlCommand(NomProc, Conexion)
Cmd.CommandType = CommandType.StoredProcedure
For i = 1 To NumParam
Cmd.Parameters.AddWithValue(xCampo(i), xValor(i))
Next
Cmd.ExecuteNonQuery()
Conexion.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Function Listado(ByVal NomProc, ByVal NumParam) As DataTable
Try
Dset = New DataSet
Cmd = New SqlCommand(NomProc, Conexion)
Cmd.CommandType = CommandType.StoredProcedure
For i = 1 To NumParam
Cmd.Parameters.AddWithValue(xCampo(i), xValor(i))
Next
Conexion.Open()
Adap = New SqlDataAdapter(Cmd)
Adap.Fill(Dset, NomProc)
Conexion.Close()
Return Dset.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
End Class

2) Clase Empleado
Public Class ClsEmpleado
#Region "Declaraciones"
Dim Conexion As New ClsConexion
#End Region
#Region "Atributos"
Dim IdALL As Integer
Dim DniALL As String
Dim NombresALL As String
Dim DireccionALL As String
Dim IngresoALL As Date
Dim SueldoALL As Decimal
#End Region
#Region "Propiedades"
Public Property _IdALL() As Integer
Get
Return IdALL
End Get
Set(ByVal value As Integer)
IdALL = value
End Set
End Property
Public Property _DniALL() As String
Get
Return DniALL
End Get
Set(ByVal value As String)
DniALL = value
End Set
End Property
Public Property _NombresALL() As String
Get
Return NombresALL
End Get
Set(ByVal value As String)
NombresALL = value
End Set
End Property
Public Property _DireccionALL() As String
Get
Return DireccionALL
End Get
Set(ByVal value As String)
DireccionALL = value
End Set
End Property
Public Property _IngresoALL() As Date
Get
Return IngresoALL
End Get
Set(ByVal value As Date)
IngresoALL = value
End Set
End Property
Public Property _SueldoALL() As Decimal
Get
Return SueldoALL
End Get
Set(ByVal value As Decimal)
SueldoALL = value
End Set
End Property
#End Region
#Region "Metodos"
Public Sub InsertarEmpleado()
Conexion.xCampo(1) = "@DniALL"
Conexion.xCampo(2) = "@NombresALL"
Conexion.xCampo(3) = "@DireccionALL"
Conexion.xCampo(4) = "@IngresoALL"
Conexion.xCampo(5) = "@SueldoALL"
Conexion.xValor(1) = DniALL
Conexion.xValor(2) = NombresALL
Conexion.xValor(3) = DireccionALL
Conexion.xValor(4) = IngresoALL
Conexion.xValor(5) = SueldoALL
Conexion.Procedimiento("InsertarEmpleado", 5)
End Sub
Public Sub ModificarEmpleado()
Conexion.xCampo(1) = "@IDALL"
Conexion.xCampo(2) = "@DniALL"
Conexion.xCampo(3) = "@NombresALL"
Conexion.xCampo(4) = "@DireccionALL"
Conexion.xCampo(5) = "@IngresoALL"
Conexion.xCampo(6) = "@SueldoALL"
Conexion.xValor(1) = IdALL
Conexion.xValor(2) = DniALL
Conexion.xValor(3) = NombresALL
Conexion.xValor(4) = DireccionALL
Conexion.xValor(5) = IngresoALL
Conexion.xValor(6) = SueldoALL
Conexion.Procedimiento("ModificarEmpleado", 6)
End Sub
Public Sub EliminarEmpleado()
Conexion.xCampo(1) = "@IDALL"
Conexion.xValor(1) = IdALL
Conexion.Procedimiento("EliminarEmpleado", 1)
End Sub
#End Region
#Region "Funciones"
Public Function ListarEmpleado() As DataTable
Return Conexion.Listado("ListarEmpleado", 0)
End Function
Public Function BuscarEmpleadoXDni() As DataTable
Conexion.xCampo(1) = "@DniALL"
Conexion.xValor(1) = DniALL
Return Conexion.Listado("BuscarEmpleadoXDni", 1)
End Function
Public Function BuscarEmpleadoXNombres() As DataTable
Conexion.xCampo(1) = "@NombresALL"
Conexion.xValor(1) = NombresALL
Return Conexion.Listado("BuscarEmpleadoXNombres", 1)
End Function
#End Region
End Class
FORMULARIOS

3) Formulario Empleado

3.1) Agregar:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
FrmAgregarEmpleado.ShowDialog()
FrmEmpleado_Load(sender, e)
End Sub

3.2) Modificar:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
emp._IdALL = DataGridView1.CurrentRow.Cells(0).Value
FrmModificarEmpleado.TextBox1.Text = DataGridView1.CurrentRow.Cells(1).Value
FrmModificarEmpleado.TextBox2.Text = DataGridView1.CurrentRow.Cells(2).Value
FrmModificarEmpleado.TextBox3.Text = DataGridView1.CurrentRow.Cells(3).Value
FrmModificarEmpleado.DateTimePicker1.Text = DataGridView1.CurrentRow.Cells(4).Value
FrmModificarEmpleado.TextBox4.Text = DataGridView1.CurrentRow.Cells(5).Value
FrmModificarEmpleado.ShowDialog()
FrmEmpleado_Load(sender, e)
End Sub

3.3) Eliminar:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
emp._IdALL = DataGridView1.CurrentRow.Cells(0).Value
emp.EliminarEmpleado()
FrmEmpleado_Load(sender, e)
End Sub
3.4) Actualizar:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
TextBox1.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
FrmEmpleado_Load(sender, e)
End Sub

3.5) RadioButton: BuscarXDNI


Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton1.CheckedChanged
TextBox1.Text = ""
TextBox1.Focus()
End Sub

3.6) RadioButton: BuscarXNombres


Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton2.CheckedChanged
TextBox1.Text = ""
TextBox1.Focus()
End Sub

3.7) TextBox para Buscar


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
If RadioButton1.Checked = True Then
emp._DniALL = TextBox1.Text.Trim
DataGridView1.DataSource = emp.BuscarEmpleadoXDni
DataGridView1.AutoResizeColumns()
End If
If RadioButton2.Checked = True Then
emp._NombresALL = TextBox1.Text.Trim
DataGridView1.DataSource = emp.BuscarEmpleadoXNombres
DataGridView1.AutoResizeColumns()
End If
End Sub

4) Formulario AgregarEmpleado

4.1) Button Agregar:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
FrmEmpleado.emp._DniALL = TextBox1.Text.Trim
FrmEmpleado.emp._NombresALL = TextBox2.Text.Trim
FrmEmpleado.emp._DireccionALL = TextBox3.Text.Trim
FrmEmpleado.emp._IngresoALL = DateTimePicker1.Text
FrmEmpleado.emp._SueldoALL = TextBox4.Text.Trim
FrmEmpleado.emp.InsertarEmpleado()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
DateTimePicker1.Text = Date.Now
Me.Close()
End Sub

5) Formulario ModificarEmpleado

5.1) Button Modificar:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
FrmEmpleado.emp._DniALL = TextBox1.Text.Trim
FrmEmpleado.emp._NombresALL = TextBox2.Text.Trim
FrmEmpleado.emp._DireccionALL = TextBox3.Text.Trim
FrmEmpleado.emp._IngresoALL = DateTimePicker1.Text
FrmEmpleado.emp._SueldoALL = TextBox4.Text.Trim
FrmEmpleado.emp.ModificarEmpleado()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
DateTimePicker1.Text = Date.Now
Me.Close()
End Sub

PROCEDIMIENTOS ALMACENADOS

6) BuscarEmpleadoXDNI
ALTER PROCEDURE BuscarEmpleadoXDni
@DniALL varchar(8)
AS
select * from empleado where
DniALL like @DniALL + '%'
RETURN

7) BuscarEmpleadoXNombres
ALTER PROCEDURE BuscarEmpleadoXNombres
@NombresALL varchar(20)
AS
select * from empleado where
NombresALL like @NombresALL + '%'
RETURN

8) EliminarEmpleado
ALTER PROCEDURE EliminarEmpleado
@IdALL INT
AS
DELETE FROM Empleado WHERE IdALL=@IdALL
RETURN
9) InsertarEmpleado
ALTER PROCEDURE InsertarEmpleado
@DniALL CHAR(8),
@NombresALL VARCHAR(100),
@DireccionALL VARCHAR(100),
@IngresoALL DATETIME,
@SueldoALL DECIMAL(8,2)
AS
INSERT INTO Empleado VALUES(@DniALL,
@NombresALL,@DireccionALL,@IngresoALL,@SueldoALL)
RETURN

10) ListarEmpleado
ALTER PROCEDURE ListarEmpleado

AS
select * from Empleado
RETURN

11) ModificarEmpleado
ALTER PROCEDURE ModificarEmpleado
@IdALL INT,
@DniALL CHAR(8),
@NombresALL VARCHAR(100),
@DireccionALL VARCHAR(100),
@IngresoALL DATETIME,
@SueldoALL DECIMAL(8,2)
AS
UPDATE Empleado SET DniALL=@DniALL,
NombresALL=@NombresALL,
DireccionALL=@DireccionALL,
IngresoALL=@IngresoALL,
SueldoALL=@SueldoALL
WHERE IdALL=@IdALL
RETURN

Você também pode gostar