Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class Bancos_CatTiposCuenta Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then ViewState("Orden") = "" ViewState("OTipoCuenta") = "TipoCuenta DESC" ViewState("OEstatus") = "Estatus DESC" ViewState("OFechaIng") = "FechaIng DESC" ViewState("OUsuario") = "Usuario DESC" CargaDatos() ''Permiso Registro 'If PermisoRegistro Then ' LbAgregar.Enabled = True 'Else ' LbAgregar.Enabled = False 'End If End If End Sub Public Sub CargaDatos() Dim ObjTipoCuentas As New ClsBancos If ObjTipoCuentas.GetBancos_TiposCuenta() Then ViewState("DTTipoCuentas") = ObjTipoCuentas.DtResultados GlobalDTTipoCuenta = ObjTipoCuentas.DtResultados Else Me.GvDatos.DataSource = Nothing End If ObjTipoCuentas.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub #Region "ORDEN" Protected Sub LbAgregar_Click(sender As Object, e As System.EventArgs) Handles LbAgregar.Click Dim ObjTipoCuentas As New ClsBancos If ObjTipoCuentas.AddBancos_TiposCuenta(TxtTipoCuenta.Text.Trim, UsuarioActual.CveUsuario) Then TxtTipoCuenta.Text = "" Alert("El nuevo TipoCuenta se guardó correctamente.", TipoMensaje.MsgInformacion) UpTitulos.Update() ViewState("DTTipoCuentas") = ObjTipoCuentas.DtResultados GlobalDTTipoCuenta = ObjTipoCuentas.DtResultados If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End If ObjTipoCuentas.Dispose() End Sub Protected Sub LbTipoCuenta_Click(sender As Object, e As System.EventArgs) Handles LbTipoCuenta.Click, ImgTipoCuenta.Click If ViewState("OTipoCuenta").ToString() = "TipoCuenta DESC" Then ViewState("OTipoCuenta") = "TipoCuenta ASC" ImgTipoCuenta.ImageUrl = "/Imagenes/FlechasArriba.gif" Else ViewState("OTipoCuenta") = "TipoCuenta DESC" ImgTipoCuenta.ImageUrl = "/Imagenes/FlechasAbajo.gif" End If ViewState("Orden") = ViewState("OTipoCuenta") CargaGrid(ViewState("Orden").ToString()) End Sub Protected Sub LbEstatus_Click(sender As Object, e As System.EventArgs) Handles LbEstatus.Click, ImgEstatus.Click If ViewState("OEstatus").ToString() = "Estatus DESC" Then ViewState("OEstatus") = "Estatus ASC" ImgEstatus.ImageUrl = "/Imagenes/FlechasArriba.gif" Else ViewState("OEstatus") = "Estatus DESC" ImgEstatus.ImageUrl = "/Imagenes/FlechasAbajo.gif" End If ViewState("Orden") = ViewState("OEstatus") CargaGrid(ViewState("Orden").ToString()) End Sub Protected Sub LbFechaIng_Click(sender As Object, e As System.EventArgs) Handles LbFechaIng.Click, ImgFechaIng.Click If ViewState("OFechaIng").ToString() = "FechaIng DESC" Then ViewState("OFechaIng") = "FechaIng ASC" ImgFechaIng.ImageUrl = "/Imagenes/FlechasArriba.gif" Else ViewState("OFechaIng") = "FechaIng DESC" ImgFechaIng.ImageUrl = "/Imagenes/FlechasAbajo.gif" End If ViewState("Orden") = ViewState("OFechaIng") CargaGrid(ViewState("Orden").ToString()) End Sub Protected Sub LbUsuario_Click(sender As Object, e As System.EventArgs) Handles LbUsuario.Click, ImgUsuario.Click If ViewState("OUsuario").ToString() = "Usuario DESC" Then ViewState("OUsuario") = "Usuario ASC" ImgUsuario.ImageUrl = "/Imagenes/FlechasArriba.gif" Else ViewState("OUsuario") = "Usuario DESC" ImgUsuario.ImageUrl = "/Imagenes/FlechasAbajo.gif" End If ViewState("Orden") = ViewState("OUsuario") CargaGrid(ViewState("Orden").ToString()) End Sub #End Region Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(250) e.Row.Cells(1).Width = Unit.Pixel(100) e.Row.Cells(2).Width = Unit.Pixel(100) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(50) e.Row.Cells(5).Width = Unit.Pixel(50) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left End If End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim ObjTipoCuentas As New ClsBancos If ObjTipoCuentas.RemoveBancos_TiposCuenta(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatos.EditIndex = -1 ViewState("DTTipoCuentas") = ObjTipoCuentas.DtResultados GlobalDTTipoCuenta = ObjTipoCuentas.DtResultados Alert("El Tipo de Cuenta se eliminó correctamente.", TipoMensaje.MsgInformacion) End If ObjTipoCuentas.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatos_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit GvDatos.EditIndex = -1 If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatos_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatos.RowUpdating Dim ObjTipoCuentas As New ClsBancos Dim TipoCuenta As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtTipoCuenta"), TextBox).Text.Trim Dim Estatus As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstatus").Checked Dim CveTipoCuenta As Integer = GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero If ObjTipoCuentas.UpdateBancos_TiposCuenta(TipoCuenta, Estatus, CveTipoCuenta) Then GvDatos.EditIndex = -1 ViewState("DTTipoCuentas") = ObjTipoCuentas.DtResultados GlobalDTTipoCuenta = ObjTipoCuentas.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) End If ObjTipoCuentas.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatos_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatos.RowEditing GvDatos.EditIndex = e.NewEditIndex If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Private Sub CargaGrid(Orden As String) If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTTipoCuentas"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatos.DataSource = DV.ToTable() DV.Dispose() Else GvDatos.DataSource = CType(ViewState("DTTipoCuentas"), DataTable) End If GvDatos.DataBind() UpDatos.Update() End Sub End Class