📄 settings.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Wrox.WebModules.Accounts.Business;
namespace Wrox.WebModules.NewsManager.Web
{
public class Settings : Wrox.ThePhile.Web.PhilePage
{
protected System.Web.UI.WebControls.Table TableSettings;
protected System.Web.UI.WebControls.Button Update;
protected System.Web.UI.WebControls.TextBox NewsURL;
protected System.Web.UI.WebControls.TextBox ConnectionString;
protected System.Web.UI.WebControls.TextBox AbstractLength;
protected void Page_Load(object sender, EventArgs e)
{
// check if the current user is allowed to administer the news
if (!Context.User.Identity.IsAuthenticated ||
!((PhilePrincipal)Context.User).HasPermission((int)NewsManagerPermissions.AdministerNews))
{
// if not, redirect to the Login page
Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true", true);
}
if (!IsPostBack)
{
// load all the settings
Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings();
ConnectionString.Text = settings.ConnectionString;
NewsURL.Text = settings.NewsUrl;
AbstractLength.Text = settings.AbstractLength.ToString();
}
}
protected void Update_Click(object sender, EventArgs e)
{
Configuration.ModuleSettings settings = new Configuration.ModuleSettings();
// set the new properties values and update everything
settings.ConnectionString = ConnectionString.Text.Trim();
settings.NewsUrl = NewsURL.Text.Trim();
// if no abstract length is specified (textbox empty), set to -1 (whole news body)
if (AbstractLength.Text.Trim().Length > 0)
settings.AbstractLength = int.Parse(AbstractLength.Text);
else
{
AbstractLength.Text = "-1";
settings.AbstractLength = -1;
}
// save the new settings
Configuration.ModuleConfig.SaveSettings(settings);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -