Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class Contabilidad_ConceptosContables Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then ViewState("Orden") = "" CargaDatos() End If End Sub Public Sub CargaDatos() Dim ObjConceptoContable As New ClsContabilidad If ObjConceptoContable.GetConta_ConceptosContables() Then ViewState("DTConceptoContable") = ObjConceptoContable.DtResultados GlobalDTContaConceptosContables(-1) = ObjConceptoContable.DtResultados Else Me.GvDatos.DataSource = Nothing End If ObjConceptoContable.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Protected Sub LbAgregar_Click(sender As Object, e As System.EventArgs) Handles LbAgregar.Click Dim ObjConceptoContable As New ClsContabilidad If ObjConceptoContable.AddConta_ConceptosContables(TxtCveConceptoContable.Text.Trim.ToEntero, TxtTipo.Text.Trim, TxtConceptoContable.Text.Trim, UsuarioActual.CveUsuario) Then TxtTipo.Text = "" TxtCveConceptoContable.Text = "" Alert("El Concepto Contable se guardó correctamente.", TipoMensaje.MsgInformacion) UpTitulos.Update() ViewState("DTConceptoContable") = ObjConceptoContable.DtResultados GlobalDTContaConceptosContables(-1) = ObjConceptoContable.DtResultados If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End If ObjConceptoContable.Dispose() End Sub #Region "G V D A T O S" 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(110) e.Row.Cells(1).Width = Unit.Pixel(110) e.Row.Cells(2).Width = Unit.Pixel(260) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(100) e.Row.Cells(5).Width = Unit.Pixel(100) e.Row.Cells(6).Width = Unit.Pixel(100) e.Row.Cells(7).Width = Unit.Pixel(61) End If e.Row.Cells(2).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 ObjConceptoContable As New ClsContabilidad Dim CveConceptoContable As Integer = GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero If ObjConceptoContable.RemoveConta_ConceptosContables(CveConceptoContable) Then TxtTipo.Text = "" TxtCveConceptoContable.Text = "" TxtConceptoContable.Text = "" GvDatos.EditIndex = -1 ViewState("DTConceptoContable") = ObjConceptoContable.DtResultados GlobalDTContaConceptosContables(-1) = ObjConceptoContable.DtResultados Alert("El Concepto Contable se eliminó correctamente.", TipoMensaje.MsgInformacion) End If ObjConceptoContable.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 ObjConceptoContable As New ClsContabilidad Dim Tipo As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtTipo"), TextBox).Text.Trim Dim ConceptoContable As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtConceptoContable"), TextBox).Text.Trim Dim Estado As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstado").Checked Dim CveConceptoContable As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtCveConceptoContable"), TextBox).Text.Trim.ToEntero If ObjConceptoContable.UpdateConta_ConceptosContables(Tipo, ConceptoContable, Estado, CveConceptoContable) Then GvDatos.EditIndex = -1 ViewState("DTConceptoContable") = ObjConceptoContable.DtResultados GlobalDTContaConceptosContables(-1) = ObjConceptoContable.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) End If ObjConceptoContable.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 #End Region #Region "O R D E N A M I E N T O" Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs) Dim Orden As String = "" Dim Campo As String = "" Dim Literal As Literal = Nothing Const OrdenInicial As String = "" Dim Arg(2) As String Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c) Campo = Arg(0) Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal) If ViewState(String.Format("O{0}", Campo)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo)).ToString = String.Format("{0} DESC", Campo) Then ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo) Literal.Text = String.Format("") Else ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo) Literal.Text = String.Format("") End If Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo)).ToString ViewState("Orden") = Orden CargaGrid(Orden) End Sub Private Sub CargaGrid(Orden As String) If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTConceptoContable"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatos.DataSource = DV.ToTable() DV.Dispose() Else GvDatos.DataSource = CType(ViewState("DTConceptoContable"), DataTable) End If GvDatos.DataBind() UpDatos.Update() End Sub #End Region End Class