protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             GoogleAdsenseController objController = new GoogleAdsenseController();
             _userModuleCount = objController.CountAdSense(Int32.Parse(hdnUserModuleID.Value), GetPortalID);
         }
         catch (Exception ex)
         {
             ProcessException(ex);
         }
         if (_userModuleCount > 0)
         {
             BindAdsControl();
         }
         else if (_userModuleCount == 0)
         {
             //BindDefaultAdsControl();
         }
         else
         {
             AdsenseDisplay.Visible = false;
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         imbDelete.Attributes.Add("onclick", "javascript:return confirm('" + GetSageMessage("Adsense", "AreYouSureToDelete") + "')");
         AddImageUrls();
         BindDropDowns();
         try
         {
             GoogleAdsenseController objController = new GoogleAdsenseController();
             _userModuleCount = objController.CountAdsenseSettings(userModuleID, GetPortalID);
         }
         catch (Exception ex)
         {
             ProcessException(ex);
         }
         if (_userModuleCount > 0)
         {
             BindControls();
         }
     }
 }
        private void BindAdsControl()
        {
            try
            {
                AdsenseDisplay.Visible = true;
                GoogleAdsenseController objController = new GoogleAdsenseController();
                List<GoogleAdsenseInfo> adsenseSetting = objController.GetAdSenseSettingsByUserModuleID(Int32.Parse(hdnUserModuleID.Value), GetPortalID);
                foreach (GoogleAdsenseInfo adsContent in adsenseSetting)
                {
                    switch (adsContent.SettingName)
                    {
                        case "AdsenseUnitFormat":
                            AdsenseDisplay.AdUnitFormat = (AdUnitFormat)Enum.Parse(typeof(AdUnitFormat), adsContent.SettingValue, true);
                            break;
                        case "AdsenseUnitType":
                            AdsenseDisplay.AdUnitType = (AdUnitType)Enum.Parse(typeof(AdUnitType), adsContent.SettingValue, true);
                            break;
                        case "AdsenseChannelID":
                            AdsenseDisplay.ChannelId = adsContent.SettingValue;
                            break;
                        case "AdsenseBorderColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.BorderColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseBackColor":

                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.BackColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseLinkColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.LinkColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseTextColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.TextColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseURLColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.UrlColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseAnotherURL":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.AnotherUrl = adsContent.SettingValue.Trim();
                            }
                            break;
                        case "AdsenseSolidFillColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                AdsenseDisplay.SolidFillColor = System.Drawing.ColorTranslator.FromHtml("#" + adsContent.SettingValue.Trim());
                            }
                            break;
                        case "AdsenseAlternateAds":
                            if (adsContent.SettingValue.Trim() != "" && adsContent.SettingValue.Trim() != "-1")
                            {
                                AdsenseDisplay.AlternateAdType = (AlternateAdTypes)Enum.Parse(typeof(AlternateAdTypes), adsContent.SettingValue, true);
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        private void BindControls()
        {
            try
            {
                bool isPublic = false;
                GoogleAdsenseController objController = new GoogleAdsenseController();
                List<GoogleAdsenseInfo> adsenseSetting = objController.GetAdSenseSettingsByUserModuleID(userModuleID, GetPortalID);
                foreach (GoogleAdsenseInfo adsContent in adsenseSetting)
                {
                    switch (adsContent.SettingName)
                    {
                        case "AdsenseShow":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                chkShow.Checked = bool.Parse(adsContent.SettingValue);
                            }
                            break;
                        case "AdsenseUnitFormat":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                ddlUnitFormat.SelectedValue = adsContent.SettingValue;
                                chkActive.Checked = (bool)adsContent.IsActive;
                            }
                            break;
                        case "AdsenseUnitType":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                ddlAddType.SelectedValue = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseChannelID":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtChannelID.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseBorderColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtBorder.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseBackColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtbackcolor.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseLinkColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtLink.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseTextColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtText.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseURLColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                txtURL.Text = adsContent.SettingValue;
                            }
                            break;
                        case "AdsenseAnotherURL":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                if (isPublic == false)
                                {
                                    txtanotherURL.Text = adsContent.SettingValue;
                                    anotherURL.Visible = true;
                                    solidFill.Visible = false;
                                }
                            }
                            break;
                        case "AdsenseSolidFillColor":
                            if (adsContent.SettingValue.Trim() != "")
                            {
                                if (isPublic == false)
                                {
                                    txtSolidFill.Text = adsContent.SettingValue;
                                    solidFill.Visible = true;
                                    anotherURL.Visible = false;
                                }
                            }
                            break;
                        case "AdsenseAlternateAds":
                            ddlAlternateAds.SelectedValue = adsContent.SettingValue;
                            if (adsContent.SettingValue == "-1")
                            {
                                solidFill.Visible = false;
                                anotherURL.Visible = false;
                            }
                            if (adsContent.SettingValue == "0")
                            {
                                isPublic = true;
                                solidFill.Visible = false;
                                anotherURL.Visible = false;
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
            imbDelete.Visible = true;
            //lblDelete.Visible = true;

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool IsActive = false;
            bool UpdateFlag = false;
            if (chkActive.Checked == true)
            {
                IsActive = true;
            }
            try
            {
                GoogleAdsenseController objController = new GoogleAdsenseController();
                _userModuleCount = objController.CountAdsenseSettings(userModuleID, GetPortalID);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }

            if (_userModuleCount > 0)
            {
                UpdateFlag = true;
            }
            SaveAdsense(IsActive, UpdateFlag);
            PreviewAds();
        }
        private void DeleteAdsense()
        {
            try
            {
                GoogleAdsenseController objController = new GoogleAdsenseController();
                objController.DeleteAdSense(userModuleID, GetPortalID);
                ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("Adsense", "AdsenseDeletedSuccessfully"), "", SageMessageType.Success);

            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        protected void imbDelete_Click(object sender, EventArgs e)
        {
            try
            {
                GoogleAdsenseController objController = new GoogleAdsenseController();
                objController.CountAdsenseSettings(userModuleID, GetPortalID);
                ClearForm();
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }

            if (_userModuleCount > 0)
            {
                DeleteAdsense();
            }
        }
        protected void SaveAdsense(bool IsActive, bool updateFlag)
        {
            try
            {
                string channelID = string.Empty;
                if (txtChannelID.Text != string.Empty)
                {
                    channelID = txtChannelID.Text;
                }
                else
                {
                    channelID = pb.GetSettingValueByIndividualKey(SageFrameSettingKeys.PortalGoogleAdsenseChannelID);
                }

                GoogleAdsenseController objController = new GoogleAdsenseController();

                objController.AddUpdateAdSense(userModuleID, "AdsenseShow", chkShow.Checked.ToString(), IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseUnitFormat", ddlUnitFormat.SelectedValue, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseUnitType", ddlAddType.SelectedValue, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseChannelID", channelID, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseBorderColor", txtBorder.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseBackColor", txtbackcolor.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseLinkColor", txtLink.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseTextColor", txtText.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                objController.AddUpdateAdSense(userModuleID, "AdsenseURLColor", txtURL.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                if (ddlAlternateAds.SelectedValue != "-1")
                {
                    objController.AddUpdateAdSense(userModuleID, "AdsenseAlternateAds", ddlAlternateAds.SelectedValue, IsActive, GetPortalID, GetUsername, updateFlag);
                    if (ddlAlternateAds.SelectedValue == "1")
                    {

                        objController.AddUpdateAdSense(userModuleID, "AdsenseAnotherURL", txtanotherURL.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                        objController.AddUpdateAdSense(userModuleID, "AdsenseSolidFillColor", "", IsActive, GetPortalID, GetUsername, updateFlag);
                    }
                    else if (ddlAlternateAds.SelectedValue == "2")
                    {

                        objController.AddUpdateAdSense(userModuleID, "AdsenseSolidFillColor", txtSolidFill.Text, IsActive, GetPortalID, GetUsername, updateFlag);
                        objController.AddUpdateAdSense(userModuleID, "AdsenseAnotherURL", "", IsActive, GetPortalID, GetUsername, updateFlag);
                    }
                }
                else
                {

                    objController.AddUpdateAdSense(userModuleID, "AdsenseAlternateAds", ddlAlternateAds.SelectedValue, IsActive, GetPortalID, GetUsername, updateFlag);
                    objController.AddUpdateAdSense(userModuleID, "AdsenseAnotherURL", "", IsActive, GetPortalID, GetUsername, updateFlag);
                    objController.AddUpdateAdSense(userModuleID, "AdsenseSolidFillColor", "", IsActive, GetPortalID, GetUsername, updateFlag);
                }
                ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("Adsense", "AdsenseSavedSuccessfully"), "", SageMessageType.Success);

            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }