“AÑO DEL BUEN SERVICIO AL CIUDADANO”
UNIVERSIDAD POLITÉCNICA AMAZONICA
FACULTAD DE INGENIERÍA DE SISTEMAS Y TELEMATICA
ESCUELA ACADÉMICA PROFESIONAL DE INGENIERÍA DE SISTEMAS Y TELEMÁTICA
LABORATORIO DE PROGRAMACION I
CASO DE ESTUDIO
INTEGRANTE
EMELINA LISSETH DIAZ CRUZ
DOCENTE
ING. MARCO AURELIO PORRO CHULLI
CICLO
IV/A
IV/A
2017
LABORATORIO DE PROGRAMACIÓN I
Caso Práctico: Una empresa organizadora de
eventos requiere un programa que le permita registrar a sus participantes. Esta
empresa organiza Seminarios, FORUM, Talleres, etc. en los diferentes
departamentos del país registrando los Ponentes que dictan estos eventos El
participante se puede registrar el mismo día del evento haciendo el pago
respectivo en el lugar donde se organiza el evento. Se le entregara el Recibo
de Pago indicando el Número de Recibo, Fecha, Evento, Lugar e Importe
pagado.
Se tiene la base de datos:
use
master
go
if
exists (select * from sysdatabases where name='BDEvento')
drop database BDEvento
go
create
database BDEvento
go
use BDEvento
go
--creacion de las tablas
CREATE
TABLE Ponente (
codponente
varchar(4) NOT NULL,
nombre
varchar(80) NOT NULL,
fecnac
date NOT NULL,
sexo
char(1) NOT NULL,
grado
varchar(25) NOT NULL,
PRIMARY KEY (codponente)
)
Go
CREATE
TABLE Evento (
codevento
char(3) NOT NULL,
nombreevento
varchar(80) NULL,
lugar
varchar(80) NULL,
fecha datetime
NULL,
hora
datetime NULL,
precio
decimal(8,2) NULL,
idponente
varchar(4) NULL,
PRIMARY KEY (codevento),
FOREIGN KEY (idponente) REFERENCES Ponente
)
Go
CREATE
TABLE Participante (
codparticipante
int identity(1,1),
nombre
varchar(60) NULL,
direccion
varchar(40) NULL,
telefono
varchar(11) NULL,
fecnac date
NULL,
sexo
char(1) NULL,
profesion
varchar(60) NULL,
PRIMARY KEY (codparticipante)
)
go
CREATE
TABLE ReciboPago (
nrecibo
char(8) NOT NULL,
fecha
date NULL,
idparticipante
int NULL,
idevento
char(3) NULL,
PRIMARY KEY (nrecibo),
FOREIGN KEY (idparticipante) REFERENCES Participante,
FOREIGN KEY (idevento) REFERENCES Evento
)
go
CREATE
PROCEDURE sp_Inserta_ReciboPago
@col1 VARCHAR(8),
@col2 DATE,
@col3 VARCHAR(60),
@col4 VARCHAR(80)
AS
DECLARE @cod_parti INT--
DECLARE @cod_event INT--
SELECT @cod_parti=codparticipante FROM Participante WHERE nombre=@col3
SELECT @cod_event =codevento FROM evento WHERE nombreevento =@col4
INSERT ReciboPago
VALUES(@col1,@col2,@cod_parti,@cod_event)
Go
---INSERTAR LISTE EVENTOS
CREATE
PROCEDURE sp_Inserta_Evento
@col1 char(3),
@col2 varchar(80),
@col3 varchar(80),
@col4 datetime,
@col5 datetime,
@col6 decimal(8,2),
@col7 varchar(80)
AS
DECLARE @cod_ponente INT
SELECT @cod_ponente=codponente FROM Ponente WHERE nombre=@col7
INSERT evento
VALUES(@col1,@col2,@col3,@col4,@col5,@col6,@cod_ponente)
Go
-------------
CREATE
PROCEDURE sp_Listado_evento
AS
SELECT * FROM evento
Go
----insertar ponente
CREATE
PROCEDURE sp_Inserta_ponente
@col1 varchar(4),
@col2 varchar(80),
@col3 date,
@col4 char(1),
@col5 varchar(25)
AS
INSERT ponente
VALUES(@col1,@col2,@col3,@col4,@col5)
Go
--listado ponente
CREATE
PROCEDURE sp_Listado_Ponente
AS
SELECT * FROM Ponente
Go
--LISTAR PARTICIPANTE
CREATE
PROCEDURE sp_Listado_Participante
AS
SELECT * FROM Participante
Go
--------------------
INSERT
Ponente
VALUES('POO1','JOSE PEREZ TELLO','01/10/1996','M','MAGISTER')
INSERT
Ponente
VALUES('POO2','LISSETH DIAZ CRUZ','06/08/1998','F','INGENIERA')
INSERT
Ponente
VALUES('POO3','JORGE CARRAZCO HUAMAN','01/11/1993','M','LICENCIADO')
INSERT
Ponente
VALUES('POO4','NERY CRUZ GUERRERO','02/07/1980','F','INGENIERA')
INSERT
Ponente
VALUES('POO5','ELMOR DIAZ BUSTAMANTE','12/10/1965','M','MAGISTER')
INSERT
Ponente
VALUES('POO6','CARMELA GUERRERO PALACIOS','02/10/1988','F','INGENIERA')
SELECT * FROM Ponente
INSERT
Evento VALUES( '001','CUMPLEAÑOS','LAS TERRAZAS','07/05/2017','8:45',12,'P001')
INSERT
Evento VALUES( '002','FIESTA DE PROMOCION','EL ZAFIRO','02/05/2017','10:45',120,'P002')
INSERT
Evento VALUES( '003','CUMPLEAÑOS DE BODA','LAS ESFERAS','07/08/2017','9:11',180,'P003')
INSERT
Evento VALUES( '004','FIESTA DE CACHIMBO','EL ZURDO','02/05/2017','10:45',160,'P004')
INSERT
Evento VALUES( '005','CORONOCION DE REINA','HOTEL LUCERO-LIMA','09/04/2017','9:45',210,'P005')
INSERT
Evento VALUES('006','BACHILLERATO ','JAEN','11/03/2017','10:00',320,'P006')
SELECT
* FROM Evento
INSERT
Participante VALUES('ZARA HORNA TAZA','BAGUA GRANDE','04199998765','07/05/2017','F','Profesora')
INSERT
Participante VALUES('FRANK GONZALES TERRONES','LONYA GRANDE GRANDE','04195871299','12/09/2017','M','Doctor')
INSERT
Participante VALUES('LUISA GOMEZ PERALTA','PUCALPA','04194448765','07/04/2017','F','Profesora')
INSERT
Participante VALUES('FRAN TORRES IZQUIERDO ','JAEN','04169874299','12/02/2017','M','Doctor')
INSERT Participante VALUES('ZARAI PORRO CRUZ','MADRE DE DIOS','04196598765','08/05/2017','F','Profesora')
INSERT
Participante VALUES('FRANCHESCA MALDINE
TERRONES','LA
VICTORIA','04194171299','12/06/2017','F','Doctor')
SELECT * FROM Participante
EN
VISUAL.NET
1. En la Capa
de Datos importar el Espacio de Nombre para el Manejo de Base de Datos
Imports System.Data.SqlClient
2. Luego en la
misma capa crear una clase con el nombre CONEXION
Public Class CONEXION
Private con
As SqlConnection
Public Function conecta() As
SqlConnection
Con = New SqlConnection("Server=LISSETH;Initial Catalog=BDEvento; Integrated
Security=SSPI")
Return con
End Function
End Class
3. Luego crear
otra clase con el nombre PROCESOS
Imports System.Data.SqlClient
Public Class PROCESOS
Private con As SqlConnection 'Conxeion a la BD
Private cmd As SqlCommand 'Objetos de la BD
Private dtb As DataTable 'Acesso a datos
Private da As SqlDataAdapter 'Consultar a la BD
Private cn As New CONEXIÓN
Public Structure Recibopago
Public nrecibo As Integer
Public fecha As Date
Public nombreparticipante As String
Public nombreevento As String
End Structure
Public Function
insertar_recibopago(ByVal st As Recibopago) As Boolean
Dim opc As Boolean
Try
Con = Cn.conecta()
If Con.State = ConnectionState.Closed Then Con.Open()
Cmd = New SqlCommand("sp_Inserta_recibopago", Con)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.Add("@col1", SqlDbType.Char, 8).Value = st.nrecibo
Cmd.Parameters.Add("@col2", SqlDbType.Date).Value = st.fecha
Cmd.Parameters.Add("@col3", SqlDbType.VarChar, 80).Value =
st.nombreparticipante
Cmd.Parameters.Add("@col4", SqlDbType.VarChar, 80).Value =
st.nombreevento
Dim i As Integer = Cmd.ExecuteNonQuery
opc = IIf(i > 0, True, False)
Catch ex As Exception
opc = False
End Try
Return opc
End Function
Public Function
listado_evento() As DataTable
con = cn.Conecta
dtb = New DataTable
da = New SqlDataAdapter("SELECT * FROM EVENTO", con)
da.Fill(dtb)
Return dtb
End Function
''''
Public Function
listado_Participante() As DataTable
con = cn.Conecta
dtb = New DataTable
da = New SqlDataAdapter("SELECT * FROM participante", con)
da.Fill(dtb)
Return dtb
End Function
End Class
4.
En la Capa de negocios invocar la clase datos
Imports System.Data.SqlClient
Imports DATOS
5. Luego en la Capa negocios crear clase con el nombre valida
Public Class VALIDA
Private obj As New Procesos
Public Event mistake(c
As Integer) 'Manejo de Excepcion
Public Function insert(ByVal nom As PROCESOS.Recibopago) As Boolean
Dim opc As Boolean
If nom.nombreevento = "" Then
opc = False
RaiseEvent mistake(1)
Throw New Exception("Ingrese el nombre del evento")
Else
obj.insertar_recibopago(nom)
opc = True
End If
Return opc
End Function
Public Function
Mostrar_evento() As DataTable
Return obj.listado_evento
End Function
Public Function Mostrar_participante()
As DataTable
Return obj.listado_Participante
End Function
End Class
6. Luego en la capa Presentación
crear el formulario FRM_PAGO_DE_EVENTO
Imports System.Data.SqlClient
Imports DATOS
Imports NEGOCIOS
Public Class FRM_PAGO_DE_EVENTO
Dim Sw As Integer
Dim WithEvents app As New VALIDA
Dim reg As New PROCESOS.recibopago
Private Sub
FRM_PAGO_DE_EVENTO_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DTGVEVENTO.DataSource = app.Mostrar_evento
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FRM_AGREGAR_PARTICIPANTE_RECIBO_DE_PAGO.Show()
End Sub
Private Sub DTGVEVENTO_CellClick(sender As Object, e As Windows.Forms.DataGridViewCellEventArgs) Handles DTGVEVENTO.CellClick
Dim i As Integer
i = DTGVEVENTO.CurrentRow.Index
LBLCODEVENTO.Text = DTGVEVENTO(0,
i).Value()
LBLNOMBREEVENTO.Text = DTGVEVENTO(1,
i).Value()
LBLLUGAREVENTO.Text = DTGVEVENTO(2,
i).Value() + "-" & DTGVEVENTO(3, i).Value() + "-" & DTGVEVENTO(4, i).Value() + "-PRECIO:" & DTGVEVENTO(5, i).Value()
End Sub
Private Sub BTNGRABAR_Click(sender As Object, e As EventArgs) Handles BTNGRABAR.Click
Dim r As Byte
r = MsgBox("Grabar Datos ", 4 + 32 +
256, " Datos Guardados")
Try
With reg
.nrecibo = Me.Txtnumerorecibo.Text
.fecha = Me.DTPFECHAEVENTO.Text
.nombreparticipante = Me.LBLNOMPARTI.Text
.nombreevento = Me.LBLNOMBREEVENTO.Text
End With
If app.insert(reg) Then
MsgBox(" Grabacion Correctamente", 0, "OKI!!!")
Else
MsgBox("Grabación Incorrectamente", 0, "ERROR!!!")
End If
Catch ex As Exception
MsgBox(ex.Message, 0, "Error")
End Try
End Sub
Private Sub BTNSALIR_Click(sender As Object, e As EventArgs) Handles BTNSALIR.Click
Me.Close()
End Sub
Private Sub BTNNUEVO_Click(sender As Object, e As EventArgs) Handles BTNNUEVO.Click
Txtnumerorecibo.Text = ""
LBLCODEVENTO.Text = ""
LBLNOMBREEVENTO.Text = ""
LBLLUGAREVENTO.Text = ""
LBLCODPARTI.Text = ""
LBLNOMBREEVENTO.Text = ""
End Sub
Private Sub BTNCANCELAR_Click(sender As Object, e As EventArgs) Handles BTNCANCELAR.Click
LBLCODPARTI.Text = ""
LBLNOMBREEVENTO.Text = ""
End Sub
End Class
7. Luego en la capa Presentacion
crear el formulario FRM_AGREGAR_PARTICIPANTE_RECIBO_DE_PAGO.
Imports System.Data.SqlClient
Imports DATOS
Imports NEGOCIOS
Public Class FRM_AGREGAR_PARTICIPANTE_RECIBO_DE_PAGO
Dim WithEvents app As New VALIDA
Private Sub
FRM_AGREGAR_PARTICIPANTE_RECIBO_DE_PAGO_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DTGVPARTICIPANTE.DataSource = app.Mostrar_participante
End Sub
Private Sub
DTGVPARTICIPANTE_CellContentClick(sender As Object, e As Windows.Forms.DataGridViewCellEventArgs) Handles DTGVPARTICIPANTE.CellContentClick
Dim Dt As SqlDataAdapter
Dim Tb As New DataTable
Dim codigo As String
Dim Con As SqlConnection
Dim cn As New CONEXION
Con = cn.Conecta
codigo = Me.DTGVPARTICIPANTE.Rows(Me.DTGVPARTICIPANTE.CurrentRow.Index).Cells(0).Value
Dt = New SqlDataAdapter("SELECT * FROM participante WHERE
codparticipante='" & codigo & "'", Con)
Dt.Fill(Tb)
If Tb.Rows.Count > 0 Then
FRM_PAGO_DE_EVENTO.LBLCODPARTI.Text
= Tb.Rows(0).Item(0)
FRM_PAGO_DE_EVENTO.LBLNOMPARTI.Text
= Tb.Rows(0).Item(1)
End If
Me.Close()
End Sub
End Class
8. Trabajo culminado
Luego clik en
el botón rojo y seleccione en el DataGridView










Excelente. Gracias. Saludos
ResponderBorrar