Files
SIG/Contabilidad/RepAnexoCatalogoSegmento.aspx.vb
MLopez 021e50c4b7 Limpieza masiva ClsPaginas
-RegistraScript se unifica en una sola clase static/shared y se simplica el código
-Alert se vuelve estático
-Random() no se manda a crear cada vez que se registra un script (esto tenía un costo alto)
-Se corrigieron unos errores en los nombres de funciones
-Las clases que ya heredan de Clspaginas, se les quita el this a RegistraScript y a Alert puesto que era innecesario (y además al haberlos vuelto métodos estáticos, NO pueden llamarse de un this)
2023-01-31 21:56:32 -07:00

366 lines
12 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class AC_RepAnexoCatalogoSegmento
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Property DtDatos As DataTable
Get
DtDatos = DirectCast(ViewState("DtDatos"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DtDatos") = value
End Set
End Property
Private Property DTCabeceras As DataTable
Get
DTCabeceras = DirectCast(ViewState("DTCabeceras"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DTCabeceras") = value
End Set
End Property
Private Property FechaInicio As Date
Get
FechaInicio = ViewState("FechaInicio").ToString.ToDate
End Get
Set(value As Date)
ViewState("FechaInicio") = value
End Set
End Property
Private Property FechaFin As Date
Get
FechaFin = ViewState("FechaFin").ToString.ToDate
End Get
Set(value As Date)
ViewState("FechaFin") = value
End Set
End Property
Private Property IdCuenta As Integer
Get
IdCuenta = ViewState("IdCuenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuenta") = value
End Set
End Property
Private Property IdSegNeg As Integer
Get
IdSegNeg = ViewState("IdSegNeg").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdSegNeg") = value
End Set
End Property
Private Property DTCuentas As DataTable
Get
Return CType(ViewState("DTCuentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCuentas") = value
End Set
End Property
Private Property TipoReporte As Integer
Get
TipoReporte = ViewState("TipoReporte").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("TipoReporte") = value
End Set
End Property
Private Property Segmentos As String
Get
Segmentos = ViewState("Segmentos").ToString
End Get
Set(value As String)
ViewState("Segmentos") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If UsuarioActual.Empresa.UsaContabilidad Or UsuarioActual.Empresa.UsaAC Then
InicializaValores()
CargaURLParametros()
BtnConsultar.Enabled = True
Else
Alert("La empresa no usa Contabilidad ni Armonización Contable", TipoMensaje.MsgError)
End If
End If
End Sub
#Region " INCIALIZA VALORES "
Private Sub InicializaValores()
DtDatos = Nothing
CargaTipoCuentas()
CargaSegmentosNegocio()
FechaInicio = DateSerial(Year(Now), Month(Now), 1)
FechaFin = Date.Now
If UsuarioActual.Empresa.UsaAC Then
TipoReporte = -1
Else
TipoReporte = 1
tdTipoReporte.Visible = True
tdTipoReporte2.Visible = True
End If
End Sub
Public Function WSCuentas() As String
Dim Str As New StringBuilder
Dim i As Integer = 0
Dim dt As DataTable = DTCuentas '.FiltraParametros("Afectable = 1")
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
i += 1
Str.AppendFormat("{{value:""{0}"",label:""{1}{3}""}}{2}", dr("Id"), dr("CtaCodigo").ToString.Replace("""", ""), If(i < dt.Rows.Count, ",", ""), If(dr("Afectable").ToString = "1", " *", ""))
Next
End If
Return Str.ToString
End Function
Private Sub CargaTipoCuentas()
Dim ObjTipoCuenta As New ClsContPAQi(UsuarioActual.Empresa)
Dim strGlobal As String = ""
If ObjTipoCuenta.GetCuentas(-1, "-1", -1) Then
Dim dr As DataRow = ObjTipoCuenta.DtResultados.FiltroPrimero("Codigo IN ('_GLOBAL')")
If dr IsNot Nothing Then strGlobal = dr.Item(0).ToString
DTCuentas = ObjTipoCuenta.DtResultados '.FiltraParametros("Afectable = 1")
DdlTipoCuentas.DataSource = ObjTipoCuenta.DtResultados.FiltraParametros("Codigo IN ('_ACTIVO', '_BPASIVO', '_CAPITAL', '_CUADRE', '_ESTADISTICAS', '_ORDEN', '_RACREEDOR', '_RDEUDOR', '_UTILIDAD')")
End If
ObjTipoCuenta.Dispose()
DdlTipoCuentas.DataBind()
'If strGlobal.Length > 0 Then DdlTipoCuentas.Items.Insert(0, New ListItem("Todas", strGlobal))
DdlTipoCuentas.Items.Insert(0, New ListItem("Todas las Cuentas", "1"))
DdlTipoCuentas.Items.Add(New ListItem("Algun específico", "-2"))
DdlTipoCuentas.SelectedIndex = 0
End Sub
Private Sub CargaSegmentosNegocio()
Dim ObjContpaq As New ClsContPAQi(UsuarioActual.Empresa)
Dim strGlobal As String = ""
If ObjContpaq.GetSegmentosNegocio(-1, "-1") Then
DdlSegmentoNegocio.DataSource = ObjContpaq.DtResultados
DdlSegmentoNegocio.DataBind()
End If
ObjContpaq.Dispose()
DdlSegmentoNegocio.Items.Insert(0, New ListItem("Todos", "-1"))
DdlSegmentoNegocio.SelectedValue = "-1"
End Sub
#End Region
#Region "CARGA DATOS"
Private Sub CargaURLParametros()
Dim ErrorParametros = True
If Request("ID") IsNot Nothing AndAlso IsNumeric(Request("ID")) AndAlso Request("ID").ToEntero > 0 Then
'If Request("FI") IsNot Nothing AndAlso Request("FI").ToString.Length = 10 AndAlso Request("FI").ToDate > "01/01/1000".ToDate Then
If Request("FF") IsNot Nothing AndAlso Request("FF").ToString.Length = 10 AndAlso Request("FF").ToDate > "01/01/1000".ToDate Then
IdCuenta = Request("ID").ToEntero
'FechaInicio = Request("FI").ToDate
FechaFin = Request("FF").ToDate
If Request("FI") IsNot Nothing AndAlso Request("FI").ToString.Length = 10 AndAlso Request("FI").ToDate > "01/01/1000".ToDate Then
FechaInicio = Request("FI").ToDate
Else
FechaInicio = DateSerial(Year(FechaFin), Month(FechaFin), 1)
End If
DdlTipoCuentas.SelectedValueExist("-2")
HdnCveCuenta.Value = IdCuenta.ToString
TxtCuenta.Text = DTCuentas.FiltroPrimeroValor("CtaCodigo", $"Id={Request("ID")}")
If Request("CM") IsNot Nothing AndAlso IsNumeric(Request("CM")) AndAlso Request("CM").ToEntero > 0 Then
DdlCuenta.SelectedValueExist(Request("CM").ToString)
End If
Segmentos = Request("Segmentos")
ErrorParametros = False
If Request("TP") IsNot Nothing AndAlso IsNumeric(Request("TP")) AndAlso Request("TP").ToEntero > 0 Then
TipoReporte = Request("TP").ToEntero
DdlTipoReporte.SelectedValue = TipoReporte.ToString
End If
If Request("IdSegNeg") IsNot Nothing AndAlso IsNumeric(Request("IdSegNeg")) AndAlso Request("IdSegNeg").ToEntero > 0 Then
IdSegNeg = Request("IdSegNeg").ToEntero
DdlSegmentoNegocio.SelectedValue = IdSegNeg.ToString
End If
End If
'End If
End If
UPFiltros.Update()
TxtFechaDel.Text = FechaInicio.ToShortDateString
TxtFechaAl.Text = FechaFin.ToShortDateString
If Not ErrorParametros Then
CargaDatos()
End If
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
FechaInicio = If(TxtFechaDel.Text = "" Or TxtFechaDel.Text = "__/__/____", Date.Now, TxtFechaDel.Text.ToDate)
FechaFin = If(TxtFechaAl.Text = "" Or TxtFechaAl.Text = "__/__/____", Date.Now, TxtFechaAl.Text.ToDate)
'IdCuenta = If(DdlTipoCuentas.SelectedValue.ToEntero = -2, HdnCveCuenta.Value.ToEntero, DdlTipoCuentas.SelectedValue.ToEntero)
CargaDatos()
End Sub
Private Sub CargaDatos()
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
'Dim DTCabeceras As New DataTable
TipoReporte = If(TipoReporte = -1, -1, DdlTipoReporte.SelectedValue.ToEntero)
If ObjConta.GetEstadoActividadesSegmentoDetalle(FechaInicio, FechaFin, IdCuenta, Segmentos) Then
DtDatos = ObjConta.DSResultados.Tables(1)
DTCabeceras = ObjConta.DSResultados.Tables(0)
Else
DtDatos = New DataTable
DTCabeceras = New DataTable
Alert("Ocurrio un error al cargar los datos del Anexo del Catálogo", TipoMensaje.MsgError)
End If
ObjConta.Dispose()
Dim IndexActual As Integer = 0
For Each Dr As DataRow In DTCabeceras.Rows
Dim IndexGV As Integer = 3 + IndexActual
GvDatos.Columns(IndexGV).Visible = True
CType(GvDatos.Columns(IndexGV), BoundField).DataField = Dr("id").ToString
GvDatos.Columns(IndexGV).HeaderText = Dr("Nombre").ToString
GvDatos.Columns(IndexGV).Visible = True
CType(GvDatos.Columns(IndexGV), BoundField).DataField = Dr("id").ToString
GvDatos.Columns(IndexGV).HeaderText = Dr("Nombre").ToString
IndexActual = IndexActual + 1
If IndexGV >= 200 Then
Exit For
End If
Next
CargaGrid()
End Sub
Private Sub CargaGrid()
GvDatos.DataSource = DtDatos
GvDatos.DataBind()
UpDatos.Update()
If DtDatos.Rows.Count > 0 Then
RegistraScript("Scroll();")
End If
End Sub
#End Region
#Region "GV ROW DATA BOUND"
Protected Sub GvIngresos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("IdCuenta").ToEntero = IdCuenta Then
e.Row.ControlStyle.Font.Bold = True
Else
e.Row.ControlStyle.Font.Bold = False
End If
Dim IndexActual As Integer = 0
For Each Dr As DataRow In DTCabeceras.Rows
Dim IndexGV As Integer = 3 + IndexActual
e.Row.Cells(IndexGV).Text = $"<a class='Texto' target='_blank' href='/Contabilidad/RepMovimientosAuxiliaresCatalogo.aspx?ID={e.Row.DBCampo("IdCuenta").ToEntero}&FI{TxtFechaDel.Text}&FF={TxtFechaAl.Text}&IdSegNeg={ Dr("id").ToString}'>{e.Row.Cells(IndexGV).Text }</a>"
IndexActual = IndexActual + 1
If IndexGV >= 200 Then
Exit For
End If
Next
End If
End Sub
#End Region
#Region " IMPRIMIR "
'Protected Sub LnkImprimir_Click(sender As Object, e As EventArgs) Handles LnkImprimir.Click
' If Not IsNothing(DtDatos) Then
' ImprimirReporte()
' Else
' Alert("Primero debe consultar el Anexo del Catálogo", TipoMensaje.MsgAdvertencia)
' End If
'End Sub
Protected Sub LnkExcel_Click(sender As Object, e As EventArgs) Handles LnkExcel.Click
'GvDatos.ExportToExcelG("RepAnexoCatalogoSegmento", "RepAnexoCatalogoSegmento", UsuarioActual)
GvDatos.ExportToExcelX("RepAnexoCatalogoSegmento")
End Sub
'Private Sub ImprimirReporte(Optional Formato As String = "PDF")
' Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
' 'ubicacion del rdlc
' Dim reportpath As String = "Contabilidad/Reportes/RepAnexoCatalogo.rdlc"
' 'nombre del reporte
' Dim fileName As String = "AnexoCatalogo"
' 'parametros a enviar al reporte
' Dim params As New List(Of ReportParameter)
' params.Add(New ReportParameter("IdCuenta", IdCuenta.ToString))
' params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa))
' params.Add(New ReportParameter("pImg", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
' End If
' params.Add(New ReportParameter("pFechaFin", FechaFin.ToString("dd/MM/yyyy")))
' ImprimirPDF(reportpath, DtDatos, params, fileName, Formato)
'End Sub
#End Region
End Class