diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index d63910d2f..e8a08ddee 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -9441,6 +9441,9 @@ Public Class ClsPaginas #Region "Transportes" PaginaDict.Add("/Transportes/ContratoTransporte.aspx".ToUpper(), 598) + PaginaDict.Add("/Transportes/ListadoContratos.aspx".ToUpper(), 598) + PaginaDict.Add("/Transportes/CrearViaje.aspx".ToUpper(), 598) + PaginaDict.Add("/Transportes/ListadoViajes.aspx".ToUpper(), 598) #End Region 'Antes de aquí. diff --git a/App_Code/ClsViajes.vb b/App_Code/ClsViajes.vb index cc207147e..7ee08071c 100644 --- a/App_Code/ClsViajes.vb +++ b/App_Code/ClsViajes.vb @@ -28,19 +28,22 @@ Public Class ClsViajes #Region "Propiedades" Public Property CveViaje As Integer - Public Property CveRuta As String + Public Property CveRuta As Integer Public Property CveAF As Integer - Public Property CvePersonal As String + Public Property CvePersonal As Integer Public Property CveEmpresa As Integer - Public Property Fecha As String + Public Property CvePartida As Integer + Public Property CveDestino As Integer + Public Property Fecha As DateTime #End Region #Region "Funciones básicas" Sub New(Optional TransaccionCompartida As SqlTransaction = Nothing) If TransaccionCompartida Is Nothing Then - SqlConexion = New SqlConnection - SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString + SqlConexion = New SqlConnection With { + .ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString + } Try SqlConexion.Open() Catch ex As Exception @@ -60,7 +63,7 @@ Public Class ClsViajes .CommandText = StrSQL .CommandType = TipoComando End With - If Not SqlTransacc Is Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc + If SqlTransacc IsNot Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc Data = New DataTable End Sub #Region "Conexiones" @@ -75,7 +78,7 @@ Public Class ClsViajes .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output End With SqlAdapter.Fill(Data) - CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + CveConexion = CInt(SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString) Catch ex As Exception OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) End Try @@ -131,7 +134,8 @@ Public Class ClsViajes End Sub #End Region - Public Function AddViajes(CveRuta As Integer, CveAF As Integer, CvePersonal As Integer, CveEmpresa As Integer, Fecha As DateTime) As Integer +#Region "Métodos" + Public Function AddViajes(CveRuta As Integer, CveAF As Integer, CvePersonal As Integer, CveEmpresa As Integer, Fecha As DateTime, CvePartida As Integer, CveDestino As Integer) As Integer Dim Retorno As Integer = -1 DataAdapter("PA_Trans_ViajesAdd") @@ -143,12 +147,13 @@ Public Class ClsViajes .Add("@CvePersonal", SqlDbType.Int).Value = CvePersonal .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa .Add("@Fecha", SqlDbType.DateTime).Value = Fecha - + .Add("@CvePartida", SqlDbType.Int).Value = CvePartida + .Add("@CveDestino", SqlDbType.Int).Value = CveDestino End With Try SqlAdapter.Fill(Data) - Retorno = SqlAdapter.SelectCommand.Parameters("@CveViaje").Value.ToString.ToEntero + Retorno = CInt(SqlAdapter.SelectCommand.Parameters("@CveViaje").Value.ToString) Catch ex As Exception OnError("Ocurrió un error al guardar el nuevo viaje.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) @@ -156,4 +161,76 @@ Public Class ClsViajes Return Retorno End Function + + Public Function GetViajes(Optional CveViaje As Integer = 0) As Boolean + Dim Retorno As Boolean = False + DataAdapter("PA_Trans_ViajesGet") + If CveViaje > 0 Then + With SqlAdapter.SelectCommand.Parameters + .Add("@CveViajeSeleccionado", SqlDbType.Int).Value = CveViaje + End With + End If + Try + SqlAdapter.Fill(Data) + If CveViaje > 0 AndAlso Data IsNot Nothing AndAlso Data.Rows.Count > 0 Then + CveRuta = Data.Rows(0)("CveRuta").ToString.ToEntero + CveAF = Data.Rows(0)("CveAF").ToString.ToEntero + CvePersonal = Data.Rows(0)("CvePersonal").ToString.ToEntero + CveEmpresa = Data.Rows(0)("CveEmpresa").ToString.ToEntero + CvePartida = Data.Rows(0)("CvePartida").ToString.ToEntero + CveDestino = Data.Rows(0)("CveDestino").ToString.ToEntero + Fecha = Data.Rows(0)("Fecha").ToString.ToDate + End If + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener el catálogo de viajes.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function + + Public Function RemoveViaje(CveViaje As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Trans_ViajesRemove") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveViaje", SqlDbType.Int).Value = CveViaje + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al eliminar el contrato.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function + + Public Function UpdateViajes(CveViaje As Integer, CveRuta As Integer, CveAF As Integer, CvePersonal As Integer, CveEmpresa As Integer, Fecha As DateTime, CvePartida As Integer, CveDestino As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Trans_ViajesUpdate") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveViaje", SqlDbType.Int).Value = CveViaje + .Add("@CveRuta", SqlDbType.Int).Value = CveRuta + .Add("@CveAF", SqlDbType.Int).Value = CveAF + .Add("@CvePersonal", SqlDbType.Int).Value = CvePersonal + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@Fecha", SqlDbType.Date).Value = Fecha + .Add("@CvePartida", SqlDbType.Int).Value = CvePartida + .Add("@CveDestino", SqlDbType.Int).Value = CveDestino + + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al actualizar el Contrato.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function +#End Region End Class diff --git a/Transportes/ContratoTransporte.aspx b/Transportes/ContratoTransporte.aspx index ba6064227..faabd6ff8 100644 --- a/Transportes/ContratoTransporte.aspx +++ b/Transportes/ContratoTransporte.aspx @@ -95,16 +95,22 @@ - -
+
- + + + + + +
diff --git a/Transportes/ContratoTransporte.aspx.vb b/Transportes/ContratoTransporte.aspx.vb index 2243b0433..550aad649 100644 --- a/Transportes/ContratoTransporte.aspx.vb +++ b/Transportes/ContratoTransporte.aspx.vb @@ -11,7 +11,17 @@ Partial Class ContratoTransportes If Not IsPostBack Then DdlClientes.setEsWebService(True) + '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() If Not String.IsNullOrEmpty(Request.QueryString("CveContrato")) Then Dim id As Integer = Convert.ToInt32(Request.QueryString("CveContrato")) diff --git a/Transportes/CrearViaje.aspx.vb b/Transportes/CrearViaje.aspx.vb index 686454cfb..514394678 100644 --- a/Transportes/CrearViaje.aspx.vb +++ b/Transportes/CrearViaje.aspx.vb @@ -9,6 +9,29 @@ Partial Class CrearViaje If Not IsPostBack Then CargaDatos() + + If Not String.IsNullOrEmpty(Request.QueryString("CveViaje")) Then + + Dim id As Integer = Convert.ToInt32(Request.QueryString("CveViaje")) + + Dim ObjViajes As New ClsViajes + If ObjViajes.GetViajes(CveViaje:=id) Then + Dim fecha As DateTime + + If DateTime.TryParse(ObjViajes.Fecha.ToString, fecha) Then + TxtFechaViaje.Text = fecha.ToString("yyyy-MM-dd").Replace(" ", "T") + End If + + DdlRutas.Text = ObjViajes.CveRuta.ToString + DdlTransporte.Text = ObjViajes.CveAF.ToString + DdlPartida.Text = ObjViajes.CvePartida.ToString + DdlDestino.Text = ObjViajes.CveDestino.ToString + DdlChofer.Text = ObjViajes.CvePersonal.ToString + + BtnGuardar.Text = "Editar" + End If + + End If End If End Sub @@ -28,7 +51,6 @@ Partial Class CrearViaje 'Lista Rutas' Dim ObjRutas As New ClsRutas() If ObjRutas.GetRutas(-1, -1, -1, "", True, DateTime.Now) Then - Page.Response.Write("") If ObjRutas.DtResultados.Rows.Count > 0 Then DdlRutas.DataSource = ObjRutas.DtResultados @@ -41,7 +63,6 @@ Partial Class CrearViaje 'Lista Destinos' Dim ObjDestinos As New ClsDestinos() If ObjDestinos.GetDestinos(-1, -1, -1, "", True, True, DateTime.Now) Then - Page.Response.Write("") If ObjDestinos.DtResultados.Rows.Count > 0 Then @@ -63,10 +84,46 @@ Partial Class CrearViaje End Sub Protected Sub AddViaje(sender As Object, e As EventArgs) - Dim ObjViajes As New ClsViajes() - If ObjViajes.AddViajes(DdlRutas.Text.ToEntero, DdlTransporte.Text.ToEntero, DdlChofer.Text.ToEntero, UsuarioActual.CveEmpresa.ToEntero, TxtFechaViaje.Text.ToDate) = -1 Then - Alert("El Contrato se agregó correctamente.", TipoMensaje.MsgAdvertencia) - End If + Dim ObjViajes As New ClsViajes + + + ObjViajes.IniciaTransacSQL() + + 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 Sub End Class \ No newline at end of file diff --git a/Transportes/ListadoContratos.aspx b/Transportes/ListadoContratos.aspx index ce2b31699..f8e63a7bc 100644 --- a/Transportes/ListadoContratos.aspx +++ b/Transportes/ListadoContratos.aspx @@ -41,6 +41,10 @@
  • Crear Viaje +
  • +
  • + Listado de Viajes
  • diff --git a/Transportes/ListadoViajes.aspx b/Transportes/ListadoViajes.aspx new file mode 100644 index 000000000..b26a1da91 --- /dev/null +++ b/Transportes/ListadoViajes.aspx @@ -0,0 +1,69 @@ +<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/Site.master" CodeFile="ListadoViajes.aspx.vb" + Inherits="ListadoViajes" %> + + +Listado de Viajes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Transportes/ListadoViajes.aspx.vb b/Transportes/ListadoViajes.aspx.vb new file mode 100644 index 000000000..b3f110e31 --- /dev/null +++ b/Transportes/ListadoViajes.aspx.vb @@ -0,0 +1,56 @@ +Option Explicit On +Option Strict On + + +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 + + + If ObjViajes.GetViajes() Then + GvViajes.DataSource = ObjViajes.DtResultados + Else + Me.GvViajes.DataSource = Nothing + End If + + ObjViajes.Dispose() + GvViajes.DataBind() + Page.Response.Write("") + End Sub + + Protected Sub GvViajes_Comandos(sender As Object, e As GridViewCommandEventArgs) + Dim id As Integer = Convert.ToInt32(e.CommandArgument) + Dim url As String = $"CrearViaje.aspx?CveViaje={id}" + + If e.CommandName = "Editar" Then + Dim script As String = $"window.open('{url}', '_blank');" + Page.ClientScript.RegisterStartupScript(Me.GetType(), "OpenWindow", script, True) + End If + + If e.CommandName = "Eliminar" Then + Dim ObjViajes As New ClsViajes + ObjViajes.IniciaTransacSQL() + + Try + ObjViajes.RemoveViaje(id) + ObjViajes.Commit() + Catch ex As Exception + ObjViajes.RollBack() + Finally + ObjViajes.Dispose() + Response.Redirect("ListadoViajes.aspx") + End Try + + End If + + End Sub +End Class