📄 editcontent.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
//*********************************************************************
//
// EditContent Class
//
// WebControl that displays different actions that can be taken
// with a content page such as adding, deleting, moving, and editing.
// This control checks the current users permissions before
// displaying options.
//
//*********************************************************************
public class EditContent : WebControl {
string _addText = String.Empty;
string _editText = String.Empty;
string _deleteText = String.Empty;
string _moveText = String.Empty;
string _commentText = String.Empty;
string _moderateText = String.Empty;
string _rateText = String.Empty;
string _addUrl;
string _editUrl;
string _deleteUrl;
string _moveUrl;
string _commentUrl;
string _moderateUrl;
string _rateUrl;
//*********************************************************************
//
// EditContent Constructor
//
// Creates a WebControl with a table tag as its containing
// tag.
//
//*********************************************************************
public EditContent() : base(HtmlTextWriterTag.Table){}
//*********************************************************************
//
// AddText Property
//
// The text displayed for adding new content.
//
//*********************************************************************
public string AddText {
set { _addText = value; }
}
//*********************************************************************
//
// EditText Property
//
// The text displayed for editing content.
//
//*********************************************************************
public string EditText {
set { _editText = value; }
}
//*********************************************************************
//
// DeleteText Property
//
// The text displayed for deleting content.
//
//*********************************************************************
public string DeleteText {
set { _deleteText = value; }
}
//*********************************************************************
//
// MoveText Property
//
// The text displayed for moving content.
//
//*********************************************************************
public string MoveText {
set { _moveText = value; }
}
//*********************************************************************
//
// ModerateText Property
//
// The text displayed for moderating content.
//
//*********************************************************************
public string ModerateText {
set { _moderateText = value; }
}
//*********************************************************************
//
// RateText Property
//
// The text displayed for rating content.
//
//*********************************************************************
public string RateText {
set { _rateText = value; }
}
//*********************************************************************
//
// CommentText Property
//
// The text displayed for commenting on content.
//
//*********************************************************************
public string CommentText {
set { _commentText = value; }
}
//*********************************************************************
//
// AddUrl Property
//
// The URL for adding new content.
//
//*********************************************************************
public string AddUrl {
set { _addUrl = value; }
get { return _addUrl; }
}
//*********************************************************************
//
// EditUrl Property
//
// The URL for editing content.
//
//*********************************************************************
public string EditUrl {
set { _editUrl = value; }
get { return _editUrl; }
}
//*********************************************************************
//
// DeleteUrl Property
//
// The URL for deleting content.
//
//*********************************************************************
public string DeleteUrl {
set { _deleteUrl = value; }
get { return _deleteUrl; }
}
//*********************************************************************
//
// MoveUrl Property
//
// The URL for moving content.
//
//*********************************************************************
public string MoveUrl {
set { _moveUrl = value; }
get { return _moveUrl; }
}
//*********************************************************************
//
// ModerateUrl Property
//
// The URL for moderating content.
//
//*********************************************************************
public string ModerateUrl {
set { _moderateUrl = value; }
get { return _moderateUrl; }
}
//*********************************************************************
//
// RateUrl Property
//
// The URL for rating content.
//
//*********************************************************************
public string RateUrl {
set { _rateUrl = value; }
get { return _rateUrl; }
}
//*********************************************************************
//
// CommentUrl Property
//
// The URL for commenting on content.
//
//*********************************************************************
public string CommentUrl {
set { _commentUrl = value; }
get { return _commentUrl; }
}
//*********************************************************************
//
// CreateChildControls Method
//
// Adds the links to this control Controls collection.
//
//*********************************************************************
override protected void CreateChildControls() {
HyperLink lnk;
// Get UserInfo
UserInfo objUserInfo = (UserInfo)Context.Items["UserInfo"];
// Get SectionInfo
SectionInfo objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
// Add Link
if ((objUserInfo.MayAdd || Array.IndexOf(objSectionInfo.AddRoles, "Community-Authenticated" )!=-1)
&& _addText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _addText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_addUrl);
Controls.Add(lnk);
}
// Edit Link
if ((objUserInfo.MayEdit || Array.IndexOf(objSectionInfo.EditRoles, "Community-Authenticated")!=-1)
&& _editText!= String.Empty) {
lnk = new HyperLink();
lnk.Text = _editText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_editUrl);
Controls.Add(lnk);
}
// Delete Link
if ((objUserInfo.MayDelete || Array.IndexOf(objSectionInfo.DeleteRoles, "Community-Authenticated")!=-1)
&& _deleteText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _deleteText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_deleteUrl);
Controls.Add(lnk);
}
// Move Link
if
(
((objUserInfo.MayModerate || Array.IndexOf(objSectionInfo.ModerateRoles, "Community-Authenticated")!=-1)
|| (objUserInfo.MayEdit || Array.IndexOf(objSectionInfo.EditRoles, "Community-Authenticated")!=-1))
&& _moveText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _moveText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_moveUrl);
Controls.Add(lnk);
}
// Comment Link
if (objSectionInfo.EnableComments) {
if ((objUserInfo.MayComment || Array.IndexOf(objSectionInfo.CommentRoles, "Community-Authenticated")!=-1)
&& _commentText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _commentText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_commentUrl);
Controls.Add(lnk);
}
}
// Moderate Link
if (objSectionInfo.EnableModeration) {
if ((objUserInfo.MayModerate || Array.IndexOf(objSectionInfo.ModerateRoles, "Community-Authenticated")!=-1)
&& _moderateText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _moderateText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_moderateUrl);
Controls.Add(lnk);
}
}
// Rate Link
if (objSectionInfo.EnableRatings) {
if ((objUserInfo.MayRate || Array.IndexOf(objSectionInfo.RateRoles, "Community-Authenticated")!=-1)
&& _rateText != String.Empty) {
lnk = new HyperLink();
lnk.Text = _rateText;
lnk.NavigateUrl = CommunityGlobals.CalculatePath(_rateUrl);
Controls.Add(lnk);
}
}
}
//*********************************************************************
//
// Render Method
//
// Renders links to the browser by iterating through
// the Controls collection.
//
//*********************************************************************
protected override void Render(HtmlTextWriter tw)
{
if (Controls.Count > 0) {
tw.RenderBeginTag(HtmlTextWriterTag.Table);
tw.RenderBeginTag(HtmlTextWriterTag.Tr);
int controlCount = Controls.Count;
int counter = 0;
foreach (Control control in Controls) {
counter ++;
tw.RenderBeginTag(HtmlTextWriterTag.Td);
control.RenderControl(tw);
tw.RenderEndTag(); // close td
// Render Separator
if (counter < controlCount) {
tw.RenderBeginTag(HtmlTextWriterTag.Td);
tw.Write("|");
tw.RenderEndTag(); // close td
}
}
tw.RenderEndTag(); // close tr
tw.RenderEndTag(); // close table
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -