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

📄 infosearch.aspx.cs

📁 学生公寓管理系统使用说明: 1.服务器运行环境 SQL 2000 .NET FRAMEWORK 1.1 .NET FRAMEWORK 1.1 CHINESE (SIMPL
💻 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.InfoManage
{
	/// <summary>
	/// InfoSearch 的摘要说明。
	/// </summary>
	public class InfoSearch : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		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 System.Web.UI.WebControls.Label Label2;
		protected string cmdText;
		protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
		protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
		protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
		protected System.Data.SqlClient.SqlConnection sqlConnection1; 
		protected Manage.DataSet1 dataSet11;

		private void Data_Bind()
		{
			myConn=ConfigurationSettings.AppSettings["mySql"];
			cmdText="select * from Info";
			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,"Info");
			this.DataGrid1.DataSource=this.dataSet11;
			this.DataGrid1.DataBind();
			this.sqlConnection1.Close();
		}

		private void Grid_Bind()
		{
			myConn=ConfigurationSettings.AppSettings["mySql"];
			string s;
			s=this.DropDownList1.SelectedValue.ToString()+"="+"'"+this.TextBox1.Text+"'";
			cmdText="select * from Info 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,"Info");
			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.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
			this.Search.Click += new System.EventHandler(this.Search_Click);
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			// 
			// sqlDataAdapter1
			// 
			this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																									  new System.Data.Common.DataTableMapping("Table", "Info", new System.Data.Common.DataColumnMapping[] {
																																																			  new System.Data.Common.DataColumnMapping("Info_ID", "Info_ID"),
																																																			  new System.Data.Common.DataColumnMapping("Info_Writer", "Info_Writer"),
																																																			  new System.Data.Common.DataColumnMapping("Info_Main", "Info_Main"),
																																																			  new System.Data.Common.DataColumnMapping("Info_Kind", "Info_Kind"),
																																																			  new System.Data.Common.DataColumnMapping("Info_Text", "Info_Text"),
																																																			  new System.Data.Common.DataColumnMapping("Info_Date", "Info_Date")})});
			this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM Info WHERE (Info_ID = @Original_Info_ID) AND (Info_Date = @Original_I" +
				"nfo_Date) AND (Info_Kind = @Original_Info_Kind) AND (Info_Main = @Original_Info_" +
				"Main) AND (Info_Text = @Original_Info_Text) AND (Info_Writer = @Original_Info_Wr" +
				"iter)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_ID", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_ID", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Date", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Date", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Kind", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Kind", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Main", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Main", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Text", System.Data.SqlDbType.VarChar, 1000, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Text", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Writer", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Writer", System.Data.DataRowVersion.Original, null));
			// 
			// 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";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = @"INSERT INTO Info(Info_ID, Info_Writer, Info_Main, Info_Kind, Info_Text, Info_Date) VALUES (@Info_ID, @Info_Writer, @Info_Main, @Info_Kind, @Info_Text, @Info_Date); SELECT Info_ID, Info_Writer, Info_Main, Info_Kind, Info_Text, Info_Date FROM Info WHERE (Info_ID = @Info_ID)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_ID", System.Data.SqlDbType.BigInt, 8, "Info_ID"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Writer", System.Data.SqlDbType.VarChar, 20, "Info_Writer"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Main", System.Data.SqlDbType.VarChar, 40, "Info_Main"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Kind", System.Data.SqlDbType.VarChar, 10, "Info_Kind"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Text", System.Data.SqlDbType.VarChar, 1000, "Info_Text"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Date", System.Data.SqlDbType.NVarChar, 10, "Info_Date"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT Info_ID, Info_Writer, Info_Main, Info_Kind, Info_Text, Info_Date FROM Info" +
				"";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE Info SET Info_ID = @Info_ID, Info_Writer = @Info_Writer, Info_Main = @Info_Main, Info_Kind = @Info_Kind, Info_Text = @Info_Text, Info_Date = @Info_Date WHERE (Info_ID = @Original_Info_ID) AND (Info_Date = @Original_Info_Date) AND (Info_Kind = @Original_Info_Kind) AND (Info_Main = @Original_Info_Main) AND (Info_Text = @Original_Info_Text) AND (Info_Writer = @Original_Info_Writer); SELECT Info_ID, Info_Writer, Info_Main, Info_Kind, Info_Text, Info_Date FROM Info WHERE (Info_ID = @Info_ID)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_ID", System.Data.SqlDbType.BigInt, 8, "Info_ID"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Writer", System.Data.SqlDbType.VarChar, 20, "Info_Writer"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Main", System.Data.SqlDbType.VarChar, 40, "Info_Main"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Kind", System.Data.SqlDbType.VarChar, 10, "Info_Kind"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Text", System.Data.SqlDbType.VarChar, 1000, "Info_Text"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Info_Date", System.Data.SqlDbType.NVarChar, 10, "Info_Date"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_ID", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_ID", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Date", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Date", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Kind", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Kind", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Main", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Main", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Text", System.Data.SqlDbType.VarChar, 1000, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Text", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Info_Writer", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Info_Writer", System.Data.DataRowVersion.Original, null));
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Search_Click(object sender, System.EventArgs e)
		{
			string s;
			int i=0;
			s=this.DropDownList1.SelectedValue.ToString()+"="+"'"+this.TextBox1.Text+"'";
			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			try
			{
				if(this.TextBox1.Text!="")
				{
					cmdText="select * from Info where ";
					cmdText=cmdText+s;
					conn.Open();
					cmd=new System.Data.SqlClient.SqlCommand(cmdText,conn);
					reader=cmd.ExecuteReader();
					while(reader.Read())
						i++;
					reader.Close();
					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,"Info");
					this.DataGrid1.DataSource=this.dataSet11;
					this.DataGrid1.DataBind();
					this.sqlConnection1.Close();
					this.Label2.Text=this.DropDownList1.SelectedItem.Text+"为"+this.TextBox1.Text+"的文章共有"+Convert.ToString(i)+"篇!";
				}
				else 
				{
					Response.Write("<script>alert('请输入查询条件!')</script>");
					Data_Bind();
				}
			}
			catch(Exception ex)
			{	
				
				Response.Write("<script>alert('"+ex.Message+"查询条件格式错误!')</script>");
				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();
		}
	}
}

⌨️ 快捷键说明

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