Se creo el CRUD para ClsViajes con sus modelos y Procedimientos Almacenados

This commit is contained in:
AbrahamCastilloV
2023-12-11 08:53:56 -07:00
parent b8896b961a
commit 47caaa3997
8 changed files with 305 additions and 23 deletions

View File

@@ -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í.

View File

@@ -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

View File

@@ -95,16 +95,22 @@
</div>
</div>
</div>
<div class="row my-1" id="TrTipoUnidad" runat="server">
<div class="row margin-bottom-5" id="TrAF" runat="server">
<label class="col-md-4 bold">
<asp:Label ID="Label2" runat="server" Text="Tipo de Unidad:"></asp:Label></label><div
<asp:Label runat="server" Text="Transporte:"></asp:Label></label><div
class="col-md-8">
<asp:DropDownList ID="DdlUnidad"
runat="server" DataTextField="NombreComercial" DataValueField="CveCliente"
Class="table-group-action-input form-control input-inline input-sm select2me"
Width="75%" ValidationGroup="GrpGuardar">
<asp:DropDownList ID="DdlTransporte" AppendDataBoundItems="true" DataTextField="Descripcion"
DataValueField="CveActivoFijo" Class="table-group-action-input form-control input-inline text-center"
Width="200px" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVTransporte" runat="server" ControlToValidate="DdlTransporte"
Display="None" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Transporte''</b> es necesario, por favor ingréselo."
ValidationGroup="GrpGuardar"></asp:RequiredFieldValidator>
<ajax:ValidatorCalloutExtender ID="VCETransporte" runat="server" HighlightCssClass="vco"
TargetControlID="RFVTransporte" Width="400px" BehaviorID="_content_VCETransporte">
</ajax:ValidatorCalloutExtender>
</div>
</div>

View File

@@ -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"))

View File

@@ -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("<script>console.log('El resultado de tu variable" + ObjRutas.DtResultados.Rows.ToString + "')</script>")
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("<script>console.log('El resultado de tu variable" + ObjDestinos.DtResultados.Rows.ToString + "')</script>")
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

View File

@@ -41,6 +41,10 @@
<li>
<asp:HyperLink ID="LBCrearViaje" runat="server" NavigateUrl="CrearViaje.aspx"
Target="_blank"><i class='fa fa-car'></i> Crear Viaje</asp:HyperLink>
</li>
<li>
<asp:HyperLink ID="LBListadoViajes" runat="server" NavigateUrl="ListadoViajes.aspx"
Target="_blank"><i class='fa fa-road'></i> Listado de Viajes</asp:HyperLink>
</li>
</ContentTemplate>
</asp:UpdatePanel>

View File

@@ -0,0 +1,69 @@
<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/Site.master" CodeFile="ListadoViajes.aspx.vb"
Inherits="ListadoViajes" %>
<asp:Content ID="Content3" ContentPlaceHolderID="E" runat="Server">
Listado de Viajes</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Css" runat="Server">
<style>
.my-1 {
margin-block: 1rem;
}
</style>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="C" runat="Server">
<contenttemplate>
<asp:GridView ID="GvViajes" runat="server" AutoGenerateColumns="false" EmptyDataText="No se encontró ningún viaje registrado"
CssClass="table table-striped table-hover Widthall ScrollAD text-center" GridLines="None"
data-sort="true" OnRowCommand="GvViajes_Comandos">
<Columns>
<asp:TemplateField HeaderText="Ruta">
<ItemTemplate>
<asp:Literal ID="LtlRuta" runat="server" Text='<%# Eval("Ruta") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Partida">
<ItemTemplate>
<asp:Literal ID="LtlPartida" runat="server" Text='<%# Eval("Partida") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Destino">
<ItemTemplate>
<asp:Literal ID="LtlDestino" runat="server" Text='<%# Eval("Destino") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fecha">
<ItemTemplate>
<asp:Literal ID="LtlFecha" runat="server" Text='<%# Eval("Fecha") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Chofer">
<ItemTemplate>
<asp:Literal ID="LtlChofer" runat="server" Text='<%# Eval("Chofer") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Acciones">
<ItemTemplate>
<asp:Button ID="btnEditar" runat="server" Text="Editar" CommandName="Editar" class="btn btn-primary"
CommandArgument='<%# Eval("CveViaje") %>' />
<asp:Button ID="btnEliminar" runat="server" Text="Eliminar" CommandName="Eliminar"
class="btn btn-danger" CommandArgument='<%# Eval("CveViaje") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</contenttemplate>
</asp:Content>

View File

@@ -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("<script>console.log('El resultado de tu variable" + GvViajes.ToString + "')</script>")
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