Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class Inventarios_RepAnomalias Inherits ClsPaginas #Region "Propiedades" Public Property CveInventarioFisico As Integer Get Return CType(ViewState("CveInventarioFisico"), Integer) End Get Set(value As Integer) ViewState("CveInventarioFisico") = value End Set End Property Public Property CveAlmacen As Integer Get Return CType(ViewState("CveAlmacen"), Integer) End Get Set(value As Integer) ViewState("CveAlmacen") = value End Set End Property Public Property CveSubProyecto As Integer Get Return CType(ViewState("CveSubProyecto"), Integer) End Get Set(value As Integer) ViewState("CveSubProyecto") = value End Set End Property Public Property EsAvance As Boolean Get Return CType(ViewState("EsAvance"), Boolean) End Get Set(value As Boolean) ViewState("EsAvance") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then CveInventarioFisico = If(Request("CveInventarioFisico") IsNot Nothing AndAlso Request("CveInventarioFisico").ToEntero() > 0, Request("CveInventarioFisico").ToEntero(), -1).ToString EsAvance = If(Request("EsAvance") IsNot Nothing, CBool(Request("EsAvance").ToEntero), False) If CveInventarioFisico > 0 Then CargaDatos(CveInventarioFisico) End If End If End Sub #Region " CARGA DATOS " Private Sub CargaDatos(CveInventarioFisico As Integer) Dim Inventario As New ClsInventarios Dim dt As DataTable = Nothing If Inventario.GetInventarioFisico(CveInventarioFisico, UsuarioActual.CveEmpresa, -1, -1) Then lbTitulo.Text = Inventario.InventarioFisico lbObservaciones.Text = Inventario.Observaciones lbSubProyecto.Text = Inventario.SubProyectoInventario lbEstatus.Text = Inventario.Estatus lbFechaI.Text = Inventario.FechaI lbFechaF.Text = Inventario.FechaF CveSubProyecto = Inventario.CveSubProyectoInventario If Inventario.Estatus = "Finalizado" Then btnFin.Visible = False End If If EsAvance Then If Inventario.GetInventarioFisicoResultadosAvance(CveInventarioFisico, UsuarioActual.CveEmpresa) Then dt = Inventario.DtResultados End If Else If Inventario.GetInventarioFisicoResultados(CveInventarioFisico, UsuarioActual.CveEmpresa) Then dt = Inventario.DtResultados End If End If If Inventario.GetInventarioFisicoDetallesAlmacen(CveInventarioFisico, UsuarioActual.CveEmpresa) Then Dim dta As DataTable = Inventario.DtResultados Dim str As New StringBuilder If dta IsNot Nothing AndAlso dta.Rows.Count > 0 Then For Each dr As DataRow In dta.Rows str.AppendFormat("{0},", dr("almacen")) Next End If LblAlmacenes.Text = str.ToString End If If Inventario.GetInventarioFisicoDetallesClasificacion(CveInventarioFisico, UsuarioActual.CveEmpresa) Then Dim dta As DataTable = Inventario.DtResultados Dim str As New StringBuilder If dta IsNot Nothing AndAlso dta.Rows.Count > 0 Then For Each dr As DataRow In dta.FiltraParametros("Incluye = 1").Rows str.AppendFormat("{0},", dr("Clasificacion")) Next LblClasif.Text = str.ToString str.Clear() For Each dr As DataRow In dta.FiltraParametros("Incluye = 0").Rows str.AppendFormat("{0},", dr("Clasificacion")) Next LblClasificacionesExcluidas.Text = str.ToString End If End If If Inventario.GetInventarioFisicoDetallesProductosServicios(CveInventarioFisico, UsuarioActual.CveEmpresa) Then Dim dta As DataTable = Inventario.DtResultados Dim str As New StringBuilder If dta IsNot Nothing AndAlso dta.Rows.Count > 0 Then For Each dr As DataRow In dta.FiltraParametros("Incluye = 1").Rows str.AppendFormat("{0},", dr("CodigoPS")) Next LblProductos.Text = If(str.ToString <> "", str.ToString, "Todos") str.Clear() For Each dr As DataRow In dta.FiltraParametros("Incluye = 0").Rows str.AppendFormat("{0},", dr("CodigoPS")) Next LblProductosExcluidos.Text = str.ToString End If End If If Inventario.GetInventarioFisicoDetallesProveedores(CveInventarioFisico, UsuarioActual.CveEmpresa) Then Dim dta As DataTable = Inventario.DtResultados Dim str As New StringBuilder If dta IsNot Nothing AndAlso dt.Rows.Count > 0 Then For Each dr As DataRow In dta.FiltraParametros("Incluye = 1").Rows str.AppendFormat("{0},", dr("RazonSocial")) Next LblProveedores.Text = str.ToString str.Clear() End If End If End If Inventario.Dispose() If Not String.IsNullOrWhiteSpace(UsuarioActual.Empresa.Funcionalidad(147)) Then GvS.Columns(7).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) If Not String.IsNullOrWhiteSpace(UsuarioActual.Empresa.Funcionalidad(147)) Then GvF.Columns(7).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) GvS.DataSource = dt.FiltraParametros("Diferencia < 0") Dim DtS As DataTable = dt.FiltraParametros("Diferencia < 0") GvS.DataBind() BanderaSerieLoteCad(GvS, DtS) GvF.DataSource = dt.FiltraParametros("Diferencia > 0") Dim DtF As DataTable = dt.FiltraParametros("Diferencia > 0") GvF.DataBind() BanderaSerieLoteCad(GvF, DtF) Dim Script = "" If (GvF.Rows.Count > 0) Then GvF.UseAccessibleHeader = True GvF.HeaderRow.TableSection = TableRowSection.TableHeader Script = "OrdenarGVF();" divRegistradosFaltan.Visible = True LtlTotalRegistrosFaltan.Text = GvF.Rows.Count.ToString End If If (GvS.Rows.Count > 0) Then GvS.UseAccessibleHeader = True GvS.HeaderRow.TableSection = TableRowSection.TableHeader Script += "OrdenarGVS();" divRegistradosSobran.Visible = True LtlTotalRegistrosSobran.Text = GvS.Rows.Count.ToString End If PSIguales() RegistraScript(Script) UPAnomalias.Update() UpdateGvS.Update() UPDatos.Update() End Sub #End Region #Region " FINALIZAR " Protected Sub btnFin_Click(sender As Object, e As EventArgs) Handles btnFin.Click Dim Inventarios As New ClsInventarios Inventarios.IniciaTransacSQL() If Inventarios.AddInventarioFisicoResultados(CveInventarioFisico, UsuarioActual.CveUsuario) Then If Inventarios.UpdateInventarioFisicoEstatus(CveInventarioFisico, 3, UsuarioActual.CveEmpresa) Then Dim url As String = ("/Inventarios/RepAnomalias.aspx?CveInventarioFisico=" + CveInventarioFisico.ToString) Alert("Ha finalizado el Inventario Físico. Sera enviado al reporte de anomalías", TipoMensaje.MsgInformacion, " window.location=""" + url + """") Inventarios.Commit() Else Inventarios.RollBack() End If Else Inventarios.RollBack() End If Inventarios.Dispose() End Sub #End Region Protected Sub GV_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvF.RowDataBound, GvS.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("Costo") = "-1" Then e.Row.Cells(8).Text = "0" End If If e.Row.Cells(7).Text = MinFecha.ToString Then e.Row.Cells(7).Text = "" End If e.Row.FCLabel("Lblc").Text = e.Row.RowIndex + 1 End If End Sub #Region " IMPRIMIR " 'Protected Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click ' GvF.ExportToExcel("IF_Faltantes_" & Now.ToShortDateString()) 'End Sub 'Protected Sub LnkExportaSobrantes_Click(sender As Object, e As EventArgs) Handles LnkExportaSobrantes.Click ' GvS.ExportToExcel("IF_Sobrantes_" & Now.ToShortDateString()) 'End Sub Private Sub LnkPDF_Click(sender As Object, e As EventArgs) Handles LnkPDF.Click ImprimirbytesPDF(Impimir, Formato:="PDF") End Sub Protected Function Impimir() As Byte() Dim retorno As Byte() = Nothing Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/RepAnomalias.rdlc", UsuarioActual.Empresa.Ruta)) Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) Dim params As New List(Of ReportParameter) Dim lrds As New List(Of ReportDataSource) Dim Inventario As New ClsInventarios Dim dtS As DataTable = Nothing Dim dtF As DataTable = Nothing If Inventario.GetInventarioFisico(CveInventarioFisico, UsuarioActual.CveEmpresa, -1, -1) Then params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) params.Add(New ReportParameter("Titulo", Inventario.InventarioFisico)) params.Add(New ReportParameter("Observaciones", Inventario.Observaciones)) params.Add(New ReportParameter("Almacen", LblAlmacenes.Text)) params.Add(New ReportParameter("Estatus", Inventario.Estatus)) params.Add(New ReportParameter("FechaInicio", Inventario.FechaI)) params.Add(New ReportParameter("FechaFin", Inventario.FechaF)) params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToString)) Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) If Imagen.Exists Then params.Add(New ReportParameter("LogoPath", logouri)) Else params.Add(New ReportParameter("LogoPath", "")) End If If EsAvance Then If Inventario.GetInventarioFisicoResultadosAvance(CveInventarioFisico, UsuarioActual.CveEmpresa) Then dtS = Inventario.DtResultados.FiltraParametros("Diferencia <0") dtF = Inventario.DtResultados.FiltraParametros(" Diferencia > 0") End If Else If Inventario.GetInventarioFisicoResultados(CveInventarioFisico, UsuarioActual.CveEmpresa) Then dtS = Inventario.DtResultados.FiltraParametros("Diferencia <0") dtF = Inventario.DtResultados.FiltraParametros(" Diferencia > 0") End If End If Dim rds As New ReportDataSource With {.Name = "DataSet1", .Value = dtS} lrds.Add(rds) Dim rds2 As New ReportDataSource With {.Name = "DataSet2", .Value = dtF} lrds.Add(rds2) End If retorno = StreamPDF("Empresas/Grales/Formatos/RepAnomalias.rdlc", lrds, params, "Reporte Anomalías", "PDF", MR:=Nothing) Return retorno End Function Private Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click GvF.ExportToExcel("Reporte de Inventario Fisico - Productos que Faltan " & Now.ToShortDateString) End Sub Private Sub ImgExcel2_Click(sender As Object, e As EventArgs) Handles ImgExcel2.Click GvS.ExportToExcel("Reporte de Inventario Fisico - Productos que Sobran " & Now.ToShortDateString) End Sub #End Region Private Sub BanderaSerieLoteCad(Gv As GridView, resultado As DataTable) Gv.Columns(4).Visible = resultado.MAX("CveSeccionAlmacen").ToEntero > 0 Gv.Columns(5).Visible = resultado.MAX("Serie") <> "" Gv.Columns(6).Visible = resultado.MAX("Lote") <> "" Gv.Columns(7).Visible = resultado.MAX("FechaCaducidad").ToDate > MinFecha End Sub Private Sub LnkCrear_Click(sender As Object, e As EventArgs) Handles LnkCrear.Click If GvF.Rows.Count > 0 Then GvF.Columns(0).Visible = True LnkGuardar.Visible = True LnkCrear.Visible = False GvF.HeaderRow.FCCheckBox("ChkAllFaltante").Attributes.Add("onclick", "SeleccionarTodosFaltante(this);") End If If GvS.Rows.Count > 0 Then GvS.Columns(0).Visible = True LnkGuardar.Visible = True LnkCrear.Visible = False GvS.HeaderRow.FCCheckBox("ChkAllSobrante").Attributes.Add("onclick", "SeleccionarTodosSobrante(this);") End If UPAnomalias.Update() UpdateGvS.Update() UPAcciones.Update() End Sub Private Sub LnkGuardar_Click(sender As Object, e As EventArgs) Handles LnkGuardar.Click RegistraScript("$('#ModalGuardar').modal('show')") End Sub Private Sub BtnCrear_Click(sender As Object, e As EventArgs) Handles BtnCrear.Click Dim ErrorClasif As Boolean = False Dim ObjInventario As New ClsInventarios Dim CveInventarioFisicoNew As Integer Dim DtAlmacen, DtClasificacion, DtClasificacionExcluida, DtProveedor As DataTable DtAlmacen = Nothing DtClasificacion = Nothing DtClasificacionExcluida = Nothing DtProveedor = Nothing ObjInventario.IniciaTransacSQL() If ObjInventario.AddInventarioFisico(UsuarioActual.CveEmpresa, TxtTitulo.Text, lbObservaciones.Text, 0, CveSubProyecto) Then CveInventarioFisicoNew = ObjInventario.CveInventarioFisico If ObjInventario.GetInventarioFisicoDetallesAlmacen(CveInventarioFisico, UsuarioActual.CveEmpresa) Then DtAlmacen = ObjInventario.DtResultados End If If ObjInventario.GetInventarioFisicoDetallesClasificacion(CveInventarioFisico, UsuarioActual.CveEmpresa) Then DtClasificacion = ObjInventario.DtResultados.FiltraParametros("Incluye = 1") DtClasificacionExcluida = ObjInventario.DtResultados.FiltraParametros("Incluye = 0") End If If ObjInventario.GetInventarioFisicoDetallesProveedores(CveInventarioFisico, UsuarioActual.CveEmpresa) Then DtProveedor = ObjInventario.DtResultados.FiltraParametros("Incluye = 1") End If For Each Gvr As DataRow In DtAlmacen.Rows If Not ObjInventario.AddInventarioFisicoAlmacenes(CveInventarioFisicoNew, Gvr("CveAlmacen").ToString.ToEntero) Then ErrorClasif = True Exit For End If Next If ErrorClasif = False Then For Each Gvr As DataRow In DtClasificacion.Rows If Not ObjInventario.AddInventarioFisicoClasificaciones(CveInventarioFisicoNew, Gvr("CveClasificacion").ToString.ToEntero, UsuarioActual.CveUsuario, True) Then ErrorClasif = True Exit For End If Next For Each Gvr As DataRow In DtClasificacionExcluida.Rows If Not ObjInventario.AddInventarioFisicoClasificaciones(CveInventarioFisicoNew, Gvr("CveClasificacion").ToString.ToEntero, UsuarioActual.CveUsuario, False) Then ErrorClasif = True Exit For End If Next End If If ErrorClasif = False Then For Each Gvr As GridViewRow In GvF.Rows If Gvr.FCCheckBox("ChkPSFaltante").Checked Then If Not ObjInventario.AddInventarioFisicoProductosServicios(CveInventarioFisicoNew, Gvr.DataKey("CvePS").ToString.ToEntero, True) Then ErrorClasif = True Exit For End If End If Next For Each Gvr As GridViewRow In GvS.Rows If Gvr.FCCheckBox("ChkPSSobrante").Checked Then If Not ObjInventario.AddInventarioFisicoProductosServicios(CveInventarioFisicoNew, Gvr.DataKey("CvePS").ToString.ToEntero, True) Then ErrorClasif = True Exit For End If End If Next End If If ErrorClasif = False Then For Each Gvr As DataRow In DtProveedor.Rows If Not ObjInventario.AddInventarioFisicoProveedores(CveInventarioFisicoNew, Gvr("CveProveedor").ToString.ToEntero, True) Then ErrorClasif = True Exit For End If Next End If End If If ErrorClasif = False And CveInventarioFisicoNew > 0 Then ObjInventario.Commit() Alert("Agregado Correctamente.", TipoMensaje.MsgInformacion) RegistraScript(String.Format("$('#{0}').modal('hide');", "ModalGuardar")) GvF.Columns(0).Visible = False GvS.Columns(0).Visible = False LnkGuardar.Visible = False LnkCrear.Visible = True CargaDatos(CveInventarioFisico) Else ObjInventario.RollBack() End If ObjInventario.Dispose() End Sub Private Sub PSIguales() Dim contadorF As Integer = 0 Dim contadorS As Integer = 0 For Each dtF As GridViewRow In GvF.Rows contadorS = 0 For Each dtS As GridViewRow In GvS.Rows If dtS.DataKey("CvePS") = dtF.DataKey("CvePS") Then GvS.Rows(contadorS).BackColor = Drawing.Color.FromArgb(202, 52, 52) GvF.Rows(contadorF).BackColor = Drawing.Color.FromArgb(202, 52, 52) End If contadorS += 1 Next contadorF += 1 Next End Sub End Class