protected void Page_Load(object sender, EventArgs e)
        {
            IncludePage(HowItWorksInc, Resources.Resource.incHowItWorks);
            IncludePage(ProtectInc, Resources.Resource.incProtect);
            IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement);

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);
                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = string.Format(Resources.Resource.spnCredits, Util.GetUserCredits(Util.UserId));
                ProtectedLiteral.Text = string.Format(Resources.Resource.spnProtected, protectedTracks);
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
            }
        }
        protected void AddCoArtist(object sender, CommandEventArgs e)
        {
            bool found = false;
            if (CoArtistDropDown.SelectedIndex < 0)
                return;

            using (Database db = new MySqlDatabase())
            {
                long userId = Convert.ToInt64(CoArtistDropDown.SelectedValue);
                if (userId > 0)
                {
                    UserInfo ui = db.GetUser(userId);
                    ClientInfo ci = db.GetClientInfo(userId);

                    Session["user.userid"] = userId;
                    AddCoArtistRow(CoArtistsTable, ci.GetFullName(), CoArtistRole.Text, ci.ClientId);

                    DataView dataView = new DataView(CoArtistsTable);
                    CoArtistsList.DataSource = dataView;
                    CoArtistsList.DataBind();

                    found = true;
                }
            }
            if (!found)
                ErrorMessage.Text = Resources.Resource.ClientNotFound;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["pid"] != null)
            {
                long productId;
                if (!long.TryParse(Request.Params["pid"], out productId))
                    productId = 0;
                Session["quotation.pid"] = productId;
            }

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);
                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = string.Format(Resources.Resource.spnCredits, Util.GetUserCredits(Util.UserId));
                ProtectedLiteral.Text = string.Format(Resources.Resource.spnProtected, protectedTracks);
                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "relationships";
            IncludePage(ProtectInc, Resources.Resource.incProtect);
            IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            string fullname = string.Empty;
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                fullname = ci.FirstName; //ci.GetFullName();
                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", fullname);
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            string email = Request.Params["email"] ?? "???";
            string format = Resources.Resource.fmtInviteSuccess;
            if (Request.Params["mode"] != null)
            {
                if (Request.Params["mode"] == "1")
                    format = Resources.Resource.fmtInviteExists;
            }
            InviteSuccessLiteral.Text = string.Format(format, email);

            if (!IsPostBack)
            {
            }

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        protected void TpIdSearch(object sender, CommandEventArgs e)
        {
            string email = TpIdText.Text;
            using (Database db = new MySqlDatabase())
            {
                long userId = db.GetUserIdByEmail(email);
                UserInfo ui = db.GetUser(userId);
                ClientInfo ci = db.GetClientInfo(userId);

                Session["mgmt.userid"] = userId;
                ManagerNameLabel.Text = ci.GetFullName();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "relationships";
            Session["loggedinUserEmail"] = string.Empty;
            Util.GetUserClearanceLevels(Util.UserId, out _vcl, out _ecl);
            if (_vcl < 100 && _ecl < 100)
            {
                divManaccChk.Visible = false;
            }
            else
            {
                divManaccChk.Visible = true;
            }
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;
                Session["loggedinUserEmail"] = ui.Email;
                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            //------- Highlight the selected lang button ------- !

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);

                ddl_Language.SelectedValue = "nl";
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);

                ddl_Language.SelectedValue = "en";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                IncludePage(AccountOverviewInc, Resources.Resource.incMemberHome);
                IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

                using (Database db = new MySqlDatabase())
                {

                    UserInfo ui = db.GetUser(Util.UserId);
                    ClientInfo ci = db.GetClientInfo(Util.UserId);

                    DataSet ds = db.GetRegister(Util.UserId);
                    int protectedTracks = ds.Tables[0].Rows.Count;

                    LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                    LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); //ci.GetFullName());
                    CreditsLiteral.Text = string.Format(Resources.Resource.spnCredits, Util.GetUserCredits(Util.UserId));
                    ProtectedLiteral.Text = string.Format(Resources.Resource.spnProtected, protectedTracks);

                    string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                    decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                    Session["percentComplete"] = percentComplete;
                    CompletedLiteral.Text = string.Empty;
                    if (percentComplete < 100)
                        CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                    ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
                }

                FillAccountInformation();

                int couponEntry = 0;
                if (Session["coupon.entry"] != null)
                    couponEntry = (int)Session["coupon.entry"];

                if (!IsPostBack)
                {
                    using (Database db = new MySqlDatabase())
                    {
                        int violationState = db.GetUserWhmcsClientId(Util.UserId);
                        if (violationState == 1)
                            couponEntry = 3;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(LogLevel.Error, ex, "AccountOverView<Exception>");
            }
        }
        public void Persist(
            OAuthTokenResponse me,
            string oauth_token,
            string oauth_verifier)
        {
            if (_clientInfo == null)
                GetUser();

            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "twitterid", Convert.ToString(me.UserId));
                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "oauthtoken", oauth_token);
                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "oauthverifier", oauth_verifier);

                _clientInfo.TwitterId = me.ScreenName;

                db.RegisterClientInfo(
                    _clientInfo.LastName,
                    _clientInfo.FirstName,
                    _clientInfo.AddressLine1,
                    _clientInfo.AddressLine2,
                    _clientInfo.ZipCode,
                    _clientInfo.State,
                    _clientInfo.City,
                    _clientInfo.Country,
                    _clientInfo.Language,
                    _clientInfo.Telephone,
                    _clientInfo.Cellular,
                    _clientInfo.CompanyName,
                    _clientInfo.UserId,
                    _clientInfo.AccountOwner,
                    _clientInfo.BumaCode,
                    _clientInfo.SenaCode,
                    _clientInfo.IsrcCode,
                    _clientInfo.TwitterId,
                    _clientInfo.FacebookId,
                    _clientInfo.SoundCloudId,
                    _clientInfo.SoniallId,
                    _clientInfo.OwnerKind,
                    _clientInfo.CreditCardNr,
                    _clientInfo.CreditCardCvv,
                    _clientInfo.EmailReceipt,
                    _clientInfo.Referer,
                    _clientInfo.Gender,
                    _clientInfo.Birthdate,
                    _clientInfo.stagename);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "tracks";
            IncludePage(SelectProductInc, Resources.Resource.incSelectProduct);
            IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            long userId = Util.UserId;

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            getProductList(userId);

            SetProductItemLinks();

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript
                    (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript
                    (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript
                    (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript
                    (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            IncludePage(FAQInc, Resources.Resource.incFAQ);
            //IncludePage(ProtectInc, Resources.Resource.incProtect);
            //IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement);
            UserInformation();
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                //CreditsLiteral.Text     = string.Format(Resources.Resource.spnCredits, Util.GetUserCredits(Util.UserId));
                CreditsLiteral.Text = Convert.ToString(Util.GetUserCredits(Util.UserId));
                //ProtectedLiteral.Text = string.Format(Resources.Resource.spnProtected, protectedTracks);
                ProtectedLiteral.Text = Convert.ToString(protectedTracks);
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            //------- Highlight the selected lang button ------- !

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }

            ClientScript.RegisterStartupScript(this.GetType(), "HighLightMenu", "HighLightMenu('" + "Menu4" + "');", true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string retUrl = Request.Params["url"].Trim('#');

            string accessToken = string.Empty;

            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                string[] kvps = retUrl.Split('&');
                foreach (string kvp in kvps)
                {
                    string[] parts = kvp.Split('=');
                    if (parts.Length == 2)
                    {
                        string key = parts[0];
                        string val = parts[1];

                        if (val.EndsWith(",/social/soundcloud.aspx"))
                            val = val.Substring(0, val.Length - ",/social/soundcloud.aspx".Length);

                        if (string.Compare(key, "access_token", true) == 0)
                            accessToken = val;
                        db.UpdateSocialCredential(ci.ClientId, SocialConnector.SoundCloud, key, val);
                    }
                }
            }

            if (!string.IsNullOrEmpty(accessToken))
            {
                string userName = GetUserData(accessToken);

                using (Database db = new MySqlDatabase())
                {
                    UserInfo ui = db.GetUser(Util.UserId);

                    ClientInfo ci = db.GetClientInfo(ui.UserId);

                    db.UpdateSoundCloudId(ci.ClientId, userName);

                }
            }
        }
        protected void Page_PreRender(Object o, EventArgs e)
        {
            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                bool isNotExpired = true;

                Facebook.AuthenticationService authService = new Facebook.AuthenticationService();

                Facebook.Me me;
                string accessToken = string.Empty;

                if (authService.TryAuthenticate(out me, out accessToken))
                {
                    isNotExpired = true;
                }
                else
                {
                    db.RemoveSocialCredential(ci.ClientId, SocialConnector.Facebook);
                    db.UpdateFacebookID(ci.ClientId);

                    isNotExpired = false;
                }

                if (!string.IsNullOrEmpty(ci.SoundCloudId))
                    SoundcloudItag.Attributes.Add("class", "soundcloud");
                else
                    SoundcloudItag.Attributes.Add("class", "soundcloud disabled");

                if (isNotExpired)
                    FacebookHeading.Attributes.Add("class", "social facebook");
                else
                    FacebookHeading.Attributes.Add("class", "social facebook disabled");

                if (!string.IsNullOrEmpty(ci.TwitterId))
                    TwitterHeading.Attributes.Add("class", "social twitter");
                else
                    TwitterHeading.Attributes.Add("class", "social twitter disabled");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string scope = Request.QueryString["scope"];

            string access_token = Request.QueryString["access_token"];

            if (!string.IsNullOrEmpty(access_token))
            {
                using (Database db = new MySqlDatabase())
                {
                    UserInfo ui = db.GetUser(Util.UserId);

                    ClientInfo ci = db.GetClientInfo(ui.UserId);

                    db.UpdateSocialCredential(ci.ClientId, SocialConnector.SoundCloud, "access_token", access_token);

                    db.UpdateSocialCredential(ci.ClientId, SocialConnector.SoundCloud, "scope", scope);

                    db.UpdateSoundCloudId(ci.ClientId, GetUserData(access_token));
                }
            }
        }
        protected void CouponCodeGoCommand(object sender, CommandEventArgs e)
        {
            string couponCode = CouponCodeEdit.Text;
            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                if (db.CheckActivationCode(couponCode))
                {
                    // Code is ok, raise the number of credits for this user
                    db.MarkActivationCode(couponCode, Util.UserId);

                    Config cfg = new Config();
                    cfg.Load(Server.MapPath("~/Config/trackprotect.config"));

                    long prodid = 0;
                    if (cfg["activationcode.productid"] != null)
                        prodid = Convert.ToInt64(cfg["activationcode.productid"]);
                    // Get the credits from the database
                    ProductInfo pi = db.GetProductById(prodid);

                    if (pi != null && pi.ProductId > 0)
                    {
                        // How many credits to issue
                        string transactionIdCoupon = string.Format("COUPON {0}", couponCode);
                        long orderId = db.CreateTransaction(Util.UserId, 0m, prodid, pi.Description);
                        db.UpdateTransaction(orderId.ToString(), "OK", "OK", "Payment Completed", "COUPON", couponCode, couponCode, transactionIdCoupon, "COUPON", 0m, pi, "EUR", Util.GetCountryIso2(ci.Country));
                        db.UpdateUserCredits(Util.UserId, prodid, pi.Credits);
                        db.AddCreditHistory(Util.UserId, prodid, pi.Credits, orderId);
                        Response.Redirect(string.Format("~/Member/CouponSuccess.aspx?cradd={0}", pi.Credits), false);
                    }
                }
                else
                {
                    Response.Redirect(string.Format("~/Member/CouponFailure.aspx?couponcode={0}", couponCode), false);
                }
            }
        }
        protected void ddlManagedArtist_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["managed.userid"] = ((DropDownList)sender).SelectedValue;

            if (Convert.ToInt32(Session["managed.userid"]) > 0)
                using (Database db = new MySqlDatabase())
                {
                    ClientInfo _ManagedUserInfo = db.GetClientInfo(Convert.ToInt64(Session["managed.userid"]));

                    PopulateSocialMediaInfo(db);

                    Session["ManagedUser"] = _ManagedUserInfo.FirstName;
                }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "coupon";
            UserInfo ui = null;
            ClientInfo ci = null;

            new BasePage();

            using (Database db = new MySqlDatabase())
            {
                ui = db.GetUser(Util.UserId);
                ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);

                if (Convert.ToString(Session["culture"]).Contains("nl"))
                {
                    ClientScript.RegisterStartupScript
                        (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                    ClientScript.RegisterStartupScript
                        (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                }
                else
                {
                    ClientScript.RegisterStartupScript
                        (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                    ClientScript.RegisterStartupScript
                        (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                }

                divTrackProtected.Visible = true;

                if (Convert.ToBoolean(Session["TrackProtected"]) == true)
                {
                    TrackProtected.Text = Resources.Resource.TrackProtectedSuccessNotify;

                    #region SoundCloud

                    divSoundCloudPost.Visible = true;

                    if (Convert.ToString(Session["SoundCloud.Response"]).Contains("Deactive"))
                        divSoundCloudPost.Visible = false;
                    else if (Convert.ToString(Session["SoundCloud.Response"]).Contains("Error"))
                        SoundCloudPost.Text = Resources.Resource.SoundCloudPostFailureNotify;
                    else if (!string.IsNullOrEmpty(Convert.ToString(Session["SoundCloud.Response"])))
                        SoundCloudPost.Text = Resources.Resource.SoundCloudPostSuccessNotify;

                    #endregion

                    #region Facebook My/User wall

                    if (Request.QueryString["type"] == "own")
                    {
                        divFacebookPost.Visible = true;

                        if (Convert.ToString(Session["Facebook.Response"]).Contains("Deactive"))
                            divFacebookPost.Visible = false;
                        else if (Convert.ToString(Session["Facebook.Response"]).Contains("Error"))
                            FacebookPost.Text = string.Format(Resources.Resource.FacebookPostOnOwnWallFailureNotify, Convert.ToString(Session["TPForUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["Facebook.Response"])))
                            FacebookPost.Text = string.Format(Resources.Resource.FacebookPostOnOwnWallSuccessNotify, Convert.ToString(Session["TPForUser"]));
                    }
                    else
                    {
                        divFacebookPost.Visible = true;

                        if (Convert.ToString(Session["Facebook.Response"]).Contains("Deactive"))
                            divFacebookPost.Visible = false;
                        else if (Convert.ToString(Session["Facebook.Response"]).Contains("Error"))
                            FacebookPost.Text = string.Format(Resources.Resource.FacebookPostOnUserWallFailureNotify, Convert.ToString(Session["ManagedUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["Facebook.Response"])))
                            FacebookPost.Text = string.Format(Resources.Resource.FacebookPostOnUserWallSuccessNotify, Convert.ToString(Session["ManagedUser"]));
                    }

                    #endregion

                    #region Facebook Genre

                    divFacebookGenreCommunityPost.Visible = true;

                    if (Convert.ToString(Session["FacebookGenre.Response"]).Contains("Deactive"))
                        divFacebookGenreCommunityPost.Visible = false;
                    else if (Convert.ToString(Session["FacebookGenre.Response"]).Contains("Error"))
                        FacebookGenreCommunityPost.Text = string.Format(Resources.Resource.FacebookGenreCommunityPostFailureNotify, Convert.ToString(Session["GenrePageName"]));
                    else if (!string.IsNullOrEmpty(Convert.ToString(Session["FacebookGenre.Response"])))
                        FacebookGenreCommunityPost.Text = string.Format(Resources.Resource.FacebookGenreCommunityPostSuccessNotify, Convert.ToString(Session["GenrePageName"]));

                    #endregion

                    #region Facebook SubGenre

                    divFacebookSubGenreCommunityPost.Visible = true;

                    if (Convert.ToString(Session["FacebookSubGenre.Response"]).Contains("Deactive"))
                        divFacebookSubGenreCommunityPost.Visible = false;
                    else if (Convert.ToString(Session["FacebookSubGenre.Response"]).Contains("Error"))
                        FacebookSubGenreCommunityPost.Text = string.Format(Resources.Resource.FacebookGenreCommunityPostFailureNotify, Convert.ToString(Session["SubGenrePageName"]));
                    else if (!string.IsNullOrEmpty(Convert.ToString(Session["FacebookSubGenre.Response"])))
                        FacebookSubGenreCommunityPost.Text = string.Format(Resources.Resource.FacebookGenreCommunityPostSuccessNotify, Convert.ToString(Session["SubGenrePageName"]));

                    #endregion

                    #region Facebook to Friends

                    if (Request.QueryString["type"] == "own")
                    {
                        divPostOnFriendWall.Visible = true;

                        if (Convert.ToString(Session["ShareToFriends"]).Contains("Deactive"))
                            divPostOnFriendWall.Visible = false;
                        else if (Convert.ToString(Session["ShareToFriends"]).Contains("Error"))
                            PostOnFriendWall.Text = string.Format(Resources.Resource.PostOnMyFriendWallFailureNotify, Convert.ToString(Session["TPForUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToFriends"])))
                            PostOnFriendWall.Text = string.Format(Resources.Resource.PostOnMyFriendWallSuccessNotify, Convert.ToString(Session["TPForUser"]));
                    }
                    else
                    {
                        divPostOnFriendWall.Visible = true;

                        if (Convert.ToString(Session["ShareToFriends"]).Contains("Deactive"))
                            divPostOnFriendWall.Visible = false;
                        else if (Convert.ToString(Session["ShareToFriends"]).Contains("Error"))
                            PostOnFriendWall.Text = string.Format(Resources.Resource.PostOnFriendWallFailureNotify, Convert.ToString(Session["ManagedUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToFriends"])))
                            PostOnFriendWall.Text = string.Format(Resources.Resource.PostOnFriendWallSuccessNotify, Convert.ToString(Session["ManagedUser"]));
                    }

                    #endregion

                    #region Facebook to Pages

                    if (Request.QueryString["type"] == "own")
                    {
                        divPostOnPages.Visible = true;

                        if (Convert.ToString(Session["ShareToPages"]).Contains("Deactive"))
                            divPostOnPages.Visible = false;
                        else if (Convert.ToString(Session["ShareToPages"]).Contains("Error"))
                            PostOnPages.Text = string.Format(Resources.Resource.PostOnMyPagesFailureNotify, Convert.ToString(Session["TPForUser"]), "");
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToPages"])))
                            PostOnPages.Text = string.Format(Resources.Resource.PostOnMyPagesSuccessNotify, Convert.ToString(Session["TPForUser"]), "");
                    }
                    else
                    {
                        divPostOnPages.Visible = true;

                        if (Convert.ToString(Session["ShareToPages"]).Contains("Deactive"))
                            divPostOnPages.Visible = false;
                        else if (Convert.ToString(Session["ShareToPages"]).Contains("Error"))
                            PostOnPages.Text = string.Format(Resources.Resource.PostOnPagesFailureNotify, Convert.ToString(Session["ManagedUser"]), "");
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToPages"])))
                            PostOnPages.Text = string.Format(Resources.Resource.PostOnPagesSuccessNotify, Convert.ToString(Session["ManagedUser"]), "");
                    }

                    #endregion

                    if (Request.QueryString["type"] != "own")
                    {
                        divPostToOwnWall.Visible = true;

                        if (Convert.ToString(Session["FacebookOwnPage.Response"]).Contains("Deactive"))
                            divPostOnPages.Visible = false;
                        else if (Convert.ToString(Session["FacebookOwnPage.Response"]).Contains("Error"))
                            PostToOwnWall.Text =
                              string.Format(Resources.Resource.FacebookPostOnOwnWallFailureNotify, Convert.ToString(Session["TPForUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["FacebookOwnPage.Response"])))
                            PostToOwnWall.Text =
                                string.Format(Resources.Resource.FacebookPostOnOwnWallSuccessNotify, Convert.ToString(Session["TPForUser"]));

                        divPostOnMyFriendWall.Visible = true;

                        if (Convert.ToString(Session["ShareToOwnFriends"]).Contains("Deactive"))
                            divPostOnMyFriendWall.Visible = false;
                        else if (Convert.ToString(Session["ShareToOwnFriends"]).Contains("Error"))
                            PostOnMyFriendWall.Text = string.Format(Resources.Resource.PostOnMyFriendWallFailureNotify, Convert.ToString(Session["TPForUser"]));
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToOwnFriends"])))
                            PostOnMyFriendWall.Text = string.Format(Resources.Resource.PostOnMyFriendWallSuccessNotify, Convert.ToString(Session["TPForUser"]));

                        divPostOnMyPages.Visible = true;

                        if (Convert.ToString(Session["ShareToOwnPages"]).Contains("Deactive"))
                            divPostOnMyPages.Visible = false;
                        else if (Convert.ToString(Session["ShareToOwnPages"]).Contains("Error"))
                            PostOnMyPages.Text = string.Format(Resources.Resource.PostOnMyPagesFailureNotify, Convert.ToString(Session["TPForUser"]), "");
                        else if (!string.IsNullOrEmpty(Convert.ToString(Session["ShareToOwnPages"])))
                            PostOnMyPages.Text = string.Format(Resources.Resource.PostOnMyPagesSuccessNotify, Convert.ToString(Session["TPForUser"]), "");
                    }

                    #region Twitter

                    divTwitterpost.Visible = true;

                    if (Convert.ToString(Session["Twitter.Response"]).Contains("Deactive"))
                        divTwitterpost.Visible = false;
                    else if (Convert.ToString(Session["Twitter.Response"]).Contains("Error"))
                        Twitterpost.Text = Resources.Resource.TwitterpostFailureNotify;
                    else if (!string.IsNullOrEmpty(Convert.ToString(Session["Twitter.Response"])))
                        Twitterpost.Text = Resources.Resource.TwitterpostSuccessNotify;

                    #endregion
                }
                else
                {
                    TrackProtected.Text = Resources.Resource.TrackProtectedFailureNotify;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "tracks";
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    long managedUserId = Convert.ToInt64(Request["id"]);
                    Session["managed.userid"] = managedUserId;
                    FillRegistrationGrid(Util.UserId, managedUserId);
                }
            }

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript
                    (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript
                    (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript
                    (this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript
                    (this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        private DataTable GetManagers()
        {
            DataTable table = new DataTable("managers");
            table.Columns.Add("name", typeof (string));
            table.Columns.Add("vcl", typeof (int));
            table.Columns.Add("ecl", typeof (int));

            using (Database db = new MySqlDatabase())
            {
                DataTable dt = db.GetManagers();
                foreach (DataRow row in dt.Rows)
                {
                    long userId = (long) row["user_id"];
                    ClientInfo ci = db.GetClientInfo(userId);
                    int vcl = 0, ecl = 0;
                    Util.GetUserClearanceLevels(userId, out vcl, out ecl);

                    DataRow newRow = table.NewRow();
                    newRow["name"] = ci.GetFullName();
                    newRow["vcl"] = vcl;
                    newRow["ecl"] = ecl;
                    table.Rows.Add(newRow);
                }
            }
            return table;
        }
 private string CreateCertificate(long userid, string doc1, string doc2, string doc3, string isrcCode, string trackName, CoopArtistList coopArtists)
 {
     ClientInfo ci = null;
     using (Database db = new MySqlDatabase())
     {
         ci = db.GetClientInfo(Util.UserId);
     }
     string ret = string.Empty;
     using (CertificateManager mgr = new CertificateManager(userid, string.Empty))
     {
         mgr.AddTrackName(trackName);
         if (!string.IsNullOrEmpty(doc1))
             mgr.AddDocument(doc1);
         if (!string.IsNullOrEmpty(doc2))
             mgr.AddDocument(doc2);
         if (!string.IsNullOrEmpty(doc3))
             mgr.AddDocument(doc3);
         if (!string.IsNullOrEmpty(isrcCode))
             mgr.AddIsrcCode(isrcCode);
         foreach (CoopArtist coop in coopArtists)
             mgr.AddCoopArtist(coop.Artist, coop.Role);
         if (ci != null)
             mgr.Agent = ci.GetFullName();
         mgr.CreateCertificate(string.Format("{0}.cer", DateTime.UtcNow.ToString("yyyyMMddHHmmss")));
         ret = mgr.CertificateFilename;
     }
     return ret;
 }
        private void UserInformation()
        {
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);
                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName); // ci.GetFullName());
                CreditsLiteral.Text = Convert.ToString(Util.GetUserCredits(Util.UserId));
                ProtectedLiteral.Text = Convert.ToString(protectedTracks);

                MemberSince.Text = Convert.ToString(ui.MemberSince);

                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                Session["percentComplete"] = percentComplete;
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }
        }
        /// <summary>
        /// Fill the control with account information
        /// </summary>
        private void FillAccountInformation()
        {
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                Name.Text = ci.FirstName + " " + ci.LastName;
                StageName.Text = ci.stagename;
                CompanyName.Text = ci.CompanyName;
                if (ci.Gender == 'm' || ci.Gender == 'M')
                    Gender.Text = "Male";
                else if (ci.Gender == 'f' || ci.Gender == 'F')
                    Gender.Text = "Female";
                DOB.Text = Convert.ToString(ci.Birthdate).Split(' ')[0];
                Address.Text = ci.AddressLine1 + System.Environment.NewLine + ci.AddressLine2;
                Pincode.Text = ci.ZipCode;
                City.Text = ci.City;
                State.Text = ci.State;
                Country.Text = ci.Country;
                Number.Text = ci.Telephone;
                BumaNo.Text = ci.BumaCode;
                SenaNo.Text = ci.SenaCode;
                ISRC.Text = ci.IsrcCode;

                if (!string.IsNullOrEmpty(ci.TwitterId))
                {
                    lblTwitter.Text = "CONNECTED AS";
                    TwitterIdLabel.Text = ci.TwitterId;
                    TwitterIdLabel.Visible = true;
                    twitterdiv.Visible = true;
                    RemoveTwitter.Visible = true;
                    linkTwitter.Enabled = false;
                }
                else
                {
                    lblTwitter.Text = "CONNECT";
                    TwitterIdLabel.Visible = false;
                    RemoveTwitter.Visible = false;
                    twitterdiv.Visible = false;
                    linkTwitter.Enabled = true;
                }

                if (!string.IsNullOrEmpty(ci.FacebookId))
                {
                    lblFacebook.Text = "CONNECTED AS";
                    FacebookIdLabel.Text = ci.FacebookId;
                    FacebookIdLabel.Visible = true;
                    facebookdiv.Visible = true;
                    RemoveFacebook.Visible = true;
                    linkFacebook.Enabled = false;
                }
                else
                {
                    lblFacebook.Text = "CONNECT";
                    facebookdiv.Visible = false;
                    FacebookIdLabel.Visible = false;
                    RemoveFacebook.Visible = false;
                    linkFacebook.Enabled = true;
                }

                if (!string.IsNullOrEmpty(ci.SoundCloudId))
                {
                    lblsoundcloud.Text = "CONNECTED AS";
                    SoundCloudLabel.Text = ci.SoundCloudId;
                    SoundCloudLabel.Visible = true;
                    soundclouddiv.Visible = true;
                    RemoveSoundCloud.Visible = true;
                    linkSoundCloud.Enabled = false;
                }
                else
                {
                    lblsoundcloud.Text = "CONNECT";
                    soundclouddiv.Visible = false;
                    SoundCloudLabel.Visible = false;
                    RemoveSoundCloud.Visible = false;
                    linkSoundCloud.Enabled = true;
                }

                OwnerKind.Text = ci.OwnerKind;
                Email.Text = ui.Email;

                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                string identDocName = string.Format("ID{0:D10}.cer", ui.UserId);
                string identDocPath = Path.Combine(userDocPath, identDocName);

                // Assume the button will need to be visible, if not so we will discover afterwards
                if (File.Exists(identDocPath))
                {
                    IdentityCertificate.Text = Path.GetFileName(identDocPath);
                    DownloadIdent.Visible = true;
                    //DownloadIdent.NavigateUrl = string.Format("~/DownloadHandler.ashx?file='{0}'", Server.MapPath(identDocPath));
                    DownloadIdent.Attributes.Add("onclick", "InitializeRequest('" + identDocPath.Replace("\\", "/") + "');");
                }
                else
                {
                    // credential document has been marked as 'old' due to changed information
                    // of the client and no new credential file has been uploaded
                    identDocName = string.Format("ID{0:D10}.0.cer", ui.UserId);
                    identDocPath = Path.Combine(userDocPath, identDocName);
                    if (File.Exists(identDocPath))
                    {
                        IdentityCertificate.Text = Path.GetFileName(identDocPath);
                        DownloadIdent.Visible = true;
                        //DownloadIdent.NavigateUrl = string.Format("~/DownloadHandler.ashx?file='{0}'", Server.MapPath(identDocPath));
                        DownloadIdent.Attributes.Add("onclick", "InitializeRequest('" + identDocPath.Replace("\\", "/") + "');");
                    }
                }
            }
        }
        protected void RemoveTwitter_Submit(object sender, EventArgs e)
        {
            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                db.RemoveSocialCredential(ci.ClientId, SocialConnector.Twitter);
                db.UpdateTwitterID(ci.ClientId);
            }

            UserInformation();
            FillAccountInformation();

            Session["RemoveBtnIsFired"] = true;
        }
 private void FillManagedRelationsTable()
 {
     StringBuilder sb = new StringBuilder();
     ManagedRelations.Clear();
     using (Database db = new MySqlDatabase())
     {
         UserInfo[] uis = db.GetManagedUsers(Util.UserId, 0);
         foreach (UserInfo ui in uis)
         {
             ClientInfo ci = db.GetClientInfo(ui.UserId);
             int relType = db.DetermineRelationType(Util.UserId, ui.UserId);
             AddManagedRelationRow(sb, ManagedRelations, ci.GetFullName(), ui.UserId, relType);
         }
         ManagedRelations.DefaultView.Sort = "name ASC";
         ArtistsTable.DataSource = ManagedRelations;
         ArtistsTable.DataBind();
         dlMyRelations.DataSource = ManagedRelations;
         dlMyRelations.DataBind();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "relationships";
            //IncludePage(ProtectInc, Resources.Resource.incProtect);
            //IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            Util.GetUserClearanceLevels(Util.UserId, out _vcl, out _ecl);

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
                TpIdButton.Height = TpIdText.Height;

                if (ManagedRelations == null)
                {
                    DataTable dt = new DataTable("artists");
                    dt.Columns.Add("name", typeof(string));
                    dt.Columns.Add("userid", typeof(long));
                    dt.Columns.Add("reltype", typeof(int));
                    dt.Columns.Add("manage", typeof(bool));
                    ManagedRelations = dt;
                }
                FillManagedRelationsTable();
                if (Invitations == null)
                {
                    DataTable dt = new DataTable("confirmations");
                    dt.Columns.Add("name", typeof(string));
                    dt.Columns.Add("email", typeof(string));
                    dt.Columns.Add("confirmation_id", typeof(long));
                    dt.Columns.Add("relation_type", typeof(int));
                    Invitations = dt;
                }
                FillInvitationsTable();
            }

            //------- Highlight the selected lang button ------- !

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        private void FillInvitationsTable()
        {
            StringBuilder sb = new StringBuilder();
            Invitations.Clear();
            using (Database db = new MySqlDatabase())
            {
                DataTable dt = db.GetInvitations(Util.UserId);
                pendingInvitationsHeader.Visible = (dt.Rows.Count > 0);
                foreach (DataRow row in dt.Rows)
                {
                    long confId = Convert.ToInt64(row["confirmation_id"]);
                    long userId = Convert.ToInt64(row["requesting_user_id"]);
                    int relType = Convert.ToInt32(row["relationtype"]);

                    UserInfo ui = db.GetUser(userId);
                    ClientInfo ci = db.GetClientInfo(userId);

                    AddInvitationsRow(Invitations, ci.GetFullName(), ui.Email, confId, relType);
                }
                Invitations.DefaultView.Sort = "name ASC";
                pendingInvitations.DataSource = Invitations;
                pendingInvitations.DataBind();
            }
        }
        private void FillCoArtistsDropDown()
        {
            CoArtistDropDown.Items.Clear();

            CoArtistDropDown.Items.Add(new ListItem("---", "0"));
            using (Database db = new MySqlDatabase())
            {
                UserInfo[] uis = db.GetManagedUsers(Util.UserId, 0);
                foreach (UserInfo ui in uis)
                {
                    ClientInfo ci = db.GetClientInfo(ui.UserId);
                    CoArtistDropDown.Items.Add(new ListItem(ci.GetFullName(), ui.UserId.ToString()));
                }
            }
        }
        protected void ArtistsTable_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
                return;

            string username = string.Empty;
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                // check all cells in one row
                foreach (Control control in cell.Controls)
                {
                    if (control is HiddenField)
                    {
                        HiddenField hfd = control as HiddenField;
                        long targetId = 0;
                        if (!long.TryParse(hfd.Value, out targetId))
                            targetId = 0;

                        using (Database db = new MySqlDatabase())
                        {
                            ClientInfo ci = db.GetClientInfo(targetId);
                            username = ci.GetFullName();
                        }
                    }

                    // Must use LinkButton here instead of ImageButton
                    // if you are having Links (not images) as the command button.
                    ImageButton button = control as ImageButton;
                    if (button != null && button.CommandName == "DeleteUser")
                    {
                        // Add delete confirmation
                        if (string.IsNullOrEmpty(username))
                            username = "******";
                        string question = string.Format(Resources.Resource.ConfirmDelete, username);
                        button.OnClientClick = string.Format("if (!confirm('{0}')) return;", question);
                        DataRow row = (e.Row.DataItem as DataRowView).Row;
                        bool manage = (bool)row["manage"];
                        int reltype = (int)row["reltype"];

                        // Negate 'manage' here first since it indicates whether a user
                        // CAN be managed, not whether it IS managed.
                        button.ToolTip = (!manage) ? Resources.Resource.DeleteManagedRelation : Resources.Resource.DeleteNormalRelation;
                    }
                    else if (button != null && button.CommandName == "RelateUser")
                    {
                        DataRow row = (e.Row.DataItem as DataRowView).Row;
                        bool manage = (bool)row["manage"];
                        int reltype = (int)row["reltype"];

                        // Add relation
                        button.Visible = (_ecl >= 100 && manage && reltype == 0);
                    }
                }
            }
        }
        private bool FillFacebookInfo(ClientInfo ManagedUserInfo)
        {
            if (ManagedUserInfo != null)
                if (!string.IsNullOrEmpty(ManagedUserInfo.FacebookId))
                {
                    using (Database db = new MySqlDatabase())
                    {
                        ClientInfo ci = db.GetClientInfo(Convert.ToInt64(Session["managed.userid"]));

                        Session["FBACC"] = db.GetSocialCredential(ci.ClientId, SocialConnector.Facebook, "accesstoken");

                        string expiresRaw = db.GetSocialCredential(ci.ClientId, SocialConnector.Facebook, "accesstokenexpires");

                        Facebook.AuthenticationService authServices = new Facebook.AuthenticationService();

                        if (authServices.TryAuthenticateAdminFBCred(expiresRaw, Convert.ToString(Session["FBACC"])))
                        {
                            Me me = authServices.GetMe(Convert.ToString(Session["FBACC"]));

                            try
                            {
                                Session["FBID"] = me.Id;
                            }
                            catch { }

                            FillFBFriendList(Convert.ToString(Session["FBACC"]));

                            FillFBPageList(Convert.ToString(Session["FBACC"]));

                            cbxShareToUserWall.Enabled = true;

                            cbxShareToUserWall.Visible = true;

                            divShareToUserWall.Visible = true;

                            return true;
                        }
                        else
                        {
                            Session["FBACC"] = Session["FBID"] = null;

                            db.RemoveSocialCredential(ci.ClientId, SocialConnector.Facebook);

                            db.UpdateFacebookID(ci.ClientId);

                            FillFBFriendList(null);

                            FillFBPageList(null);

                            cbxShareToUserWall.Enabled = false;

                            cbxShareToUserWall.Visible = false;

                            divShareToUserWall.Visible = false;

                            return false;
                        }
                    }
                }

            Session["FBACC"] = Session["FBID"] = null;

            FillFBFriendList(null);

            FillFBPageList(null);

            cbxShareToUserWall.Enabled = false;

            cbxShareToUserWall.Visible = false;

            divShareToUserWall.Visible = false;

            return false;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["bodyid"] = "coupon";
            // IncludePage(ProtectInc, Resources.Resource.incProtect);
            //IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                decimal percentComplete = 0m;
                if (Session["percentComplete"] != null)
                    percentComplete = Convert.ToDecimal(Session["percentComplete"]);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
                Config cfg = new Config();
                cfg.Load(Server.MapPath("~/Config/trackprotect.config"));

                int couponCodeCount = 0;
                if (Session["coupon.entry"] != null)
                    couponCodeCount = (int)Session["coupon.entry"];
                if (couponCodeCount < 3)
                    ++couponCodeCount;
                Session["coupon.entry"] = couponCodeCount;

                if (couponCodeCount < 3)
                {
                    ErrorCode.Text = string.Format("<span style=\"color: orange;\">{0}</span>", Resources.Resource.CouponIncorrect);
                }
                else
                {
                    string couponCode = Request.Params["couponcode"];
                    using (Database db = new MySqlDatabase())
                    {
                        ClientInfo ci = db.GetClientInfo(Util.UserId);
                        ErrorCode.Text = string.Format("<span style=\"color: red;\">{0}</span>",
                                                       Resources.Resource.CouponError);
                        StringBuilder body = new StringBuilder();
                        body.AppendFormat("The user with id {0} ({1}) entered too many invalid coupon codes.",
                                          Util.UserId, ci.GetFullName());
                        body.Append(Environment.NewLine);
                        body.AppendFormat("The last coupon code entered was {0}.", couponCode);
                        body.Append(Environment.NewLine);
                        body.Append("Coupon code entry was disabled");

                        Util.SendEmail(new string[] { cfg["email.admin"] }, "*****@*****.**", "Invalid coupon entry", body.ToString(), null,0);

                        // Register entry violation in the database
                        // Alright. Some abuse here, we're going to use the whmcsclient_id here to store the violation.
                        // The id isn't used anymore since whmcs has been abandoned and thus it remains simply an integer.
                        db.UpdateUserWhmcsClientId(Util.UserId, 1);
                    }
                }
            }

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        protected void AccountOverview_Click(object sender, EventArgs e)
        {
            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                string password = Session["access"] as string;
                string uploadPath = db.GetUserDocumentPath(Util.UserId, password);

                //GenerateAccountOverView(
                //    Server.MapPath(Path.Combine(uploadPath, "/Temporaryfiles/AccInfo_" + ui.UserId + "_" + ci.FirstName + "_" + ci.LastName + ".pdf")),
                //    HttpContext.Current.Server.MapPath(Resources.Resource.AccountOverViewTemplate),
                //    ci, ui);

                using (StreamReader reader = new StreamReader(Server.MapPath("~") + "/HtmlTemplates/accountoverview_template_en_form.html"))
                {
                    String htmlText = reader.ReadToEnd();

                    HtmlToPdf(Server.MapPath(Path.Combine(uploadPath, "/Temporaryfiles/AccInfo_" + ui.UserId + "_" + ci.FirstName + "_" + ci.LastName + ".pdf")),
                        htmlText,
                        ci, ui);
                }
            }
        }