Exemple #1
0
        public override bool ApplyChanges()
        {
            EnsureChildControls();

            TitleWebpart.TitleWebpart webPartToEdit = (TitleWebpart.TitleWebpart) this.WebPartToEdit;
            if (webPartToEdit != null)
            {
                webPartToEdit.FirstString           = txtTitle1.Text;
                webPartToEdit.SecondString          = txtTitle2.Text;
                webPartToEdit.FirstBackColorString  = txtFirstBackColorBox.Text;
                webPartToEdit.FirstForeColorString  = txtFirstForeColorBox.Text;
                webPartToEdit.SecondBackColorString = txtSecondBackColorBox.Text;
                webPartToEdit.SecondForeColorString = txtSecondForeColorBox.Text;
                webPartToEdit.FirstFontName         = drpFirstFonts.SelectedValue;
                webPartToEdit.FirstFontSize         = int.Parse(drpFirstSize.SelectedValue);
                webPartToEdit.FirstFontItallic      = drpFirstItallic.SelectedIndex == 0 ? true : false;
                webPartToEdit.FirstFontBold         = drpFirstBold.SelectedIndex == 0 ? true : false;
                webPartToEdit.FirstFontUnderline    = drpFirstUnderline.SelectedIndex == 0 ? true : false;
                webPartToEdit.SecondFontName        = drpSecondFonts.SelectedValue;
                webPartToEdit.SecondFontSize        = int.Parse(drpSecondSize.SelectedValue);
                webPartToEdit.SecondFontItallic     = drpSecondItallic.SelectedIndex == 0 ? true : false;
                webPartToEdit.SecondFontBold        = drpSecondBold.SelectedIndex == 0 ? true : false;
                webPartToEdit.SecondFontUnderline   = drpSecondUnderline.SelectedIndex == 0 ? true : false;
                webPartToEdit.IsSyncronised         = drpSyncWithStore.SelectedIndex == 0 ? true : false;
                webPartToEdit.ImageUrl   = txtImageUrl.Text;
                webPartToEdit.ImageStyle = drpImageStyle.SelectedValue;
                webPartToEdit.IsDebug    = chkDebug.Checked;

                // sync with main storage
                if (drpSyncWithStore.SelectedValue.ToString().Equals("true"))
                {
                    using (SPSetttingsProvider prov = new SPSetttingsProvider())
                    {
                        bool error = prov.SaveSPSetting(webPartToEdit);
                        if (!error && prov.exception != null)
                        {
                            webPartToEdit.Error = prov.exception.ToString();
                        }
                    }

                    //SPSite site = SPContext.Current.Site;
                    //ThreadPool.QueueUserWorkItem(new WaitCallback(saveSPSettings), new ContextWrapper { _webPartToEdit = webPartToEdit, _webID = site.RootWeb.ID, _siteID = site.ID});
                }
            }
            return(true);
        }
Exemple #2
0
 void btnSyncronise_Click(object sender, EventArgs e)
 {
     TitleWebpart.TitleWebpart webPartToEditt = (TitleWebpart.TitleWebpart) this.WebPartToEdit;
     //if (drpSyncWithStore.SelectedValue.Equals("true"))
     //{
     using (SPSetttingsProvider provider = new SPSetttingsProvider())
     {
         bool error = provider.LoadSPSetting(webPartToEditt);
         if (!error && provider.exception != null)
         {
             webPartToEditt.Error = provider.exception.ToString();
         }
     }
     this.RenderControls();
     this.SyncChanges();
     //}
 }
Exemple #3
0
        public void saveSPSettings(object input)
        {
            TitleWebpart.TitleWebpart webPartToEdit = ((ContextWrapper)input)._webPartToEdit;
            Guid siteID = ((ContextWrapper)input)._siteID;
            Guid webID  = ((ContextWrapper)input)._webID;

            using (SPSite site = new SPSite(siteID))
            {
                using (SPWeb web = site.OpenWeb(webID))
                {
                    using (SPSetttingsProvider prov = new SPSetttingsProvider(site.RootWeb))
                    {
                        bool error = prov.SaveSPSetting(webPartToEdit);
                        if (!error && prov.exception != null)
                        {
                            webPartToEdit.Error = prov.exception.ToString();
                        }
                    }
                }
            }
        }
Exemple #4
0
        public bool LoadSPSetting(TitleWebpart.TitleWebpart webpart)
        {
            try
            {
                SPSite site = SPContext.Current.Site;
                using (SPWeb web = site.RootWeb)
                {
                    SPList listInstance = web.Lists.TryGetList(Constants.SettingsListName);

                    if (listInstance == null)
                    {
                        throw new Exception("Titlewebpartpropertylist is not found");
                    }
                    else
                    {
                        SPListItemCollection items = listInstance.Items;
                        foreach (SPListItem item in items)
                        {
                            // init first
                            if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstBackColorString"))
                            {
                                webpart.FirstBackColorString = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontBold"))
                            {
                                webpart.FirstFontBold = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontItallic"))
                            {
                                webpart.FirstFontItallic = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontName"))
                            {
                                webpart.FirstFontName = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontSize"))
                            {
                                webpart.FirstFontSize = item[Constants.SettingsListPropertyValue] == null ? 0 : int.Parse(item[Constants.SettingsListPropertyValue].ToString());
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontUnderline"))
                            {
                                webpart.FirstFontUnderline = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstForeColorString"))
                            {
                                webpart.FirstForeColorString = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }

                            // init second
                            if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondBackColorString"))
                            {
                                webpart.SecondBackColorString = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontBold"))
                            {
                                webpart.SecondFontBold = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontItallic"))
                            {
                                webpart.SecondFontItallic = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontName"))
                            {
                                webpart.SecondFontName = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontSize"))
                            {
                                webpart.SecondFontSize = item[Constants.SettingsListPropertyValue] == null ? 0 : int.Parse(item[Constants.SettingsListPropertyValue].ToString());
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontUnderline"))
                            {
                                webpart.SecondFontUnderline = item[Constants.SettingsListPropertyValue].ToString().Equals("true") ? true : false;
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondForeColorString"))
                            {
                                webpart.SecondForeColorString = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }

                            if (item[Constants.SettingsListPropertyName].ToString().Equals("ImageStyle"))
                            {
                                webpart.ImageStyle = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                            else if (item[Constants.SettingsListPropertyName].ToString().Equals("ImageUrl"))
                            {
                                webpart.ImageUrl = item[Constants.SettingsListPropertyValue] == null ? string.Empty : item[Constants.SettingsListPropertyValue].ToString();
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
            return(false);
        }
Exemple #5
0
        public bool SaveSPSetting(TitleWebpart.TitleWebpart webpart)
        {
            try
            {
                var webID = SPContext.Current == null ? _web.ID : SPContext.Current.Site.RootWeb.ID;

                using (SPWeb web = SPContext.Current == null ? _web : SPContext.Current.Site.OpenWeb(webID))
                {
                    bool oldUnsafe = web.AllowUnsafeUpdates;
                    web.AllowUnsafeUpdates = true;
                    SPList listInstance = web.Lists.TryGetList(Constants.SettingsListName);

                    if (listInstance == null)
                    {
                        throw new Exception("Titlewebpartpropertylist is not found");
                    }
                    else
                    {
                        SPListItemCollection items = listInstance.GetItems();

                        try
                        {
                            foreach (SPListItem item in items)
                            {
                                // init first
                                if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstBackColorString"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstBackColorString;
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontBold"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstFontBold ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontItallic"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstFontItallic ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontName"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstFontName.ToString();
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontSize"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstFontSize.ToString();
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstFontUnderline"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstFontUnderline ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("FirstForeColorString"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.FirstForeColorString;
                                }

                                // init second
                                if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondBackColorString"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondBackColorString;
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontBold"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondFontBold ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontItallic"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondFontItallic ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontName"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondFontName;
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontSize"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondFontSize;
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondFontUnderline"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondFontUnderline ? "true" : "false";
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("SecondForeColorString"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.SecondForeColorString;
                                }

                                if (item[Constants.SettingsListPropertyName].ToString().Equals("ImageStyle"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.ImageStyle;
                                }
                                else if (item[Constants.SettingsListPropertyName].ToString().Equals("ImageUrl"))
                                {
                                    item[Constants.SettingsListPropertyValue] = webpart.ImageUrl;
                                }

                                item.SystemUpdate();
                            }
                        }
                        finally
                        {
                            web.AllowUnsafeUpdates = oldUnsafe;
                        }

                        //listInstance.Update();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                exception = ex;
                //throw ex;
                return(false);
            }

            return(false);
        }
Exemple #6
0
        public override void SyncChanges()
        {
            EnsureChildControls();

            TitleWebpart.TitleWebpart webPartToEdit = (TitleWebpart.TitleWebpart) this.WebPartToEdit;
            if (webPartToEdit != null)
            {
                txtTitle1.Text             = webPartToEdit.FirstString;
                txtTitle2.Text             = webPartToEdit.SecondString;
                txtFirstBackColorBox.Text  = webPartToEdit.FirstBackColorString;
                txtFirstForeColorBox.Text  = webPartToEdit.FirstForeColorString;
                txtSecondBackColorBox.Text = webPartToEdit.SecondBackColorString;
                txtSecondForeColorBox.Text = webPartToEdit.SecondForeColorString;

                if (webPartToEdit.FirstFontItallic)
                {
                    drpFirstItallic.SelectedIndex = 0;
                }
                else
                {
                    drpFirstItallic.SelectedIndex = 1;
                }


                if (webPartToEdit.FirstFontBold)
                {
                    drpFirstBold.SelectedIndex = 0;
                }
                else
                {
                    drpFirstBold.SelectedIndex = 1;
                }


                if (webPartToEdit.FirstFontUnderline)
                {
                    drpFirstUnderline.SelectedIndex = 0;
                }
                else
                {
                    drpFirstUnderline.SelectedIndex = 1;
                }


                int fontIndex = 0;
                foreach (ListItem item in drpFirstFonts.Items)
                {
                    if (item.Text.Equals(webPartToEdit.FirstFontName))
                    {
                        break;
                    }
                    fontIndex++;
                }
                drpFirstFonts.SelectedIndex = fontIndex >= drpFirstFonts.Items.Count ? 0 : fontIndex;

                int sizeIndex = 0;
                foreach (ListItem item in drpFirstSize.Items)
                {
                    if (item.Text.Equals(webPartToEdit.FirstFontSize.ToString()))
                    {
                        break;
                    }
                    sizeIndex++;
                }
                drpFirstSize.SelectedIndex = sizeIndex >= drpFirstSize.Items.Count ? 0 : sizeIndex;


                // second stuff

                if (webPartToEdit.SecondFontItallic)
                {
                    drpSecondItallic.SelectedIndex = 0;
                }
                else
                {
                    drpSecondItallic.SelectedIndex = 1;
                }


                if (webPartToEdit.SecondFontBold)
                {
                    drpSecondBold.SelectedIndex = 0;
                }
                else
                {
                    drpSecondBold.SelectedIndex = 1;
                }

                if (webPartToEdit.SecondFontUnderline)
                {
                    drpSecondUnderline.SelectedIndex = 0;
                }
                else
                {
                    drpSecondUnderline.SelectedIndex = 1;
                }

                fontIndex = 0;
                foreach (ListItem item in drpSecondFonts.Items)
                {
                    if (item.Text.Equals(webPartToEdit.SecondFontName))
                    {
                        break;
                    }
                    fontIndex++;
                }
                drpSecondFonts.SelectedIndex = fontIndex >= drpSecondFonts.Items.Count ? 0 : fontIndex;

                sizeIndex = 0;
                foreach (ListItem item in drpSecondSize.Items)
                {
                    if (item.Text.Equals(webPartToEdit.SecondFontSize.ToString()))
                    {
                        break;
                    }
                    sizeIndex++;
                }
                drpSecondSize.SelectedIndex = sizeIndex >= drpSecondSize.Items.Count ? 0 : sizeIndex;

                if (webPartToEdit.IsSyncronised)
                {
                    drpSyncWithStore.SelectedIndex = 0;
                }
                else
                {
                    drpSyncWithStore.SelectedIndex = 1;
                }

                // color value

                txtImageUrl.Text = webPartToEdit.ImageUrl;

                int imageIndex = 0;
                foreach (ListItem item in drpImageStyle.Items)
                {
                    if (item.Text.Equals(webPartToEdit.ImageStyle))
                    {
                        break;
                    }
                    imageIndex++;
                }

                drpImageStyle.SelectedIndex = (webPartToEdit.ImageStyle == null || webPartToEdit.ImageStyle.Equals(string.Empty)) ? 0 : imageIndex;

                chkDebug.Checked = webPartToEdit.IsDebug;
            }
        }