Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/06/2011, 08:11
Piboy
 
Fecha de Ingreso: junio-2011
Mensajes: 3
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con Tablas dinamicas y actualizacion

PARTE DE LA CLASE DONDE SE DEFINEN LAS FUNCIONES PRINCIPALES
Código:
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ikvm;
using org.pdfbox.pdmodel;
using org.pdfbox.util;
using org.pdfbox.pdfparser;
using org.pdfbox.cos;
using System.Text.RegularExpressions;
using System.Text;
using System.Net;
using System.IO;
using java.io;
using System.Threading;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        private string patronbusqueda;
        private ArrayList resultados;
        private ArrayList ficheros = new ArrayList();
        private ArrayList contenidoaux = new ArrayList();
        private TableRow fila;
        //celda para colocar el DMC
        private TableCell celda;
        //celda para colocar la imagen
        private TableCell celda2;
        private ImageButton boton;

 FUNCION QUE TOMA LOS VALORES DE LOS CAMPOS Y BUSCA EN LOS FICHEROS

        protected void z_btnAceptar_Click(object sender, EventArgs e)
        {
            z_textMensaje.Text = "";
            resultados = new ArrayList();
            string filtro = DropDownList1.Items[DropDownList1.SelectedIndex].ToString();
            if (filtro.Equals(""))
            {
                z_textMensaje.Text = "No has elegido idioma";
                return;
            }
            else if (filtro.Equals("Español"))
            {
                filtro = "";
            }
            else if (filtro.Equals("Inglés"))
            {

                filtro = "-en";
            }
            else
            {
                filtro = "-zh";
            }

            patronbusqueda = z_textbox.Text;
            z_textMensaje.Text = "";
         
            if (z_textbox.Text.Equals(" "))
            {
                z_textMensaje.Text = "No has insertado un patrón a buscar";
                return;
            }
            if (patronbusqueda.Contains(" "))
            {
                patronbusqueda = patronbusqueda.Replace(" ", "");
            }
            try
            {
                string dir = "D:\\PROGRAMAS\\Herramientas\\SearchPDF\\PruebaPDF\\";
                ListItemCollection capitulos = ListBox1.Items;
                if (capitulos.Count != 0)
                {
                    
                    ficheros = this.filesDir(dir, filtro, capitulos);
                    if (ficheros.Count == 0)
                    {
                        z_textMensaje.Text = "La ruta especificada no contiene ningún fichero PDF. Por favor, compruébelo";
                        return;
                    }
                    else
                    {
                        string minus = patronbusqueda.ToLower();
                        string mayus = patronbusqueda.ToUpper();

                        for (int j=0; j < ficheros.Count; j++)
                        {
                            contenidoaux.Clear();
                            java.io.File fichero = new java.io.File(ficheros[j].ToString());
                            PDFParser parser = new PDFParser(new java.io.FileInputStream(fichero));
                            parser.parse();
                            COSDocument cosDoc = parser.getDocument();
                            PDFTextStripper pdfStripper = new PDFTextStripper();
                            PDDocument pdDoc = new PDDocument(cosDoc);
                            string parsedText = pdfStripper.getText(pdDoc);
                            char[] delim = { '\n' };
                            string[] contenido;
                            contenido = parsedText.Split(delim);
                            for (int i = 0; i < contenido.Length; i++)
                            {
                                contenidoaux.Add(contenido[i].Replace("\r", "").Replace("/", "").Trim().TrimEnd().TrimStart());

                            }
                            for (int i = 0; i < contenidoaux.Count; i++)
                            {
                                string parte = contenidoaux[i].ToString();
                                string parteaux = Regex.Replace(parte, @"\s+", "");
                                //busco el patron en minusculas, mayusculas y literalmente lo que el usuario a escrito
                                int resultado1 = parteaux.IndexOf(minus);
                                int resultado2 = parteaux.IndexOf(mayus);
                                int resultado3 = parteaux.IndexOf(patronbusqueda);

                                if ((resultado1 != -1) || (resultado2 != -1) || (resultado3 != -1))
                                {
                                    resultados.Add(ficheros[j].ToString());
                                    if (z_textMensaje.Text.Equals(""))
                                    {
                                        //z_textMensaje.Text = ficheros[j].ToString();
                                        //rompo bucle para que muestre una unica vez que lo ha encontrado
                                        break;
                                    }
                                    else
                                    {

                                        //z_textMensaje.Text = z_textMensaje.Text + "---" + ficheros[j].ToString();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    z_textMensaje.Text = "No has elegido un capítulo";
                    return;
                }
                if (resultados.Count == 0)
                {
                    z_textMensaje.Text = "No se ha encontrado ninguna coincidencia";
                }
                else
                {
                    createTable();
                }              
            }
            catch (Exception ex)
            {
                z_textMensaje.Text = "La ruta especificada no contiene ningún fichero PDF. Por favor, compruébelo."+ ex.Message;
            } 
        }


FUNCION QUE CREA LAS FILAS DE LA TABLA
        protected void createTable()
        {
            Label1.Visible = true;
            Table1.Visible = true;
            for (int i = 0; i < resultados.Count; i++)
            {
                fila = new TableRow();
                //celda para colocar el DMC
                celda = new TableCell();
                //celda para colocar la imagen
                celda2 = new TableCell();
                System.Web.UI.WebControls.Image imagen = new System.Web.UI.WebControls.Image();
                imagen.ImageUrl = "http://icons.iconarchive.com/icons/treetog/i/24/PDF-icon.png";
                boton = new ImageButton();
                string[] partes = resultados[i].ToString().Split('\\');
                celda.Text = partes[6].ToString();
                boton.ImageUrl = imagen.ImageUrl;
                string aux = " " + celda.Text + " ";
                aux = aux.Replace(" ", "\"");
                boton.Attributes.Add("onclick", "clickboton(" + aux + ")");
                celda2.Controls.Add(boton);
                fila.Cells.Add(celda);
                fila.Cells.Add(celda2);
                Table1.Rows.Add(fila);
            }
            
            Table1.Style.Remove("width");
            Table1.Style["width"] = "155px";
        }

Última edición por Piboy; 22/06/2011 a las 08:26