Option Explicit On Option Strict On Partial Class CatRutas Inherits ClsPaginas Private Property Cve As Integer Get Return ViewState("Cve").ToString().ToEntero End Get Set(value As Integer) ViewState("Cve") = value End Set End Property Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then ViewState("Cve") = 0 InicializarCombos() CargaDatos() End If End Sub Private Sub CargaDatos() 'Lista Rutas' Dim ObjRutas As New ClsTransportes() If ObjRutas.GetRutas(-1, -1, -1, "", True, DateTime.Now) Then If ObjRutas.DtResultados.Rows.Count > 0 Then GvRutas.DataSource = ObjRutas.DtResultados GvRutas.DataBind() End If End If 'Lista Destinos' If ObjRutas.GetDestinos() Then If ObjRutas.DtResultados.Rows.Count > 0 Then GvDestinos.DataSource = ObjRutas.DtResultados GvDestinos.DataBind() End If End If 'Lista Importes' If ObjRutas.GetDestinosTarifas(-1, -1) Then If ObjRutas.DtResultados.Rows.Count > 0 Then GvImportes.DataSource = ObjRutas.DtResultados GvImportes.DataBind() End If End If UpPanel.Update() End Sub Private Sub InicializarCombos() Dim ObjDestinos As New ClsTransportes() If ObjDestinos.GetDestinos() Then If ObjDestinos.DtResultados.Rows.Count > 0 Then DdlOrigen.DataSource = ObjDestinos.DtResultados DdlOrigen.DataBind() DdlOrigen.Items.Insert(0, New ListItem("Seleccione Partida", "")) DdlFinal.DataSource = ObjDestinos.DtResultados DdlFinal.DataBind() DdlFinal.Items.Insert(0, New ListItem("Seleccione Destino", "")) End If End If ObjDestinos.Dispose() 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 End Sub Protected Sub MostrarModal(sender As Object, e As EventArgs) TxtRuta.Text = "" DdlRutaEstatus.SelectedValue = "" TxtDestino.Text = "" DdlEsNacional.SelectedValue = "" DdlDestinoEstatus.SelectedValue = "" DdlOrigen.SelectedValue = "" DdlFinal.SelectedValue = "" TxtImporte.Text = "" BtnAddRuta.Visible = False BtnAddDestino.Visible = False BtnAddImporte.Visible = False PnRuta.Visible = False PnDestino.Visible = False PnImporte.Visible = False Dim id As String = DirectCast(sender, LinkButton).ID If id.Contains("Editar") Then Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Select Case id Case "BtnEditarRuta" ModalLabel.Text = "Editar Ruta" PnRuta.Visible = True TxtRuta.Text = GvRow.DataKey("Ruta") DdlRutaEstatus.SelectedValue = GvRow.DataKey("Estatus") BtnAddRuta.Visible = True BtnAddRuta.Text = "Editar" ViewState("Cve") = GvRow.DataKey("CveRuta").ToEntero Case "BtnEditarDestino" ModalLabel.Text = "Editar Destino" TxtDestino.Text = GvRow.DataKey("Destino") DdlEsNacional.SelectedValue = GvRow.DataKey("EsNacional") DdlDestinoEstatus.SelectedValue = GvRow.DataKey("Estatus") PnDestino.Visible = True BtnAddDestino.Visible = True BtnAddDestino.Text = "Editar" ViewState("Cve") = GvRow.DataKey("CveDestino").ToEntero Case "BtnEditarImporte" ModalLabel.Text = "Editar Importe" DdlRutas.SelectedValue = GvRow.DataKey("CveRuta") DdlOrigen.SelectedValue = GvRow.DataKey("CveDestinoOrigen") DdlFinal.SelectedValue = GvRow.DataKey("CveDestinoFinal") TxtImporte.Text = GvRow.DataKey("Importe") PnImporte.Visible = True BtnAddImporte.Visible = True BtnAddImporte.Text = "Editar" ViewState("Cve") = GvRow.DataKey("CveDestinoTarifa").ToEntero End Select End If If id.Contains("Agregar") Then Select Case id Case "BtnAgregarRuta" ModalLabel.Text = "Agregar Ruta" PnRuta.Visible = True BtnAddRuta.Visible = True BtnAddRuta.Text = "Guardar" Case "BtnAgregarDestino" ModalLabel.Text = "Agregar Destino" PnDestino.Visible = True BtnAddDestino.Visible = True BtnAddDestino.Text = "Guardar" Case "BtnAgregarImporte" ModalLabel.Text = "Agregar Importe" PnImporte.Visible = True BtnAddImporte.Visible = True BtnAddImporte.Text = "Guardar" End Select End If UpModal.Update() RegistraScript(String.Format("$('#{0}').modal('show');", "Modal")) End Sub #Region "Rutas" Protected Sub AddRuta(sender As Object, e As EventArgs) Dim ObjRuta As New ClsTransportes ObjRuta.IniciaTransacSQL() Try If BtnAddRuta.Text = "Guardar" Then If ObjRuta.AddRuta(TxtRuta.Text, DdlRutaEstatus.SelectedValue, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) > 1 Then ObjRuta.Commit() Alert("Ruta Agregada Correctamente.") End If End If If BtnAddRuta.Text = "Editar" Then If ObjRuta.UpdateRuta(Cve, TxtRuta.Text, DdlRutaEstatus.SelectedValue, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then ObjRuta.Commit() Alert("Ruta Actualizada Correctamente.") End If End If Catch ex As Exception ObjRuta.RollBack() Finally CargaDatos() ObjRuta.Dispose() End Try End Sub Protected Sub RemoveRuta(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Dim ObjRuta As New ClsTransportes If ObjRuta.RemoveRuta(GvRow.DataKey("CveRuta").ToEntero) Then Alert("Ruta eliminada correctamente") CargaDatos() End If ObjRuta.Dispose() End Sub #End Region #Region "Destinos" Protected Sub AddDestino(sender As Object, e As EventArgs) Dim ObjDestino As New ClsTransportes ObjDestino.IniciaTransacSQL() Try If BtnAddDestino.Text = "Guardar" Then If ObjDestino.AddDestino(TxtDestino.Text, DdlDestinoEstatus.SelectedValue, DdlEsNacional.SelectedValue, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) > 1 Then ObjDestino.Commit() Alert("Destino agregado correctamente.") End If End If If BtnAddDestino.Text = "Editar" Then If ObjDestino.UpdateDestino(Cve, TxtDestino.Text, DdlDestinoEstatus.SelectedValue, DdlEsNacional.SelectedValue, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then ObjDestino.Commit() Alert("Destino actualizado correctamente.") End If End If Catch ex As Exception ObjDestino.RollBack() Finally CargaDatos() ObjDestino.Dispose() End Try End Sub Protected Sub RemoveDestino(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Dim ObjDestino As New ClsTransportes If ObjDestino.RemoveDestino(GvRow.DataKey("CveDestino").ToEntero) Then Alert("Destino eliminado correctamente") CargaDatos() End If ObjDestino.Dispose() End Sub #End Region #Region "Importes" Protected Sub AddImporte(sender As Object, e As EventArgs) Dim ObjImporte As New ClsTransportes ObjImporte.IniciaTransacSQL() Try If BtnAddImporte.Text = "Guardar" Then If ObjImporte.AddDestinosTarifas(DdlRutas.SelectedValue, DdlOrigen.SelectedValue, DdlFinal.SelectedValue, TxtImporte.Text) > 1 Then ObjImporte.Commit() Alert("Importe agregado correctamente.") End If End If If BtnAddImporte.Text = "Editar" Then If ObjImporte.UpdateDestinosTarifas(Cve, DdlRutas.SelectedValue, DdlOrigen.SelectedValue, DdlFinal.SelectedValue, TxtImporte.Text) Then ObjImporte.Commit() Alert("Importe actualizado correctamente.") End If End If Catch ex As Exception ObjImporte.RollBack() Finally CargaDatos() ObjImporte.Dispose() End Try End Sub Protected Sub RemoveImporte(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Dim ObjImporte As New ClsTransportes If ObjImporte.RemoveDestinosTarifas(GvRow.DataKey("CveDestinoTarifa").ToEntero) Then Alert("Importe eliminada correctamente") CargaDatos() End If ObjImporte.Dispose() End Sub #End Region End Class