Files
SIG/Transportes/Boletos.aspx.vb
2024-01-21 16:44:58 -07:00

191 lines
6.8 KiB
VB.net

Imports System.Data
Imports Extensiones
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
If CveViaje > 0 Then
CargaDatos()
InicializaCombos()
End If
End If
End Sub
Private Sub CargaDatos()
'Datos Viaje
Dim ObjViaje As New ClsTransportes
Dim retornoViaje As Boolean = ObjViaje.GetViajes(CveViaje, UsuarioActual.CveEmpresa)
If retornoViaje AndAlso ObjViaje.CveViaje > 0 Then
CveRuta = ObjViaje.CveRuta
TxtRuta.Text = ObjViaje.Ruta
TxtFecha.Text = ObjViaje.Fecha.ToShortDateString
CargaDestinos()
'Boletos Vendidos
Dim dt As DataTable
If ObjViaje.GetViajesPasajeros(CveViaje, Estatus:=1) Then 'Poner párametro para estatus y cancelado de viajes
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
lnk.CssClass = "nodisponible"
lnk.ToolTip = dr("Nombre").ToString
End If
Next
End If
End If
ObjViaje.Dispose()
End Sub
Protected Sub InicializaCombos()
'Lista Destinos''carga específicos
End Sub
Protected Sub CargaDestinos()
Dim ObjDestinos As New ClsTransportes()
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
ObjDestinos.Dispose()
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.RoundSQL
ObjDestinos.Dispose()
If retorno Then
If ImporteR > 0 Then
ViewState("Importe") = ImporteR
TxtCosto.Text = $"El precio de su boleto es ${ImporteR.FormatoNumero}"
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)
'quitamos la selección anterior, en caso de existir.
If AsientoSeleccionado <> "" Then
Dim cph As ContentPlaceHolder = CType(Me.Master.FindControl("C"), ContentPlaceHolder)
Dim lnk As LinkButton = CType(cph.FindControl(AsientoSeleccionado), LinkButton)
lnk.CssClass = "disponible"
End If
Dim linkButton As LinkButton = DirectCast(sender, LinkButton)
Dim buttonID As String = linkButton.ID
linkButton.CssClass += " activo"
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.AddViajesPasajeros(CveViaje, DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero, Importe, AsientoSeleccionado.ToEntero, TxtNombre.Text, TxtVisa.Text, TxtCelular.Text, CBool(RblSexo.SelectedValue), TxtObservaciones.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If retorno > 1 Then
Alert("Boleto generado correctamente")
ObjTransporte.Commit()
DdlPartida.SelectedValue = ""
DdlDestino.SelectedValue = ""
TxtNombre.Text = ""
TxtVisa.Text = ""
TxtCelular.Text = ""
TxtObservaciones.Text = ""
AsientoSeleccionado = ""
upPanel.Update()
End If
Catch ex As Exception
ObjTransporte.RollBack()
Alert($"No se pudo generar el boleto {ex}", TipoMensaje.MsgError)
Finally
ObjTransporte.Dispose()
End Try
End Sub
Protected Sub DdlPartida_SelectedIndexChanged(sender As Object, e As EventArgs)
CotizarTarifa(sender, e)
End Sub
Protected Sub DdlDestino_SelectedIndexChanged(sender As Object, e As EventArgs)
CotizarTarifa(sender, e)
End Sub
End Class