private void RunCurrentInvoice() { lblError.Text = ""; try { DateTime periodEndDate; var idClient = int.Parse(ddlClients.SelectedValue); if (DateTime.TryParseExact(Request.Form[txtEndDate.UniqueID], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out periodEndDate)) { using (var client = new QCAstServiceClient()) { rptViewer.LocalReport.DataSources.Clear(); rptViewer.Reset(); List <InvoiceDetail> invoiceDetails = client.GetUninvoicedDetailsForClient(idClient, periodEndDate); List <InvoiceSummary> invoiceSummaries = client.GetUninvoicedSummaryForClient(idClient, periodEndDate); if (invoiceDetails.Count == 0) { lblError.Text = string.Format("No data available for Client {0}", ddlClients.SelectedItem.Text); } else { var rdInvDetail = new ReportDataSource("dsInvoiceDetail", invoiceDetails.AsEnumerable()); var rdInvSummary = new ReportDataSource("dsInvoiceSummary", invoiceSummaries.AsEnumerable()); rptViewer.LocalReport.DataSources.Add(rdInvDetail); rptViewer.LocalReport.DataSources.Add(rdInvSummary); rptViewer.ProcessingMode = ProcessingMode.Local; rptViewer.LocalReport.ReportPath = @"Reports\InvoiceDetail.rdlc"; var startDate = invoiceDetails.OrderByDescending(p => p.CallDate).LastOrDefault().CallDate.ToString(); var endDate = invoiceDetails.OrderByDescending(p => p.CallDate).FirstOrDefault().CallDate.ToString(); var clientDescription = new ReportParameter("ClientDescription", ddlClients.SelectedItem.ToString()); var reportDescription = new ReportParameter("ReportDescription", "From : " + startDate + Environment.NewLine + "To : " + endDate); var totalDuration = new ReportParameter("TotalDuration", client.GetTotalDuration(idClient, periodEndDate)); rptViewer.LocalReport.SetParameters(new ReportParameter[] { clientDescription, reportDescription, totalDuration }); rptViewer.LocalReport.Refresh(); btnCreateInvoice.Visible = true; } } } else { Response.Write("<script type='text/javascript'>alert('Please select a valid date');</script>"); } } catch (Exception ex) { NotifyWebmasterOfError("Billing", "Billing RunCurrentInvoice", ex.ToString()); lblError.Text = "The website encountered a problem retrieving the invoice detail for this report. The webmaster has been notified and will be attending to the problem."; } }