240 lines
9.0 KiB
VB.net
240 lines
9.0 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
Imports Extensiones.ModExtensiones
|
|
|
|
Partial Class ListadoViajes
|
|
Inherits ClsPaginas
|
|
|
|
#Region "Propiedades"
|
|
Private Property CveViaje As String
|
|
Get
|
|
Return ViewState("CveViaje").ToString()
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("CveViaje") = value
|
|
End Set
|
|
End Property
|
|
Private Property Ruta As String
|
|
Get
|
|
Return ViewState("Ruta").ToString()
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("Ruta") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
|
|
If Not IsPostBack Then
|
|
CargaDatos()
|
|
InicializaCombos()
|
|
End If
|
|
|
|
End Sub
|
|
Private Sub InicializaCombos()
|
|
'Lista Rutas'
|
|
Dim ObjRutas As New ClsTransportes()
|
|
If ObjRutas.GetRutas(-1, -1, -1, "", True, DateTime.Now) Then
|
|
|
|
If ObjRutas.DtResultados.Rows.Count > 0 Then
|
|
DdlRutas.DataSource = ObjRutas.DtResultados
|
|
DdlRutas.DataBind()
|
|
DdlRutas.Items.Insert(0, New ListItem("Seleccione Ruta", ""))
|
|
End If
|
|
End If
|
|
'Lista Destinos'
|
|
|
|
If ObjRutas.GetDestinos() Then
|
|
|
|
If ObjRutas.DtResultados.Rows.Count > 0 Then
|
|
DdlPartida.DataSource = ObjRutas.DtResultados
|
|
DdlPartida.DataBind()
|
|
DdlPartida.Items.Insert(0, New ListItem("Seleccione Partida", ""))
|
|
|
|
DdlDestino.DataSource = ObjRutas.DtResultados
|
|
DdlDestino.DataBind()
|
|
DdlDestino.Items.Insert(0, New ListItem("Seleccione Destino", ""))
|
|
End If
|
|
End If
|
|
ObjRutas.Dispose()
|
|
|
|
End Sub
|
|
Private Sub GvViajes_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvViajes.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If e.Row.DBCampo("CveMasivo") <> "" Then
|
|
e.Row.FCLabel("LtlMasivo").Text = "Sí"
|
|
e.Row.FCLabel("LtlMasivo").ForeColor = Drawing.Color.Green
|
|
End If
|
|
End If
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Dim ObjTransportes As New ClsTransportes
|
|
|
|
If ObjTransportes.GetViajes(-1, UsuarioActual.CveEmpresa) Then
|
|
GvViajes.DataSource = ObjTransportes.DtResultados
|
|
ObjTransportes.Dispose()
|
|
GvViajes.DataBind()
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub LBAgregarViaje_Click(sender As Object, e As EventArgs) Handles LBAgregarViaje.Click
|
|
MostrarModal()
|
|
End Sub
|
|
|
|
Public Sub MostrarModal()
|
|
IsMasivo.Visible = True
|
|
DdlRutas.Text = ""
|
|
TxtFechaViaje.Text = ""
|
|
DdlPartida.Text = ""
|
|
DdlDestino.SelectedValue = ""
|
|
BtnGuardar.Text = "Agregar"
|
|
ModalLabel.InnerHtml = "Agregar Nuevo Viaje"
|
|
|
|
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
|
|
End Sub
|
|
|
|
Protected Sub AddViaje(sender As Object, e As EventArgs)
|
|
Dim ObjTransportes As New ClsTransportes
|
|
|
|
ObjTransportes.IniciaTransacSQL()
|
|
|
|
If IsMasivo.Checked = True Then
|
|
If TxtFechaInicial.Text = "" Or TxtFrecuencia.Text = "" Then
|
|
Alert("Es necesario agregar la fecha inicial y la frecuencia", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim CveMasivo As Integer = DateTimeOffset.Now.ToUnixTimeSeconds().ToEntero
|
|
|
|
Dim fechaInicial As DateTime = DateTime.Parse(TxtFechaInicial.Text)
|
|
Dim frecuencia As Integer = Integer.Parse(TxtFrecuencia.Text)
|
|
Dim fechasGeneradas As New List(Of DateTime)()
|
|
While fechaInicial.Year = DateTime.Now.Year
|
|
fechasGeneradas.Add(fechaInicial)
|
|
fechaInicial = fechaInicial.AddDays(frecuencia)
|
|
End While
|
|
|
|
For Each fecha As DateTime In fechasGeneradas
|
|
Try
|
|
Dim CveContratoHijo As Integer = -1
|
|
CveContratoHijo = ObjTransportes.AddViajes(DdlRutas.Text.ToEntero, -1, -1, UsuarioActual.CveEmpresa, fecha, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero, IsMasivo:=True, CveMasivo:=CveMasivo)
|
|
|
|
If CveContratoHijo > 0 Then
|
|
ObjTransportes.Commit()
|
|
End If
|
|
Catch ex As Exception
|
|
Alert($"Ocurrió un error {ex}", TipoMensaje.MsgError)
|
|
End Try
|
|
Next
|
|
|
|
DdlRutas.Text = ""
|
|
|
|
TxtFechaViaje.Text = ""
|
|
DdlPartida.Text = ""
|
|
DdlDestino.SelectedValue = ""
|
|
ObjTransportes.Dispose()
|
|
CargaDatos()
|
|
Alert("El viaje masivo se registró correctamente.", TipoMensaje.MsgInformacion)
|
|
Else
|
|
Try
|
|
If BtnGuardar.Text = "Guardar" Then
|
|
Dim CveContratoHijo As Integer = -1
|
|
CveContratoHijo = ObjTransportes.AddViajes(DdlRutas.Text.ToEntero, -1, -1, UsuarioActual.CveEmpresa, TxtFechaViaje.Text.ToDate, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero)
|
|
|
|
If CveContratoHijo > 0 Then
|
|
ObjTransportes.Commit()
|
|
Alert("El Viaje se registró Correctamente.", TipoMensaje.MsgInformacion)
|
|
DdlRutas.Text = ""
|
|
TxtFechaViaje.Text = ""
|
|
DdlPartida.Text = ""
|
|
DdlDestino.SelectedValue = ""
|
|
End If
|
|
Else
|
|
|
|
If ObjTransportes.UpdateViajes(CveViaje.ToEntero, DdlRutas.Text.ToEntero, -1, -1, UsuarioActual.CveEmpresa, TxtFechaViaje.Text.ToDate, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero) = True Then
|
|
Alert("El viaje se modificó correctamente.", TipoMensaje.MsgInformacion)
|
|
ObjTransportes.Commit()
|
|
CargaDatos()
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
ObjTransportes.RollBack()
|
|
Finally
|
|
CargaDatos()
|
|
ObjTransportes.Dispose()
|
|
End Try
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub UpdateViaje(sender As Object, e As EventArgs)
|
|
IsMasivo.Visible = False
|
|
DivFechaMasivo.Visible = False
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
|
|
DdlRutas.SelectedValue = GvRow.DataKey("CveRuta")
|
|
DdlDestino.SelectedValue = GvRow.DataKey("CveDestino")
|
|
DdlPartida.SelectedValue = GvRow.DataKey("CvePartida")
|
|
ViewState("CveViaje") = GvRow.DataKey("CveViaje")
|
|
ViewState("Ruta") = GvRow.DataKey("Ruta")
|
|
Dim fecha As DateTime
|
|
|
|
If DateTime.TryParse(GvRow.DataKey("Fecha").ToString, fecha) Then
|
|
TxtFechaViaje.Text = fecha.ToString("yyyy-MM-dd").Replace(" ", "T")
|
|
End If
|
|
|
|
BtnGuardar.Text = "Actualizar"
|
|
ModalLabel.InnerHtml = "Actualizar Viaje"
|
|
|
|
|
|
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
|
|
|
|
End Sub
|
|
|
|
Protected Sub RemoveViaje(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
Dim CveMasivo As String = GvRow.DataKey("CveMasivo")
|
|
|
|
Dim ObjTransportes As New ClsTransportes
|
|
|
|
ObjTransportes.IniciaTransacSQL()
|
|
If CveMasivo = "" Then
|
|
Try
|
|
ObjTransportes.RemoveViaje(CveViaje:=GvRow.DataKey("CveViaje").ToEntero)
|
|
ObjTransportes.Commit()
|
|
Catch ex As Exception
|
|
Alert($"Ocurrió un error {ex}", TipoMensaje.MsgError)
|
|
End Try
|
|
Else
|
|
Try
|
|
ObjTransportes.RemoveViaje(CveMasivo:=CveMasivo.ToEntero)
|
|
ObjTransportes.Commit()
|
|
Catch ex As Exception
|
|
Alert($"Ocurrió un error {ex}", TipoMensaje.MsgError)
|
|
|
|
End Try
|
|
End If
|
|
Alert("Viaje eliminado correctamente")
|
|
CargaDatos()
|
|
ObjTransportes.Dispose()
|
|
|
|
End Sub
|
|
|
|
Protected Sub ToggleMasivo(sender As Object, e As EventArgs)
|
|
DivFechaMasivo.Visible = IsMasivo.Checked
|
|
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
|
|
End Sub
|
|
|
|
Protected Sub GoViaje(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
Dim CveViaje As String = GvRow.DataKey("CveViaje")
|
|
Response.Redirect(String.Format("~/Transportes/Boletos.aspx?CveViaje={0}", CveViaje))
|
|
End Sub
|
|
Protected Sub GoBoletos(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
Dim CveViaje As String = GvRow.DataKey("CveViaje")
|
|
Dim Ruta As String = GvRow.DataKey("Ruta")
|
|
Response.Redirect(String.Format("~/Transportes/RepBoletos.aspx?CveViaje={0}&Ruta={1}", CveViaje, Ruta))
|
|
End Sub
|
|
End Class
|