Files
SIG/Contabilidad2/RepAnexoCatalogoAnual.aspx.vb

423 lines
14 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Partial Class Contabilidad2_RepAnexoCatalogoAnual
Inherits ClsPaginas
#Region " PROPIEDADES "
Public Property CveCuenta As Integer
Get
Return ViewState("CveCuenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuenta") = value
End Set
End Property
Public Property EsVertical As Integer
Get
Return ViewState("EsVertical").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("EsVertical") = value
End Set
End Property
Private Property listacolores As List(Of String)
Get
Return DirectCast(ViewState("listacolores"), List(Of String))
End Get
Set(value As List(Of String))
ViewState("listacolores") = value
End Set
End Property
Private Property listaCamposanios As List(Of String())
Get
Return DirectCast(ViewState("listaCamposanios"), List(Of String()))
End Get
Set(value As List(Of String()))
ViewState("listaCamposanios") = value
End Set
End Property
Public Property DtHeadersCount As Integer
Get
If ViewState("DtHeadersCount") Is Nothing Then
Return -1
Else
Return ViewState("DtHeadersCount").ToString.ToEntero
End If
End Get
Set(value As Integer)
ViewState("DtHeadersCount") = value
End Set
End Property
Private Property DTHeaders As DataTable
Get
If ViewState("DTHeaders") Is Nothing Then
Return New DataTable
Else
Return DirectCast(ViewState("DTHeaders"), DataTable)
End If
End Get
Set(value As DataTable)
ViewState("DTHeaders") = value
End Set
End Property
Private Property DTDatos As DataTable
Get
If ViewState("DTDatos") Is Nothing Then
Return New DataTable
Else
Return DirectCast(ViewState("DTDatos"), DataTable)
End If
End Get
Set(value As DataTable)
ViewState("DTDatos") = 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
listacolores = New List(Of String)
listaCamposanios = New List(Of String())
listacolores.Add("#FF0F00")
listacolores.Add("#FF6600")
listacolores.Add("#F8FF01")
listacolores.Add("#04D215")
listacolores.Add("#2A0CD0")
listacolores.Add("#8A0CCF")
listacolores.Add("#CD0D74")
listacolores.Add("#754DEB")
listacolores.Add("#DDDDDD")
listacolores.Add("#999999")
listacolores.Add("#000000")
listacolores.Add("#FF0F00")
Dim EjercicioParametro, EjercicioParametroFinal, SubProyectoParametro, DivisorParametro, Periodo As Integer
CveCuenta = IfNull(Request("CveCuenta"), "-1").ToString.ToEntero
EjercicioParametro = IfNull(Request("Ejercicio"), "-1").ToString.ToEntero
EjercicioParametroFinal = IfNull(Request("EjercicioFinal"), "-1").ToString.ToEntero
SubProyectoParametro = IfNull(Request("CveSubproyecto"), "-1").ToString.ToEntero
DivisorParametro = IfNull(Request("Divisor"), "-1").ToString.ToEntero
Periodo = IfNull(Request("Periodo"), "-1").ToString.ToEntero
EsVertical = IfNull(Request("V"), "-1").ToString.ToEntero
InicializaValores()
DdlEjercicio.SelectedValueExist(EjercicioParametro.ToString)
DdlEjercicio2.SelectedValueExist(EjercicioParametroFinal.ToString)
DdlSubProyecto.SelectedValueExist(SubProyectoParametro.ToString)
DdlDivisor.SelectedValueExist(DivisorParametro.ToString)
DdlPeriodo.SelectedValueExist(Periodo)
CargaDatos()
End If
End Sub
#Region " INICIALIZA VALORES "
Private Sub InicializaValores()
CargaCombos()
End Sub
Private Sub CargaCombos()
Dim Conta As New ClsContabilidad
If Conta.GetEjercicios(UsuarioActual.CveEmpresa) Then
DdlEjercicio.DataSource = Conta.DtResultados
DdlEjercicio2.DataSource = Conta.DtResultados
Else
DdlEjercicio.DataSource = Nothing
DdlEjercicio2.DataSource = Nothing
End If
Conta.Dispose()
DdlEjercicio.DataBind()
DdlEjercicio2.DataBind()
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 BtnCargaAsignados_Click(sender As Object, e As EventArgs) Handles BtnCargaAsignados.Click
CargaDatos()
End Sub
Private Sub CargaDatos()
If CveCuenta <= -1 Then
Alert("No hay una cuenta expecificada.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
DTHeaders = New DataTable
DTDatos = New DataTable
Dim Conta As New ClsContabilidad
DtHeadersCount = 0
If Conta.GetAnexoCatalogoAnual(CveCuenta, DdlEjercicio.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlEjercicio2.SelectedValue.ToEntero, DdlDivisor.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlPeriodo.SelectedValue.ToEntero) Then
'Dim DtHeaders As DataTable = Conta.DSResultados.Tables(0)
DTHeaders = Conta.DSResultados.Tables(0)
DTDatos = Conta.DSResultados.Tables(1)
DtHeadersCount = DTHeaders.Rows.Count
GvAnual.DataSource = Conta.DSResultados.Tables(1)
Dim Index = 2
For Index = 2 To GvAnual.Columns.Count - 1
GvAnual.Columns(Index).Visible = False
Next Index
listaCamposanios.Clear()
Index = 2
For Each Dr As DataRow In DTHeaders.Rows
GvAnual.Columns(Index).Visible = True
CType(GvAnual.Columns(Index), BoundField).DataField = String.Format("Ejercicio{0}", Dr("Ejercicio"))
GvAnual.Columns(Index).HeaderText = Dr("Ejercicio").ToString
listaCamposanios.Add(New String() {String.Format("Ejercicio{0}", Dr("Ejercicio")), Dr("Ejercicio").ToString()})
If Not DdlEjercicio.SelectedValue = Dr("Ejercicio").ToString Then
If EsVertical <> 1 Then
GvAnual.Columns(Index + 1).Visible = True
CType(GvAnual.Columns(Index + 1), BoundField).DataField = String.Format("Ejercicio{0}VariacionImporte", Dr("Ejercicio"))
GvAnual.Columns(Index + 1).HeaderText = "$"
End If
GvAnual.Columns(Index + 2).Visible = True
CType(GvAnual.Columns(Index + 2), BoundField).DataField = String.Format("Ejercicio{0}{1}Porcentaje", Dr("Ejercicio"), If(EsVertical = 1, "", "Variacion"))
GvAnual.Columns(Index + 2).HeaderText = "%"
End If
Index += 3
Next
GvAnual.DataBind()
UpAnual.Update()
Else
GvAnual.DataSource = Nothing
End If
GvAnual.DataBind()
UpAnual.Update()
'RegistraScript($"LimpiaCeros({DdlDivisor.SelectedValue});")
'RegistraScript($"LimpiaCeros();")
Conta.Dispose()
If GvAnual.Rows.Count > 0 Then
LnkExportar.Visible = True
UpAcciones.Update()
End If
End Sub
#End Region
#Region " GV ROW DATABOUND "
Protected Sub GvAnual_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvAnual.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
setgraficaCC(e)
If e.Row.RowIndex = 0 Then
e.Row.Style.Add("font-weight", "bold")
End If
If e.Row.DataKey("Level").ToEntero = 0 Then
e.Row.CssClass = "Totales"
End If
If e.Row.DataKey("Level").ToEntero = 1 Then
e.Row.CssClass = "SubTotales"
End If
Dim CveCunetaRow As Integer = e.Row.DataKey("CveCuenta").ToEntero
Dim inicial As Boolean = True
Dim Index As Integer = 2
For Each DRow As DataRow In DTHeaders.Rows
Dim Importe As Decimal = e.Row.DBCampo($"Ejercicio{DRow("Ejercicio")}").ToDecimal
Dim Anio As Integer = DRow("Ejercicio").ToString.ToEntero
If Importe <> 0 Then
e.Row.Cells(Index).Text = $"<a { If(Importe < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF=31/12/{Anio}&FI=01/01/{Anio}&ER=1&CveSubProyecto={DdlSubProyecto.SelectedValue.ToEntero}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Importe.ToString("###,###,##0"), Importe.ToString("###,###,###.00")) }</a>"
End If
If e.Row.Cells(Index + 1).Text.ToDecimal = 0 Then
e.Row.Cells(Index + 1).Text = "-"
ElseIf e.Row.Cells(Index + 1).Text.ToDecimal < 0 Then
e.Row.Cells(Index + 1).ForeColor = Drawing.Color.Red
End If
If e.Row.Cells(Index + 2).Text.Replace("%", "").ToDecimal = 0 Then
e.Row.Cells(Index + 2).Text = "-"
ElseIf e.Row.Cells(Index + 2).Text.Replace("%", "").ToDecimal < 0 Then
e.Row.Cells(Index + 2).ForeColor = Drawing.Color.Red
End If
'If inicial Then
' Index = Indice + 1
' inicial = False
' Continue For
'End If
Index += 3
Next
'e.Row.Cells(1).Style.Add("text-indent", $"{e.Row.DBCampo("Level").ToString.ToEntero * 2}em")
End If
End Sub
Public Sub setgraficaCC(e As GridViewRowEventArgs)
Dim lista As New List(Of Object)
Dim colorindex As Integer = 0
For Each campo As String() In listaCamposanios
lista.Add(New With {.Texto = campo(1), .Valor = e.Row.DBCampo(campo(0)).ToDecimal(), .Color = listacolores(colorindex)})
colorindex = colorindex + 1
If colorindex >= listacolores.Count Then
colorindex = 0
End If
Next
e.Row.FCHyperLink("Hypgrafica").Attributes.Add("data-values", Newtonsoft.Json.JsonConvert.SerializeObject(lista))
End Sub
Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click
Dim SubProyecto As String = ""
If DdlSubProyecto.SelectedValue.ToEntero > 0 Then
SubProyecto = DdlSubProyecto.SelectedItem.Text
End If
Dim SbFiltros As New StringBuilder()
SbFiltros.AppendFormat("Fecha Inicio: {0} Fecha Fin: {1}|", $"01/01/{DdlEjercicio.SelectedValue}", $"31/12/{DdlEjercicio2.SelectedValue}")
SbFiltros.AppendFormat("SubProyecto: {0}|", SubProyecto)
SbFiltros.AppendFormat("Divisor : {0}|", DdlDivisor.SelectedItem.Text)
GvAnual.ExportToExcelGembox("AnexoCatálogoAnual", UsuarioActual, "Anexo del Catálogo - Anual", DatoTituloExtra:=$"Periodo{DdlPeriodo.SelectedItem.Text}", DatosFiltros:=SbFiltros.ToString())
'GvAnual.ExportToExcelGembox("AnexoCatálogoAnual", UsuarioActual, $"01/01/{DdlEjercicio.SelectedValue}", $"31/12/{DdlEjercicio2.SelectedValue}", "Anexo del Catálogo - Anual", SubProyecto, DdlDivisor.SelectedValue.ToEntero, DatoTituloExtra:=$"Periodo {DdlPeriodo.SelectedItem.Text}")
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
#End Region
Protected Sub GvAnual_DataBound(sender As Object, e As EventArgs)
'If DtHeadersCount > 0 Then
' '96 32
' Dim NColumns As Integer = GvAnual.Columns.Count
' Dim row As New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal)
' Dim cell1 As New TableHeaderCell()
' cell1.Text = ""
' cell1.ColumnSpan = 1
' row.Controls.Add(cell1)
' Dim cell2 As New TableHeaderCell()
' cell2.Text = ""
' cell2.ColumnSpan = 1
' row.Controls.Add(cell2)
' Dim cell3 As New TableHeaderCell()
' cell3.Text = ""
' cell3.ColumnSpan = 1
' row.Controls.Add(cell3)
' Dim cell4 As New TableHeaderCell()
' cell4.Text = ""
' cell4.ColumnSpan = 1
' row.Controls.Add(cell4)
' For x = 0 To DtHeadersCount
' Dim cell As New TableHeaderCell()
' cell.Text = ""
' cell.ColumnSpan = 1
' row.Controls.Add(cell)
' Dim cellColspan2 = New TableHeaderCell()
' cellColspan2.ColumnSpan = 2
' cellColspan2.Text = "Variación"
' row.Controls.Add(cellColspan2)
' x = x + 1
' Next
' GvAnual.HeaderRow.Parent.Controls.AddAt(0, row)
'End If
End Sub
End Class