⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settings.aspx.cs

📁 wrox c#高级编程
💻 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.Polls.Web
{
	/// <summary>
	/// Summary description for Settings.
	/// </summary>
	public class Settings : Wrox.ThePhile.Web.PhilePage
	{

		protected System.Web.UI.WebControls.Button Update;
		protected System.Web.UI.WebControls.TextBox ConnectionString;
		protected System.Web.UI.WebControls.TextBox LockDuration;
		protected System.Web.UI.WebControls.CheckBox LockByCookie;
		protected System.Web.UI.WebControls.CheckBox LockByIP;
		protected System.Web.UI.WebControls.Table Table1;

		protected void Page_Load(object sender, EventArgs e)
		{
			// check if the current user is allowed to administer the polls
			if (!Context.User.Identity.IsAuthenticated || 
				!((PhilePrincipal)Context.User).HasPermission((int)PollsPermissions.AdministerPolls))
			{
				// 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;
				LockDuration.Text = settings.LockDuration.ToString();
				LockByCookie.Checked = settings.LockByCookie;
				LockByIP.Checked = settings.LockByIP;
			}
		}

		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.LockByCookie = LockByCookie.Checked;
			settings.LockByIP = LockByIP.Checked;
			
			if(LockDuration.Text.Trim().Length > 0)
				settings.LockDuration = int.Parse(LockDuration.Text.Trim());
			else
			{
				settings.LockDuration = -1;
				LockDuration.Text = "-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 + -