Ejemplo n.º 1
0
        public void RaiseCallbackEvent(string eventArgument)
        {
            string[] eventArg = eventArgument.Split(new string[1] {
                "#;"
            }, StringSplitOptions.None);

            action = eventArg[0];
            source = Utilities.DeserializeObject <DesignDataSource>(eventArg[1]);


            formWebPart = WebPartToEdit as FormWebPart;

            if (formWebPart != null)
            {
                if (!string.IsNullOrEmpty(formWebPart.DataSourcesData))
                {
                    sources = Utilities.DeserializeObject <List <DesignDataSource> >(SourceValue);
                }

                if (sources == null)
                {
                    sources = new List <DesignDataSource>();
                }

                if (action.ToLower() == "delete")
                {
                    DesignDataSource found = sources.Single(n => n.Id == source.Id);
                    if (found.ListRoleChange)
                    {
                        ResetListSettings(ref found);
                    }
                    if (sources.Remove(found))
                    {
                        result = "DataSource Deleted";
                    }
                }

                if (action.ToLower() == "update")
                {
                    int index = sources.FindIndex(n => n.Id == source.Id);
                    if (index >= 0)
                    {
                        sources[index] = source;
                        result         = "DataSource Updated";
                    }
                    else
                    {
                        sources.Add(source);
                        result = "DataSource Added";
                    }
                }

                SourceValue = Utilities.SerializeObject(sources);
                formWebPart.DataSourcesData = SourceValue;
                repeater.DataSource         = sources;
                repeater.DataBind();
                this.DataBind(true);
            }
        }
Ejemplo n.º 2
0
        private void CreateItemforForm()
        {
            FormWebPart wp = (FormWebPart)this.WebPart;

            List <BaseFieldControl> fields = new List <BaseFieldControl>();

            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(wp.DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(wp.DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = SPContext.Current.Site;

                site.AllowUnsafeUpdates = true;
                foreach (DesignDataSource source in sources)
                {
                    fields    = new List <BaseFieldControl>();
                    SPWeb web = site.OpenWeb(new Guid(source.WebId));
                    web.AllowUnsafeUpdates           = true;
                    SPList list                      = web.Lists[new Guid(source.ListId)];
                    SPView view                      = list.GetView(new Guid(source.ViewId));
                    SPViewFieldCollection viewfields = view.ViewFields;

                    foreach (var viewfield in viewfields)
                    {
                        BaseFieldControl formField = (BaseFieldControl)FindControl(viewfield.ToString());
                        if (formField == null)
                        {
                            continue;
                        }

                        fields.Add(formField);
                    }

                    SPListItem item = list.Items.Add();

                    foreach (BaseFieldControl Fld in fields)
                    {
                        try
                        {
                            item[Fld.FieldName] = Fld.Value;
                        }
                        catch { };
                    }
                    UpdateUserInfo(item);

                    item.Update();

                    web.AllowUnsafeUpdates = false;
                }
                site.AllowUnsafeUpdates = false;
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// sync changes from web part
        /// </summary>
        public override void SyncChanges()
        {
            EnsureChildControls();

            formWebPart = WebPartToEdit as FormWebPart;
            if (formWebPart == null)
            {
                return;
            }

            SourceValue = formWebPart.DataSourcesData;
            SyncSources();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// apply changes to web part
 /// </summary>
 /// <returns></returns>
 public override bool ApplyChanges()
 {
     try
     {
         UpdateListSettings();
         formWebPart = WebPartToEdit as FormWebPart;
         if (formWebPart == null)
         {
             return(false);
         }
         formWebPart.DataSourcesData = SourceValue;
     }
     catch (Exception)
     {
         return(true);
     }
     return(true);
 }
Ejemplo n.º 5
0
        internal List <BaseFieldControl> FieldList(WebPart webpart)
        {
            FormWebPart wp = (FormWebPart)webpart;

            List <BaseFieldControl> fields = new List <BaseFieldControl>();

            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(wp.DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(wp.DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = SPContext.Current.Site;

                foreach (DesignDataSource source in sources)
                {
                    SPWeb web   = site.OpenWeb(new Guid(source.WebId));
                    SPList list = web.Lists[new Guid(source.ListId)];
                    SPView view = list.GetView(new Guid(source.ViewId));
                    SPViewFieldCollection viewfields = view.ViewFields;

                    foreach (var viewfield in viewfields)
                    {
                        BaseFieldControl formField = (BaseFieldControl)FindControl(viewfield.ToString());
                        //formField.ControlMode = Microsoft.SharePoint.WebControls.SPControlMode.Display;
                        if (formField == null)
                        {
                            continue;
                        }

                        fields.Add(formField);
                    }
                }
            });

            return(fields);
        }