Files
SIG/Transportes/Boletos.aspx.vb

164 lines
5.8 KiB
VB.net

Imports Extensiones
Imports System.Data
Partial Class Boletos
Inherits ClsPaginas
#Region "Propiedades"
Private Property AsientoSeleccionado As String
Get
Return ViewState("AsientoSeleccionado").ToString()
End Get
Set(value As String)
ViewState("AsientoSeleccionado") = value
End Set
End Property
Private Property Importe As Decimal
Get
Return ViewState("Importe").ToString().ToDecimal
End Get
Set(value As Decimal)
ViewState("Importe") = value
End Set
End Property
Private Property CveViaje As Integer
Get
Return ViewState("CveViaje").ToString().ToEntero
End Get
Set(value As Integer)
ViewState("CveViaje") = value
End Set
End Property
Private Property CveRuta As Integer
Get
Return ViewState("CveRuta").ToString().ToEntero
End Get
Set(value As Integer)
ViewState("CveRuta") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.QueryString("CveViaje") Is Nothing Then
Response.Redirect("/Transportes/ListadoViajes.aspx")
End If
AsientoSeleccionado = ""
CveRuta = 0
CveViaje = Request.QueryString("CveViaje").ToEntero
DirectCast(Master.FindControl("TSM"), ScriptManager).EnablePageMethods = True
CargaDatos()
InicializaCombos()
End If
End Sub
Private Sub CargaDatos()
'Datos Viaje
Dim ObjViaje As New ClsTransportes
Dim retornoViaje As Boolean = ObjViaje.GetViajes(CveViaje, UsuarioActual.CveEmpresa)
ViewState("CveRuta") = ObjViaje.CveRuta
If retornoViaje Then
TxtRuta.Text = ObjViaje.Ruta
TxtFecha.Text = ObjViaje.Fecha.ToShortDateString
'Boletos Vendidos
Dim dt As DataTable
If ObjViaje.GetViajesPasajeros(CveViaje) Then
GvBoletos.DataSource = ObjViaje.DtResultados
dt = ObjViaje.DtResultados
Dim cph As ContentPlaceHolder = CType(Me.Master.FindControl("C"), ContentPlaceHolder)
For Each dr As DataRow In dt.Rows
Dim lnk As LinkButton = CType(cph.FindControl($"A{dr("Asiento")}"), LinkButton)
If lnk IsNot Nothing Then
lnk.Enabled = False ' se vendieron
lnk.BackColor = Drawing.Color.Red
'falta ponerlelos colores rojos, colorear con
End If
Next
End If
End If
ObjViaje.Dispose()
GvBoletos.DataBind()
End Sub
Protected Sub InicializaCombos()
'Lista Destinos''carga específicos
Dim ObjDestinos As New ClsDestinos()
If ObjDestinos.GetDestinos(CveRuta:=CveRuta) Then
If ObjDestinos.DtResultados.Rows.Count > 0 Then
DdlPartida.DataSource = ObjDestinos.DtResultados
DdlPartida.DataBind()
DdlPartida.Items.Insert(0, New ListItem("Seleccione Partida", ""))
DdlDestino.DataSource = ObjDestinos.DtResultados
DdlDestino.DataBind()
DdlDestino.Items.Insert(0, New ListItem("Seleccione Destino", ""))
End If
End If
End Sub
Protected Sub CotizarTarifa(sender As Object, e As EventArgs)
If DdlDestino.SelectedValue <> "" And DdlPartida.SelectedValue <> "" Then
Dim ObjDestinos As New ClsTransportes()
Dim retorno As Boolean = ObjDestinos.GetDestinosTarifas(DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero)
Dim ImporteR As Decimal = ObjDestinos.DtResultados.FiltroPrimeroValor("Importe").ToDecimal
If retorno Then
If ImporteR > 0 Then
Dim redondeado As String = CStr(Math.Round(ImporteR, 2))
ViewState("Importe") = redondeado
TxtCosto.Text = $"El precio de su boleto es ${Importe}"
BtnGuardar.Visible = True
upPanel.Visible = True
Else
TxtCosto.Text = ""
BtnGuardar.Visible = False
upPanel.Visible = False
ViewState("Importe") = 0
End If
End If
End If
End Sub
Protected Sub OnLinkButtonClick(sender As Object, e As EventArgs)
Dim linkButton As LinkButton = DirectCast(sender, LinkButton)
Dim buttonID As String = linkButton.ID
linkButton.CssClass += " activo"
ViewState("AsientoSeleccionado") = buttonID
End Sub
Protected Sub AddBoleto(sender As Object, e As EventArgs)
If AsientoSeleccionado = "" Then
Alert("Se requiere seleccionar su asiento", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjTransporte As New ClsTransportes()
ObjTransporte.IniciaTransacSQL()
Try
AsientoSeleccionado = AsientoSeleccionado.Replace("A", "")
Dim retorno As Integer = ObjTransporte.AddViajePasajeros(CveViaje, DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero, Importe, AsientoSeleccionado.ToEntero, TxtNombre.Text, TxtVisa.Text, TxtCelular.Text, CBool(RblSexo.SelectedValue), TxtObservaciones.Text, UsuarioActual.CveUsuario)
If retorno > 1 Then
ObjTransporte.Commit()
End If
Catch ex As Exception
Alert($"No se pudo generar el boleto {ex}", TipoMensaje.MsgError)
Finally
ObjTransporte.Dispose()
End Try
End Sub
End Class