Files
SIG/Transportes/Boletos.aspx.vb
2023-12-26 19:24:48 -07:00

169 lines
6.1 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
InicializaCombos()
CargaDatos()
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)
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, Estatus:=True) 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
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)
'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)
If retorno > 1 Then
ObjTransporte.Commit()
Alert("El Boleto se ha registrado. ", TipoMensaje.MsgInformacion)
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