internal static List <ListItem> GetAvailableValues(FilteredLookupField f, HttpContext ctx) { List <ListItem> _v = null; SPListItemCollection items = null; Guid fId = new Guid(f.LookupField); SPSite s = SPControl.GetContextSite(ctx); SPWeb lookupWeb = s.OpenWeb(f.LookupWebId); SPList lookupList = lookupWeb.Lists[new Guid(f.LookupList)]; try { if (f.QueryFilter != null) { items = lookupList.GetItems(f.QueryFilter); } } catch { } if (items == null) { items = lookupList.Items; } if ((items != null && items.Count > 0)) { _v = items .Cast <SPListItem>() .Where(e => e[fId] != null) .Select(e => new ListItem(( e.Fields[fId].GetFieldValueAsText(e[fId])), e.ID.ToString())) .ToList <ListItem>(); } return(_v); }
private void InitializeFieldViews(SPField field, string webId, string listId) { SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(webId)); SPList list = _web.Lists[new Guid(listId)]; foreach (SPView view in list.Views) { if ((view.Hidden || view.PersonalView) || !view.Type.Equals("HTML")) { continue; } ListItem item = new ListItem(view.Title, view.ID.ToString() + "|" + view.Url); string viewId = string.Empty; if (field != null) { CustomDropDownList f = field as CustomDropDownList; if (Convert.ToString(f.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(f.GetCustomProperty(CustomDropDownList.VIEW)); } } if (((view.ID.ToString() == viewId) || (view.ID.ToString() + "|" + view.Url == viewId))) { item.Selected = true; } ddlView.Items.Add(item); } ddlView.Items.Insert(0, new ListItem("", "")); ddlView.Visible = true; lbView.Visible = true; }
/// <summary> /// /// </summary> /// <param name="action">新的操作名称</param> /// <param name="typeFldName">类别字段名称</param> /// <param name="typeID">类别值</param> private int AddOperate(string action, int typeID) { CustomConcatenatedField f = (CustomConcatenatedField)base.Field; string lstID = f.LookupList; SPSite s = SPControl.GetContextSite(Context); int itemID = 0; SPWeb lookupWeb = SPControl.GetContextWeb(Context); int userID = lookupWeb.CurrentUser.ID; SPField typeFld = GetCascadedField; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(lookupWeb.Site.ID)) { using (SPWeb web = site.AllWebs[lookupWeb.ID]) { SPList lookupList = web.Lists[new Guid(lstID)]; SPListItem addItem = lookupList.Items.Add(); addItem["Title"] = action; addItem[typeFld.Title] = typeID; addItem[lookupList.Fields.GetFieldByInternalName("Flag").Title] = "11"; addItem["Author"] = userID; web.AllowUnsafeUpdates = true; addItem.Update(); web.AllowUnsafeUpdates = false; itemID = addItem.ID; } } }); return(itemID); }
/// <summary> /// 返回当前父级下的第一项的ID /// </summary> /// <param name="lstID"></param> /// <param name="fldInterlName"></param> /// <param name="fldCascaded"></param> /// <param name="cateID"></param> /// <returns></returns> private int GetListItemsOfFirstID(string lstID, string fldInterlName, string fldCascaded, int cateID) { SPSite s = SPControl.GetContextSite(Context); SPWeb lookupWeb = SPControl.GetContextWeb(Context); SPList lookupList = lookupWeb.Lists[new Guid(lstID)]; SPQuery qry = new SPQuery(); if (fldCascaded == "")//没有层次级别的分类,直接获取表中的所有数据 { qry.Query = @""; } else //通过父类ID进行层次级别的标识 { if (cateID > 0) { qry.Query = @"<Where><Eq><FieldRef Name='" + fldCascaded + "' LookupId='True' /><Value Type='Lookup'>" + cateID + "</Value></Eq></Where>"; } else { qry.Query = @"<Where><IsNull><FieldRef Name='" + fldCascaded + "' /></IsNull></Where>"; } } //查阅项列表 SPListItemCollection items = lookupList.GetItems(qry); int id = 0; if (items.Count > 0) { id = items[0].ID; } return(id); }
private void SetTargetWeb() { listTargetWeb.Items.Clear(); List <ListItem> str = new List <ListItem>(); //using (SPSite _site = SPControl.GetContextSite(this.Context)) { SPSite _site = SPControl.GetContextSite(this.Context); SPWebCollection _webCollection = _site.AllWebs; string contextWebId = SPControl.GetContextWeb(this.Context).ID.ToString(); foreach (SPWeb web in _webCollection) { try { if (web.DoesUserHavePermissions( SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems)) { str.Add(new ListItem(web.Title, web.ID.ToString())); } } catch (Exception ex) { LoggingService.WriteTrace(Area.EPMLiveCore, Categories.EPMLiveCore.IntegrationCore, TraceSeverity.Medium, ex.ToString()); } finally { if (web != null) { web.Dispose(); } } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetWeb.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetWebId)) { bitem = listTargetWeb.Items.FindByValue(TargetWebId); } else { bitem = listTargetWeb.Items.FindByValue(contextWebId); } if (bitem != null) { listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem); } else { listTargetWeb.SelectedIndex = 0; } SetTargetList(listTargetWeb.SelectedItem.Value, true); } }
/// <summary> /// Overridden method CreateChildControls from the Webpart class /// </summary> protected override void CreateChildControls() { this.currentSite = SPControl.GetContextSite(Context); this.currentWeb = this.currentSite.OpenWeb(WebName); try { this.currentList = this.currentWeb.Lists[ListName]; this.listRootFolder = this.currentWeb.Lists[ListName].RootFolder.ToString(); } }
private void InitializeApplication() { UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString()); ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url); ForumApplication.Instance.Title = this.Name; ForumApplication.Instance.ForumCache = this.Page.Cache; ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath; ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser; ForumApplication.Instance.AppPoolUser = SPControl.GetContextSite(Context).OpenWeb().CurrentUser; ForumApplication.Instance.SpWeb = SPControl.GetContextSite(Context).OpenWeb(); }
private void SetTargetList(string selectedWebId, bool setTargetColumn) { listTargetList.Items.Clear(); if (!string.IsNullOrEmpty(selectedWebId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(selectedWebId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(selectedWebId))) { List <ListItem> str = new List <ListItem>(); SPListCollection _listCollection = _web.Lists; foreach (SPList list in _listCollection) { if (!list.Hidden) { str.Add(new ListItem(list.Title, list.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetList.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetListId)) { bitem = listTargetList.Items.FindByValue(TargetListId); } if (bitem != null) { listTargetList.SelectedIndex = listTargetList.Items.IndexOf(bitem); } else { listTargetList.SelectedIndex = 0; } if (setTargetColumn) { SetTargetColumn(selectedWebId, listTargetList.SelectedItem.Value); } SetTargetListView(selectedWebId, listTargetList.SelectedItem.Value); } } } }
private void SetTargetListView(string webId, string selectedListId) { listTargetListView.Items.Clear(); // clear list, first and foremost if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPList list = _web.Lists[new Guid(selectedListId)]; SPViewCollection views = list.Views; List <ListItem> str = new List <ListItem>(); foreach (SPView v in views) { // use only views that are both visible and shared if (!v.Hidden && !v.PersonalView) { str.Add(new ListItem( string.Format(CultureInfo.InvariantCulture, "{0}", v.Title), v.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetListView.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetListViewId)) { bitem = listTargetListView.Items.FindByValue(TargetListViewId); } if (bitem != null) { listTargetListView.SelectedIndex = listTargetListView.Items.IndexOf(bitem); } else { listTargetListView.SelectedIndex = 0; } } } } }
private void SetTargetColumn(string webId, string selectedListId) { listTargetColumn.Items.Clear(); if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPList list = _web.Lists[new Guid(selectedListId)]; SPFieldCollection fields = list.Fields; List <ListItem> str = new List <ListItem>(); foreach (SPField f in fields) { if (CanFieldBeDisplayed(f)) { str.Add(new ListItem( string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetColumn.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetColumnId)) { bitem = listTargetColumn.Items.FindByValue(TargetColumnId); } if (bitem != null) { listTargetColumn.SelectedIndex = listTargetColumn.Items.IndexOf(bitem); } else { listTargetColumn.SelectedIndex = 0; } } } } }
private void SetTargetWeb() { listTargetWeb.Items.Clear(); List <ListItem> str = new List <ListItem>(); SPSite _site = SPControl.GetContextSite(this.Context); SPWebCollection _webCollection = _site.AllWebs; string contextWebId = SPControl.GetContextWeb(this.Context).ID.ToString(); foreach (SPWeb web in _webCollection) { if (web.DoesUserHavePermissions( SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems)) { str.Add(new ListItem(web.Title, web.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetWeb.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetWebId)) { bitem = listTargetWeb.Items.FindByValue(TargetWebId); } else { bitem = listTargetWeb.Items.FindByValue(contextWebId); } if (bitem != null) { listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem); } else { listTargetWeb.SelectedIndex = 0; } SetTargetList(listTargetWeb.SelectedItem.Value, true); } }
void IFieldEditor.OnSaveChange(SPField field, bool isNewField) { this.EnsureChildControls(); if (field != null) { CustomConcatenatedField _f = field as CustomConcatenatedField; SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(); _f.LookupWebId = _web.ID; _f.LookupList = ddlListName.SelectedValue; _f.LookupField = ddlFieldName.SelectedValue; _f.SPLookupList = ddlListName.SelectedValue; _f.SPLookupField = ddlFieldName.SelectedValue; _f.SPLookupWidth = txtWidth.Text; } }
public void OnSaveChange(SPField field, bool isNewField) { FilteredLookupField _f = null; try { _f = field as FilteredLookupField; } catch { } if (_f != null) { string s = txtQueryFilter.Text; bool rec = cbxRecursiveFilter.Checked; string view = (listTargetListView.SelectedIndex > -1) ? listTargetListView.SelectedItem.Value : string.Empty; string col = listTargetColumn.SelectedItem.Value; string list = listTargetList.SelectedItem.Value; bool multi = cbxAllowMultiValue.Checked; if (isNewField) { // can only change list and web if new field SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(listTargetWeb.SelectedItem.Value))) { _f.LookupWebId = _web.ID; _f.LookupList = list; } } if (rdFilterOption.SelectedItem.Value == "Query") { _f.QueryFilterAsString = (!string.IsNullOrEmpty(s)) ? SPHttpUtility.HtmlEncode(s) : ""; _f.ListViewFilter = ""; } else if (rdFilterOption.SelectedItem.Value == "ListView") { _f.ListViewFilter = (!string.IsNullOrEmpty(view)) ? view : ""; _f.QueryFilterAsString = ""; } _f.LookupField = col; _f.IsFilterRecursive = rec; _f.UnlimitedLengthInDocumentLibrary = cbxUnlimitedLengthInDocLib.Checked; _f.CountRelated = IsCountRelated(_f.LookupField, _f.LookupList); _f.AllowMultipleValues = (_f.CountRelated) ? false : multi; } }
private void InitializeFieldAdvanceSettings(string webId, string listId) { SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(webId)); SPList list = _web.Lists[new Guid(listId)]; SPFieldCollection fields = list.Fields; foreach (SPField f in fields) { if (CanFieldBeDisplayed(f)) { if (f.Type == SPFieldType.Lookup || f.TypeAsString == "CustomDropDownList") { if (f.ShowInViewForms != true) { // cblAdditionalFilters.Items.Add(new ListItem(string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } else { if (basic_field(f)) { cblAdditionalFields.Items.Add(new ListItem(string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } } } if (cblAdditionalFilters.Items.Count > 0) { lbAdditionalFilters.Visible = true; cblAdditionalFilters.Visible = true; } else { lbAdditionalFilters.Visible = false; cblAdditionalFilters.Visible = false; } cblAdditionalFields.Visible = true; chkSortByView.Visible = true; chkAddingNewValues.Visible = true; chkUseNewForm.Visible = true; pnlConvertFromRegular.Visible = false; }
/// <summary> /// 返回级联相关的数据 /// </summary> /// <param name="lstID">查阅项列表iD</param> /// <param name="fldInterlName">查阅项显示字段</param> /// <param name="fldCascaded">父类字段(查阅项字段)</param> /// <param name="cateID"></param> /// <returns></returns> private ListItem[] GetListItems(string lstID, string fldInterlName, string fldCascaded, int cateID, ref List <ListItem> itemDesc) { SPSite s = SPControl.GetContextSite(Context); SPWeb lookupWeb = SPControl.GetContextWeb(Context); SPList lookupList = lookupWeb.Lists[new Guid(lstID)]; SPQuery qry = new SPQuery(); if (fldCascaded == "")//二级的顶级 { //填充类别 if (lookupList.Fields.ContainsFieldWithStaticName("SN")) { qry.Query = @"<OrderBy><FieldRef Name='SN' Ascending='true' /></OrderBy>"; } else { qry.Query = @""; } } else//多级的顶级及下一级的填充 { if (lookupList.Fields.ContainsFieldWithStaticName("Flag")) { int userID = SPContext.Current.Web.CurrentUser.ID; if (cateID > 0) { qry.Query = @"<Where><And><Eq><FieldRef Name='" + fldCascaded + "' LookupId='True' /><Value Type='Lookup'>" + cateID + "</Value></Eq><Or><Eq><FieldRef Name='Flag' /><Value Type='Number'>0</Value></Eq><And><Eq><FieldRef Name='Flag' /><Value Type='Number'>11</Value></Eq><Eq><FieldRef Name = 'Author' LookupId = 'TRUE'></FieldRef><Value Type = 'User'>" + userID + "</Value></Eq></And></Or></And></Where>"; } else { qry.Query = @"<Where><And><IsNull><FieldRef Name='" + fldCascaded + "' /></IsNull><Or><Eq><FieldRef Name='Flag' /><Value Type='Number'>0</Value></Eq><And><Eq><FieldRef Name='Flag' /><Value Type='Number'>11</Value></Eq><Eq><FieldRef Name = 'Author' LookupId = 'TRUE'></FieldRef><Value Type = 'User'>" + userID + "</Value></Eq></And></Or></And></Where>"; } } else { if (cateID > 0) { qry.Query = @"<Where><Eq><FieldRef Name='" + fldCascaded + "' LookupId='True' /><Value Type='Lookup'>" + cateID + "</Value></Eq></Where>"; } else { qry.Query = @"<Where><IsNull><FieldRef Name='" + fldCascaded + "' /></IsNull></Where>"; } } } //查阅项列表 SPListItemCollection items = lookupList.GetItems(qry); List <ListItem> desItems = new List <ListItem>(); SPField lookupField = lookupList.Fields.GetFieldByInternalName(fldInterlName == "ID"?"Title":fldInterlName); Guid FieldID = lookupField.Id; foreach (SPListItem i in items) { ListItem _s = new System.Web.UI.WebControls.ListItem( i.Fields[FieldID].GetFieldValueAsText(i[FieldID]), i.ID.ToString()); desItems.Add(_s); string fldDescName = "Desc"; if (fldCascaded == "" && lookupList.Fields.ContainsFieldWithStaticName(fldDescName)) { SPField fld = lookupList.Fields.GetFieldByInternalName(fldDescName); ListItem _sDes = new ListItem(i.Fields[fld.Id].GetFieldValueAsText(i[fld.Id]), i.ID.ToString()); itemDesc.Add(_sDes); } } return(desItems.ToArray());; }
protected void SelectedParentColumnChanged(Object sender, EventArgs args) { string webId = listTargetWeb.SelectedItem.Value; string targetListId = listTargetList.SelectedItem.Value; SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(webId)); SPList list = _web.Lists[new Guid(targetListId)]; SPList curList = SPContext.Current.List; SPFieldCollection fields = list.Fields; SPFieldCollection curFields = curList.Fields; string parent_column_lookup_id = ((SPFieldLookup)curFields[listParentColumn.SelectedItem.Text]).LookupList; List <ListItem> str2 = new List <ListItem>(); str2.Clear(); foreach (SPField f in fields) { if (CanFieldBeDisplayed(f)) { if (parent_column_lookup_id != null) { string typename = f.TypeDisplayName; bool temp = Convert.ToString(f.GetCustomProperty(CustomDropDownList.LINK)) == Boolean.TrueString; if ((typename.Equals("CustomDropDownList") && !temp) || f.Type == SPFieldType.Lookup) { if (parent_column_lookup_id.ToLower() == ((SPFieldLookup)f).LookupList.ToLower()) { str2.Add(new ListItem(string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } } } } if (str2.Count > 0) { str2.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listLinkColumn.Items.Clear(); listLinkColumn.Items.AddRange(str2.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetLinkColumnId)) { bitem = listLinkColumn.Items.FindByValue(TargetLinkColumnId); } if (bitem != null) { listLinkColumn.SelectedIndex = listLinkColumn.Items.IndexOf(bitem); } else { listLinkColumn.SelectedIndex = 0; } } }
public void OnSaveChange(SPField field, bool isNewField) { CustomDropDownList _f = null; try { _f = field as CustomDropDownList; } catch { } SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(listTargetWeb.SelectedItem.Value)); _f.LookupWebId = _web.ID; if (listTargetList.SelectedIndex < 0) { listTargetList.SelectedIndex = 0; } _f.LookupList = listTargetList.SelectedItem.Value; _f.LookupField = listTargetColumn.SelectedItem.Value; _f.SetCustomProperty(CustomDropDownList.LINK, cbxLinkParent.Checked); _f.SetCustomProperty(CustomDropDownList.ALLOW_MULTIPLE, cbxMultipleValues.Checked); _f.SetCustomProperty(CustomDropDownList.SHOW_ALL_VALUES, cbxParentEmpty.Checked); if (cbxLinkParent.Checked && cbxLinkParent.Enabled) { // if (listParentColumn.Items.Count != 0) { _f.SetCustomProperty(CustomDropDownList.PARENT_COLUMN, listParentColumn.SelectedItem.Value); } /* else * { * _f.SetCustomProperty(CustomDropDownList.PARENT_COLUMN, ""); * } * if (listLinkColumn.Items.Count != 0)*/ { _f.SetCustomProperty(CustomDropDownList.LINK_COLUMN, listLinkColumn.SelectedItem.Value); } /* else * { * _f.SetCustomProperty(CustomDropDownList.LINK_COLUMN, ""); * }*/ } else { _f.SetCustomProperty(CustomDropDownList.PARENT_COLUMN, ""); _f.SetCustomProperty(CustomDropDownList.LINK_COLUMN, ""); } _f.SetCustomProperty(CustomDropDownList.AUTO_COMPLETE, cbxAutoCompleteORFilter.Checked); _f.SetCustomProperty(CustomDropDownList.ADVANCE_SETTINGS, cbxAdvanceSettings.Checked); if (cbxAdvanceSettings.Checked) { if (!string.IsNullOrEmpty(ddlView.SelectedItem.Value)) { _f.SetCustomProperty(CustomDropDownList.VIEW, ddlView.SelectedItem.Value); } _f.SetCustomProperty(CustomDropDownList.SORT_BY_VIEW, chkSortByView.Checked); _f.SetCustomProperty(CustomDropDownList.ADDING_NEW_VALUES, chkAddingNewValues.Checked); _f.SetCustomProperty(CustomDropDownList.NEW_FORM, chkUseNewForm.Checked); string checked_additional_fields = string.Empty; string unchecked_additional_fields = string.Empty; foreach (ListItem item in cblAdditionalFields.Items) { if (item.Selected) { if (!string.IsNullOrEmpty(checked_additional_fields)) { checked_additional_fields = checked_additional_fields + ";"; } checked_additional_fields = checked_additional_fields + item.Value; } else { if (!string.IsNullOrEmpty(unchecked_additional_fields)) { unchecked_additional_fields = unchecked_additional_fields + ";"; } unchecked_additional_fields = unchecked_additional_fields + item.Value; } } _f.SetCustomProperty(CustomDropDownList.ADDITIONAL_FIELDS, checked_additional_fields); _f.EnsureAdditionalFields(checked_additional_fields, unchecked_additional_fields); string str = string.Empty; foreach (ListItem item in cblAdditionalFilters.Items) { if (item.Selected) { if (!string.IsNullOrEmpty(str)) { str = str + ";"; } str = str + item.Value; } } _f.SetCustomProperty(CustomDropDownList.ADDITIONAL_FILTERS, str); } _f.SetCustomProperty(CustomDropDownList.RELATIONSHIP_BEHAVIOR, cbxRelationshipBehavior.Checked); _f.SetCustomProperty(CustomDropDownList.RELATIONSHIP_BEHAVIOR_CASCADE, rdbCascadeDelete.Checked); if (!_f.AllowMultipleValues && cbxRelationshipBehavior.Checked) { if (rdbCascadeDelete.Checked) { _f.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Cascade; } else if (rdbRestrictDelete.Checked) { _f.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Restrict; } else { _f.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.None; } _f.Indexed = true; } else { _f.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.None; _f.Indexed = false; } }
private void SetTargetColumn(string webId, string selectedListId) { listTargetColumn.Items.Clear(); listParentColumn.Items.Clear(); listLinkColumn.Items.Clear(); if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId)) { SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(webId)); SPList list = _web.Lists[new Guid(selectedListId)]; SPList curList = SPContext.Current.List; SPFieldCollection fields = list.Fields; SPFieldCollection curFields = curList.Fields; List <ListItem> str = new List <ListItem>(); List <ListItem> str1 = new List <ListItem>(); List <ListItem> str2 = new List <ListItem>(); str1.Clear(); str2.Clear(); foreach (SPField f in curFields) { if (CanFieldBeDisplayed(f)) { bool found = false; foreach (SPField f1 in fields) { string typename = f.TypeDisplayName; bool temp = Convert.ToString(f.GetCustomProperty(CustomDropDownList.LINK)) == Boolean.TrueString; if (((typename.Equals("CustomDropDownList") && !temp) || f.Type == SPFieldType.Lookup) && (f1.Type == SPFieldType.Lookup || f1.TypeAsString == "Lookup" || f1.TypeAsString == "CustomDropDownList")) { string left = ((SPFieldLookup)f1).LookupList.ToString(); left = left.TrimEnd('}'); left = left.TrimStart('{').ToLower(); string right = ((SPFieldLookup)f).LookupList.ToString(); right = right.TrimEnd('}'); right = right.TrimStart('{').ToLower(); if (left.Equals(right)) { found = true; break; } } } if (found) { str1.Add(new ListItem(string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } } string parent_column_lookup_id = null; if (str1.Count != 0) { parent_column_lookup_id = ((SPFieldLookup)curFields[str1.ToArray()[0].Text]).LookupList.ToString(); } foreach (SPField f in fields) { if (CanFieldBeDisplayed(f)) { if (parent_column_lookup_id != null) { string typename = f.TypeDisplayName; bool temp = Convert.ToString(f.GetCustomProperty(CustomDropDownList.LINK)) == Boolean.TrueString; if ((typename.Equals("CustomDropDownList") && !temp) || f.Type == SPFieldType.Lookup) { string f_lookuplist = ((SPFieldLookup)f).LookupList.ToString(); f_lookuplist = f_lookuplist.TrimEnd('}'); f_lookuplist = f_lookuplist.TrimStart('{'); parent_column_lookup_id = parent_column_lookup_id.TrimEnd('}'); parent_column_lookup_id = parent_column_lookup_id.TrimStart('{'); if (parent_column_lookup_id.ToLower() == f_lookuplist.ToLower()) { str2.Add(new ListItem(string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } } if (!f.TypeDisplayName.Equals("CustomDropDownList") && f.Type != SPFieldType.Lookup && basic_field(f)) { str.Add(new ListItem( string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetColumn.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetColumnId)) { bitem = listTargetColumn.Items.FindByValue(TargetColumnId); } if (bitem != null) { listTargetColumn.SelectedIndex = listTargetColumn.Items.IndexOf(bitem); } else { listTargetColumn.SelectedIndex = 0; } } if (str1.Count > 0) { str1.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listParentColumn.Items.AddRange(str1.ToArray()); if (listParentColumn.SelectedIndex < 0) { listParentColumn.SelectedIndex = 0; } ListItem bitem = null; if (!string.IsNullOrEmpty(TargetParentColumnId)) { bitem = listParentColumn.Items.FindByValue(TargetParentColumnId); } if (bitem != null) { listParentColumn.SelectedIndex = listParentColumn.Items.IndexOf(bitem); } else { listParentColumn.SelectedIndex = 0; } } if (str2.Count > 0) { str2.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listLinkColumn.Items.AddRange(str2.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetLinkColumnId)) { bitem = listLinkColumn.Items.FindByValue(TargetLinkColumnId); } if (bitem != null) { listLinkColumn.SelectedIndex = listLinkColumn.Items.IndexOf(bitem); } else { listLinkColumn.SelectedIndex = 0; } } } if (listParentColumn.Items.Count == 0 || listTargetList.SelectedValue == SPContext.Current.ListId.ToString() || !cbxLinkParent.Checked) { InitialParentColumnValues_with_false(); cbxLinkParent.Enabled = false; } else { InitialParentColumnValues_with_true(); cbxLinkParent.Enabled = true; } }
protected void Page_Load(object sender, EventArgs e) { /*using (TPP bd = new TPP()) * { * * }*/ /*TPP bd = new TPP(); * bd.Materials.Add(new Material() * { * Assortment = "erhrh", * DesignOfStandard = "htdfdh", * Name = "rth", * Stamp = "hfhrfr" * }); * bd.SaveChanges();*/ TPP bd = new TPP(); SPSite site = SPControl.GetContextSite(Context); SPWeb web = site.OpenWeb(); /*SPListCollection collList = web.Lists; * * foreach (var oList in collList) * { * Console.WriteLine("Title: {0} Created: {1}", oList., oList.Created.ToString()); * }*/ //SPUser developer = web.Users.GetByID(route.NameOfDeveloper); //cell4.Text = developer.LoginName; SPGroupCollection collGroups = web.Groups; foreach (SPGroup oGroup in collGroups) { foreach (SPUser user in oGroup.Users) { routeNameOfDeveloper.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardAgreed.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardApproved.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardChecked.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardDeveloper.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardNormController.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); } } //add materials foreach (var mat in bd.Materials) { //fill dropdowns technologicalProcessMaterial.Items.Add( new ListItem(mat.MaterialId.ToString(), mat.MaterialId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = mat.MaterialId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = mat.Assortment; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = mat.Name; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = mat.Stamp; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = mat.DesignOfStandard; row.Cells.Add(cell5); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Materials.Attach(mat); lbd.Entry(mat).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell6 = new TableCell(); cell6.Controls.Add(button); row.Cells.Add(cell6); materials.Rows.Add(row); } //fill Equipment table foreach (var eqip in bd.Equipments) { //add to dropdown operationEquipment.Items.Add( new ListItem(eqip.EquipmentId.ToString(), eqip.EquipmentId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = eqip.EquipmentId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = eqip.DetailNumber.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = eqip.Name; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = eqip.Quantity.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = eqip.Department; row.Cells.Add(cell5); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Equipments.Attach(eqip); lbd.Entry(eqip).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell6 = new TableCell(); cell6.Controls.Add(button); row.Cells.Add(cell6); equipments.Rows.Add(row); } //add rigging foreach (var rig in bd.Riggings) { //add to dropdowns operationRigging.Items.Add( new ListItem(rig.RiggingId.ToString(), rig.RiggingId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = rig.RiggingId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = rig.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = rig.TypeOfTool; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = rig.Quantity.ToString(); row.Cells.Add(cell4); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Riggings.Attach(rig); lbd.Entry(rig).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell5 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell5); riggings.Rows.Add(row); } //fill operations table foreach (var oper in bd.Operations) { //add to dropdowns technologicalProcessOperation.Items.Add( new ListItem(oper.OperationId.ToString(), oper.OperationId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = oper.OperationId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = oper.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = oper.Number.ToString(); row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = oper.TransitionId.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = oper.TransitionName; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = oper.EquipmentId.ToString(); row.Cells.Add(cell6); TableCell cell7 = new TableCell(); cell7.Text = oper.RiggingId.ToString(); row.Cells.Add(cell7); TableCell cell8 = new TableCell(); cell8.Text = oper.DepartmentNumber.ToString(); row.Cells.Add(cell8); TableCell cell9 = new TableCell(); cell9.Text = oper.SiteNumber.ToString(); row.Cells.Add(cell9); TableCell cell10 = new TableCell(); cell10.Text = oper.WorkplaceNumber.ToString(); row.Cells.Add(cell10); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Operations.Attach(oper); lbd.Entry(oper).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell11 = new TableCell(); cell11.Controls.Add(button); row.Cells.Add(cell11); operations.Rows.Add(row); } //add transitions foreach (var trans in bd.Transitions) { //add to dropdowns operationTransition.Items.Add( new ListItem(trans.TransitionId.ToString(), trans.TransitionId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = trans.TransitionId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = trans.TransitionNumber.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = trans.Keyword; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = trans.TransitionType; row.Cells.Add(cell4); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Transitions.Attach(trans); lbd.Entry(trans).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell5 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell5); transitions.Rows.Add(row); } //fill TechnologicalProcesses foreach (var tp in bd.TechnologicalProcesseses) { //add to routes this.routeTechProc.Items.Add( new ListItem(tp.TechProcId.ToString(), tp.TechProcId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = tp.TechProcId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = tp.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = tp.OperationId.ToString(); row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = tp.MaterialId.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = tp.TypeByExecution; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = tp.ActNumber.ToString(); row.Cells.Add(cell6); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.TechnologicalProcesseses.Attach(tp); lbd.Entry(tp).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell7 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell7); technologicalProcesses.Rows.Add(row); } //fill route foreach (var route in bd.Routes) { //add to route card this.routeCardRoute.Items.Add( new ListItem(route.RouteId.ToString(), route.RouteId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = route.RouteId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = route.TechProcId.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = route.NameTechProc; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); SPUserCollection users = web.SiteUsers; SPUser user = users.GetByID(route.NameOfDeveloper); //SPUser developer = web.Users.GetByID(route.NameOfDeveloper); //cell4.Text = developer.LoginName; //cell4.Text = route.NameOfDeveloper.ToString(); cell4.Text = user.LoginName; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = route.DetailsDesignation; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = route.DetailsName; row.Cells.Add(cell6); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Routes.Attach(route); lbd.Entry(route).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell7 = new TableCell(); cell7.Controls.Add(button); row.Cells.Add(cell7); routes.Rows.Add(row); } //fill routeCard foreach (var rc in bd.RouteCars) { TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = rc.RouteCarId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = rc.RouteId.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = rc.CompanyName; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); SPUserCollection users = web.SiteUsers; SPUser user = users.GetByID(rc.Developer); //cell4.Text = rc.Developer.ToString(); cell4.Text = user.LoginName; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); //cell5.Text = rc.Checked.ToString(); user = users.GetByID(rc.Checked); cell5.Text = user.LoginName; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); //cell6.Text = rc.Agreed.ToString(); user = users.GetByID(rc.Agreed); cell6.Text = user.LoginName; row.Cells.Add(cell6); TableCell cell7 = new TableCell(); //cell7.Text = rc.Approved.ToString(); user = users.GetByID(rc.Approved); cell7.Text = user.LoginName; row.Cells.Add(cell7); TableCell cell8 = new TableCell(); //cell8.Text = rc.NormСontroller.ToString(); user = users.GetByID(rc.NormСontroller); cell8.Text = user.LoginName; row.Cells.Add(cell8); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.RouteCars.Attach(rc); lbd.Entry(rc).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell9 = new TableCell(); cell9.Controls.Add(button); row.Cells.Add(cell9); routeCards.Rows.Add(row); } }
protected override void CreateChildControls() { this.ChromeType = PartChromeType.None; string text = this._MenuList + "spCustomMenu"; AspMenu aspMenu = new AspMenu(); //aspMenu.Orientation = Orientation.Vertical; SPWeb sPWeb = null; try { aspMenu.UseSimpleRendering = true; aspMenu.CssClass = "spNavigation"; if (this.Set_TopNavigationMenu.ToLower() != "yes" && this.Set_TopNavigationMenu.ToLower() != "no") { this.Set_TopNavigationMenu = "yes"; } if (this.Set_TopNavigationMenu.ToLower() == "yes") { this.Set_MenuName = "TopNavigationMenu"; this.Set_MenuOrientation = "horizontal"; } aspMenu.ID = this.Set_MenuName; aspMenu.EnableViewState = false; if (this.Set_MenuOrientation.ToLower() == "horizontal") { aspMenu.Orientation = Orientation.Horizontal; } else { aspMenu.Orientation = Orientation.Vertical; } SPSite sPSite; if (this.Set_ServerURL == "" || this.Set_ServerURL == null) { sPSite = SPControl.GetContextSite(this.Context); this.Set_ServerURL = sPSite.Url; } else { sPSite = new SPSite(this.Set_ServerURL); } sPWeb = sPSite.OpenWeb("/"); SPList sPList = sPWeb.Lists[this.Set_MenuList]; this._NewWindowFieldExists = sPList.Fields.ContainsField("OpenNewWindow"); SPQuery sPQuery = new SPQuery(); MenuItem menuItem = new MenuItem(); this.Controls.Add(new LiteralControl("made it this far")); sPQuery.Query = "<OrderBy><FieldRef Name='LinkOrder' Ascending='True' /><FieldRef Name='Title' Ascending='True' /></OrderBy><Where><And><IsNull><FieldRef Name='ParentMenu' /></IsNull><Eq><FieldRef Name='ShowMenuItem' /><Value Type='Choice'>Yes</Value></Eq></And></Where>"; SPListItemCollection items = sPList.GetItems(sPQuery); //SPListItemCollection items = sPList.GetItems(); foreach (SPListItem sPListItem in items) { if (sPListItem["Link URL"] == null) { menuItem = new MenuItem(sPListItem["Title"].ToString()); } /* else * { * menuItem = new MenuItem(sPListItem["Title"].ToString(), "", "", this.SetServerURL(sPListItem["Link URL"].ToString())); * }*/ // this.GetListItems(sPListItem["ID"].ToString(), menuItem, sPList); aspMenu.Items.Add(menuItem); } this.Controls.Add(aspMenu); } catch (Exception ex) { this.Controls.Add(new LiteralControl("An error has occured with this web part. Please contact your system administrator and relay this error message: " + ex.InnerException.ToString() + " sub:CreateChildControls ")); } finally { if (sPWeb != null) { sPWeb.Dispose(); } } }