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) 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 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 ObjDestinos.Dispose() 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() End If Catch ex As Exception ObjTransporte.RollBack() Alert($"No se pudo generar el boleto {ex}", TipoMensaje.MsgError) Finally ObjTransporte.Dispose() Response.Redirect($"/Transportes/Boletos.aspx?CveViaje={CveViaje}") End Try End Sub End Class