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

📄 district.aspx.cs

📁 前台:asp.net;后台: sql server 一个功能完善的BBS系统源码。
💻 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 Stella.Web.ProcessFlow;
using Stella.Model;
using System.Security.Permissions;

namespace Stella.Web.admin
{
	/// <summary>
	/// district
	/// </summary>
	[PrincipalPermission(SecurityAction.Demand,Role="adminer")]
	public class district : PageBase
	{
		protected System.Web.UI.WebControls.DataGrid oldData;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.TextBox dname;
		protected System.Web.UI.WebControls.TextBox comment;
		protected System.Web.UI.WebControls.TextBox lv;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.DataGrid newData;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				setUp();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.oldData.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.oldData_CancelCommand);
			this.oldData.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.oldData_EditCommand);
			this.oldData.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.oldData_UpdateCommand);
			this.oldData.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.oldData_DeleteCommand);
			this.oldData.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.oldData_ItemDataBound);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void setUp()
		{
			CacheController cc=new CacheController();
			Forum forum=cc.GetCachedForum();
			this.oldData.DataSource=forum.Districts;
			this.oldData.DataBind();
			
			if(Session["newDists"]!=null)
			{
				Forum newDists=(Forum)Session["newDists"];
				this.newData.DataSource=newDists.Districts;
				this.newData.DataBind();
				this.Button2.Visible=true;
			}
		}

		private void oldData_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.oldData.EditItemIndex=e.Item.ItemIndex;
			setUp();
		}

		
		private void oldData_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			District dist=new District();
			dist.Did=int.Parse(e.Item.Cells[0].Text);
			dist.Dname=((TextBox)e.Item.Cells[1].Controls[0]).Text;
			dist.Comment=((TextBox)e.Item.Cells[2].Controls[0]).Text;
			dist.Lv=short.Parse(((TextBox)e.Item.Cells[3].Controls[0]).Text);

			this.districtLogic.Update(dist);
			this.oldData.EditItemIndex=-1;
			setUp();
		}

		private void oldData_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.oldData.EditItemIndex=-1;
			setUp();
		}

		[PrincipalPermission(SecurityAction.Demand,Role="adminer")]
		private void oldData_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.districtLogic.Remove(int.Parse(e.Item.Cells[0].Text));
			setUp();		
		}

		private void oldData_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
			{
				LinkButton del=(LinkButton)e.Item.FindControl("del");
				del.Attributes.Add("onclick","javascript:return confirm('确认要删除吗?')");
			}
		}

		[PrincipalPermission(SecurityAction.Demand,Role="adminer")]
		private void Button1_Click(object sender, System.EventArgs e)
		{
			if(!this.IsRefresh)
			{
				District dist=new District();
				dist.Dname=this.dname.Text;
				dist.Comment=this.comment.Text;
				dist.Lv=short.Parse(this.lv.Text);
				if(Session["newDists"]==null)
				{
					Forum fourm=new Forum();
					Session["newDists"]=fourm;
				}
				Forum newDists=(Forum)Session["newDists"];
				newDists.AddDistrict(dist);
			}
			setUp();
		}

		[PrincipalPermission(SecurityAction.Demand,Role="adminer")]
		private void Button2_Click(object sender, System.EventArgs e)
		{
			if(Session["newDists"]!=null)
			{
				this.districtLogic.Create((Forum)Session["newDists"]);
				Session["newDists"]=null;
				Session.Remove("newDists");
				this.Button2.Visible=false;
			}

			setUp();
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -