📄 roominfo.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 System.Configuration;
namespace Manage.RoomManage
{
/// <summary>
/// RoomInfo 的摘要说明。
/// </summary>
public class RoomInfo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Data.SqlClient.SqlConnection conn;
protected System.Data.SqlClient.SqlCommand cmd;
protected System.Data.SqlClient.SqlDataReader reader;
protected string myConn;
protected System.Web.UI.WebControls.Button Search;
protected System.Web.UI.WebControls.Label Label1;
protected string cmdText;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected Manage.DataSet1 dataSet11;
private void Data_Bind()
{
cmdText="select * from Repair";
myConn=ConfigurationSettings.AppSettings["mySql"];
this.sqlConnection1=new System.Data.SqlClient.SqlConnection(myConn);
this.sqlConnection1.Open();
this.sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(cmdText,this.sqlConnection1);
this.dataSet11=new DataSet1();
this.sqlDataAdapter1.Fill(this.dataSet11,"Repair");
this.DataGrid1.DataSource=this.dataSet11;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
private void Grid_Bind()
{
myConn=ConfigurationSettings.AppSettings["mySql"];
string s;
s="Room_ID"+"="+"'"+this.TextBox1.Text+"'";
cmdText="select * from Room where ";
cmdText=cmdText+s;
this.sqlConnection1=new System.Data.SqlClient.SqlConnection(myConn);
this.sqlConnection1.Open();
this.sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(cmdText,this.sqlConnection1);
this.dataSet11=new DataSet1();
this.sqlDataAdapter1.Fill(this.dataSet11,"Repair");
this.DataGrid1.DataSource=this.dataSet11;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
Data_Bind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.Search.Click += new System.EventHandler(this.Search_Click);
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Repair", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Room_ID", "Room_ID"),
new System.Data.Common.DataColumnMapping("Room_Repair", "Room_Repair"),
new System.Data.Common.DataColumnMapping("Room_NO", "Room_NO"),
new System.Data.Common.DataColumnMapping("Floor_ID", "Floor_ID"),
new System.Data.Common.DataColumnMapping("Floor_Area", "Floor_Area"),
new System.Data.Common.DataColumnMapping("Floor_NO", "Floor_NO"),
new System.Data.Common.DataColumnMapping("Expr1", "Expr1"),
new System.Data.Common.DataColumnMapping("Expr2", "Expr2")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = @"SELECT Repair.Room_ID, Repair.Room_Repair, Room.Room_NO, Room.Floor_ID, Floor.Floor_Area, Floor.Floor_NO, Floor.Floor_ID AS Expr1, Room.Room_ID AS Expr2 FROM Repair INNER JOIN Room ON Repair.Room_ID = Room.Room_ID INNER JOIN Floor ON Room.Floor_ID = Floor.Floor_ID";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"BBS-HZ0752-NET\";packet size=4096;integrated security=SSPI;data so" +
"urce=\"BBS-HZ0752-NET\";persist security info=False;initial catalog=student";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void Search_Click(object sender, System.EventArgs e)
{
string s;
s="Room_ID"+"="+"'"+this.TextBox1.Text+"'";
cmdText="select * from Repair where ";
cmdText=cmdText+s;
this.myConn=ConfigurationSettings.AppSettings["mySql"];
this.conn=new System.Data.SqlClient.SqlConnection(myConn);
if(this.TextBox1.Text!="")
{
this.sqlConnection1=new System.Data.SqlClient.SqlConnection(myConn);
this.sqlConnection1.Open();
this.sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(cmdText,this.sqlConnection1);
this.dataSet11=new DataSet1();
this.sqlDataAdapter1.Fill(this.dataSet11,"Repair");
this.DataGrid1.DataSource=this.dataSet11;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
else
{
Response.Write("<script>alert('请输入查询条件!')</script>");
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if(DataGrid1.Items.Count==0)
{
if(DataGrid1.CurrentPageIndex!=0)
{
DataGrid1.CurrentPageIndex=DataGrid1.CurrentPageIndex-1;
}
}
else
{
string SqlStr="delete Repair where Room_ID='"+e.Item.Cells[0].Text+"'";
myConn=System.Configuration.ConfigurationSettings.AppSettings["mySql"];
conn=new System.Data.SqlClient.SqlConnection(myConn);
conn.Open();
cmd=new System.Data.SqlClient.SqlCommand(SqlStr,conn);
cmd.ExecuteNonQuery();;
conn.Close();
Response.Write("<script>alert('删除成功!')</script>");
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
Data_Bind();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -