📄 notify.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// Notify Class
//
// WebControl that displays a checkbox indicating whether or not
// user has requested a notification email when new items are listed.
//
//*********************************************************************
public class Notify : CheckBox {
SectionInfo objSectionInfo;
PageInfo objPageInfo;
UserInfo objUserInfo;
//*********************************************************************
//
// Notify Constructor
//
// Retrieves the UserInfo, SectionInfo, and PageInfo objects
// from context. This control hides itself if notification
// is not enabled for this section.
//
//*********************************************************************
public Notify() : base() {
if (Context != null) {
objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
objPageInfo = (PageInfo)Context.Items["PageInfo"];
objUserInfo = (UserInfo)Context.Items["UserInfo"];
this.CssClass = "NotifyLink";
// hide me if notification or comments not enabled
if (!objSectionInfo.EnableNotifications || (!objSectionInfo.EnableComments && objPageInfo.ID != -1))
Visible = false;
}
// Enable autopostback
AutoPostBack = true;
}
//*********************************************************************
//
// OnLoad Method
//
// Checks the checkbox when the user has asked to be notified.
//
//*********************************************************************
protected override void OnLoad(EventArgs e) {
if (!Page.IsPostBack)
Checked = NotifyUtility.GetNotificationStatus(objPageInfo.ID, objSectionInfo.ID, objUserInfo.Username);
// call base method
base.OnLoad(e);
}
//*********************************************************************
//
// OnCheckedChanged Method
//
// Changes notification status for user in database.
// If the user is not authenticated, redirects to login page.
//
//*********************************************************************
protected override void OnCheckedChanged(EventArgs e) {
// Check if authenticated
if (!objUserInfo.IsAuthenticated)
CommunityGlobals.ForceLogin();
// Update Database
NotifyUtility.UpdateNotificationStatus(objPageInfo.ID, objSectionInfo.ID, objUserInfo.Username, Checked);
// call base method
base.OnCheckedChanged(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -