Ejemplo n.º 1
0
        private void actualizaListaEnTrabajo(int i, string carpeta)
        {
            try
            {
                DirectoryInfo enTrabajoDir      = new DirectoryInfo(carpeta);
                archivosExcel archivosEnTrabajo = new archivosExcel();
                DataTable     listaArchivos     = archivosEnTrabajo.getArchivosDeCarpeta(enTrabajoDir);

                //thread safe call to a windows form control
                if (this.dgvEnTrabajo.InvokeRequired)
                {
                    actualizaListaETCallback d = new actualizaListaETCallback(actualizaListaEnTrabajo);
                    this.Invoke(d, new object[] { i, carpeta });
                }
                else
                {
                    dgvEnTrabajo.DataSource = listaArchivos;
                    dgvEnTrabajo.Refresh();
                }
            }
            catch (Exception errGral)
            {
                txtbxMensajes.AppendText("Excepción encontrada al leer archivos En Trabajo. " + errGral.Message + " [actualizaListaEnTrabajo]" + "\r\n");
                txtbxMensajes.Refresh();
            }
        }
Ejemplo n.º 2
0
        public void ProcesaCarpetaEnTrabajo(string transicion, List <string> archivosSeleccionados)
        {
            try
            {
                _iError = 0;
                DirectoryInfo enTrabajoDir      = new DirectoryInfo(this._ParamExcel.rutaCarpeta.ToString() + "\\EnTrabajo");
                archivosExcel archivosEnTrabajo = new archivosExcel();

                foreach (string item in archivosSeleccionados)
                {
                    _iError = 0;
                    string sTimeStamp     = System.DateTime.Now.ToString("yyMMddHHmmssfff");
                    string sNombreArchivo = item;

                    archivosEnTrabajo.abreArchivoExcel(enTrabajoDir.ToString(), sNombreArchivo);
                    ExcelWorksheet hojaXl = archivosEnTrabajo.paqueteExcel.Workbook.Worksheets.First();
                    if (archivosEnTrabajo.iError == 0)
                    {
                        int startRow            = _ParamExcel.FacturaSopFilaInicial;
                        int iTotal              = hojaXl.Dimension.End.Row - startRow + 1;
                        int iFacturasIntegradas = 0;
                        int iFilasIntegradas    = 0;
                        int iFacturaIniciaEn    = 0;
                        int iAntesIntegradas    = 0;
                        OnProgreso(1, "INICIANDO CARGA DE ARCHIVO " + sNombreArchivo + "...");              //Notifica al suscriptor
                        if (startRow > 1)
                        {
                            hojaXl.Cells[startRow - 1, this._ParamExcel.FacturaSopColumnaMensajes].Value = "Observaciones";
                        }

                        for (int rowNumber = startRow; rowNumber <= hojaXl.Dimension.End.Row; rowNumber++)
                        {
                            if (hojaXl.Cells[rowNumber, this._ParamExcel.FacturaSopColumnaMensajes].Value == null ||
                                !hojaXl.Cells[rowNumber, this._ParamExcel.FacturaSopColumnaMensajes].Value.ToString().Equals("Integrado a GP"))
                            {
                                IntegraFacturaSOP(hojaXl, rowNumber, sTimeStamp);

                                iFacturaIniciaEn = rowNumber;
                                rowNumber        = _filaNuevaFactura - 1;

                                if (_iError == 0)
                                {
                                    iFacturasIntegradas++;
                                    for (int ind = iFacturaIniciaEn; ind <= rowNumber; ind++)
                                    {
                                        hojaXl.Cells[ind, this._ParamExcel.FacturaSopColumnaMensajes].Value = "Integrado a GP";
                                        iFilasIntegradas++;
                                    }
                                }
                                else
                                {
                                    hojaXl.Cells[rowNumber, this._ParamExcel.FacturaSopColumnaMensajes].Value = _sMensajeErr;
                                }
                            }
                            else
                            {
                                iAntesIntegradas++;
                                this._mensaje     = "Fila: " + rowNumber.ToString();
                                this._sMensajeErr = "anteriormente integrada.";
                            }
                            OnProgreso(100 / iTotal, _mensaje + " " + _sMensajeErr);
                        }
                        OnProgreso(100, "----------------------------------------------");
                        _sMensajeErr = "INTEGRACION FINALIZADA";
                        OnProgreso(100, _sMensajeErr);
                        OnProgreso(100, "Nuevas facturas integradas: " + iFacturasIntegradas.ToString());
                        OnProgreso(100, "Nuevas filas integradas: " + iFilasIntegradas.ToString());
                        OnProgreso(100, "Número de filas con error: " + (iTotal - iFilasIntegradas - iAntesIntegradas).ToString());
                        OnProgreso(100, "Número de filas anteriormente integradas: " + iAntesIntegradas.ToString());
                        OnProgreso(100, "Total de filas leídas: " + iTotal.ToString());
                        archivosEnTrabajo.paqueteExcel.Save();
                        archivosEnTrabajo.paqueteExcel.Dispose();
                        archivosEnTrabajo.mueveAFinalizado(sNombreArchivo, this._ParamExcel.rutaCarpeta.ToString(), sTimeStamp);

                        if (archivosEnTrabajo.iError != 0)
                        {
                            OnProgreso(100, archivosEnTrabajo.sMensaje);
                        }

                        OnActualiza(0, _ParamExcel.rutaCarpeta);
                    }
                    else
                    {
                        OnProgreso(0, archivosEnTrabajo.sMensaje);
                    }
                }
            }
            catch (Exception errorGral)
            {
                String im = errorGral.InnerException == null ? " " : " " + errorGral.InnerException.Message;
                if (errorGral.InnerException != null)
                {
                    im += errorGral.InnerException.InnerException == null ? " " : " " + errorGral.InnerException.InnerException.Message;
                }

                _sMensajeErr = "Excepción al leer la carpeta En trabajo. (Verifique que la versión del archivo excel sea 2007 o superior) " + errorGral.Message + im + errorGral.TargetSite.ToString();
                _iError++;
                OnProgreso(0, _sMensajeErr);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Abre los archivos excel de una carpeta y los integra a GP.
        /// </summary>
        public void procesaCarpetaEnTrabajo(List <string> archivosSeleccionados)
        {
            try
            {
                this.iError = 0;
                DirectoryInfo enTrabajoDir      = new DirectoryInfo(this._Param.rutaCarpeta.ToString() + "\\EnTrabajo");
                archivosExcel archivosEnTrabajo = new archivosExcel();

                foreach (string item in archivosSeleccionados)
                {
                    this.iError = 0;
                    string sTimeStamp     = System.DateTime.Now.ToString("yyMMdd.HHmmss");
                    string sNombreArchivo = item;

                    archivosEnTrabajo.abreArchivoExcel(enTrabajoDir.ToString(), sNombreArchivo);
                    ExcelWorksheet hojaXl = archivosEnTrabajo.paqueteExcel.Workbook.Worksheets.First();
                    if (archivosEnTrabajo.iError == 0)
                    {
                        int startRow            = _Param.facturaPmFilaInicial;
                        int iTotal              = hojaXl.Dimension.End.Row - startRow + 1;
                        int iFacturasIntegradas = 0;
                        int iFilasIntegradas    = 0;
                        int iFacturaIniciaEn    = 0;
                        int iAntesIntegradas    = 0;
                        int _columnaMensajes    = 20;

                        bool facturasPm = _DatosConexionDB.NombreArchivoParametros.Contains("facturaspm");
                        bool pagosPm    = _DatosConexionDB.NombreArchivoParametros.Contains("pagospm");

                        if (facturasPm)
                        {
                            _columnaMensajes = _Param.facturaPmColumnaMensajes;
                        }
                        if (pagosPm)
                        {
                            _columnaMensajes = _Param.PagosPmColMensajes;
                        }


                        OnProgreso(1, "INICIANDO CARGA DE ARCHIVO " + sNombreArchivo + "...");              //Notifica al suscriptor
                        if (startRow > 1)
                        {
                            hojaXl.Cells[startRow - 1, _columnaMensajes].Value = "Observaciones";
                        }

                        for (int rowNumber = startRow; rowNumber <= hojaXl.Dimension.End.Row; rowNumber++)
                        {
                            if (hojaXl.Cells[rowNumber, _columnaMensajes].Value == null ||
                                !hojaXl.Cells[rowNumber, _columnaMensajes].Value.ToString().Equals("Integrado a GP"))
                            {
                                if (facturasPm)
                                {
                                    integraFacturaPM(hojaXl, rowNumber, "F" + sTimeStamp);
                                }
                                else if (pagosPm)
                                {
                                    integraPagoPM(hojaXl, rowNumber, "P" + sTimeStamp);
                                }
                                else
                                {
                                    iError++;
                                    sMensaje = "No ha ingresado un nombre válido para el archivo de parámetros al iniciar la aplicación. " + _DatosConexionDB.NombreArchivoParametros;
                                }

                                //this.integraFacturaPOP(hojaXl, rowNumber, sTimeStamp);
                                iFacturaIniciaEn = rowNumber;
                                rowNumber        = _filaNuevaFactura - 1;

                                if (this.iError == 0)
                                {
                                    iFacturasIntegradas++;
                                    for (int ind = iFacturaIniciaEn; ind <= rowNumber; ind++)
                                    {
                                        hojaXl.Cells[ind, _columnaMensajes].Value = "Integrado a GP";
                                        iFilasIntegradas++;
                                    }
                                }
                                else
                                {
                                    hojaXl.Cells[rowNumber, _columnaMensajes].Value = this.sMensaje;
                                }
                            }
                            else
                            {
                                iAntesIntegradas++;
                                this.sMensajeDocu = "Fila: " + rowNumber.ToString();
                                this.sMensaje     = "anteriormente integrada.";
                            }
                            OnProgreso(100 / iTotal, this.sMensajeDocu + " " + this.sMensaje);
                        }
                        OnProgreso(100, "----------------------------------------------");
                        this.sMensaje = "INTEGRACION FINALIZADA";
                        OnProgreso(100, this.sMensaje);
                        OnProgreso(100, "Nuevos documentos integrados: " + iFacturasIntegradas.ToString());
                        OnProgreso(100, "Nuevas filas integradas: " + iFilasIntegradas.ToString());
                        OnProgreso(100, "Número de filas con error: " + (iTotal - iFilasIntegradas - iAntesIntegradas).ToString());
                        OnProgreso(100, "Número de filas anteriormente integradas: " + iAntesIntegradas.ToString());
                        OnProgreso(100, "Total de filas leídas: " + iTotal.ToString());
                        archivosEnTrabajo.paqueteExcel.Save();
                        archivosEnTrabajo.paqueteExcel.Dispose();
                        archivosEnTrabajo.mueveAFinalizado(sNombreArchivo, this._Param.rutaCarpeta.ToString(), sTimeStamp);

                        if (archivosEnTrabajo.iError != 0)
                        {
                            OnProgreso(100, archivosEnTrabajo.sMensaje);
                        }

                        OnActualiza(0, _Param.rutaCarpeta);
                    }
                    else
                    {
                        OnProgreso(0, archivosEnTrabajo.sMensaje);
                    }
                }
            }
            catch (Exception errorGral)
            {
                this.sMensaje = "Excepción encontrada al leer la carpeta En trabajo. " + errorGral.Message + " " + errorGral.TargetSite.ToString();
                iError++;
                OnProgreso(0, this.sMensaje);
            }
        }