Files
SIG/Bancos/RepSaldosDetalle.aspx.vb

370 lines
15 KiB
VB.net

Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class Bancos_RepSaldosDetalle
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Property FechaI As String
Get
FechaI = ViewState("FechaI").ToString
End Get
Set(value As String)
ViewState("FechaI") = value
End Set
End Property
Private Property FechaF As String
Get
FechaF = ViewState("FechaF").ToString
End Get
Set(value As String)
ViewState("FechaF") = value
End Set
End Property
Private Property Opcion As Integer
Get
Opcion = ViewState("Opcion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Opcion") = value
End Set
End Property
Private Property CveBanco As Integer
Get
CveBanco = ViewState("CveBanco").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveBanco") = value
End Set
End Property
Private Property CveCuenta As Integer
Get
CveCuenta = ViewState("CveCuenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuenta") = value
End Set
End Property
Private Property CveMoneda As Integer
Get
CveMoneda = ViewState("CveMoneda").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMoneda") = value
End Set
End Property
Private Property Cuenta As String
Get
Cuenta = ViewState("Cuenta").ToString
End Get
Set(value As String)
ViewState("Cuenta") = value
End Set
End Property
Private Property CLABE As String
Get
CLABE = ViewState("CLABE").ToString
End Get
Set(value As String)
ViewState("CLABE") = value
End Set
End Property
Private Property Banco As String
Get
Banco = ViewState("Banco").ToString
End Get
Set(value As String)
ViewState("Banco") = 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 Request("CveBanco") IsNot Nothing AndAlso Request("CveCuenta") IsNot Nothing Then
FechaI = If(Request("FechaI") IsNot Nothing, Request("FechaI").ToString, "-1")
FechaF = If(Request("FechaF") IsNot Nothing, Request("FechaF").ToString, "-1")
Opcion = IfNull(Request("Opcion"), "0").ToString.ToEntero
CveBanco = Request("CveBanco").ToEntero
CveCuenta = Request("CveCuenta").ToEntero
CveMoneda = IfNull(Request("CveMoneda"), "-1").ToString.ToEntero
CargaDatos(Request("CveBanco").ToEntero, Request("CveCuenta").ToEntero, IfNull(Request("CveMoneda"), "-1").ToString.ToEntero, FechaI, FechaF, Opcion)
' CargaDatosReporteConciliaciones(Request("CveCuenta").ToEntero, FechaI, FechaF)
Else
FechaI = ""
FechaF = ""
End If
End If
End Sub
Protected Sub GvCxC_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvS.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 1 Then
e.Row.Cells(0).Width = Unit.Pixel(50)
e.Row.Cells(1).Width = Unit.Pixel(70)
e.Row.Cells(2).Width = Unit.Pixel(80)
e.Row.Cells(3).Width = Unit.Pixel(250)
e.Row.Cells(4).Width = Unit.Pixel(250)
e.Row.Cells(5).Width = Unit.Pixel(80)
e.Row.Cells(6).Width = Unit.Pixel(100)
e.Row.Cells(7).Width = Unit.Pixel(100)
'e.Row.Cells(6).Width = Unit.Pixel(100)
End If
If e.Row.FCLiteral("LtlCargo").Text = "0.00" Then e.Row.FCLiteral("LtlCargo").Text = ""
If e.Row.FCLiteral("LtlAbono").Text = "0.00" Then e.Row.FCLiteral("LtlAbono").Text = ""
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(7).Font.Bold = True
e.Row.Cells(8).Font.Bold = True
e.Row.Cells(7).Text = HdnTotalCargo.Value.FormatoNumero
e.Row.Cells(8).Text = HdnTotalAbono.Value.FormatoNumero
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
End If
End Sub
Private Sub CargaDatos(CveBanco As Integer, CveCuenta As Integer, CveMoneda As Integer, FechaInicio As String, FechaFin As String, Opcion As Integer)
Dim Ban As New ClsBancos
If Ban.GetBancosSaldosDetalle(CveBanco, CveCuenta, CveMoneda, FechaInicio, FechaFin, Opcion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
GvS.DataSource = Ban.DtResultados
If Ban.DtResultados.Rows.Count > 0 Then
'Campos requeridos para reporte PDF
Dim dr As DataRow = Ban.DtResultados.Rows(0)
Cuenta = dr("NumCuenta").ToString
CLABE = dr("CLABE").ToString
Banco = dr("Banco").ToString
lbBancoNombre.Text = Banco
LblFechaI.Text = FechaInicio
LblFechaF.Text = FechaFin
If CveCuenta > 0 Then
LblCuenta.Text = dr("NumCuenta").ToString
LblSaldoInicial.Text = dr("SaldoInicial").ToString.ToDouble.FormatoNumero
HdnTotalCargo.Value = Ban.DtResultados.SUM("Cargo").ToString
HdnTotalAbono.Value = Ban.DtResultados.SUM("Abono").ToString
Else
GvS.Columns(0).Visible = True
Cuenta = ""
End If
End If
End If
Ban.Dispose()
GvS.DataBind()
End Sub
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
ImprimirReporte("Excel")
End Sub
#Region "P D F"
Private Sub LinkPDF_Click(sender As Object, e As EventArgs) Handles LinkPDF.Click
ImprimirReporte("PDF")
End Sub
Private Sub ImprimirReporte(formato As String)
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
'OBTENEMOS LOS DATOS
Dim dt As DataTable
Dim Ban As New ClsBancos
If Ban.GetBancosSaldosDetalle(CveBanco, CveCuenta, CveMoneda, FechaI, FechaF, Opcion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
dt = Ban.DtResultados
Else
dt = Nothing
End If
Dim NombreCuenta As String = String.Format("{0} - {1}", Banco, Cuenta)
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("RFC", UsuarioActual.Empresa.RFC))
params.Add(New ReportParameter("DireccionEmpresa", UsuarioActual.Empresa.Direccion))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToString()))
params.Add(New ReportParameter("FechaInicio", FechaI))
params.Add(New ReportParameter("FechaFin", FechaF))
params.Add(New ReportParameter("NombreCuenta", NombreCuenta))
params.Add(New ReportParameter("SaldoInicial", LblSaldoInicial.Text))
params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
ImprimirPDF("Empresas/Grales/Formatos/RepSaldosDetalle.rdlc", dt, params, "RepSaldosDetalle", Formato:=formato)
Ban.Dispose()
End Sub
#End Region
#Region " COMENTADO "
'Private Sub CargaDatosReporteConciliaciones(CveCuenta As Integer, FechaInicio As String, FechaFin As String)
' If CveCuenta < 0 Then Exit Sub
' Dim ObjBancos As New ClsBancos
' If ObjBancos.GetConciliacionesReporte(CveCuenta, FechaInicio, FechaFin, UsuarioActual.CveEmpresa) Then
' DtConciliaciones = ObjBancos.DtResultados
' ' GvRepConciliaciones.DataSource = DtConciliaciones
' Else
' DtConciliaciones = Nothing
' End If
' ObjBancos.Dispose()
' ' 'DatosGenerales
' ' If DtConciliaciones.Rows.Count > 0 Then
' ' LtTotalConciliaciones.Text = DtConciliaciones.Rows(0)("Total").ToString.FormatoNumero
' ' LtTotalNoConciliado.Text = DtConciliaciones.Rows(0)("NoConciliado").ToString.FormatoNumero
' ' LtTotalConciliado.Text = DtConciliaciones.Rows(0)("Conciliado").ToString.FormatoNumero
' ' End If
' ' 'Llena grid
' ' GvRepConciliaciones.DataBind()
' ' UpRepConciliaciones.Update()
'End Sub
'Protected Sub ImgExcel_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles ImgExcel.Click
' 'GvS.ExportToExcel("ReporteSaldos" & Now.ToShortDateString)
' 'GvRepConciliaciones.ExportToExcel("ReporteConciliacionBancaria" & Now.ToShortDateString)
' ExportExcel()
'End Sub
'Private Sub ExportExcel()
' 'If Not DtConciliaciones.Rows.Count > 0 Then
' ' Alert("No hay detalles para generar el reporte.")
' ' Exit Sub
' 'End If
' If Not File.Exists(String.Format("{0}Formatos\ReporteConciliaciones.xlsm", UsuarioActual.Empresa.Ruta)) Then
' Alert("El archivo base del documento no existe, por favor contacte al administrador.")
' Exit Sub
' End If
' Dim Excel As msExcel.Application = New msExcel.Application()
' Dim VB_Module As VBComponent = Nothing
' Excel.Visible = True
' Excel.ScreenUpdating = True
' Excel.DisplayAlerts = True
' Dim NombreArchivo = String.Format("Conciliacion-{0}-{1}", Cuenta, Date.Now.ToShortDateString.Replace("/", ""))
' Dim ArchivoBase As New System.IO.FileInfo(String.Format("{0}Formatos\ReporteConciliaciones.xlsm", UsuarioActual.Empresa.Ruta))
' ArchivoBase.CopyTo(String.Format("{0}Formatos\{1}.xlsm", UsuarioActual.Empresa.Ruta, NombreArchivo), True)
' Dim ArchivoTemp As New System.IO.FileInfo(String.Format("{0}Formatos\{1}.xlsm", UsuarioActual.Empresa.Ruta, NombreArchivo))
' Dim Libro As msExcel.Workbook = Excel.Workbooks.Open(ArchivoTemp.FullName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
' Libro.Activate()
' Dim Hoja As msExcel.Worksheet = CType(Libro.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
' Hoja.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetVisible
' Hoja.Activate()
' 'Cuenta
' Hoja.Range("B6:B6").Value = Cuenta
' Hoja.Range("F6:F6").Value = CLABE
' Hoja.Range("B7:B7").Value = Banco
' 'Fechas
' Hoja.Range("G2:G2").Value = FechaI.ToDate.ToString("MM/dd/yyyy")
' Hoja.Range("G4:G4").Value = FechaF.ToDate.ToString("MM/dd/yyyy")
' 'Totales
' Hoja.Range("G9:G9").Value = DtConciliaciones.Rows(0)("Conciliado").ToString.FormatoNumero
' Hoja.Range("G15:G15").Value = DtConciliaciones.Rows(0)("NoConciliado").ToString.FormatoNumero
' Hoja.Range("G18:G18").Value = DtConciliaciones.Rows(0)("Total").ToString.FormatoNumero
' VB_Module = CType(Libro.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule), VBComponent)
' VB_Module.CodeModule.AddFromString(GetMacro)
' Dim CeldaI As Integer = 13
' Dim CeldaF As Integer = 13
' 'Conceptos
' For Each Row As DataRow In DtConciliaciones.Rows
' Hoja.Range(String.Format("A{0}:A{0}", CeldaF)).Value = Row("FechaDocumento").ToString.ToDate.ToShortDateString
' Hoja.Range(String.Format("B{0}:B{0}", CeldaF)).Value = Row("IdPoliza").ToString
' Hoja.Range(String.Format("C{0}:C{0}", CeldaF)).Value = Row("PagueseA").ToString
' Hoja.Range(String.Format("G{0}:G{0}", CeldaF)).Value = Row("Importe").ToString.FormatoNumero
' If DtConciliaciones.Rows.Count > 1 AndAlso CeldaF - CeldaI < DtConciliaciones.Rows.Count - 1 Then
' CeldaF = CeldaF + 1
' Libro.Application.Run("AddRow", (CeldaF - 1).ToString, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing,
' missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
' Libro.Save()
' Libro.Application.DisplayAlerts = False
' Libro.Application.ScreenUpdating = False
' End If
' Next
' Dim EsVistaPrevia As Boolean = True
' 'Exportar PDF
' Dim pdfFileOut As String = String.Format("{0}PDF\ReporteConciliacion-{1}.pdf", UsuarioActual.Empresa.Ruta, NombreArchivo)
' Dim outputFileName As Object = pdfFileOut
' Dim fileFormat As msExcel.XlFixedFormatType = msExcel.XlFixedFormatType.xlTypePDF
' Hoja.ExportAsFixedFormat(fileFormat, outputFileName, missing, missing, missing, missing, missing, missing, missing)
' System.Runtime.InteropServices.Marshal.ReleaseComObject(Hoja)
' Hoja = Nothing
' Dim saveChanges As Object = msExcel.XlSaveAction.xlDoNotSaveChanges
' CType(Libro, msExcel._Workbook).Close(saveChanges, missing, missing)
' System.Runtime.InteropServices.Marshal.ReleaseComObject(Libro)
' Libro = Nothing
' Excel.Quit()
' System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
' Excel = Nothing
' GC.Collect()
' GC.WaitForPendingFinalizers()
' ArchivoTemp.Delete()
' Dim Descargas As New StringBuilder()
' Descargas.AppendFormat("<li><a class=""Texto"" href=""/Empresas/{0}/PDF/ReporteConciliacion-{1}.pdf?Id={2}"" target='_blank'>PDF</a></li>", UsuarioActual.CveEmpresa, NombreArchivo, now.Ticks)
' Alert(String.Format("<br />El reporte se generó correctamente.<br /><br /><br />Descargas:<ul>{0}</ul>", Descargas), TipoMensaje.MsgInformacion)
'End Sub
'Private Function GetMacro() As String
' Dim SB As New StringBuilder
' SB.Append(" Sub AddRow(Row As String) " & vbLf)
' SB.Append(" Rows(Row & "":"" & Row).Select " & vbLf)
' SB.Append(" Selection.Copy " & vbLf)
' SB.Append(" Selection.Insert Shift:=xlDown " & vbLf)
' SB.Append(" End Sub ")
' Return SB.ToString
'End Function
#End Region
End Class