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

📄 userserchar.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.SqlClient;
using System.Configuration;

namespace WareStore.UserBusiness
{
	/// <summary>
	/// UserSerchar 的摘要说明。
	/// </summary>
	public class UserSerchar : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.RadioButton rbtn_uname;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.RadioButton rbt_pdept;
		protected System.Web.UI.WebControls.RadioButton RadioButton1;
		protected System.Web.UI.WebControls.RadioButton rbtn_uid;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
			BindGrid();
			}

			RadioCheck();
			// 在此处放置用户代码以初始化页面
		}
		
		private void RadioCheck()
		{
           if(this.RadioButton1.Checked)
			   this.TextBox1.Visible=false;
		  else
			   this.TextBox1.Visible=true;
		}
		private void BindGrid()
		{
            string str=ConfigurationSettings.AppSettings["dsn"];
		   SqlConnection cn=new SqlConnection(str);
			cn.Open();
		   // SqlCommand cmd=new SqlCommand("UserDisplay",cn);
			//cmd.CommandType=CommandType.StoredProcedure;
              SqlDataAdapter da=new SqlDataAdapter("UserDisplay",cn);
			DataSet ds=new DataSet();
			da.Fill(ds);
			this.DataGrid1.DataSource=ds;
			this.DataGrid1.DataBind();
			cn.Close();

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.TextBox1.TextChanged += new System.EventHandler(this.TextBox1_TextChanged);
			this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
			this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
			this.RadioButton1.CheckedChanged += new System.EventHandler(this.RadioButton1_CheckedChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void RadioButton2_CheckedChanged(object sender, System.EventArgs e)
		{
		
		}

		private void RadioButton1_CheckedChanged(object sender, System.EventArgs e)
		{
		}

		private void TextBox1_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
		    string str=ConfigurationSettings.AppSettings["dsn"];
			SqlConnection cn=new SqlConnection(str);
			cn.Open();
			if(this.rbtn_uid.Checked)
			{
				string sel="select Uid,Uname,Usex,Uaddress,Uemail,Utelephone,Ddept,Ppower from Users,Depart,Power where Udept=Did and Upower=Pid and Uid like '%"+this.TextBox1.Text+"%'";
				try
				{
					SqlCommand cmd=new SqlCommand(sel,cn);
					SqlDataAdapter ad=new SqlDataAdapter();
					ad.SelectCommand=cmd;
					DataSet ds=new DataSet();
					ad.Fill(ds);
					this.DataGrid1.DataSource=ds;
					this.DataGrid1.DataBind();
							  
				}
				catch
				{
                    
				}
				finally
				{
					cn.Close();
				}
			}
			if(this.rbt_pdept.Checked)
			{
				string sel="select Uid,Uname,Usex,Uaddress,Uemail,Utelephone,Ddept,Ppower from Users,Depart,Power where Udept=Did and Upower=Pid and Ddept='"+this.TextBox1.Text+"'";
				try
				{
					SqlCommand cmd=new SqlCommand(sel,cn);
					SqlDataAdapter ad=new SqlDataAdapter();
					ad.SelectCommand=cmd;
					DataSet ds=new DataSet();
					ad.Fill(ds);
					this.DataGrid1.DataSource=ds;
					this.DataGrid1.DataBind();
							  
				}
				catch
				{
                    
				}
				finally
				{
					cn.Close();
				}
			}

			if(this.rbtn_uname.Checked)
			{
				string sel="select Uid,Uname,Usex,Uaddress,Uemail,Utelephone,Ddept,Ppower from Users,Depart,Power where Udept=Did and Upower=Pid and Uname='"+this.TextBox1.Text+"'";
				try
				{
					SqlCommand cmd=new SqlCommand(sel,cn);
					SqlDataAdapter ad=new SqlDataAdapter();
					ad.SelectCommand=cmd;
					DataSet ds=new DataSet();
					ad.Fill(ds);
					this.DataGrid1.DataSource=ds;
					this.DataGrid1.DataBind();
							  
				}
				catch
				{
                    
				}
				finally
				{
					cn.Close();
				}
			}
			if(this.RadioButton1.Checked)//all the information
			{
				BindGrid();
			}
			
		
		}

		private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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