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

📄 roomfloorinfomng.aspx.cs

📁 房屋管理系统 房屋管理系统 房屋管理系统 房屋管理系统
💻 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 System.Data.Odbc;
using System.Configuration;

namespace RoomMngSystem.Operator
{
	/// <summary>
	/// RoomFloorMng 的摘要说明。
	/// </summary>
	public class RoomFloorMng : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button5;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.Button Button7;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Button Button8;
		protected System.Web.UI.WebControls.Image Image1;
		protected System.Web.UI.WebControls.Button Button4;

		private void DataBindGrid()
		{			
			//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
			OdbcDataAdapter da;
			OdbcConnection conn = new OdbcConnection();
			conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
			//创建数据适配器对象
			da =new OdbcDataAdapter("Select * from [FloorInfo]",conn);
			//创建DataSet对象
			DataSet ds = new DataSet();
			try
			{
				//填充数据集
				da.Fill(ds,"testTable");
				//进行数据绑定
				DataGrid1.DataSource = ds.Tables["testTable"];
				DataGrid1.DataBind();
			}
			catch
			{

			}				
		}
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			string user;
			try
			{	
				user=Session["UserName"].ToString();				
			}
			catch
			{
				this.Response.Redirect("../Enter.aspx");
			}

			if(!IsPostBack)
			{
				DataBindGrid();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button5.Click += new System.EventHandler(this.LinkButton1_Click);
			this.Button6.Click += new System.EventHandler(this.LinkButton2_Click);
			this.Button7.Click += new System.EventHandler(this.LinkButton3_Click);
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.OnPageIndexChanged);
			this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnCancelCommand);
			this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnEditCommand);
			this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnUpdateCommand);
			this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnDeleteCommand);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button4.Click += new System.EventHandler(this.Button4_Click);
			this.Button8.Click += new System.EventHandler(this.Button8_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void OnEditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex=e.Item.ItemIndex;
			DataBindGrid();
		}

		private void OnDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			OdbcConnection conn = new OdbcConnection();
			conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
			string sqlcom;
			//打开数据连接
			conn.Open();
			try
			{
				sqlcom="delete [floorinfo] where [bno]='"+((Label)e.Item.FindControl("NameLabel")).Text+"' and [floor]='"+((Label)e.Item.FindControl("Label11")).Text+"'";
				//定义命令对象
				OdbcCommand cmd = new OdbcCommand(sqlcom,conn);
				//执行SQL命令
				cmd.ExecuteNonQuery();
				DataBindGrid();
			}
			catch
			{

			}
			//关闭连接对象
			conn.Close();
		}

		private void OnCancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex=-1;
			DataBindGrid();
		}

		private void OnPageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
			DataBindGrid();
		}

		private void OnUpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string cell3=((Label)e.Item.FindControl("NameLabel")).Text;		//编号
			string cell4=((Label)e.Item.FindControl("Label11")).Text;		//层号
			string cell5=((TextBox)e.Item.FindControl("Textbox3")).Text;		//建筑面积
			string cell6=((TextBox)e.Item.FindControl("Textbox4")).Text;		//房间数
			string cell7=((TextBox)e.Item.FindControl("Textbox5")).Text;		//教室
			string cell9=((TextBox)e.Item.FindControl("Textbox7")).Text;		//办公室
			string cell11=((TextBox)e.Item.FindControl("Textbox9")).Text;		//实验室

			string sqlcom="UPDATE [floorInfo] SET buildingarea='"+cell5+"',roomnum='"+cell6+"',tchroom='"+cell7+"',officeroom='"+cell9+"',labroom='"+cell11+"' WHERE bno='"+cell3+"' and floor='"+cell4+"'";
			OdbcConnection conn = new OdbcConnection();
			conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
			//定义命令对象
			OdbcCommand cmd = new OdbcCommand(sqlcom,conn);

			try
			{
				conn.Open();
				//取消编辑
				DataGrid1.EditItemIndex=-1;
				//执行SQL命令
				cmd.ExecuteNonQuery();
				DataBindGrid();
			}
			catch
			{
				//输出异常信息
			}
			finally
			{
				//关闭连接对象
				conn.Close();
			}
			
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			System.Web.UI.WebControls.CheckBox chkExport;
			foreach(DataGridItem oDataGridItem in DataGrid1.Items)
			{
				chkExport=(CheckBox)oDataGridItem.FindControl("chkExport");
				chkExport.Checked=true;
			}
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			System.Web.UI.WebControls.CheckBox chkExport;
			foreach(DataGridItem oDataGridItem in DataGrid1.Items)
			{
				chkExport=(CheckBox)oDataGridItem.FindControl("chkExport");
				chkExport.Checked=false;
			}
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			System.Web.UI.WebControls.CheckBox chkExport;
			string sID,sFloor,sqlcom;

			OdbcConnection conn = new OdbcConnection();
			conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
			//打开数据连接
			conn.Open();			

			foreach(DataGridItem oDataGridItem in DataGrid1.Items)
			{
				chkExport=(CheckBox)oDataGridItem.FindControl("chkExport");
				if(true==chkExport.Checked)
				{	
					try
					{	
						sID=((Label)(oDataGridItem.FindControl("NameLabel"))).Text;
						sFloor=((Label)(oDataGridItem.FindControl("Label11"))).Text;
						sqlcom="delete [floorinfo] where [bno]='"+sID+"' and [floor]='"+sFloor+"'";
						//定义命令对象
						OdbcCommand cmd = new OdbcCommand(sqlcom,conn);
						//执行SQL命令
						cmd.ExecuteNonQuery();
					}
					catch
					{						
						return;
					}
				}
			}
			DataBindGrid();
		}

		private void LinkButton1_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomUserMng.aspx");
		}

		private void LinkButton3_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomDataMng.aspx");
		}

		private void LinkButton2_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomSysMng.aspx");
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomFloorAdd.aspx");
		}

		private void Button8_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomFileUpload.aspx");
		}
	}
}

⌨️ 快捷键说明

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