Ejemplo n.º 1
0
        private async Task validaArchivosAsync(IProgress <int> prbar, UtilitarioArchivos utileria)
        {
            string archivo    = String.Empty;
            string directorio = String.Empty;

            //carga y validar archivos
            int i   = 1;
            int max = gridFiles.Rows.Count;

            foreach (DataGridViewRow row in gridFiles.Rows)
            {
                try
                {
                    var item = row.DataBoundItem;
                    if (item != null)
                    {
                        System.Type type = item.GetType();
                        archivo    = (string)type.GetProperty("archivo").GetValue(item, null);
                        directorio = (string)type.GetProperty("directorio").GetValue(item, null);

                        var cmp = await utileria.CargarArchivoAsync(directorio + "\\" + archivo);

                        if (cmp.ValidaSelloAsync())
                        {
                            row.Cells[1].Style.BackColor = Color.LawnGreen;
                        }
                        else
                        {
                            row.Cells[1].Style.BackColor = Color.LightGray;
                        }

                        if (prbar != null)
                        {
                            prbar.Report(100 * i / max);
                            //lblProcesos.Text += "Validando : " + archivo + Environment.NewLine ;
                        }
                        i++;
                    }
                }
                catch (Exception ex)
                {
                    lblError.Text += "Excepción al leer " + archivo + " " + ex.Message + Environment.NewLine;
                }
            }
            prbar.Report(0);
        }
Ejemplo n.º 2
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (gridVista.SelectedRows.Count != 0)
            {
                try
                {
                    string             carpeta = System.Configuration.ConfigurationManager.AppSettings[companySelected() + "_directorio"].ToString();
                    DcemVwContabilidad item    = (DcemVwContabilidad)gridVista.SelectedRows[0].DataBoundItem;
                    if (item != null)
                    {
                        var    iTipoDoc      = lParametros.Where(x => x.Tipo == item.tipodoc);
                        string nombreArchivo = iTipoDoc.First().Archivo;
                        nombreArchivo = Path.GetFileNameWithoutExtension(nombreArchivo) + "_" + DateTime.Now.ToString("yyyyMMdd HHmmss");
                        string archivo = Path.Combine(carpeta, nombreArchivo + ".xlsx");

                        object    items   = mostrarContenido(item.year1, item.periodid, item.tipodoc);
                        DataTable dtItems = ContabilidadElectronicaPresentacion.ConvierteLinqQueryADataTable((IEnumerable <dynamic>)items);
                        var       wb      = new ClosedXML.Excel.XLWorkbook();

                        dtItems.TableName = "test";
                        wb.Worksheets.Add(dtItems);
                        //wb.Worksheet(1).Cell("B1").Value = "0";

                        //wb.Worksheet(1).Column(2).CellsUsed().SetDataType(XLDataType.Number);

                        //wb.Worksheet(1).Cell("B1").Value = "Saldo Inicial";

                        wb.SaveAs(archivo);
                        UtilitarioArchivos.AbrirArchivo(archivo);
                        lblProcesos.Text = "Archivo guardado en: " + archivo;
                    }
                }
                catch (Exception exl)
                {
                    grid.DataSource = null;
                    lblError.Text   = exl.Message;
                }
            }
        }
Ejemplo n.º 3
0
 private void inicializarImportarXML()
 {
     utileria = new UtilitarioArchivos(@"http://www.sat.gob.mx/cfd/3", System.Configuration.ConfigurationManager.AppSettings[companySelected() + "_archivoXslt"].ToString());
 }