protected override PickerEntity[] ResolveErrorBySearch(string unresolvedText) { LoadContract(); if (!String.IsNullOrEmpty(SearchListGuid) && !String.IsNullOrEmpty(SearchColumnsGuid) && !String.IsNullOrEmpty(SearchDisplayName) && !String.IsNullOrEmpty(SearchKeyName)) { using (SPWeb web = SPContext.Current.Web) { SPList searchList = web.TryGetList(SearchListGuid); List <string> searchColumns = new List <string>(); CustomPickerHelper helper = new CustomPickerHelper(); if (searchList != null) { helper.SplitGuidColumns(SearchColumnsGuid).ForEach((i) => { string column = searchList.TryGetFieldName(i); if (!string.IsNullOrEmpty(column)) { searchColumns.Add(column); } }); SPQuery query = new SPQuery(); query.Query = helper.BuildWhereQuery(searchColumns, unresolvedText, "BeginsWith", "Or"); query.ViewFields = helper.BuildViewQuery(searchColumns, SearchKeyName); query.RowLimit = 5; var results = searchList.GetItems(query); if (results != null) { List <PickerEntity> entities = new List <PickerEntity>(); foreach (SPItem result in results) { PickerEntity entity = new PickerEntity(); entity.IsResolved = true; string keyValue = result.TryGetItemValue(SearchKeyName); string displayValue = result.TryGetItemValue(SearchDisplayName); if (!String.IsNullOrEmpty(keyValue) && !String.IsNullOrEmpty(displayValue)) { entity.Key = displayValue; entity.DisplayText = displayValue; entity.EntityData.Add(displayValue, keyValue); entities.Add(entity); } } return(entities.ToArray()); } } else { this.ErrorLabel.Text = "List " + SearchListGuid + " doesn't exists."; } } } return(base.ResolveErrorBySearch(unresolvedText)); }
public override PickerEntity ValidateEntity(PickerEntity needsValidation) { if (needsValidation.IsResolved) { return(needsValidation); } LoadContract(); if (!String.IsNullOrEmpty(SearchListGuid) && !String.IsNullOrEmpty(SearchColumnsGuid) && !String.IsNullOrEmpty(SearchDisplayName) && !String.IsNullOrEmpty(SearchKeyName)) { using (SPWeb web = SPContext.Current.Web) { SPList searchList = web.TryGetList(SearchListGuid); List <string> searchColumns = new List <string>(); CustomPickerHelper helper = new CustomPickerHelper(); if (searchList != null) { helper.SplitGuidColumns(SearchColumnsGuid).ForEach((i) => { string column = searchList.TryGetFieldName(i); if (!string.IsNullOrEmpty(column)) { searchColumns.Add(column); } }); SPQuery query = new SPQuery(); query.Query = helper.BuildWhereQuery(searchColumns, needsValidation.Key, "Eq", "Or"); query.ViewFields = helper.BuildViewQuery(searchColumns, SearchKeyName); query.RowLimit = 1; var results = searchList.GetItems(query); if (results != null && results.Count >= 1) { SPItem result = results[0]; string keyValue = result.TryGetItemValue(SearchKeyName); string displayValue = result.TryGetItemValue(SearchDisplayName); if (/*!String.IsNullOrEmpty(keyValue) && */ !String.IsNullOrEmpty(displayValue)) { needsValidation.IsResolved = true; needsValidation.Key = needsValidation.Key; needsValidation.DisplayText = displayValue; needsValidation.EntityData.Clear(); needsValidation.EntityData.Add(needsValidation.Key, keyValue); } } } else { this.ErrorLabel.Text = "List " + SearchListGuid + " doesn't exists."; } } } return(needsValidation); }
public DataTable getFilteredData(string search, string groupName) { DataTable dt = new DataTable(); bool displayColumnAdded = false; bool keyColumnAdded = false; foreach (string column in ((CustomPickerDialog)this.PickerDialog).NamedColumns) { dt.Columns.Add(column); if (column.Equals(contract.DisplayColumn)) { displayColumnAdded = true; } if (column.Equals(contract.KeyColumn)) { keyColumnAdded = true; } } if (!displayColumnAdded) { dt.Columns.Add(contract.DisplayColumn); } if (!keyColumnAdded) { dt.Columns.Add(contract.KeyColumn); } CustomPickerHelper helper = new CustomPickerHelper(); SPQuery query = new SPQuery(); List <string> searchColumns = new List <string>(); searchColumns.Add(groupName); query.Query = helper.BuildWhereQuery(searchColumns, search, "BeginsWith", "Or"); query.ViewFields = helper.BuildViewQuery(dt.Columns); query.RowLimit = 1; using (SPWeb web = SPContext.Current.Site.OpenWeb()) { SPList searchList = web.TryGetList(contract.LookupGuid); if (searchList != null) { var results = searchList.GetItems(query); if (results != null && results.Count >= 1) { foreach (SPItem result in results) { var values = new object[((CustomPickerDialog)this.PickerDialog).NamedColumns.Count]; for (int x = 0; x < ((CustomPickerDialog)this.PickerDialog).NamedColumns.Count; x++) { values[x] = result.TryGetItemValue(((CustomPickerDialog)this.PickerDialog).NamedColumns[x]); } dt.Rows.Add(values); } } } } return(dt); }