private async void exportar_button_Click(object sender, EventArgs e) { if (resultados == null || resultados.DataSource == null) { return; } using (var dialogGuardar = new SaveFileDialog()) { dialogGuardar.Filter = "CSV |*.csv"; dialogGuardar.OverwritePrompt = true; if (dialogGuardar.ShowDialog() == DialogResult.OK) { FileInfo archivo = new FileInfo(dialogGuardar.FileName); try { Exportando(true); ConfigTareaLabel($"Exportando { resultados.List.Count.ToString("#,##0") } filas..."); await Ayudantes.GuardarCsvReporteAsync(reportes : resultados.List.Cast <ReporteVentaModelo>().ToList(), archivo : archivo); MessageBox.Show("Tarea completada", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (IOException ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Exportando(false); ConfigTareaLabel(visible: false); }
private async void exportar_inventario_button_Click(object sender, EventArgs e) { var frm = new HistorialLotesFiltroForm(this); this.Hide(); frm.ShowDialog(); this.Show(); var destino = GuardarDialogo(); if (destino == null) { return; } Exportando(true); CambiarTareaLabel("Exportando..."); List <ReporteInventarioModelo> reportes; int?comienzo = 0; try { do { reportes = await Task.Run(() => ConfigGlobal.conexion.CargarReporteInventario(reporteFiltro, limiteFilas: LimiteFilas, comienzo: comienzo) ); await Ayudantes.GuardarCsvReporteAsync(reportes, destino); comienzo = reportes.LastOrDefault()?.LoteId; } while (reportes.Count > 0); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); Exportando(false); return; } MessageBox.Show("Tarea completada", "", MessageBoxButtons.OK, MessageBoxIcon.Information); Exportando(false); reporteFiltro = null; }