Files
SIG/Contabilidad2/RepAnexoCatalogoCC.aspx.vb
2023-05-23 06:30:20 -07:00

337 lines
12 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Partial Class Contabilidad2_RepAnexoCatalogoCC
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
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 listaCampos As List(Of String())
Get
Return DirectCast(ViewState("listaCampos"), List(Of String()))
End Get
Set(value As List(Of String()))
ViewState("listaCampos") = 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)
listaCampos = 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, SubProyectoParametro, DivisorParametro As Integer
'CveCuenta = IfNull(Request("C"), "-1").ToString.ToEntero
'EjercicioParametro = IfNull(Request("E"), "-1").ToString.ToEntero
'SubProyectoParametro = IfNull(Request("S"), "-1").ToString.ToEntero
'DivisorParametro = IfNull(Request("D"), "-1").ToString.ToEntero
Dim EjercicioParametro, SubProyectoParametro, DivisorParametro, Periodo As Integer
CveCuenta = IfNull(Request("CveCuenta"), "-1").ToString.ToEntero
EjercicioParametro = IfNull(Request("Ejercicio"), "-1").ToString.ToEntero
SubProyectoParametro = IfNull(Request("CveSubProyecto"), "-1").ToString.ToEntero
DivisorParametro = IfNull(Request("Divisor"), "-1").ToString.ToEntero
Periodo = IfNull(Request("Periodo"), "-1").ToString.ToEntero
InicializaValores()
CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, LblSubProyecto)
DdlEjercicio.SelectedValueExist(EjercicioParametro.ToString)
DdlSubProyecto.SelectedValueExist(SubProyectoParametro.ToString)
DdlDivisor.SelectedValueExist(DivisorParametro.ToString)
DdlPeriodo.SelectedValueExist(Periodo)
If CveCuenta > 0 Then
DdlCuentas.SelectedValueExist(CveCuenta)
CargaDatos()
End If
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
Else
DdlEjercicio.DataSource = Nothing
End If
Dim strGlobal As String = ""
If Conta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) Then
Dim dr As DataRow = Conta.DtResultados.FiltroPrimero("Codigo IN ('_GLOBAL')")
If dr IsNot Nothing Then strGlobal = dr.Item(0).ToString
DdlCuentas.DataSource = Conta.DtResultados
End If
Conta.Dispose()
DdlEjercicio.DataBind()
DdlEjercicio.SelectedValueExist(Now.Year.ToString)
DdlCuentas.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 Not DdlCuentas.SelectedValue.ToEntero > 0 Then
Alert("Debe de seleccionar una cuenta.")
Exit Sub
End If
DTHeaders = New DataTable
DTDatos = New DataTable
Dim Conta As New ClsContabilidad
If Conta.GetAnexoCatalagoCC(DdlCuentas.SelectedValue.ToEntero, DdlEjercicio.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlDivisor.SelectedValue.ToEntero, DdlPeriodo.SelectedValue.ToEntero, UsuarioActual.CveUsuario) Then
DTHeaders = Conta.DSResultados.Tables(0)
DTDatos = Conta.DSResultados.Tables(1)
GvCC.DataSource = Conta.DSResultados.Tables(1)
Dim Index = 4
For Index = 4 To GvCC.Columns.Count - 1
GvCC.Columns(Index).Visible = False
Next Index
listaCampos.Clear()
Index = 4
For Each Dr As DataRow In DTHeaders.Rows
GvCC.Columns(Index).Visible = True
CType(GvCC.Columns(Index), BoundField).DataField = String.Format("SubProyecto{0}", Dr("SubProyecto"))
GvCC.Columns(Index).HeaderText = Dr("SubProyecto").ToString()
listaCampos.Add(New String() {String.Format("SubProyecto{0}", Dr("SubProyecto")), Dr("SubProyecto").ToString()})
'GvCC.Columns(Index + 1).Visible = True
'CType(GvCC.Columns(Index + 1), BoundField).DataField = String.Format("SubProyecto{0}Porcentaje", Dr("SubProyecto"))
'GvCC.Columns(Index + 1).HeaderText = "%"
'Index += 2
Index += 1
Next
GvCC.DataBind()
UpCC.Update()
Else
GvCC.DataSource = Nothing
End If
If GvCC.Rows.Count > 0 Then
LnkExportar.Visible = True
UpAcciones.Update()
End If
'RegistraScript($"LimpiaCeros({DdlDivisor.SelectedValue});")
Conta.Dispose()
End Sub
#End Region
#Region " GV ROW DATABOUND "
Protected Sub GvCC_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCC.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.Style.Add("font-weight", "bold")
End If
setgraficaCC(e)
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 Index As Integer = 2
For Each DRow As DataRow In DTHeaders.Rows
Dim Importe As Decimal = e.Row.DBCampo($"SubProyecto{DRow("SubProyecto")}").ToDecimal
'Dim Anio As Integer = DRow("SubProyecto").ToString.ToEntero
If e.Row.CssClass = "Totales" And Index = 2 Then
e.Row.Cells(Index).ForeColor = Drawing.ColorTranslator.FromHtml("#337ab7")
End If
If e.Row.Cells(Index).Text.Replace("%", "").ToDecimal = 0 Then
e.Row.Cells(Index).Text = "-"
ElseIf e.Row.Cells(Index).Text.Replace("%", "").ToDecimal < 0 Then
e.Row.Cells(Index).ForeColor = Drawing.Color.Red
End If
Index += 1
Next
Dim CveCunetaRow As Integer = e.Row.DataKey("CveCuenta").ToEntero
Dim inicial As Boolean = True
Index = 4
For Each DRow As DataRow In DTHeaders.Rows
Dim Importe As Decimal = e.Row.DBCampo($"SubProyecto{DRow("SubProyecto")}").ToDecimal
If e.Row.Cells(Index).Text.Replace("%", "").ToDecimal = 0 Then
e.Row.Cells(Index).Text = "-"
ElseIf e.Row.Cells(Index).Text.Replace("%", "").ToDecimal < 0 Then
e.Row.Cells(Index).ForeColor = Drawing.Color.Red
End If
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/{DdlEjercicio.SelectedValue}&FI=01/01/{DdlEjercicio.SelectedValue}&ER=1&CveSubProyecto={ If(DRow("CveSubProyecto").ToString.ToEntero > 0, DRow("CveSubProyecto").ToString, "-1")}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Importe.ToString("###,###,##0"), Importe.ToString("###,###,###.00")) }</a>"
End If
Index += 1
Next
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 listaCampos
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
#End Region
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/{DdlEjercicio.SelectedValue}")
SbFiltros.AppendFormat("Estado de Resultados Horizontal por : {0}|", SubProyecto)
SbFiltros.AppendFormat("Divisor : {0}|", DdlDivisor.SelectedItem.Text)
SbFiltros.AppendFormat("Periodo : {0}|", DdlPeriodo.SelectedItem.Text)
GvCC.ExportToExcelGembox("AnexoCatálogoMensual", UsuarioActual, $"Estado de Resultados Horizontal por {LblSubProyecto.Text}", DatoTituloExtra:="", DatosFiltros:=SbFiltros.ToString())
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
End Class