private void InsertEPMLiveGenericPickerControl(FormField formField, LookupConfigData lookupData, string fieldType) { if (formField == null) { throw new ArgumentNullException(nameof(formField)); } picker = new GenericEntityEditor(); var fieldLookup = GetFieldLookup(formField); picker.MultiSelect = fieldLookup.AllowMultipleValues; var customValue = GetCustomValue(formField, lookupData, fieldLookup, fieldType); SPFieldLookupValueCollection lookupValCol = null; if (mode == SPControlMode.New) { lookupValCol = GetQueryStringLookupVal(formField); } else { try { lookupValCol = new SPFieldLookupValueCollection(ListItem[fieldLookup.Id].ToString()); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } } if (lookupValCol?.Count > 0) { var alItems = new ArrayList(); foreach (var field in lookupValCol) { var entity = new PickerEntity { Key = field.LookupId.ToString(), DisplayText = field.LookupValue, IsResolved = true }; alItems.Add(entity); } picker.UpdateEntities(alItems); } picker.CustomProperty = customValue; formField.Controls.Add(picker); }
private void AddTypeAheadFieldControls(SPField fld) { if (mode == SPControlMode.New || mode == SPControlMode.Edit) { // this represents a comma separated list of lookup field internal names to modify EnhancedLookupConfigValuesHelper valueHelper = null; string unprocessedModCandidates = string.Empty; GridGanttSettings gSettings = new GridGanttSettings(this.list); try { string rawValue = gSettings.Lookups; //string rawValue = "Region^dropdown^none^none^xxx|State^autocomplete^Region^Region^xxx|City^autocomplete^State^State^xxx"; valueHelper = new EnhancedLookupConfigValuesHelper(rawValue); } catch { } if (valueHelper == null) { return; } bool isEnhanced = valueHelper.ContainsKey(fld.InternalName); bool isParent = valueHelper.IsParentField(fld.InternalName); if (!isEnhanced && !isParent) { return; } LookupConfigData lookupData = valueHelper.GetFieldData(fld.InternalName); if (isParent && !isEnhanced) { SPFieldLookup lookupFld = fld as SPFieldLookup; if (!lookupFld.AllowMultipleValues) { CascadingLookupRenderControl ctrl = new CascadingLookupRenderControl(); if (lookupData == null) { lookupData = new LookupConfigData(); lookupData.IsParent = true; } ctrl.LookupData = lookupData; ctrl.LookupField = lookupFld; string customValue = "<Data>" + "<Param key=\"SPFieldType\">SPFieldUser</Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "</Data>"; ctrl.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, ctrl); } } } else if (isParent && isEnhanced) { if (lookupData.Type == GenericType) { #region INSERT EPMLIVE GENERIC PICKER CONTROL picker = new GenericEntityEditor(); SPFieldLookup lookupFld = fld as SPFieldLookup; picker.MultiSelect = lookupFld.AllowMultipleValues; string customValue = "<Data>" + "<Param key=\"SPFieldType\"></Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "<Param key=\"Field\">" + lookupData.Field + "</Param>" + "<Param key=\"ControlType\">" + lookupData.Type + "</Param>" + "<Param key=\"Parent\">" + lookupData.Parent + "</Param>" + "<Param key=\"ParentListField\">" + lookupData.ParentListField + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required.ToString() + "</Param>" + "</Data>"; SPFieldLookupValueCollection lookupValCol = null; if (mode == SPControlMode.New || (this.list.BaseTemplate == SPListTemplateType.DocumentLibrary && !string.IsNullOrEmpty(Page.Request[ModeParam]) && Page.Request[ModeParam] == Upload && mode == SPControlMode.Edit)) { lookupValCol = GetQueryStringLookupVal(fld); } else { try { lookupValCol = new SPFieldLookupValueCollection(this.ListItem[lookupFld.Id].ToString()); } catch { } } if (lookupValCol != null && lookupValCol.Count > 0) { ArrayList alItems = new ArrayList(); PickerEntity entity; foreach (SPFieldLookupValue v in lookupValCol) { entity = new PickerEntity(); entity.Key = v.LookupId.ToString(); entity.DisplayText = v.LookupValue; entity.IsResolved = true; alItems.Add(entity); } picker.UpdateEntities(alItems); } picker.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, picker); } #endregion } else if (lookupData.Type == ModifiedType) { #region INSERT MODIFIED SP CONTROL SPFieldLookup lookupFld = fld as SPFieldLookup; if (!lookupFld.AllowMultipleValues) { CascadingLookupRenderControl cclrCtrl = new CascadingLookupRenderControl(); cclrCtrl.LookupData = lookupData; cclrCtrl.LookupField = lookupFld; string customValue = "<Data>" + "<Param key=\"SPFieldType\">SPFieldUser</Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "</Data>"; cclrCtrl.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, cclrCtrl); } } #endregion } } else if (!isParent && isEnhanced) { if (lookupData.Type == GenericType) { #region INSERT EPMLIVE GENERIC PICKER CONTROL picker = new GenericEntityEditor(); SPFieldLookup lookupFld = fld as SPFieldLookup; picker.MultiSelect = lookupFld.AllowMultipleValues; string customValue = "<Data>" + "<Param key=\"SPFieldType\">SPFieldUser</Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "<Param key=\"Field\">" + lookupData.Field + "</Param>" + "<Param key=\"ControlType\">" + lookupData.Type + "</Param>" + "<Param key=\"Parent\">" + lookupData.Parent + "</Param>" + "<Param key=\"ParentListField\">" + lookupData.ParentListField + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required.ToString() + "</Param>" + "</Data>"; SPFieldLookupValueCollection lookupValCol = null; if (mode == SPControlMode.New || (this.list.BaseTemplate == SPListTemplateType.DocumentLibrary && !string.IsNullOrEmpty(Page.Request[ModeParam]) && Page.Request[ModeParam] == Upload && mode == SPControlMode.Edit)) { lookupValCol = GetQueryStringLookupVal(fld); } else { try { lookupValCol = new SPFieldLookupValueCollection(this.ListItem[lookupFld.Id].ToString()); } catch { } } if (lookupValCol != null && lookupValCol.Count > 0) { ArrayList alItems = new ArrayList(); PickerEntity entity; foreach (SPFieldLookupValue v in lookupValCol) { entity = new PickerEntity(); entity.Key = v.LookupId.ToString(); entity.DisplayText = v.LookupValue; entity.IsResolved = true; alItems.Add(entity); } picker.UpdateEntities(alItems); } picker.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, picker); } #endregion } else if (lookupData.Type == ModifiedType) { #region INSERT MODIFIED SP CONTROL SPFieldLookup lookupFld = fld as SPFieldLookup; if (!lookupFld.AllowMultipleValues) { CascadingLookupRenderControl cclrCtrl = new CascadingLookupRenderControl(); cclrCtrl.LookupData = lookupData; cclrCtrl.LookupField = lookupFld; string customValue = "<Data>" + "<Param key=\"SPFieldType\">SPFieldUser</Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "</Data>"; cclrCtrl.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, cclrCtrl); } } else { CascadingMultiLookupRenderControl cclrCtrl = new CascadingMultiLookupRenderControl(); cclrCtrl.LookupData = lookupData; cclrCtrl.LookupField = lookupFld; string customValue = "<Data>" + "<Param key=\"SPFieldType\">SPFieldUser</Param>" + "<Param key=\"ParentWebID\">" + lookupFld.ParentList.ParentWeb.ID.ToString() + "</Param>" + "<Param key=\"LookupWebID\">" + lookupFld.LookupWebId.ToString() + "</Param>" + "<Param key=\"LookupListID\">" + lookupFld.LookupList + "</Param>" + "<Param key=\"LookupFieldInternalName\">" + lookupFld.LookupField + "</Param>" + "<Param key=\"LookupFieldID\">" + lookupFld.Id + "</Param>" + "<Param key=\"IsMultiSelect\">" + lookupFld.AllowMultipleValues.ToString() + "</Param>" + "<Param key=\"ListID\">" + this.ListId.ToString() + "</Param>" + "<Param key=\"ItemID\">" + this.ItemId.ToString() + "</Param>" + "<Param key=\"Required\">" + lookupFld.Required + "</Param>" + GenerateControlDataForLookupField(fld, lookupFld.AllowMultipleValues) + "</Data>"; cclrCtrl.CustomProperty = customValue; FormField ff = this.GetFormFieldByField(fld); if (ff != null) { ff.Parent.Controls.AddAfter(ff, cclrCtrl); } } #endregion } } } }