507 lines
24 KiB
VB.net
507 lines
24 KiB
VB.net
Imports System.Data
|
|
Imports System.IO
|
|
Imports Extensiones
|
|
Imports GemBox.Spreadsheet
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Partial Class Inventarios_KardexAlmacen
|
|
Inherits ClsPaginas
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
'TxtFechaI.Text = Now.AddMonths(-1).ToShortDateString
|
|
TxtFechaF.Text = Now.ToShortDateString
|
|
CargaCombos()
|
|
ddlAlmacen.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
LblOrden.Visible = False
|
|
DdlOrden.Visible = False
|
|
LblMarca.Visible = False
|
|
DdlMarca.Visible = False
|
|
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
|
|
LblOrden.Visible = True
|
|
DdlOrden.Visible = True
|
|
LblMarca.Visible = True
|
|
DdlMarca.Visible = True
|
|
DdlOrden.SelectedValue = 2
|
|
End If
|
|
If IfNull(Request("CvePS"), "-1").ToString.ToEntero > 0 Then CargarKardex(Request("CvePS").ToString.ToEntero)
|
|
ddlProducto2.SelectedValue = If(Request("CvePS") IsNot Nothing, Request("CvePS").ToString, "-1")
|
|
End If
|
|
End Sub
|
|
Private Sub CargaCombos()
|
|
|
|
CargaFuncionalidad105()
|
|
CargaPS()
|
|
|
|
Using ObjPS As New ClsProductosServicios
|
|
If ObjPS.GetMarcas(UsuarioActual.CveEmpresa) Then
|
|
DdlMarca.DataSource = ObjPS.DtResultados.Copy().FiltraParametros("", Orderby:="Marca")
|
|
End If
|
|
End Using
|
|
DdlMarca.DataBind()
|
|
DdlMarca.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
ddlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1)
|
|
ddlAlmacen.DataBind()
|
|
|
|
Dim ObjInv As New ClsInventarios()
|
|
If ObjInv.GetTiposAlmacenes() Then
|
|
DdlTipoAlmacen.DataSource = ObjInv.DtResultados
|
|
End If
|
|
ObjInv.Dispose()
|
|
DdlTipoAlmacen.DataBind()
|
|
|
|
DdlTipoAlmacen.SelectedValueExist(1)
|
|
|
|
If IfNull(Request("CveAlmacen"), "-1").ToString.ToEntero > 0 Then ddlAlmacen.SelectedValue = Request("CveAlmacen").ToString
|
|
CargaClasificaciones()
|
|
End Sub
|
|
|
|
Private Sub CargaClasificaciones()
|
|
Dim CveClasificacion = If(Request("CveClasificacion") IsNot Nothing, Request("CveClasificacion").ToString, "-1")
|
|
|
|
Dim ObjClasificaciones As New ClsClasificaciones
|
|
If UsuarioActual.Empresa.UsaAC Then
|
|
If ObjClasificaciones.GetClasificacionesExistencias(UsuarioActual.CveEmpresa) Then
|
|
DdlClasificacion.DataSource = ObjClasificaciones.DtResultados
|
|
DdlClasificacion.DataBind()
|
|
End If
|
|
Else
|
|
If ObjClasificaciones.GetClasificacionesExistencias(UsuarioActual.CveEmpresa) Then
|
|
DdlClasificacion.DataSource = ObjClasificaciones.DtResultados
|
|
DdlClasificacion.DataBind()
|
|
End If
|
|
End If
|
|
ObjClasificaciones.Dispose()
|
|
|
|
DdlClasificacion.DataBind()
|
|
DdlClasificacion.SelectedValueExist(CveClasificacion)
|
|
|
|
End Sub
|
|
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged
|
|
CargaPS()
|
|
End Sub
|
|
Private Sub CargaPS()
|
|
|
|
If Not ddlProducto2.UsaWebService Then
|
|
'Dim Filtro = If(DdlClasificacion.SelectedValue >= 0, String.Format("CveClasificacion={0}", DdlClasificacion.SelectedValue), "")
|
|
ddlProducto2.ddl.Items.Clear()
|
|
ddlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltraParametros($"CveTipoPS=2", "PSCodigo")
|
|
ddlProducto2.DataBind()
|
|
ddlProducto2.ddl.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
|
|
End If
|
|
End Sub
|
|
Private Sub CargaFuncionalidad105()
|
|
ddlProducto2.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
|
|
DdlProveedor.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
|
|
|
|
If ddlProducto2.UsaWebService Then
|
|
ddlProducto2.ddlWS.Attributes.Add("data-Estatus", "-1")
|
|
ddlProducto2.ddlWS.Attributes.Add("data-pagina", "Inventarios")
|
|
ddlProducto2.ddlWS.Attributes.Add("data-idClasificacion", DdlClasificacion.ClientID)
|
|
DdlClasificacion.AutoPostBack = False
|
|
|
|
DdlProveedor.Attributes.Add("data-metodo", "getproveedores")
|
|
Else
|
|
ddlProducto2.ddl.Items.Add(New ListItem("Seleccione", "-1"))
|
|
ddlProducto2.ddl.Items.Add(New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2"))
|
|
|
|
DdlProveedor.ddl.Items.Add(New ListItem("Seleccione", "-1"))
|
|
DdlProveedor.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa)
|
|
DdlProveedor.DataBind()
|
|
End If
|
|
|
|
End Sub
|
|
Protected Sub ddlProducto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProducto2.selectedindexchange
|
|
|
|
DdlUnidadMedida.Items.Clear()
|
|
DdlUnidadMedida.DataSource = GlobalDTProductosServiciosEquivalencias(ddlProducto2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa)
|
|
DdlUnidadMedida.DataBind()
|
|
DdlUnidadMedida.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
End Sub
|
|
Protected Sub btConsultar_Click(sender As Object, e As EventArgs) Handles btConsultar.Click
|
|
Dim CveProducto As Integer = ddlProducto2.SelectedValue.ToEntero
|
|
CargarKardex(CveProducto)
|
|
'If CveProducto > 0 Then
|
|
|
|
'Else
|
|
' Alert("Seleccione un producto.", TipoMensaje.MsgAdvertencia)
|
|
'End If
|
|
|
|
End Sub
|
|
Private Sub CargarKardex(CvePS As Integer)
|
|
Dim dt As DataTable = Nothing
|
|
Dim ObjMovimientos As New ClsInventarios
|
|
Dim FechaI As String = "-1" ' If(TxtFechaI.Text <> "" AndAlso TxtFechaI.Text <> "__/__/____", TxtFechaI.Text, "-1")
|
|
' Dim FechaF As String = If(TxtFechaF.Text <> "" AndAlso TxtFechaF.Text <> "__/__/____", TxtFechaF.Text, "-1")
|
|
Dim FechaF As Date = TxtFechaF.Text.ToDate
|
|
Dim CveAlmacenes As String = ddlAlmacen.GetSelectedValues()
|
|
Dim CveProveedorCompra As Integer = If(DdlProveedor.SelectedValue.ToEntero > 0, DdlProveedor.SelectedValue.ToEntero, -1)
|
|
Dim Marcas As String = If(DdlMarca.GetSelectedValuesM = "", "-1", DdlMarca.GetSelectedValuesM)
|
|
Dim dtMovs As DataTable = Nothing
|
|
|
|
If chkAgruparSubProyecto.Checked Then
|
|
If ObjMovimientos.GetKardexAlmacenHorizontalAgrupado(CvePS, FechaF, -1, DdlUnidadMedida.SelectedValue.ToEntero, CveProveedorCompra, DdlTipoAlmacen.SelectedValue.ToEntero(), DdlIncluyeTransitorios.SelectedValue.ToEntero(), DdlClasificacion.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CondicionExistencias:=DdlExistencia.SelectedValue, Orden:=DdlOrden.SelectedValue.ToEntero(), Marcas:=Marcas, IncluyeProyectado:=DdlProyeccionFiltro.SelectedValue.ToEntero, CveAlmacenes:=CveAlmacenes) Then
|
|
If ObjMovimientos.DtResultados IsNot Nothing AndAlso ObjMovimientos.DtResultados.Rows.Count > 0 Then
|
|
dt = ObjMovimientos.DtResultados
|
|
End If
|
|
Else
|
|
ObjMovimientos.Dispose()
|
|
Alert("Ocurrió un error al consultar el Kardex.", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
Else
|
|
If ObjMovimientos.GetKardexAlmacenHorizontal(CvePS, FechaF, -1, DdlUnidadMedida.SelectedValue.ToEntero, CveProveedorCompra, DdlTipoAlmacen.SelectedValue.ToEntero(), DdlIncluyeTransitorios.SelectedValue.ToEntero(), DdlClasificacion.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CondicionExistencias:=DdlExistencia.SelectedValue, Orden:=DdlOrden.SelectedValue.ToEntero(), Marcas:=Marcas, IncluyeProyectado:=DdlProyeccionFiltro.SelectedValue.ToEntero, CveAlmacenes:=CveAlmacenes) Then
|
|
If ObjMovimientos.DtResultados IsNot Nothing AndAlso ObjMovimientos.DtResultados.Rows.Count > 0 Then
|
|
dt = ObjMovimientos.DtResultados
|
|
End If
|
|
Else
|
|
ObjMovimientos.Dispose()
|
|
Alert("Ocurrió un error al consultar el Kardex.", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
|
|
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
Dim ListaBorrar As New List(Of DataColumn)
|
|
For index = 3 To dt.Columns.Count - 1
|
|
Dim TotColumna As Double = 0
|
|
For Each Dr As DataRow In dt.Rows
|
|
TotColumna += Dr.Item(index).ToString.ToDouble
|
|
Next
|
|
'If Not TotColumna > 0 Then
|
|
' ListaBorrar.Add(dt.Columns(index))
|
|
'End If
|
|
Next
|
|
For Each item As DataColumn In ListaBorrar
|
|
dt.Columns().Remove(item)
|
|
Next
|
|
dt.AcceptChanges()
|
|
GvDatos.DataSource = dt
|
|
GvDatos.DataBind()
|
|
Else
|
|
Alert("La búsqueda no contiene resultados.", TipoMensaje.MsgAdvertencia)
|
|
GvDatos.Columns.Clear()
|
|
dt = Nothing
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
For index = 4 To GvDatos.Rows(0).Cells.Count - 1
|
|
GvDatos.HeaderRow.Cells(index).Text = GvDatos.HeaderRow.Cells(index).Text.Split("|")(0)
|
|
Next
|
|
ObjMovimientos.Dispose()
|
|
End Sub
|
|
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
'Dim Liga As String = String.Format($"/Inventarios/Kardex.aspx?CvePS={ddlProducto2.SelectedValue.ToEntero}&CveAlmacen={e.Row.DataKey("CveAlmacen")}&CveUM={DdlUnidadMedida.SelectedValue.ToEntero}&FechaI={TxtFechaI.Text}&FechaF={TxtFechaF.Text}")
|
|
'e.Row.FCHyperLink("HplAlmacen").NavigateUrl = Liga
|
|
|
|
If e.Row.RowIndex = 0 Then
|
|
e.Row.CssClass = "Totales"
|
|
End If
|
|
|
|
e.Row.HorizontalAlign = HorizontalAlign.Right
|
|
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
|
|
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left
|
|
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Left
|
|
Dim Index As Integer = 0
|
|
|
|
For Each Cells As TableCell In e.Row.Cells
|
|
Dim Celda As String = Cells.Text
|
|
If IsNumeric(Celda) Then
|
|
Dim CveAlmacen2 As Integer = -1
|
|
If Index >= 5 Then
|
|
Dim Array = GvDatos.HeaderRow.Cells(Index).Text.Split("|")
|
|
If Array.Length > 1 Then
|
|
CveAlmacen2 = Array(1)
|
|
End If
|
|
End If
|
|
|
|
If Celda.ToDouble = 0 Then
|
|
Cells.Text = ""
|
|
Else
|
|
Dim ce = DirectCast(Cells, System.Web.UI.WebControls.DataControlFieldCell)
|
|
|
|
If ce.ContainingField.HeaderText = "CP" Then
|
|
Cells.Text = Cells.Text.FormatoNumero(2)
|
|
ElseIf ce.ContainingField.HeaderText = "Valor" Then
|
|
Cells.Text = Cells.Text.FormatoNumero(2)
|
|
'ElseIf ce.ContainingField.HeaderText = "Total" Then
|
|
' Cells.Text = Cells.Text.FormatoNumero(2)
|
|
Else
|
|
Cells.Text = String.Format("{0:#,###.##}", Cells.Text.ToDecimal)
|
|
End If
|
|
End If
|
|
e.Row.Cells(e.Row.Cells.GetCellIndex(Cells)).Width = Unit.Pixel(80)
|
|
'Dim Liga2 As String = String.Format($"/Inventarios/Kardex.aspx?CvePS={ddlProducto2.SelectedValue.ToEntero}&CveAlmacen={CveAlmacen2}&CveUM={DdlUnidadMedida.SelectedValue.ToEntero}&FechaI={TxtFechaI.Text}&FechaF={TxtFechaF.Text}")
|
|
'Cells.Text = String.Format("<a href=""{1}"">{0}</a>", Celda.FormatoNumero(), Liga2)
|
|
End If
|
|
Index = Index + 1
|
|
Next
|
|
|
|
End If
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub GvDatos_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowCreated
|
|
'Escondo CvePS y CveAlmacén (Se generan por autogeneratecolumns por eso se borran por aqui).
|
|
' e.Row.Cells(0).Width = New Unit("200px")
|
|
e.Row.Cells(2).Visible = False
|
|
e.Row.Cells(3).Visible = False
|
|
If e.Row.RowType = DataControlRowType.Header Then
|
|
'e.Row.Cells(6).ToolTip = "Costo"
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click
|
|
|
|
Imprimir("Excel")
|
|
End Sub
|
|
Private Sub Imprimir(Optional reporte As String = "PDF")
|
|
If GvDatos.Rows.Count > 0 Then
|
|
Dim StrFiltro As New StringBuilder
|
|
If DdlProveedor.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat("Proveedor: {0},", DdlProveedor.SelectedText)
|
|
If ddlProducto2.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat(" Producto/Servicio: {0},", ddlProducto2.SelectedText)
|
|
If TxtFechaF.Text <> "" Then StrFiltro.AppendFormat(" Fecha Fin: {0}", TxtFechaF.Text)
|
|
ExportToExcelG(GvDatos, "ExistenciasHorizontal.xlsx", "Existencias Almacen", UsuarioActual, StrFiltro.ToString, 100, 200)
|
|
Else
|
|
Alert("Debe consultar para generar un excel", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub ExportToExcelG(Gv As GridView, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
|
Dim sw As New StringWriter()
|
|
Dim htw As New HtmlTextWriter(sw)
|
|
Gv.RenderControl(htw)
|
|
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("ESWN-4QFD-26JF-1SZ8")
|
|
|
|
Dim excel As GemBox.Spreadsheet.ExcelFile
|
|
Dim options = GemBox.Spreadsheet.LoadOptions.HtmlDefault
|
|
Using htmlStream = New MemoryStream(options.Encoding.GetBytes(sw.ToString()))
|
|
excel = GemBox.Spreadsheet.ExcelFile.Load(htmlStream, options)
|
|
If Usuario IsNot Nothing Then
|
|
Dim TotalRowHeader As Integer = 8
|
|
Dim TotalRowFooter As Integer = 2
|
|
|
|
Dim worksheet = excel.Worksheets(0)
|
|
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
|
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
|
celdasConTexto.Style.Font.Name = "Calibri Light"
|
|
|
|
Dim RangoNombreEmpresa = worksheet.Cells.GetSubrangeAbsolute(1, celdasConTexto.FirstColumnIndex, 1, celdasConTexto.LastColumnIndex)
|
|
RangoNombreEmpresa.Merged = True
|
|
RangoNombreEmpresa.Value = Usuario.Empresa.Empresa
|
|
RangoNombreEmpresa.Style.Font.Size = 18 * 20
|
|
RangoNombreEmpresa.Style.Font.Name = "Calibri Light"
|
|
RangoNombreEmpresa.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoNombreEmpresa.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
Dim RangoFiltros = worksheet.Cells.GetSubrangeAbsolute(6, celdasConTexto.FirstColumnIndex, 6, celdasConTexto.LastColumnIndex)
|
|
RangoFiltros.Merged = True
|
|
RangoFiltros.Value = Filtros
|
|
RangoFiltros.Style.Font.Size = 15 * 20
|
|
RangoFiltros.Style.Font.Name = "Calibri Light"
|
|
RangoFiltros.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Left
|
|
RangoFiltros.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
Dim RangoTitulo = worksheet.Cells.GetSubrangeAbsolute(3, celdasConTexto.FirstColumnIndex, 3, celdasConTexto.LastColumnIndex)
|
|
RangoTitulo.Merged = True
|
|
RangoTitulo.Value = Titulo
|
|
RangoTitulo.Style.Font.Size = 20 * 20
|
|
RangoTitulo.Style.Font.Name = "Calibri Light"
|
|
RangoTitulo.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoTitulo.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
For i = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
|
|
worksheet.Rows(8).Cells(i).Style.Font.Size = 12 * 20
|
|
worksheet.Rows(8).Cells(i).Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
worksheet.Rows(8).Cells(i).Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
worksheet.Rows(8).Cells(i).Style.FillPattern.SetPattern(GemBox.Spreadsheet.FillPatternStyle.Solid, GemBox.Spreadsheet.SpreadsheetColor.FromArgb(75, 119, 190), GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255))
|
|
worksheet.Rows(8).Cells(i).Style.Font.Color = GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255)
|
|
If i > 0 Then
|
|
Try
|
|
worksheet.Columns(i).AutoFit(1)
|
|
Catch ex As Exception
|
|
End Try
|
|
End If
|
|
Next
|
|
|
|
Dim IndexEndTable As Integer = Gv.Rows.Count + TotalRowHeader + TotalRowFooter
|
|
|
|
worksheet.Rows(IndexEndTable).Cells(2).Value = "Usuario Imprimió"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(2).Value = Usuario.Nombre
|
|
|
|
worksheet.Rows(IndexEndTable).Cells(6).Value = "Fecha Impresión"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(6).Value = DateTime.Now.ToString("dd/MM/yyyy")
|
|
|
|
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", Usuario.Empresa.Ruta))
|
|
|
|
If Imagen.Exists Then
|
|
Dim Ruta As String = String.Format("{0}/Logo.png", Usuario.Empresa.Ruta)
|
|
Using sr As New StreamReader(Ruta)
|
|
Dim ms As New MemoryStream()
|
|
sr.BaseStream.CopyTo(ms)
|
|
worksheet.Pictures.Add(ms, ExcelPictureFormat.Png, "A1", AnchoImagen, AlturaImagen, LengthUnit.Pixel)
|
|
End Using
|
|
End If
|
|
End If
|
|
|
|
End Using
|
|
htw.Dispose()
|
|
|
|
excel.Save(HttpContext.Current.Response, $"{NombreArchivoXLSx}.xlsx")
|
|
|
|
End Sub
|
|
|
|
Protected Sub LnkProyectado_Click(sender As Object, e As EventArgs)
|
|
RegistraScript(String.Format("$('#{0}').modal();", "DivProyeccion"))
|
|
End Sub
|
|
|
|
Protected Sub BtnDescargarFormato_Click(sender As Object, e As EventArgs)
|
|
Dim Directorio As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\Formatos\KardexProyeccion.xlsx"
|
|
|
|
Dim Archivo As New IO.FileInfo(Directorio)
|
|
If Archivo.Exists Then
|
|
Response.Clear()
|
|
Response.ClearHeaders()
|
|
Response.ClearContent()
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name)
|
|
Response.AddHeader("Content-Length", Archivo.Length.ToString())
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
Response.Flush()
|
|
Response.TransmitFile(Archivo.FullName)
|
|
Response.End()
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub BtnAgregarProyeccion_Click(sender As Object, e As EventArgs)
|
|
If TxtProyeccionExcel.getfiles().Archivos.Count > 0 Then
|
|
Dim file As Archivo = TxtProyeccionExcel.getfiles().Archivos(0)
|
|
Dim Directorio As String = Server.MapPath("~") & file.patch
|
|
Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
|
|
CargarArchivo(Directorio, file.filename, Tipo)
|
|
Else
|
|
Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String)
|
|
Dim dt As New DataTable
|
|
dt = ReadExcelFile(Ruta + FileName, True)
|
|
If Not dt.Columns(0).ColumnName = "Código" Then
|
|
Alert("La primera columna del archivo debe ser 'Código'", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
If Not dt.Columns(1).ColumnName = "Cantidad" Then
|
|
Alert("La primera columna del archivo debe ser 'Cantidad'", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
AgregarProyeccion(dt)
|
|
End Sub
|
|
|
|
Private Sub AgregarProyeccion(dt As DataTable)
|
|
Dim TieneError As Boolean = False
|
|
Dim StrCodigo As New StringBuilder
|
|
Dim ObjInventarios As New ClsInventarios
|
|
ObjInventarios.IniciaTransacSQL()
|
|
|
|
If ObjInventarios.DeleteMovimientosProyectados(RblProyeccionOpcion.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
Dim DtProductosEmpresas As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
For Each dtRow As DataRow In dt.Rows
|
|
Dim Codigo As String = dtRow("Código").ToString
|
|
|
|
If Codigo <> "" Then
|
|
Dim CvePS As Integer = DtProductosEmpresas.FiltroPrimeroValor("CvePS", String.Format("Codigo = '{0}'", Codigo)).ToEntero
|
|
Dim Cantidad As Decimal = dtRow("Cantidad").ToString.ToDecimal
|
|
If CvePS <= 0 Then
|
|
TieneError = True
|
|
StrCodigo.AppendFormat(" {0}<br/>", Codigo)
|
|
Exit For
|
|
ElseIf Not ObjInventarios.AddMovimientosProyectados(CvePS, Cantidad, RblProyeccionOpcion.SelectedValue.ToEntero()) Then
|
|
TieneError = True
|
|
StrCodigo.Append("Ocurrio un error al registrar")
|
|
Exit For
|
|
End If
|
|
End If
|
|
|
|
Next
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
If TieneError Then
|
|
Alert("Ocurrio un error al registrar el Código no encontrado: " & StrCodigo.ToString, TipoMensaje.MsgError)
|
|
ObjInventarios.RollBack()
|
|
Else
|
|
ObjInventarios.Commit()
|
|
Alert("Se ha agregado la proyección de productos correctamente")
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivProyeccion"))
|
|
|
|
End Sub
|
|
|
|
Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
|
Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath)
|
|
|
|
Dim unnamed As Integer = 0
|
|
Dim cols As Integer
|
|
Dim columns As String()
|
|
Dim curRow As Integer = 0
|
|
Dim curCol As Integer = 0
|
|
Dim dataTable As DataTable = New DataTable()
|
|
Dim worksheet As ExcelWorksheet = excelFile.Worksheets(0)
|
|
|
|
For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1
|
|
|
|
If firstRowHasHeaders Then
|
|
|
|
If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then
|
|
dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString().Trim)
|
|
Else
|
|
dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed)))
|
|
End If
|
|
|
|
curRow = 1
|
|
Else
|
|
dataTable.Columns.Add("Column " & (cols + 1))
|
|
End If
|
|
|
|
Next
|
|
|
|
While curRow < worksheet.Rows.Count
|
|
|
|
columns = New String(cols - 1) {}
|
|
|
|
For curCol = 0 To cols - 1
|
|
|
|
If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then
|
|
columns(curCol) = ""
|
|
Else
|
|
columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString()
|
|
End If
|
|
|
|
Next
|
|
|
|
dataTable.Rows.Add(columns)
|
|
curRow += 1
|
|
|
|
End While
|
|
|
|
Return dataTable
|
|
|
|
End Function
|
|
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
|
|
End Sub
|
|
End Class
|