internal static void GenerarReporte() { const string methodName = "GenerarReporte"; Collection <Empleado> colEmpleados; List <Empleado> colEmp; reportInfo rptInfoStateObj; try { Log.WriteEntry(ClassName, methodName, TraceEventType.Information, "Generar Reporte."); EsperaPorTarea(TipoEspera.Reporte); colEmpleados = bdsTodosEmpleados.DataSource as Collection <Empleado>; colEmp = new List <Empleado>(colEmpleados); rptInfoStateObj = new reportInfo(); rptInfoStateObj.DataSet = colEmp; rptInfoStateObj.DataSetName = "Empleados"; rptInfoStateObj.Parameter = _fechaConsulta.TextoNombreMesReporte; rptInfoStateObj.ParameterName = "parNombreMesAnno"; rptInfoStateObj.ReportAsString = myReport.ReportAsString; const string rptPath = "Reports\\"; rptInfoStateObj.ReportLoadPath = rptPath + "report.frx"; if (_userRole == UserRoleEnum.JefeDepartamento) { //rptInfoStateObj.PdfReportPath = rptPath + "reporte_" + _userDeptName + "_" + rptInfoStateObj.Parameter + ".pdf"; rptInfoStateObj.PdfReportPath = string.Format("{0}reporte_{1}_{2}.pdf", rptPath, _userDeptName, rptInfoStateObj.Parameter); } else { //rptInfoStateObj.PdfReportPath = rptPath + "reporte_" + rptInfoStateObj.Parameter + ".pdf"; rptInfoStateObj.PdfReportPath = string.Format("{0}reporte_{1}.pdf", rptPath, rptInfoStateObj.Parameter); } ReporteOnTaskDelegate rtd = GenerarReporteOnTask; rtd.BeginInvoke(rptInfoStateObj, ReporteOnTaskCompleted, rtd); } catch (Exception ex) { Log.WriteEntry(ClassName, methodName, TraceEventType.Error, string.Format("Error: {0}", ex.Message)); } finally { colEmpleados = null; colEmp = null; rptInfoStateObj = null; } }
// Callback asíncrono. private static void ReporteOnTaskCompleted(IAsyncResult ar) { ReporteOnTaskDelegate rtd = ar.AsyncState as ReporteOnTaskDelegate; bool ret = rtd.EndInvoke(ar); if (ret) { FinEsperaPorTarea(TipoEspera.Reporte); } else { FinEsperaPorTarea(TipoEspera.ReporteError); } }