private void RunSummaryByOrigin()
 {
     var clientId = int.Parse(ddlClient.SelectedValue);
     if (ddlClient.SelectedIndex == 0)
     {
         Response.Write("<script type='text/javascript'>alert('Please select a client!');</script>");
     }
     else
     {
         try
         {
             using (var client = new QCAstServiceClient())
             {
                 var clientName = client.GetClientFromId(clientId).ClientName;
                 rptViewer.LocalReport.DataSources.Add(new ReportDataSource("dsInvoiceSummary", client.GetSummaryByOrigin(clientId)));
                 rptViewer.ProcessingMode = ProcessingMode.Local;
                 rptViewer.LocalReport.ReportPath = @"Reports\StatementSummaryBySrc.rdlc";
                 var clientDescription = new ReportParameter("ClientDescription", clientName);
                 rptViewer.LocalReport.SetParameters(new[] { clientDescription });
                 rptViewer.LocalReport.EnableHyperlinks = true;
                 rptViewer.LocalReport.Refresh();
                 rptViewer.LocalReport.DataSources.Clear();
                 rptViewer.Reset();
             }
         }
         catch (Exception ex)
         {
             NotifyWebmasterOfError("Billing", "Report RunTopTwentyCallsByDuration", ex.ToString());
         }
     }
 }
        private void RunInvoiceHistory()
        {
            lblError.Text = "";
            try
            {
                int idClient  = int.Parse(Session["IdClient"].ToString());
                int idInvoice = int.Parse(ddlClientInvoiceHistory.SelectedValue);
                using (QCAstServiceClient client = new QCAstServiceClient())
                {
                    Client clientName = client.GetClientFromId(idClient);
                    rptViewer.LocalReport.DataSources.Clear();
                    rptViewer.Reset();
                    DateTime              invoiceDate      = client.GetInvoiceDate(idInvoice);
                    List <InvoiceDetail>  invoiceDetails   = client.GetInvoicedDetailsForClient(idClient, idInvoice);
                    List <InvoiceSummary> invoiceSummaries = client.GetInvoicedSummaryForClient(idClient, idInvoice);
                    if (invoiceDetails.Count == 0)
                    {
                        lblError.Text = string.Format("No data available for invoice date {0}", invoiceDate);
                    }
                    else
                    {
                        ReportDataSource rdInvDetail = new ReportDataSource("dsInvoiceDetail",
                                                                            invoiceDetails.AsEnumerable());
                        ReportDataSource 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";

                        string startDate =
                            invoiceDetails.OrderByDescending(p => p.CallDate).LastOrDefault().CallDate.ToString();
                        string endDate =
                            invoiceDetails.OrderByDescending(p => p.CallDate).FirstOrDefault().CallDate.ToString();

                        ReportParameter ClientDescription = new ReportParameter("ClientDescription", clientName.ClientName);
                        ReportParameter ReportDescription = new ReportParameter("ReportDescription",
                                                                                "From : " + startDate +
                                                                                Environment.NewLine + "To     : " +
                                                                                endDate);
                        ReportParameter TotalDuration = new ReportParameter("TotalDuration",
                                                                            client.GetTotalDuration(idClient, invoiceDate));
                        rptViewer.LocalReport.SetParameters(new ReportParameter[]
                        {
                            ClientDescription, ReportDescription, TotalDuration
                        });
                        rptViewer.LocalReport.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                NotifyWebmasterOfError("ClientBilling", "Billing RunInvoiceHistory", 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.";
            }
        }
        protected void lbSearchedClients_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = int.Parse(((ListBox)sender).SelectedValue);

            ClearListAndTextboxes();
            try
            {
                using (QCAstServiceClient client = new QCAstServiceClient())
                {
                    Client fetchedClient = client.GetClientFromId(id);
                    tbClientId.Text   = fetchedClient.IdClient.ToString();
                    tbClientDesc.Text = fetchedClient.ClientName;
                    tbRangeFrom.Text  = fetchedClient.RangeFrom != null?fetchedClient.RangeFrom.Value.ToString() : "";

                    tbRangeTo.Text = fetchedClient.RangeTo != null?fetchedClient.RangeTo.Value.ToString() : "";

                    tbClientCode.Text     = fetchedClient.ClientCode;
                    tbAccountingCode.Text = fetchedClient.AccountingCode;
                    tbCellular.Text       = fetchedClient.CellularNumber ?? "";
                    tbEmail.Text          = fetchedClient.Email ?? "";
                    ddlPrefContactMethod.SelectedIndex =
                        ddlPrefContactMethod.Items.IndexOf(
                            ddlPrefContactMethod.Items.FindByValue(fetchedClient.ContactMethod.ToString()));
                    tbMaxDuration.Text = fetchedClient.MaxCallDuration != null
                                             ? fetchedClient.MaxCallDuration.Value.ToString()
                                             : "";

                    tbMaxIntDuration.Text = fetchedClient.MaxIntCallDuration != null
                                                ? fetchedClient.MaxIntCallDuration.Value.ToString()
                                                : "";

                    string maxIntPrice = fetchedClient.MaxIntCallPrice != null
                                             ? fetchedClient.MaxIntCallPrice.Value.ToString()
                                             : "";

                    tbMaxIntPrice.Text = maxIntPrice != "" ? maxIntPrice.Remove(maxIntPrice.Length - 4, 3) : "";
                    string maxPrice = fetchedClient.MaxCallPrice != null
                                          ? fetchedClient.MaxCallPrice.Value.ToString()
                                          : "";

                    tbMaxPrice.Text = maxPrice != "" ? maxPrice.Remove(maxPrice.Length - 4, 3) : "";
                }
                ibEditClient.Enabled   = true;
                ibDeleteClient.Enabled = true;
            }
            catch (Exception ex)
            {
                NotifyWebmasterOfError("Billing", "User Management SearchSelectedIndexChanged", ex.ToString());
            }
        }