public PickerEntity GetEntityById(int id)
        {
            PickerEntity entity = null;
            if (id > 0)
            {
                    LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);
                    SPWeb web = SPContext.Current.Site.OpenWeb(propertyBag.WebId);
                    SPList list = web.Lists[propertyBag.ListId];
                    SPQuery queryById = new SPQuery();
                    queryById.ViewAttributes = "Scope=\"Recursive\"";
                    queryById.Query = string.Format("<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">{0}</Value></Eq></Where>", id);
                    SPListItemCollection items = list.GetItems(queryById);
                    if (items.Count > 0)
                    {
                        entity = this.GetEntity(items[0]);
                    }
                    web.Dispose();
            }

            return entity;
        }
        public override PickerEntity ValidateEntity(PickerEntity needsValidation)
        {
            PickerEntity entity = needsValidation;

            LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);

            if (!string.IsNullOrEmpty(needsValidation.DisplayText))
            {
                    // Get reference to LookUp List
                    SPList list = null;
                    SPWeb ObjWeb = SPContext.Current.Web;
                    list = ObjWeb.Lists[propertyBag.ListId];

                    SPQuery queryById = new SPQuery();
                    queryById.ViewAttributes = "Scope=\"Recursive\"";
                    queryById.Query = string.Format("<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">{0}</Value></Eq></Where>", needsValidation.Key);
                    SPListItemCollection items = list.GetItems(queryById);
                    if (items.Count > 0)
                    {
                        entity = this.GetEntity(items[0]);
                    }
                    else
                    {
                        SPQuery queryByTitle = new SPQuery();
                        queryByTitle.Query = string.Format("<Where><Eq><FieldRef ID=\"{0}\"/><Value Type=\"Text\">{1}</Value></Eq></Where>", propertyBag.FieldId, needsValidation.DisplayText);
                        queryByTitle.ViewAttributes = "Scope=\"Recursive\"";
                        items = list.GetItems(queryByTitle);
                        if (items.Count > 0)
                        {
                            entity = this.GetEntity(items[0]);
                        }
                    }
                    if (this.Entities != null)
                    {
                        Context.Application["Picker_" + SPContext.Current.Web.CurrentUser.ID + propertyBag.ListName + propertyBag.FieldName] = this.Entities;
                        //AddToContext(propertyBag.ListName, propertyBag.FieldName, (PickerEntity)base.EditorControl.Entities[0]);
                    }
            }
            return entity;
        }
        private PickerEntity GetEntity(SPListItem item)
        {
            LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);

            PickerEntity entity = new PickerEntity();
            string displayValue = null;
            try
            {
                displayValue = item[propertyBag.FieldId] as String;
            }
            catch
            {
                //field has been deleted
            }

            if (displayValue != null
                && item.Fields[propertyBag.FieldId].Type == SPFieldType.Calculated
                && item[propertyBag.FieldId] != null
                && item[propertyBag.FieldId].ToString().Contains("#"))
            {
                entity.DisplayText = displayValue.ToString().Split('#')[1];
            }
            else
                entity.DisplayText = displayValue ?? "";
            entity.Key = item.ID.ToString();
            entity.Description = entity.DisplayText;
            entity.IsResolved = true;

            return entity;
        }
        protected override PickerEntity[] ResolveErrorBySearch(string unresolvedText)
        {
            List<PickerEntity> entities = new List<PickerEntity>();
            LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);

            SPWeb web = SPContext.Current.Site.OpenWeb(propertyBag.WebId);

                SPList list = web.Lists[propertyBag.ListId];
                SPQuery query = new SPQuery();
                query.ViewAttributes = "Scope=\"Recursive\"";
                query.Query = string.Format("<Where><Contains><FieldRef ID=\"{0}\"/><Value Type=\"Text\">{1}</Value></Contains></Where>", propertyBag.FieldId, unresolvedText);
                SPListItemCollection items = list.GetItems(query);

                foreach (SPListItem item in items)
                {
                    entities.Add(this.GetEntity(item));
                }

                web.Dispose();

            return entities.ToArray();
        }
Example #5
0
        protected override void OnLoad(EventArgs e)
        {
            ArrayList columnDisplayNames = ((TableResultControl)base.ResultControl).ColumnDisplayNames;
            columnDisplayNames.Clear();

            ArrayList columnNames = ((TableResultControl)base.ResultControl).ColumnNames;
            columnNames.Clear();

            ArrayList columnWidths = ((TableResultControl)base.ResultControl).ColumnWidths;
            columnWidths.Clear();

            LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);

            //Get reference to LookUp List
            SPList list = null;
            SPWeb ObjWeb = SPContext.Current.Web;
            list = ObjWeb.Lists[propertyBag.ListId];

            List<string> searchFields = propertyBag.SearchFields;

            foreach (SPField field in list.Fields)
            {
                //Add 'ID' Columns in the SearchFields/FieldId Parameter
                if (propertyBag.SearchFields.Contains(field.Id.ToString()) || propertyBag.FieldId == field.Id)
                {
                    if (columnDisplayNames.Contains(field.Title) == false)
                    {
                        columnDisplayNames.Add(field.Title);
                        columnNames.Add(field.Id.ToString());
                    }
                }

                //Add Columns in the the SearchFields Parameter
                if (propertyBag.SearchFields.Contains(field.InternalName))
                {
                    if (columnDisplayNames.Contains(field.Title) == false)
                    {
                        columnDisplayNames.Add(field.Title);
                        columnNames.Add(field.Id.ToString());
                    }
                }

                //Add Organisation(s) Column in the Popup List if exists
                if (field.InternalName.ToLower() == "organisation" || field.InternalName.ToLower() == "organisations")
                {
                    if (field.InternalName.ToLower() == "organisations")
                    {
                        columnDisplayNames.Insert(1, "Organisation(s)");
                        columnNames.Insert(1, field.Id.ToString());
                    }
                    else
                    {
                        columnDisplayNames.Insert(1, field.Title);
                        columnNames.Insert(1, field.Id.ToString());
                    }
                }
                //Add Area/Areas Column in the Popup List if exists
                if (field.InternalName.ToLower() == "areas" || field.InternalName.ToLower() == "area")
                {
                    columnDisplayNames.Add(field.Title);
                    columnNames.Add(field.Id.ToString());
                }
            }

            //Adjust Column Widths
            if (columnNames.Count > 0)
            {
                int width = (int)(100 / columnNames.Count);
                for (int i = 0; i < columnNames.Count; i++)
                {
                    columnWidths.Add(width.ToString() + "%");
                }
            }
            base.OnLoad(e);
        }
Example #6
0
        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
            if (base.EditorControl.Entities.Count > 0)
            {
                LookupFieldWithPickerPropertyBag propertyBag = new LookupFieldWithPickerPropertyBag(this.CustomProperty);

                AddToContext(propertyBag.ListName,propertyBag.FieldName,(PickerEntity)base.EditorControl.Entities[0]);
            }
        }
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     propertyBag = new LookupFieldWithPickerPropertyBag(this.PickerDialog.CustomProperty);
 }