Files
SIG/Transportes/ListadoViajes.aspx.vb

210 lines
7.9 KiB
VB.net

Option Explicit On
Option Strict On
Imports ADSNetLibrary.SIGAPI.Helpers
Imports Extensiones.ModExtensiones
Partial Class ListadoViajes
Inherits ClsPaginas
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
CargaDatos()
End If
End Sub
Private Sub CargaDatos()
Dim ObjViajes As New ClsViajes
ObjViajes.IniciaTransacSQL()
If ObjViajes.GetViajes() Then
GvViajes.DataSource = ObjViajes.DtResultados
ObjViajes.Dispose()
GvViajes.DataBind()
Else
Me.GvViajes.DataSource = Nothing
End If
'Lista Activos Fijos'
Dim ObjAF As New ClsAF()
If ObjAF.GetActivosFijos(-1, 13, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, 1, "-1", -1, -1, -1) Then
If ObjAF.DtResultados.Rows.Count > 0 Then
DdlTransporte.DataSource = ObjAF.DtResultados
DdlTransporte.DataBind()
DdlTransporte.Items.Insert(0, New ListItem("Seleccione Transporte", ""))
End If
End If
ObjAF.Dispose()
'Lista Rutas'
Dim ObjRutas As New ClsRutas()
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
ObjRutas.Dispose()
'Lista Destinos'
Dim ObjDestinos As New ClsDestinos()
If ObjDestinos.GetDestinos(-1, -1, -1, "", True, True, DateTime.Now) 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
ObjRutas.Dispose()
'Lista Chofer'
DdlChofer.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa)
DdlChofer.DataBind()
DdlChofer.Items.Insert(0, New ListItem("Seleccione Chofer", ""))
End Sub
Protected Sub MostrarModal(sender As Object, e As System.EventArgs)
DdlRutas.Text = ""
DdlTransporte.Text = ""
DdlChofer.Text = ""
TxtFechaViaje.Text = ""
DdlPartida.Text = ""
DdlDestino.SelectedValue = ""
BtnGuardar.Text = "Guardar"
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
End Sub
Protected Sub AddViaje(sender As Object, e As EventArgs)
Dim ObjViajes As New ClsViajes
ObjViajes.IniciaTransacSQL()
Page.Response.Write("<script>console.log('El resultado de tu variable" + IsMasivo.Checked.ToString + "')</script>")
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 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 = ObjViajes.AddViajes(DdlRutas.Text.ToEntero, DdlTransporte.Text.ToEntero, DdlChofer.Text.ToEntero, UsuarioActual.CveEmpresa, fecha, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero)
If CveContratoHijo > 0 Then
ObjViajes.Commit()
End If
Catch ex As Exception
Alert($"Ocurrió un error {ex}", TipoMensaje.MsgError)
End Try
Next
DdlRutas.Text = ""
DdlTransporte.Text = ""
DdlChofer.Text = ""
TxtFechaViaje.Text = ""
DdlPartida.Text = ""
DdlDestino.SelectedValue = ""
ObjViajes.Dispose()
Response.Redirect("ListadoViajes.aspx")
Alert("El viaje masivo se registró correctamente.", TipoMensaje.MsgInformacion)
Else
Try
If BtnGuardar.Text = "Guardar" Then
Dim CveContratoHijo As Integer = -1
CveContratoHijo = ObjViajes.AddViajes(DdlRutas.Text.ToEntero, DdlTransporte.Text.ToEntero, DdlChofer.Text.ToEntero, UsuarioActual.CveEmpresa, TxtFechaViaje.Text.ToDate, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero)
If CveContratoHijo > 0 Then
ObjViajes.Commit()
Alert("El Viaje se registró Correctamente.", TipoMensaje.MsgInformacion)
DdlRutas.Text = ""
DdlTransporte.Text = ""
DdlChofer.Text = ""
TxtFechaViaje.Text = ""
DdlPartida.Text = ""
DdlDestino.SelectedValue = ""
End If
Else
Dim id As Integer = Convert.ToInt32(Request.QueryString("CveViaje"))
If ObjViajes.UpdateViajes(id, DdlRutas.Text.ToEntero, DdlTransporte.Text.ToEntero, DdlChofer.Text.ToEntero, UsuarioActual.CveEmpresa, TxtFechaViaje.Text.ToDate, DdlPartida.Text.ToEntero, DdlDestino.Text.ToEntero) = True Then
Alert("El viaje se modificó correctamente.", TipoMensaje.MsgInformacion)
ObjViajes.Commit()
End If
End If
Catch ex As Exception
ObjViajes.RollBack()
Finally
ObjViajes.Dispose()
Response.Redirect("ListadoViajes.aspx")
End Try
End If
End Sub
Protected Sub UpdateViaje(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
DdlTransporte.SelectedValue = GvRow.DataKey("CveAF")
DdlRutas.SelectedValue = GvRow.DataKey("CveRuta")
DdlDestino.SelectedValue = GvRow.DataKey("CveDestino")
DdlPartida.SelectedValue = GvRow.DataKey("CvePartida")
DdlChofer.SelectedValue = GvRow.DataKey("CvePersonal")
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 = "Editar"
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 ObjViajes As New ClsViajes
ObjViajes.IniciaTransacSQL()
Try
ObjViajes.RemoveViaje(GvRow.DataKey("CveViaje").ToEntero)
ObjViajes.Commit()
Response.Redirect(Request.RawUrl)
Catch ex As Exception
Alert($"Ocurrió un error {ex}", TipoMensaje.MsgError)
Finally
ObjViajes.Dispose()
End Try
End Sub
Protected Sub ToggleMasivo(sender As Object, e As EventArgs)
DivFechaMasivo.Visible = IsMasivo.Checked
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
End Sub
End Class