Пример #1
0
        /**
         *
         *
         *
         */
        public List <Planilla> traerSinProcesar()
        {
            SQLiteConnection con       = this.crearConneccion();
            List <Planilla>  planillas = new List <Planilla>();

            try
            {
                string query = string.Empty;
                query = "select id, idtribunal, fecha, ruta, procesar FROM Planilla where procesar = 0 order by id asc";

                SQLiteCommand    command = new SQLiteCommand(query, con);
                SQLiteDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    Planilla planilla = new Planilla();
                    planilla.id         = reader.GetInt32(0);
                    planilla.idtribunal = reader.GetInt32(1);
                    planilla.fecha      = reader.GetString(2);
                    planilla.ruta       = reader.GetString(3);
                    planilla.procesar   = reader.GetInt32(4);
                    planillas.Add(planilla);
                }
                reader.Close();
                con.Close();
            }
            catch (Exception ex)
            {
                if (con.State != System.Data.ConnectionState.Closed)
                {
                    con.Close();
                }
            }

            return(planillas);
        }
Пример #2
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            string pathExcel = Settings.Default.ExcelPath;

            /**
             * Vamos a extraer el estado diario
             *   Rol
             *   Partes
             *   Fecha
             *   Tribunal
             *   Texto Completo
             */

            //Folder donde ejecutar, validar argumentos
            //1.- Download Excels diarios
            //2.- Procesar Excels
            //3.- Procesar Cola
            string command = args[0];

            switch (command)
            {
            //1.- Download Excels diarios
            case "1":
                Corte           corteInfo = new Corte();
                List <Corte>    cortes    = corteInfo.traerTodas();
                IFormatProvider culture   = new CultureInfo("es-ES", true);
                string          fecha     = DateTime.Today.AddDays(-1).ToString("dd/MM/yyyy", culture);

                foreach (Corte corte in cortes)
                {
                    if (corte.tienePlanillaDiaria(fecha))
                    {
                        continue;
                    }

                    Console.WriteLine("===================================================================");
                    Console.Write("Descargando planilla: " + corte.jurisdiccion);

                    string docImportSrc = string.Empty;
                    string excelDocPath = string.Empty;
                    string fileName     = string.Empty;

                    try
                    {
                        //Tratamos de descargar el archivo
                        using (WebClient webClient = new WebClient())
                        {
                            docImportSrc = "https://www.pjud.cl/estado-diario?p_p_id=estadodiario_WAR_estadodiarioportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-3&p_p_col_pos=1&p_p_col_count=2&_estadodiario_WAR_estadodiarioportlet_campoTribunal=" + corte.codtribunalpj + "&_estadodiario_WAR_estadodiarioportlet_cur=1&tipoArchivo=EXCEL&fechaComun=" + fecha + "&campoSecretaria=&codTribunal=" + corte.codtribunalpj;
                            fileName     = corte.jurisdiccion + "-" + fecha.Replace("/", "") + ".xls";
                            excelDocPath = @pathExcel + "\\" + fileName;
                            webClient.DownloadFile(docImportSrc, @excelDocPath);
                        }
                        Console.WriteLine("........Ok");
                    }
                    catch (Exception ex)
                    {
                        FirstTestCase.regLog("[Fatal Error]\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.InnerException + "\r\n" + ex.Source);
                        Console.WriteLine("........Fail");
                        //si no logra descargar no registra nada en la db
                        continue;
                    }

                    Console.WriteLine("-Registramos en la base de datos");

                    Planilla planilla = new Planilla();
                    planilla.idtribunal = corte.id;
                    planilla.fecha      = fecha;
                    planilla.ruta       = fileName;
                    if (planilla.Grabar())
                    {
                        Console.WriteLine("Guardado...........................Ok");
                    }
                    else
                    {
                        Console.WriteLine("Guardado.........................Fail");
                    }
                }
                break;

            //2.- Procesar Excels
            case "2":
                Planilla planillaInfo = new Planilla();
                foreach (Planilla planilla in planillaInfo.traerSinProcesar())
                {
                    //Procesamos el excel e insertamos en la tabla registro
                    if (planilla.cargarExcel())
                    {
                        planilla.procesar = 1;
                        planilla.Grabar();
                    }
                }

                break;

            //3.- Procesar Cola
            case "3":
                Registro        registroInfo  = new Registro();
                List <Registro> registrosCola = registroInfo.traerSinProcesar(Settings.Default.DocumentosLote);

                //Limpiamos lod directorios

                //Principal pdf
                FirstTestCase.cleanWorkingDir(Settings.Default.PDFPath);

                Corte cortesList = new Corte();

                //las carpetas de cada corte
                foreach (Corte c in cortesList.traerTodas())
                {
                    FirstTestCase.cleanWorkingDir(@Settings.Default.PathTxt + "\\" + c.loesid.ToString());
                }


                foreach (Registro r in registrosCola)
                {
                    Corte corte = new Corte();
                    corte.id = r.idtribunal;
                    corte.traer();

                    try{
                        string fileName   = string.Empty;
                        string pdfDocPath = string.Empty;

                        //Descargamos el archivo
                        using (WebClient webClient = new WebClient())
                        {
                            //Antes de hacer la descarga verificamos que el documento no este registrado en la base de datos de manera de optimizar el proceso
                            Fallo fallo = new Fallo();
                            fallo.fecha    = r.fecha;
                            fallo.rol      = r.rol;
                            fallo.tribunal = corte.loesid.ToString();

                            if (fallo.Existe())
                            {
                                FirstTestCase.regLog("El fallo ROL: " + r.rol + ", del tribunal " + corte.jurisdiccion + ", y fecha " + fallo.fecha + ", ya se encuentra registrado.");
                                continue;
                            }

                            string falloImportSrc = "https://www.pjud.cl/estado-diario?p_p_id=estadodiario_WAR_estadodiarioportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-3&p_p_col_pos=1&p_p_col_count=2&_estadodiario_WAR_estadodiarioportlet_campoTribunal=" + corte.codtribunalpj + "&_estadodiario_WAR_estadodiarioportlet_cur=1&crr_documento=" + r.traerNumerodocumento() + "&tipoModulo=" + corte.modulo + "&fuenteDocumento=" + corte.fuentedocumento;
                            fileName   = r.rol + "-" + r.ndocumento.ToString() + ".pdf";
                            pdfDocPath = @Settings.Default.PDFPath + "\\" + fileName;
                            webClient.DownloadFile(falloImportSrc, pdfDocPath);
                            FirstTestCase.regLog("El fallo ROL: " + r.rol + ", del tribunal " + corte.jurisdiccion + ", ha sido descargado");

                            ConvertFiles(r, corte, fileName);
                            r.procesado = 1;
                            r.Save();
                        }
                    }catch (Exception ex) {
                        FirstTestCase.regLog("El fallo ROL: " + r.rol + ", del tribunal " + corte.jurisdiccion + ", No ha podido ser descargado");
                    }
                }
                break;

            //3.- Procesar Cola
            case "4":
                FirstTestCase.enviarEmail();
                break;
            }
        }