Option Explicit On Option Strict On Imports System.Data Imports Extensiones Partial Class Contabilidad_RepBalanceGeneralHorizontal Inherits ClsPaginas #Region " PROPIEDADES " Public Property EjercicioMin As Integer Get Return ViewState("EjercicioMin").ToString.ToEntero End Get Set(value As Integer) ViewState("EjercicioMin") = value End Set End Property Public Property DtHeadersAnual As DataTable Get Return CType(ViewState("DtHeadersAnual"), DataTable) End Get Set(value As DataTable) ViewState("DtHeadersAnual") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then InicializaValores() Else ReCreate() End If End Sub #Region " INICIALIZA VALORES " Private Sub InicializaValores() CargaCombos() DdlEjercicio.SelectedValueExist(Now.Year.ToString) CargaDatos() End Sub Private Sub CargaCombos() Dim Conta As New ClsContabilidad If Conta.GetEjercicios(UsuarioActual.CveEmpresa) Then DdlEjercicio.DataSource = Conta.DtResultados EjercicioMin = Conta.DtResultados.MIN("Ejercicio").ToEntero Else DdlEjercicio.DataSource = Nothing End If Conta.Dispose() DdlEjercicio.DataBind() DdlEjercicio.SelectedValueExist(Now.Year.ToString) DdlSubProyecto.DataSource = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa) DdlSubProyecto.DataBind() DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1")) DdlSubProyecto.SelectedValue = "-1" End Sub #End Region #Region " CARGA DATOS " Protected Sub BtnCargaDatos_Click(sender As Object, e As EventArgs) Handles BtnCargaDatos.Click CargaDatos() End Sub Protected Sub Tab_ActiveTabChanged(sender As Object, e As EventArgs) If Tab.ActiveTabIndex = 1 Then DdlEjercicio.SelectedValueExist(EjercicioMin.ToString) End If CargaDatos() End Sub Private Sub ReCreate() If DtHeadersAnual Is Nothing Then Exit Sub End If Dim Index = 1 For Each Dr As DataRow In DtHeadersAnual.Rows Dim Test As New LinkButton Test.CssClass = "Texto" Test.Text = Dr("Ejercicio").ToString Test.CommandArgument = Dr("Ejercicio").ToString AddHandler Test.Click, AddressOf AnualToMensual GvAnual.HeaderRow.Cells(Index).Controls.Add(Test) Index += 3 Next End Sub Protected Sub AnualToMensual(sender As Object, e As EventArgs) Tab.ActiveTabIndex = 0 DdlEjercicio.SelectedValue = CType(sender, LinkButton).CommandArgument CargaDatos() End Sub Private Sub CargaDatos() Dim Conta As New ClsContabilidad Dim ColumnasEsconder = "" Dim Script = $"LimpiaCeros({DdlDivisor.SelectedValue});" DtHeadersAnual = Nothing Dim IdGV = "" If Tab.ActiveTabIndex = 0 Then IdGV = GvMensual2.ClientID If Conta.GetBalanceGeneralMensualVertical(DdlEjercicio.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) Then Conta.DtResultados.Columns.Add("EjercicioFiltro", GetType(Integer)) Conta.DtResultados.Columns.Add("SubProyectoFiltro", GetType(Integer)) Conta.DtResultados.Columns.Add("DivisorFiltro", GetType(Integer)) GvMensual2.DataSource = Conta.DtResultados Else GvMensual2.DataSource = Nothing End If GvMensual2.DataBind() UpMensual.Update() ElseIf Tab.ActiveTabIndex = 1 Then IdGV = GvAnual.ClientID If Conta.GetBalanceGeneralAnualVertical(DdlEjercicio.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) Then Dim DtHeaders As DataTable = Conta.DSResultados.Tables(0) GvAnual.DataSource = Conta.DSResultados.Tables(1) Dim Index = 1 For Index = 1 To GvAnual.Columns.Count - 1 GvAnual.Columns(Index).Visible = False Next Index Index = 1 Dim titulos As New StringBuilder For Each Dr As DataRow In DtHeaders.Rows GvAnual.Columns(Index).Visible = True CType(GvAnual.Columns(Index), BoundField).DataField = $"a{Dr("Ejercicio").ToString}" GvAnual.Columns(Index).HeaderText = Dr("Ejercicio").ToString titulos.Append($"{IIf(Index = 1, "", ",")}{Dr("Ejercicio").ToString}") If Not DdlEjercicio.SelectedValue = Dr("Ejercicio").ToString Then GvAnual.Columns(Index + 1).Visible = True CType(GvAnual.Columns(Index + 1), BoundField).DataField = $"Variaciona{Dr("Ejercicio").ToString}Importe" GvAnual.Columns(Index + 1).HeaderText = "$" GvAnual.Columns(Index + 2).Visible = True CType(GvAnual.Columns(Index + 2), BoundField).DataField = $"Variaciona{Dr("Ejercicio").ToString}Porcentaje" GvAnual.Columns(Index + 2).HeaderText = "%" End If Index += 3 Next HdfTitulosA.Value = titulos.ToString GvAnual.DataBind() DtHeadersAnual = DtHeaders Index = 1 For Each Dr As DataRow In DtHeaders.Rows Dim Test As New LinkButton Test.CssClass = "Texto" Test.Text = Dr("Ejercicio").ToString Test.CommandArgument = Dr("Ejercicio").ToString AddHandler Test.Click, AddressOf AnualToMensual GvAnual.HeaderRow.Cells(Index).Controls.Add(Test) Index += 3 Next Index = 1 Dim IndexRow As Integer = 0 For Each row As DataRow In Conta.DSResultados.Tables(1).Rows Dim valores As New StringBuilder Dim Porcentajes As New StringBuilder Dim prefix As String = "" For Each Dr As DataRow In DtHeaders.Rows valores.Append($"{prefix}{row($"a{Dr("Ejercicio").ToString}")}") If Not DdlEjercicio.SelectedValue = Dr("Ejercicio").ToString Then Porcentajes.Append($"{prefix}{row($"Variaciona{Dr("Ejercicio").ToString}Porcentaje")}") Else Porcentajes.Append($"{prefix}0") End If Index += 3 prefix = "," Next Dim lbl As Label = GvAnual.Rows(IndexRow).FCLabel("lblchart") lbl.Attributes.Add("data-value", valores.ToString) lbl.Attributes.Add("data-porcentaje", Porcentajes.ToString) IndexRow += 1 Next UPModal.Update() UpAnual.Update() Else GvAnual.DataSource = Nothing End If ElseIf Tab.ActiveTabIndex = 2 Then IdGV = GvCC.ClientID If Conta.GetBalanceGeneralHorizontalCC(DdlEjercicio.SelectedValue.ToEntero, -1, DdlSubProyecto.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) Then Dim DtHeaders As DataTable = Conta.DSResultados.Tables(0) GvCC.DataSource = Conta.DSResultados.Tables(1) Dim Index = 4 For Index = 4 To GvCC.Columns.Count - 1 GvCC.Columns(Index).Visible = False Next Index Index = 4 Dim Titulos As New StringBuilder ColumnasEsconder = "3" Titulos.Append("Sin SubProyecto") For Each Dr As DataRow In DtHeaders.Rows GvCC.Columns(Index).Visible = True CType(GvCC.Columns(Index), BoundField).DataField = $"SubProyecto{Dr("SubProyecto").ToString}" GvCC.Columns(Index).HeaderText = Dr("SubProyecto").ToString Titulos.Append($",{Dr("SubProyecto")}") GvCC.Columns(Index + 1).Visible = True CType(GvCC.Columns(Index + 1), BoundField).DataField = $"SubProyecto{Dr("SubProyecto").ToString}Porcentaje" GvCC.Columns(Index + 1).HeaderText = "%" ColumnasEsconder = $"{ColumnasEsconder},{Index + 1}" Index += 2 'If Conta.DSResultados.Tables(1).SUM($"SubProyecto{Dr("SubProyecto").ToString}") = 0 Then ' GvCC.Columns(Index).Visible = False ' GvCC.Columns(Index + 1).Visible = False 'End If Next HdfTituloscc.Value = Titulos.ToString GvCC.DataBind() Dim IndexRow As Integer = 0 For Each row As DataRow In Conta.DSResultados.Tables(1).Rows Dim valores As New StringBuilder Dim Porcentajes As New StringBuilder valores.Append($"{row($"SubProyectoNA")}") Porcentajes.Append($"{row($"SubProyectoNAPorcentaje")}") For Each Dr As DataRow In DtHeaders.Rows valores.Append($",{row($"SubProyecto{Dr("SubProyecto").ToString}")}") If Not DdlSubProyecto.SelectedValue = Dr("SubProyecto").ToString Then Porcentajes.Append($",{row($"SubProyecto{Dr("SubProyecto").ToString}Porcentaje")}") Else Porcentajes.Append($",0") End If Next Dim lbl As Label = GvCC.Rows(IndexRow).FCLabel("lblchart") lbl.Attributes.Add("data-value", valores.ToString) lbl.Attributes.Add("data-porcentaje", Porcentajes.ToString) IndexRow += 1 Next UpCC.Update() UPModal.Update() Script = $"LimpiaCeros({DdlDivisor.SelectedValue});EscondeCC({ColumnasEsconder});" Else GvCC.DataSource = Nothing End If End If If DdlTipo.SelectedValue.ToEntero > 0 Then Script = $"{Script};EscondeRenglones('{IdGV}');" End If RegistraScript(Script) UpFiltros.Update() Conta.Dispose() End Sub #End Region #Region " GV ROW DATABOUND " Protected Sub GvMensual1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvMensual2.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'LIGA SOLO EN DETALLE POR CAMPO CVECUENTA - TEMPORAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then e.Row.FCHyperLink("HLNombre").NavigateUrl = $"/Contabilidad2/RepAnexoCatalogoMensual.aspx?C={e.Row.DBCampo("CveCuenta")}&E={DdlEjercicio.SelectedValue}&S={DdlSubProyecto.SelectedValue}&D={DdlDivisor.SelectedValue}" End If Dim cssclass As String = "" e.Row.Attributes.Add("style", "height:28px;") 'TOTAL If e.Row.DBCampo("CtaMayor").ToString = "99" Then e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") cssclass = "txtid2em" End If 'SUMNA If e.Row.DBCampo("Clasificacion").ToString = "Z" Then e.Row.Style.Add("background-color", "#DDD") e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") End If 'NORMAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then cssclass = "txtid4em" Dim lbl As Label = e.Row.FCLabel("lblchart") lbl.Visible = True lbl.Attributes.Add("data-value", String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", e.Row.DBCampo("Enero"), e.Row.DBCampo("Febrero"), e.Row.DBCampo("Marzo"), e.Row.DBCampo("Abril"), e.Row.DBCampo("Mayo"), e.Row.DBCampo("Junio"), e.Row.DBCampo("Julio"), e.Row.DBCampo("Agosto"), e.Row.DBCampo("Septiembre"), e.Row.DBCampo("Octubre"), e.Row.DBCampo("Noviembre"), e.Row.DBCampo("Diciembre"))) lbl.Attributes.Add("data-porcentaje", String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", e.Row.DBCampo("EneroPorcentaje"), e.Row.DBCampo("FebreroPorcentaje"), e.Row.DBCampo("MarzoPorcentaje"), e.Row.DBCampo("AbrilPorcentaje"), e.Row.DBCampo("MayoPorcentaje"), e.Row.DBCampo("JunioPorcentaje"), e.Row.DBCampo("JulioPorcentaje"), e.Row.DBCampo("AgostoPorcentaje"), e.Row.DBCampo("SeptiembrePorcentaje"), e.Row.DBCampo("OctubrePorcentaje"), e.Row.DBCampo("NoviembrePorcentaje"), e.Row.DBCampo("DiciembrePorcentaje"))) End If 'CABECERA If e.Row.DBCampo("CtaMayor").ToString = "3" Then e.Row.Style.Add("font-weight", "bold") cssclass = "txtid2em" For Index = 1 To GvMensual2.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If 'GENERAL e.Row.CssClass = cssclass If e.Row.DBCampo("Clasificacion").ToString = "A" Then e.Row.CssClass = "Totales " & cssclass For Index = 1 To GvMensual2.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If End If End Sub Protected Sub GvAnual_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvAnual.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'LIGA SOLO EN DETALLE POR CAMPO CVECUENTA - TEMPORAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then e.Row.FCHyperLink("HLNombre").NavigateUrl = $"/Contabilidad2/RepAnexoCatalogoAnual.aspx?C={e.Row.DBCampo("CveCuenta")}&E={DdlEjercicio.SelectedValue}&S={DdlSubProyecto.SelectedValue}&D={DdlDivisor.SelectedValue}" End If 'TOTAL Dim cssclass As String = "" If e.Row.DBCampo("CtaMayor").ToString = "99" Then e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") cssclass = "txtid2em" End If 'SUMA If e.Row.DBCampo("Clasificacion").ToString = "Z" Then e.Row.Style.Add("background-color", "#DDD") e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") End If 'NORMAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then cssclass = "txtid4em" e.Row.FindControl("lblchart").Visible = True End If 'CABECERA If e.Row.DBCampo("CtaMayor").ToString = "3" Then e.Row.Style.Add("font-weight", "bold") cssclass = "txtid2em" Dim Index = 0 For Index = 1 To GvAnual.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If 'GENERAL e.Row.CssClass = cssclass If e.Row.DBCampo("Clasificacion").ToString = "A" Then e.Row.CssClass = "Totales " & cssclass For Index = 1 To GvAnual.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If End If End Sub Protected Sub GvCC_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCC.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'LIGA SOLO EN DETALLE POR CAMPO CVECUENTA - TEMPORAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then e.Row.FCHyperLink("HLNombre").NavigateUrl = $"/Contabilidad2/RepAnexoCatalogoCC.aspx?C={e.Row.DBCampo("CveCuenta")}&E={DdlEjercicio.SelectedValue}&S={DdlSubProyecto.SelectedValue}&D={DdlDivisor.SelectedValue}" End If 'TOTAL Dim cssclass As String = "" If e.Row.DBCampo("CtaMayor").ToString = "99" Then e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") cssclass = "txtid2em" End If 'SUMA If e.Row.DBCampo("Clasificacion").ToString = "Z" Then e.Row.Style.Add("background-color", "#DDD") e.Row.Style.Add("font-weight", "bold") e.Row.Style.Add("font-style", "italic") End If 'NORMAL If e.Row.DBCampo("CtaMayor").ToString = "1" Then cssclass = "txtid4em" e.Row.FindControl("lblchart").Visible = True End If 'CABECERA If e.Row.DBCampo("CtaMayor").ToString = "3" Then e.Row.Style.Add("font-weight", "bold") cssclass = "txtid2em" Dim Index = 0 For Index = 1 To GvAnual.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If 'GENERAL e.Row.CssClass = cssclass If e.Row.DBCampo("Clasificacion").ToString = "A" Then e.Row.CssClass = "Totales " & cssclass For Index = 1 To GvAnual.Columns.Count - 1 e.Row.Cells(Index).Text = "" Next Index End If End If End Sub #End Region End Class