reporte Sabana de Venta, generacion de los excel

This commit is contained in:
HECTOR RODRIGUEZ
2021-02-22 16:35:26 -07:00
parent c1876f3897
commit 1f93d82fa9
3 changed files with 210 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Imports GemBox.Spreadsheet
Imports System.IO
Partial Class Acumuladores_RepEntradasUsados
Inherits ClsPaginas
@@ -22,6 +24,9 @@ Partial Class Acumuladores_RepEntradasUsados
txtFechaI.Text = Today.AddDays((-1) * (Today.Day - 1))
txtFechaF.Text = Today
CargarDatos()
CargarCombos()
End If
End Sub
@@ -30,6 +35,18 @@ Partial Class Acumuladores_RepEntradasUsados
DdlAlmacenes.DataBind()
End Sub
Protected Sub CargarCombos()
Dim ObjAcum As New ClsAcumuladores
Dim fecha As Date = Date.Now.AddMonths(-1)
ObjAcum.GetAñosVentas(UsuarioActual.CveEmpresa)
DdlAño.DataSource = ObjAcum.DtResultados
DdlAño.DataBind()
DdlAño.SelectedValue = fecha.Year.ToEntero
ObjAcum.Dispose()
DdlMes.SelectedValue = fecha.Month.ToEntero
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
Dim ObjAcum As New ClsAcumuladores
@@ -63,5 +80,77 @@ Partial Class Acumuladores_RepEntradasUsados
ImprimirPDF(String.Format("Empresas/{0}/Formatos/RepEntradasUsados.rdlc", UsuarioActual.CveEmpresa), DatosEntradasUsados, params, "Reporte entrada usados", "PDF")
End Sub
Protected Sub BtnDescargaSabana_Click(sender As Object, e As EventArgs) Handles BtnDescargaSabana.Click
RegistraScript(String.Format("$('#{0}').modal('show');", "DivModalSabana"))
'RegistraScript("$('#DModalEditarFecha').modal('hide')")
End Sub
Protected Sub BtnDescargarSabana_Click(sender As Object, e As EventArgs) Handles BtnDescargarSabana.Click
Dim Retorno As New IO.MemoryStream()
Dim ObjAcum As New ClsAcumuladores
Dim Mes As String = DdlMes.SelectedValue.ToString
Dim Año As String = DdlAño.SelectedValue.ToString
Dim Fecha As Date = (String.Format("01/{0}/{1}", Mes, Año)).ToDate
Dim dt As DataTable
Dim NombreArchivo As String
Try
If DdlOpcion.SelectedValue = 1 Then
ObjAcum.GetSabanaVenta(Fecha, 1, UsuarioActual.CveEmpresa)
ElseIf DdlOpcion.SelectedValue = 2 Then
ObjAcum.GetSabanaVenta(Fecha, 2, UsuarioActual.CveEmpresa)
End If
dt = ObjAcum.DtResultados
If dt IsNot Nothing And dt.Rows.Count > 0 Then
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
Dim workbook As New ExcelFile()
Dim worksheet = workbook.Worksheets.Add("Sabana de ventas")
worksheet.InsertDataTable(dt, New InsertDataTableOptions() With
{
.ColumnHeaders = True,
.StartRow = 0,
.StartColumn = 0
})
worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255))
worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255)
Dim columnCount = worksheet.CalculateMaxUsedColumns()
For i = 0 To columnCount
worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1))
Next
Año = Strings.Right(Año, 2)
If Mes.ToEntero < 10 Then
Mes = String.Format("0{0}", Mes)
End If
If DdlOpcion.SelectedValue = 1 Then
NombreArchivo = String.Format("700415-{0}{1}-GE", Mes, Año)
workbook.Save(Response, $"{NombreArchivo}.xlsx", SaveOptions.XlsxDefault)
ElseIf DdlOpcion.SelectedValue = 2 Then
NombreArchivo = String.Format("700415-{0}{1}-CS", Mes, Año)
workbook.Save(Response, $"{NombreArchivo}.xlsx", SaveOptions.XlsxDefault)
End If
End If
Catch ex As Exception
GuardaLog(String.Format("Ocurrio un error al generar el excel {0}", ex.Message))
End Try
ObjAcum.Dispose()
RegistraScript("$('#DModalEditarFecha').modal('hide')")
End Sub
End Class