Option Explicit On Option Strict On Imports Extensiones Imports System.Data 'Imports msExcel = Microsoft.Office.Interop.Excel 'Imports System.Xml 'Imports System.Collections.Generic 'Imports System.Runtime.InteropServices 'Imports VBIDE Imports iTextSharp.text.pdf Partial Class Prospectos_GeneradorEncuestas Inherits System.Web.UI.Page ReadOnly Property UsuarioActual() As Usuario Get UsuarioActual = DirectCast(Session("UsuarioSIG"), Usuario) End Get End Property Private Property DisLoc As String Get Return ViewState("DisLoc").ToString End Get Set(value As String) ViewState("DisLoc") = value End Set End Property Private Property Seccion As String Get Return ViewState("Seccion").ToString End Get Set(value As String) ViewState("Seccion") = value End Set End Property Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then ViewState("Orden") = String.Empty DisLoc = "-1" : Seccion = "-1" CargaFiltros() 'CargaDatos() End If End Sub Private Sub CargaFiltros() Dim ObjProspectos As New ClsProspectos 'Municipio If ObjProspectos.GetFiltros("Mun") Then DdlMunicipio.DataSource = ObjProspectos.DtResultados Else DdlMunicipio.DataSource = Nothing End If DdlMunicipio.DataBind() DdlMunicipio.Items.Insert(0, New ListItem("Todos", "-1")) 'Distritos Dim DT As DataTable = Nothing If ObjProspectos.GetFiltros("Dist") Then DT = ObjProspectos.DtResultados Else DT = Nothing End If If DT IsNot Nothing AndAlso DT.Rows.Count > 0 Then 'Cargo DistLoc DdlDistLoc.DataSource = DT.FiltraParametros("", "", {"Dist_Loc"}) DdlDistLoc.DataBind() DdlDistLoc.Items.Insert(0, New ListItem("Todos", "-1")) 'Cargo Secciones Dim FiltroDistLoc As String = String.Empty If DdlDistLoc.SelectedIndex > 0 Then FiltroDistLoc = "Dist_Loc = '" & DdlDistLoc.SelectedValue & "'" DdlSeccion.DataSource = DT.FiltraParametros(FiltroDistLoc, "", {"seccion"}) DdlSeccion.DataBind() DdlSeccion.Items.Insert(0, New ListItem("Todas", "-1")) End If If DT IsNot Nothing Then DT.Dispose() 'Ocupacion If ObjProspectos.GetFiltros("Colonias") Then DdlColonia.DataSource = ObjProspectos.DtResultados Else DdlColonia.DataSource = Nothing End If DdlColonia.DataBind() DdlColonia.Items.Insert(0, New ListItem("Todas", "-1")) ObjProspectos.Dispose() End Sub Public Sub CargaDatos() Dim ObjProspectos As New ClsProspectos Dim Calle As String = "-1" If TxtCalle.Text.Trim <> String.Empty Then Calle = TxtCalle.Text.Trim If ObjProspectos.GeneradorEncuestas(DdlTipo.SelectedValue.ToEntero, DdlMunicipio.SelectedValue.ToEntero, DdlDistLoc.SelectedValue.ToEntero, DdlSeccion.SelectedValue.ToEntero, DdlColonia.SelectedValue, Calle) Then ViewState("DTProspectos") = ObjProspectos.DtResultados Else Me.GvDatos.DataSource = Nothing End If ObjProspectos.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If UPDatos.Update() End Sub Private Sub CargaGrid(Orden As String) If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTProspectos"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatos.DataSource = DV.ToTable() DV.Dispose() Else GvDatos.DataSource = CType(ViewState("DTProspectos"), DataTable) End If GvDatos.DataBind() LtlNumRegistros.Text = GvDatos.Rows.Count.ToString.FormatoNumero(0) 'Quitar o comentas 'GV.DataSource = CType(ViewState("DTProspectos"), DataTable) 'GV.DataBind() End Sub Protected Sub GvDatos_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvDatos.RowCreated If (e.Row.RowType = DataControlRowType.DataRow AndAlso (e.Row.RowState = DataControlRowState.Normal OrElse e.Row.RowState = DataControlRowState.Alternate)) Then e.Row.TabIndex = -1 e.Row.Attributes("onclick") = String.Format("javascript:SelectRow(this, {0});", e.Row.RowIndex) e.Row.Attributes("onkeydown") = "javascript:return SelectSibling(event);" e.Row.Attributes("onselectstart") = "javascript:return false;" 'e.Row.Cells(10).Attributes.Add("onclick", "EC();") End If End Sub Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then ElseIf e.Row.RowIndex = 1 Then 'e.Row.Cells(0).Width = Unit.Pixel(120) 'Gpo End If End If End Sub Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click CargaDatos() UPDatos.Update() RegistraScript("UpperBound = " & GvDatos.Rows.Count - 1 & ";") End Sub Protected Sub ImgExcel_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles ImgExcel.Click GvDatos.ExportToExcel(DdlTipo.SelectedItem.Text) End Sub Private Shared missing As Object = System.Reflection.Missing.Value 'Private Sub GeneraHoja(ByRef Hoja As msExcel.Worksheet, NumHoja As Integer, BarCode As String, URLBarCode As String, Tipo As String, Folio As String, Calle As String, Numero As String, Interior As String, Colonia As String, ' Seccion As String, CP As String, Municipio As String, Paterno As String, Materno As String, Nombres As String) ' 'Capturo Datos ' NumHoja = (NumHoja * 43) - 43 ' Hoja.Range("F" & NumHoja + 2 & ":F" & NumHoja + 2).Value = Tipo : Hoja.Range("J" & NumHoja + 2 & ":J" & NumHoja + 2).Value = Folio ' Hoja.Range("A" & NumHoja + 3 & ":A" & NumHoja + 3).Value = BarCode ' Hoja.Range("A" & NumHoja + 4 & ":A" & NumHoja + 4).Value = Calle : Hoja.Range("E" & NumHoja + 4 & ":E" & NumHoja + 4).Value = Numero : Hoja.Range("G" & NumHoja + 4 & ":G" & NumHoja + 4).Value = Interior : Hoja.Range("I" & NumHoja + 4 & ":I" & NumHoja + 4).Value = Colonia ' Hoja.Range("A" & NumHoja + 7 & ":A" & NumHoja + 7).Value = Seccion : Hoja.Range("E" & NumHoja + 7 & ":E" & NumHoja + 7).Value = CP : Hoja.Range("I" & NumHoja + 7 & ":I" & NumHoja + 7).Value = Municipio ' Hoja.Range("A" & NumHoja + 10 & ":A" & NumHoja + 10).Value = Paterno : Hoja.Range("E" & NumHoja + 10 & ":E" & NumHoja + 10).Value = Materno : Hoja.Range("I" & NumHoja + 10 & ":I" & NumHoja + 10).Value = Nombres ' 'CB ' If URLBarCode <> String.Empty Then ' Dim Top, Left, Width, Height As Single ' Left = 0 ' Top = CSng(Hoja.Range("B" & NumHoja + 2 & ":B" & NumHoja + 2).Top) ' Width = CSng(Hoja.Range("B" & NumHoja + 2 & ":B" & NumHoja + 2).Width) ' Height = CSng(Hoja.Range("B" & NumHoja + 2 & ":B" & NumHoja + 2).Height) ' Hoja.Shapes.AddPicture(URLBarCode, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, Width, Height) ' End If 'End Sub Protected Sub Btn_Click(sender As Object, e As EventArgs) Handles Btn.Click 'Dim Excel As msExcel.Application = New msExcel.Application() 'Dim VB_Module As VBComponent = Nothing ''Excel.Visible = True ''Excel.ScreenUpdating = True ''Excel.DisplayAlerts = True 'Dim Formato As String = "Formato Entrevista 3.xlsm" 'Dim ArchivoBase As New System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory & "Recursos\" & Formato) 'ArchivoBase.CopyTo(AppDomain.CurrentDomain.BaseDirectory & "Recursos\Temp\" & UsuarioActual.CveUsuario & ".xlsm", True) 'Dim ArchivoTemp As New System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory & "Recursos\Temp\" & UsuarioActual.CveUsuario & ".xlsm") '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() 'Dim AddPage As New StringBuilder 'AddPage.Append(" Sub AddPage(RowF As String) " & vbLf) 'AddPage.Append(" Rows(""1:43"").Select " & vbLf) 'AddPage.Append(" Selection.Copy " & vbLf) 'AddPage.Append(" Rows(RowF & "":"" & RowF).Select " & vbLf) 'AddPage.Append(" Selection.Insert Shift:=xlDown " & vbLf) 'AddPage.Append(" End Sub " & vbLf) 'Dim RemoveFirstPage As New StringBuilder 'RemoveFirstPage.Append(" Sub RemoveFirst() " & vbLf) 'RemoveFirstPage.Append(" Rows(""1:43"").Select " & vbLf) 'RemoveFirstPage.Append(" Selection.Delete Shift:=xlUp " & vbLf) 'RemoveFirstPage.Append(" ActiveSheet.Shapes.Range(Array(""Picture 23"", ""Picture 16"", ""Picture 17"", ""Picture 18"", ""Picture 19"", ""Picture 20"", ""Picture 21"", ""Picture 22"", ""Picture 32"", ""Picture 33"", ""Picture 34"", ""Picture 35"", ""Picture 36"", ""Picture 37"", ""Picture 38"", ""Picture 39"", ""Picture 40"", ""Picture 41"", ""Picture 42"", ""Picture 43"", ""Picture 44"", ""Picture 45"", ""Picture 46"", ""Picture 47"", ""Picture 72"", ""Picture 73"", ""Picture 74"", ""Picture 75"", ""Picture 76"", ""Picture 77"", ""Picture 78"", ""Picture 80"", ""Picture 105"", ""Picture 104"", ""Picture 85"", ""Picture 87"", ""Picture 88"", ""Picture 89"", ""Picture 90"", ""Picture 96"", ""Picture 97"", ""Picture 98"", ""Picture 99"", ""Picture 100"", ""Picture 101"", ""Picture 102"", ""Picture 103"")).Select " & vbLf) 'RemoveFirstPage.Append(" Selection.Delete " & vbLf) 'RemoveFirstPage.Append(" End Sub " & vbLf) 'VB_Module = CType(Libro.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule), VBComponent) 'VB_Module.CodeModule.AddFromString(AddPage.ToString) 'VB_Module.CodeModule.AddFromString(RemoveFirstPage.ToString) 'Dim ObjProspectos As New ClsProspectos 'Dim NumHoja As Integer = 2 'For Each Row As GridViewRow In GvDatos.Rows ' 'If Row.FCCheckBox("Chk").Checked Then ' ''BarCode ' Dim BC39 As New Barcode39 ' BC39.Code = Row.DataKey("Consec") ' Dim ObjImg As System.Drawing.Image = BC39.CreateDrawingImage(Drawing.Color.Black, Drawing.Color.White) ' ObjImg.Save(AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\{0}.png", UsuarioActual.CveUsuario), System.Drawing.Imaging.ImageFormat.Png) ' ObjImg.Dispose() ' Dim ImgBC As String = String.Empty ' If System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\{0}.png", UsuarioActual.CveUsuario)) Then ImgBC = AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\{0}.png", UsuarioActual.CveUsuario) ' Dim Folio As String = Row.DataKey("Seccion") & "-" & ObjProspectos.EncuestaFolioAdd(Row.DataKey("Tipo").ToEntero, 18, Row.DataKey("Seccion").ToEntero, Row.DataKey("IFE")).ToString ' Libro.Application.Run("AddPage", (NumHoja * 43) - 42, 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) ' GeneraHoja(Hoja, NumHoja, Row.DataKey("Consec"), ImgBC, Row.DataKey("Tipo"), Folio, Row.DataKey("Calle"), Row.DataKey("NumExterior"), Row.DataKey("NumInterior"), ' Row.DataKey("Colonia"), Row.DataKey("Seccion"), Row.DataKey("CP"), Row.DataKey("PadronMunicipio"), Row.DataKey("APaterno"), Row.DataKey("AMaterno"), Row.DataKey("Nombres")) ' NumHoja = NumHoja + 1 ' 'End If 'Next 'ObjProspectos.Dispose() 'Libro.Application.Run("RemoveFirst", 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, missing) ''Exportar PDF 'Dim pdfFileOut As String = AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\Tipo_{0}_Mun_{1}_Secc_{2}_.pdf", DdlTipo.SelectedItem.Text, DdlMunicipio.SelectedItem.Text, DdlSeccion.SelectedItem.Text) 'Dim outputFileName As Object = pdfFileOut 'Dim fileFormat As msExcel.XlFixedFormatType = msExcel.XlFixedFormatType.xlTypePDF 'Libro.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() 'If System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\{0}.png", UsuarioActual.CveUsuario)) Then System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory & String.Format("Recursos\Temp\{0}.png", UsuarioActual.CveUsuario)) 'Dim Descargas As New StringBuilder() 'Descargas.AppendFormat("