private void btnGenerateCsv_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } int depotId = 0; int.TryParse(cboDepot.SelectedValue, out depotId); int vehicleId = 0; int.TryParse(cboVehicle.SelectedValue, out vehicleId); RevenuePerVehicleReportData reportData; Facade.IJob facJob = new Facade.Job(); if (depotId == 0 && vehicleId == 0) //All Depots - All Vehicles { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value); } else if (depotId != 0 && vehicleId == 0) //Single Depot - All Vehicle { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value, depotId); } else //Doesn't Matter - Single Vehicle { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value, depotId, vehicleId); } var vehicles = reportData.Depots.SelectMany(dptSummary => dptSummary.Vehicles); List <CsvExport.PropertyMapping <VehicleRevenue> > mappings = new List <CsvExport.PropertyMapping <VehicleRevenue> >(); if (vehicleId == 0) { mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Depot", t => t.DepotName)); mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Vehicle", t => t.VehicleName)); } else { mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Vehicle", t => t.DepotName)); mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Driver", t => t.VehicleName)); } mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Revenue", t => t.Revenue_Formatted)); mappings.Add(new CsvExport.PropertyMapping <VehicleRevenue>("Percent Of Total", t => t.PercentOfDepotTotal_Formatted)); CsvExport.Export <VehicleRevenue>(vehicles, "RevenuePerVehicleReport.csv", mappings); }
private InstanceReportSource GenerateReport() { int depotId = 0; int.TryParse(cboDepot.SelectedValue, out depotId); int vehicleId = 0; int.TryParse(cboVehicle.SelectedValue, out vehicleId); RevenuePerVehicleReportData reportData; Facade.IJob facJob = new Facade.Job(); if (depotId == 0 && vehicleId == 0) //All Depots - All Vehicles { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value); } else if (depotId != 0 && vehicleId == 0) //Single Depot - All Vehicle { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value, depotId); } else //Doesn't Matter - Single Vehicle { reportData = facJob.GetRevenuePerVehicleData(dteStartDate.SelectedDate.Value, dteEndDate.SelectedDate.Value, depotId, vehicleId); } var typeName = "Orchestrator.Reports.rptRevenuePerVehicle, Orchestrator.Reports"; var reportType = Type.GetType(typeName); var report = (Telerik.Reporting.Report)Activator.CreateInstance(reportType, reportData); foreach (IReportParameter reportParameter in report.ReportParameters) { switch (reportParameter.Name) { case "fromDate": reportParameter.Value = dteStartDate.SelectedDate.Value.ToShortDateString(); break; case "toDate": reportParameter.Value = dteEndDate.SelectedDate.Value.ToShortDateString(); break; case "depot": reportParameter.Value = cboDepot.Text; break; case "vehicle": reportParameter.Value = cboVehicle.Text; break; } } return(new InstanceReportSource { ReportDocument = report }); }