Cine.vd and Service.vd Code Explanation
app_code
cine.vd
Imports Microsoft.VisualBasic
Public Class Cine
Private xId As Integer
Private xDescripcion As String
Private xHoraInicio As Integer
Private xHoraFin As Integer
Private xNroSala As Integer
Private xCantAsistentes As Integer
Private xTotalAsientos As Integer
Private xPrecioEntrada As Decimal
Public Sub New()
xId = 0
xDescripcion = “”
xHoraInicio = 0
xHoraFin = 0
xNroSala = 0
xCantAsistentes = 0
xTotalAsientos = 0
xPrecioEntrada = 0
End Sub
Public Property Id() As Integer
Get
Return xId
End Get
Set(ByVal value As Integer)
xId = value
End Set
End Property
Public Property Descripcion() As String
Get
Return xDescripcion
End Get
Set(ByVal value As String)
xDescripcion = value
End Set
End Property
Public Property HoraInicio() As Integer
Get
Return xHoraInicio
End Get
Set(ByVal value As Integer)
xHoraInicio = value
End Set
End Property
Public Property HoraFin() As Integer
Get
Return xHoraFin
End Get
Set(ByVal value As Integer)
xHoraFin = value
End Set
End Property
Public Property NroSala() As Integer
Get
Return xNroSala
End Get
Set(ByVal value As Integer)
xNroSala = value
End Set
End Property
Public Property CantAsistentes() As Integer
Get
Return xCantAsistentes
End Get
Set(ByVal value As Integer)
xCantAsistentes = value
End Set
End Property
Public Property TotalAsientos() As Integer
Get
Return xTotalAsientos
End Get
Set(ByVal value As Integer)
xTotalAsientos = value
End Set
End Property
Public Property PrecioEntrada() As Decimal
Get
Return xPrecioEntrada
End Get
Set(ByVal value As Decimal)
xPrecioEntrada = value
End Set
End Property
End Class
service.vd
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
‘ To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
‘ <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:=”http://tempuri.org/“)> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
Dim strString As String = ConfigurationManager.ConnectionStrings(“StringConexion”).ConnectionString
<WebMethod()> _
Public Function Insertar(ByVal Descrip As String, ByVal Inicio As Integer, ByVal Fin As Integer, _
ByVal NroSala As Integer, ByVal Asistentes As Integer, ByVal Total As Integer, _
ByVal Valor As Double) As String
Using con As New SqlConnection(strString)
con.Open()
Dim trans As SqlTransaction = con.BeginTransaction
Using cmd As New SqlCommand(“Ingresar”, con, trans)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@Descrip”, Descrip)
cmd.Parameters.AddWithValue(“@Inicio”, Inicio)
cmd.Parameters.AddWithValue(“@Fin”, Fin)
cmd.Parameters.AddWithValue(“@NroSala”, NroSala)
cmd.Parameters.AddWithValue(“@Asistentes”, Asistentes)
cmd.Parameters.AddWithValue(“@Total”, Total)
cmd.Parameters.AddWithValue(“@Valor”, Valor)
Try
cmd.ExecuteNonQuery()
trans.Commit()
Return “Registro ingresado”
Catch ex As Exception
trans.Rollback()
Return “Error: ” & ex.Message
Finally
con.Close()
End Try
End Using
End Using
End Function
<WebMethod()> _
Public Function BuscarDatos(ByVal Descrip As String) As Cine
Dim retorno As Cine = New Cine()
Dim dr As SqlDataReader
Using con As New SqlConnection(strString)
con.Open()
Using cmd As New SqlCommand(“Buscar”, con)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@Descrip”, Descrip)
dr = cmd.ExecuteReader
While (dr.Read)
retorno.Id = dr(“id”)
retorno.HoraInicio = dr(“horaInicio”)
retorno.HoraFin = dr(“horaFin”)
retorno.NroSala = dr(“nroSala”)
retorno.CantAsistentes = dr(“cantAsistentes”)
retorno.TotalAsientos = dr(“totalAsientos”)
retorno.PrecioEntrada = dr(“precioEntrada”)
End While
con.Close()
End Using
End Using
Return retorno
End Function
<WebMethod()> _
Public Function Modificar(ByVal Id As Integer, ByVal Descrip As String, ByVal Inicio As Integer, ByVal Fin As Integer, _
ByVal NroSala As Integer, ByVal Asistentes As Integer, ByVal Total As Integer, _
ByVal Valor As Double) As String
Using con As New SqlConnection(strString)
con.Open()
Dim trans As SqlTransaction = con.BeginTransaction
Using cmd As New SqlCommand(“Modificar”, con, trans)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@Id”, Id)
cmd.Parameters.AddWithValue(“@Descrip”, Descrip)
cmd.Parameters.AddWithValue(“@HoraInicio”, Inicio)
cmd.Parameters.AddWithValue(“@HoraFin”, Fin)
cmd.Parameters.AddWithValue(“@NroSala”, NroSala)
cmd.Parameters.AddWithValue(“@CantAsistentes”, Asistentes)
cmd.Parameters.AddWithValue(“@TotalAsientos”, Total)
cmd.Parameters.AddWithValue(“@PrecioEntrada”, Valor)
Try
cmd.ExecuteNonQuery()
trans.Commit()
Return “Registro Modificado”
Catch ex As Exception
trans.Rollback()
Return “Error: ” & ex.Message
Finally
con.Close()
End Try
End Using
End Using
End Function
<WebMethod()> _
Public Function Eliminar(ByVal Id As Integer) As String
Using con As New SqlConnection(strString)
con.Open()
Dim trans As SqlTransaction = con.BeginTransaction
Using cmd As New SqlCommand(“Eliminar”, con, trans)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@Id”, Id)
Try
cmd.ExecuteNonQuery()
trans.Commit()
Return “Registro Eliminado”
Catch ex As Exception
trans.Rollback()
Return “Error: ” & ex.Message
Finally
con.Close()
End Try
End Using
End Using
End Function
<WebMethod()> _
Public Function BuscarxRango(ByVal horaInicio As Integer, ByVal horaFin As Integer) As Data.DataSet
Dim retorno As New Data.DataSet
Dim da As SqlDataAdapter
Using con As New SqlConnection(strString)
con.Open()
Using cmd As New SqlCommand(“BuscarxRango”, con)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@HoraInicio”, horaInicio)
cmd.Parameters.AddWithValue(“@HoraFin”, horaFin)
da = New SqlDataAdapter(cmd)
da.Fill(retorno, “Cine”)
con.Close()
End Using
End Using
Return retorno
End Function
<WebMethod()> _
Public Function BuscarxSala(ByVal NroSala As Integer) As Data.DataSet
Dim retorno As New Data.DataSet
Dim da As SqlDataAdapter
Using con As New SqlConnection(strString)
con.Open()
Using cmd As New SqlCommand(“BuscarxSala”, con)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue(“@NroSala”, NroSala)
da = New SqlDataAdapter(cmd)
da.Fill(retorno, “Cine”)
con.Close()
End Using
End Using
Return retorno
End Function
End Class