163 lines
6.4 KiB
VB.net
163 lines
6.4 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports GemBox.Spreadsheet
|
|
Imports System.IO
|
|
|
|
Partial Class Acumuladores_RepEntradasUsados
|
|
Inherits ClsPaginas
|
|
|
|
Private DiasSemana(7) As String
|
|
Private Meses(12) As String
|
|
Private Cargado As Integer = 0
|
|
|
|
Private Property DatosEntradasUsados() As DataTable
|
|
Get
|
|
Return CType(ViewState("DatosEntradasUsados"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DatosEntradasUsados") = value
|
|
End Set
|
|
End Property
|
|
|
|
Protected Sub Page_Load() Handles Me.Load
|
|
If Not IsPostBack Then
|
|
txtFechaI.Text = Today.AddDays((-1) * (Today.Day - 1))
|
|
txtFechaF.Text = Today
|
|
CargarDatos()
|
|
CargarCombos()
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub CargarDatos()
|
|
DdlAlmacenes.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen = 22")
|
|
DdlAlmacenes.DataBind()
|
|
End Sub
|
|
|
|
Protected Sub CargarCombos()
|
|
Dim fecha As Date = Date.Now.AddMonths(-1)
|
|
Dim Años As New ListItem
|
|
Dim i As Integer
|
|
If Cargado = 0 Then
|
|
For i = Date.Now.Year.ToEntero To (fecha.Year.ToEntero - 5) Step -1
|
|
Años = New ListItem(i, i)
|
|
DdlAño.Items.Add(Años)
|
|
Next
|
|
End If
|
|
Cargado = 1
|
|
|
|
DdlAño.SelectedValue = fecha.Year.ToEntero
|
|
DdlMes.SelectedValue = fecha.Month.ToEntero
|
|
End Sub
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
Dim ObjAcum As New ClsAcumuladores
|
|
|
|
If ObjAcum.EntradasUsadosGet(UsuarioActual.CveEmpresa, DdlAlmacenes.SelectedValue.ToEntero, txtFechaI.Text, txtFechaF.Text) Then
|
|
GvAcum.DataSource = ObjAcum.DtResultados
|
|
DatosEntradasUsados = ObjAcum.DtResultados
|
|
|
|
End If
|
|
ObjAcum.Dispose()
|
|
GvAcum.DataBind()
|
|
|
|
End Sub
|
|
|
|
Protected Sub BtnImprimir_Click(sender As Object, e As EventArgs)
|
|
|
|
|
|
Dim Dia As String = {"lunes", "martes", "miércoles", "jueves", "viernes", "sábado", "domingo"}(If((Weekday(Today) - 2) = -1, 7, Weekday(Today) - 2))
|
|
Dim Mes As String = {"enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"}(Month(Today) - 1)
|
|
|
|
Dim FechaConFormato As String = String.Format("{0}, {1} de {2} de {3}", Dia, Day(Today), Mes, Year(Today))
|
|
Dim Direccion As String = String.Format("{0} {1}", UsuarioActual.Empresa.Direccion.ToString, UsuarioActual.Empresa.NoExt.ToString)
|
|
Dim params As New List(Of ReportParameter)
|
|
|
|
params.Add(New ReportParameter("Direccion", Direccion))
|
|
params.Add(New ReportParameter("FechaConFormato", Date.Now.ToString))
|
|
params.Add(New ReportParameter("FechaInicial", txtFechaI.Text))
|
|
params.Add(New ReportParameter("FechaFinal", txtFechaF.Text))
|
|
params.Add(New ReportParameter("Sucursal", "Sucursal"))
|
|
params.Add(New ReportParameter("Almacen", DdlAlmacenes.SelectedItem.ToString))
|
|
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
|
|
|
|
|
|
Dim rds As New ReportDataSource With {.Name = "DataSet1", .Value = DatosEntradasUsados}
|
|
|
|
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
|