protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    using (QCAstServiceClient client = new QCAstServiceClient())
                    {
                        int  idUser = int.Parse(Session["IdUser"].ToString());
                        User user   = client.GetUserFromId(idUser);

                        if (user.IdProfile != 4 & user.IdProfile != 3)
                        {
                            Response.Redirect("ErrorPage.aspx?Error=NotAuthorised", false);
                        }
                        else
                        {
                            ddlPrefContactMethod.DataSource = client.GetAllContactMethods();
                            ddlPrefContactMethod.DataBind();
                            lbSearchedClients.DataSource = client.GetAllClients("All", "");
                            lbSearchedClients.DataBind();
                            ddlPrefContactMethod.Items.Insert(0, new ListItem("Please select..", "0"));
                            trButtons.Visible      = false;
                            ibEditClient.Enabled   = false;
                            ibDeleteClient.Enabled = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    NotifyWebmasterOfError("Billing", "Client Management Page Load", ex.ToString());
                    Response.Redirect("ErrorPage.aspx?Error=GeneralError", true);
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         if (Session["IdUser"] == null)
         {
             FormsAuthentication.RedirectToLoginPage();
         }
         else
         {
             var idUser = int.Parse(Session["IdUser"].ToString());
             try
             {
                 using (var serviceClient = new QCAstServiceClient())
                 {
                     var user = serviceClient.GetUserFromId(idUser);
                     if (user.IdProfile != 4)
                     {
                         Response.Redirect("ErrorPage.aspx?Error=NotAuthorised");
                     }
                     else
                     {
                         ddlReport.DataSource = serviceClient.GetAllReports();
                         ddlReport.DataBind();
                         ddlReport.Items.Insert(0, new ListItem("Please select..", "0"));
                         ddlClient.DataSource = serviceClient.GetAllClients("All", "");
                         ddlClient.DataBind();
                         ddlClient.Items.Insert(0, new ListItem("Please select..", "0"));
                         ClearListAndTextBoxes();
                     }
                 }
             }
             catch (Exception ex)
             {
                 NotifyWebmasterOfError("Billing", "Reports PageLoad", ex.ToString());   
             }
         }
     }
 }
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            string searchTerm = tbSearch.Text;

            ClearListAndTextboxes();

            if (searchTerm == "" & rblSearchFormat.SelectedValue != "All")
            {
                lblSearchError.Text = "Please enter a search term";
            }
            else
            {
                try
                {
                    using (QCAstServiceClient client = new QCAstServiceClient())
                    {
                        lblSearchError.Text = "";
                        List <Client> clients = client.GetAllClients(rblSearchFormat.SelectedValue, searchTerm);

                        if (clients == null)
                        {
                            lblSearchError.Text    = "No results found";
                            lblSearchError.Visible = true;
                        }
                        else
                        {
                            lbSearchedClients.DataSource = clients;
                            lbSearchedClients.DataBind();
                        }
                    }
                }
                catch (Exception ex)
                {
                    NotifyWebmasterOfError("Billing", "Client Management Search", ex.ToString());
                    lblSearchError.Text = "Error experienced";
                }
            }
        }