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

📄 serch.aspx.cs

📁 校友录的总体功能分为三个子功能模块:管理功能模块,用户注册功能模块,用户个性化服务
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;

using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Drawing ;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class serch : System.Web.UI.Page
{

    public int pageindex=0;
    private void Binder()
    {

        //绑定省
        ////string cmd2 = "select * from province";
        //SqlCommand cmd=new SqlCommand("select * from province")
        ////SqlDataAdapter sda2 = new SqlDataAdapter(cmd2, con);
        //SqlDataReader ds2 =cmd.ExecuteReader() ;
        ////sda2.Fill(ds2, "t2");
        //this.Province.DataSource = ds2;
        //this.Province.DataTextField = "t2.province";
        //this.Province.DataValueField = "t2.id";
        ////this.Province.DataBind();
        //绑定市
        //string cmd3 = "select * from 市表 where 行省编号=" + (this.CBProvince.SelectedValue);
        //SqlDataAdapter sda3 = new SqlDataAdapter(cmd3, con);
        //DataSet ds3 = new DataSet();
        //sda3.Fill(ds3, "t3");
        //this.CBCity.DataSource = ds3;
        //this.CBCity.DisplayMember = "t3.市名称";
        //this.CBCity.ValueMember = "t3.市编号";
        //SqlConnection conn = DB.createSqlConnection();
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select  id,province from province ";//distinct
        SqlDataReader sdr = cmd.ExecuteReader();
        this.Province.DataSource = sdr;
        this.Province.DataTextField = "province";
        this.Province.DataValueField = "id";
        this.Province.DataBind();
        conn.Close();
     //   Session["TempPro"] = this.Province.SelectedItem.Text;
        //绑定市
        SqlConnection conn2 = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        conn2.Open();
        SqlCommand cmd2 = new SqlCommand();
        cmd2.Connection = conn2;
        cmd2.CommandText = "select  distinct id,city from city where father IN (select provinceID from province where province='" + this.Province.SelectedItem.Text + "')";//"+this.Province.Text.ToString()+"

        SqlDataReader sdr2 = cmd2.ExecuteReader();
        this.City.DataSource = sdr2;
        this.City.DataTextField = "city";
        this.City.DataValueField = "id";
        this.City.DataBind();

        //SqlDataAdapter sda3 = new SqlDataAdapter(cmd3, con);
        //DataSet ds3 = new DataSet();
        //sda3.Fill(ds3, "t3");
        //this.CBCity.DataSource = ds3;
        //this.CBCity.DisplayMember = "t3.市名称";
        //this.CBCity.ValueMember = "t3.市编号";

        conn2.Close();
        //    Session["TempPro"] = this.Province.SelectedItem.Text;

    }
    private void SetCountry()
    {
        ArrayList CountryList = new ArrayList();

        CountryList.Add("境内");
        CountryList.Add("境外");

        this.Country.DataSource = CountryList;
        this.Country.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["UserID"] == null)
            Response.Redirect("index.aspx");

         //   Session["UserID"] = "04157008";
        
        this.SerchText.Focus();

        if (!IsPostBack)
        {


            if (Session["Serchname"]!= null)
            {
                string cmd = "  SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID where  UserInfo.StudentID IN (select StudentID from StudentInfo where Name LIKE '" + "%" + Session["Serchname"].ToString() + "%" + "')";//"+this.Province.Text.ToString()+" ; //设置SQL命令

                this.SqlDataSource1.SelectCommand = cmd;
                this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
                this.GridView1.DataBind();             //对GridView进行绑定
                this.SerchLab.Text = Session["Serchname"].ToString().Trim();
                this.SerchText.Text = Session["Serchname"].ToString().Trim(); 
                Session["Serchname"] = null;

                //  Session["MailTo"] = "lsjf";
            }
        }
        
        if (!IsPostBack)
        {

              
            
            this.Binder();

            this.SetCountry();

        }
        this.SerchText.Attributes.Add("onkeydown", "if(event.keyCode==13){   event.keyCode=9;   document.getElementById('SerchBtn').click();}");
        this.SerchText.Attributes.Add("onfocus", "setFocus(this)");
        
        //SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        //conn.Open();
        ////SqlCommand cmd = new SqlCommand();
        //cmd.Connection = conn;
        //cmd.CommandText = "select distinct id,province from province ";
        //SqlDataReader sdr = cmd.ExecuteReader();
        //this.SerchData.DataSource = sdr;
     //   this.SerchData.DataTextField = "province";
      //  this.SerchData.DataValueField = "id";
        //   @UserID  char(20),
        //@StudentID char(10),
        //@PWD nchar(16),
        //@NickName char(10),
        //@Question varchar(50),
        //@Answer varchar(50),
        //@PicName nchar(30),
        //@Remark nvarchar(200),
        //@Sex char(10),
        //@Tele  char(20),
        //@MobilePh nchar(16),
        //@QQ  char(10),
        //@Email nchar(30),
        //@Country  char(10),
        //@Province char(10),
        //@City Char(10),
        //@Address nchar(40),
        //@PostNum nchar(10),
        ////@RegClass nchar(10)
        //SqlDataAdapter myda = new SqlDataAdapter("select Sex ,Answer from UserInfo ", conn);
        //DataSet myds = new DataSet();
        //myda.Fill(myds, "RusTable0");
        //if (myds.Tables["RusTable0"].Rows.Count > 0)
        //{
        //    GridView2.DataSource = myds;
        //     GridView2.DataBind();
        //}
       
        //conn.Close();
        ////SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);
        ////sql = "select * from view_JobSeYw";
        ////conn.Open();
        //SqlDataAdapter myda = new SqlDataAdapter(sql, conn);
        //DataSet myds = new DataSet();
        //myda.Fill(myds, "RusTable0");
        //if (myds.Tables["RusTable0"].Rows.Count > 0)
        //{
        //    GridView1.DataSource = myds;
        //    GridView1.DataBind();
        //}
        //conn.Close(); 

      //  this.SqlDataSource1.SelectCommand("select * from user");
      //  test();
    
    }
    private void test()
    {

        //SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        //string sql = "select ClassName from UserToClass"; //设置SQL命令
        //SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
        //DataSet dataset = new DataSet();
        //adapter.Fill(dataset, "mybook");
        //this.DropDownList2.DataSource = dataset;
        //this.DropDownList2.DataBind();
        //conn.Close();
    }

    public ArrayList GetClass(object source)
    {


        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
       conn.Open(); //打开数据库连接
        //SqlCommand cmd = new SqlCommand();
        //cmd.Connection = conn;
        //cmd.CommandText = "select ClassName from UserToClass";// where StudentID='" +source.ToString()+"'";//distinct
        //SqlDataReader sdr = cmd.ExecuteReader();
     
        //   conn.Close();
        ////    return sdr;
        //SqlDataAdapter adapter = new SqlDataAdapter("select ClassName from UserToClass", conn);
        //    DataSet dataset = new DataSet();
        //    adapter.Fill(dataset, "mybook");

        //    //DataGrid1.DataBind();
    //    return dataset;
                     DataSet ds=new DataSet();
                    SqlDataAdapter command=new SqlDataAdapter("",conn);


                    command.SelectCommand.CommandText = "select ClassName from UserToClass where UserID='" +source.ToString()+"'";
                    command.Fill(ds,"table1");
                    conn.Close();

                    ArrayList ClassList = new ArrayList();
                        ClassList.Add("所注册班级");
                    
                    for(int i=0;i<ds.Tables["table1"].Rows.Count;i++)
                    {

                        ClassList.Add(ds.Tables["table1"].Rows[i][0].ToString());
                   //   this.DropDownList2.Items.Add(new ListItem(ds.Tables["table1"].Rows[i][1].ToString(),ds.Tables["table1"].Rows[i][0].ToString()));
                    
                    
                    }





        //ArrayList ListImg = new ArrayList();
        //string target = "_";
        //char[] anyOf = target.ToCharArray();

        //String Temp;
        //Temp = source.ToString();
        //int n = 0;
        //int index = 0;
        //for (int i = 0; i <= Temp.Length; i++)
        //{

        //    index = Temp.IndexOfAny(anyOf, n);
        //    // this.TextBox1.Text = Temp.Substring(0, n);
        //    if (index != -1)
        //    {
        //        ListImg.Add(Temp.Substring(n, index - n));
        //        n = index + 1;
        //    }
        //    else
        //    {
        //        ListImg.Add(Temp.Substring(n, Temp.Length - n));

        //        break;
        //    }
       return ClassList;
        
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
       // GridViewRowEventArgs e;
      ///  e.Row.con
    }
    public String IsNull(string str)
    {
        ////////////IsNull(Eval("MobilePh"))!=null
        /////////~/PICTURE/passwd.gif
        if (str.Trim().Length == 0 ||str == "" || str == null)
        {
            string pic = "passwd.gif";
            str = "<img id=\"SelPic\" alt=\"\" src=\"PICTURE/" + pic + "\" style=\"width: 20px; height: 20px\" /> ---";
        return str;
        
        }
      return str;
     
    }
     public String IsNull(object source)
    {
        ////////////IsNull(Eval("MobilePh"))!=null
         String Temp = source.ToString();
         if (Temp.Trim()!=null)
         {
           
            return Temp;
            
         }

         Temp = "211dfg12";
         return Temp;
    }
    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }
    private void Serch(string field, string condition )
    {
        string cmd;

        //////if ( other != "")
        //////{
            //  cmd = " SELECT [UserID], [Email], [Tele], [MobilePh], [PicName], [QQ], [StudentID] FROM [UserInfo] where " + field + "='" + condition + "' or" + other + "='" + condition + "'"; ;//设置SQL命令
        //}
        //else
        //{
        cmd = " SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID where UserInfo." + field + "='" + condition + "'"; ;//设置SQL命令
        //}
        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定
        this.SerchLab.Text = condition;
     

    }
    protected void Serch_Click(object sender, EventArgs e)
    {
       
        //SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        //conn.Open();
        string cmd = "  SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID where UserInfo.StudentID IN (select StudentID from StudentInfo where Name  LIKE '" + "%" + this.SerchText.Text.ToString() + "%" + "')";//"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand=cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定
        this.SerchLab.Text = this.SerchText.Text;

        this.SerchText.Focus();
        

    }
    public void Btnckick()
    {
        string cmd = "   SELECT UserInfo.UserID, UserInfo.Email, UserInfo.Tele, UserInfo.MobilePh, UserInfo.PicName, UserInfo.QQ, UserInfo.StudentID, StudentInfo.Name FROM UserInfo INNER JOIN StudentInfo ON UserInfo.StudentID = StudentInfo.StudentID where UserInfo.StudentID IN  (select StudentID from StudentInfo where Name='" + this.SerchText.Text.ToString() + "')";//"+this.Province.Text.ToString()+" ; //设置SQL命令

        this.SqlDataSource1.SelectCommand = cmd;
        this.SqlDataSource1.DataBind();   //将SqlDataSource重新绑定
        this.GridView1.DataBind();             //对GridView进行绑定
   this.SerchCount.Text = this.SerchText.Text;
         

    }
    protected void GridView1_SelectedIndexChanged2(object sender, EventArgs e)
    {

    }
  
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void SerchText_TextChanged(object sender, EventArgs e)
    {


    

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (e.NewPageIndex == -1)
            e.NewPageIndex = 0;
        GridView1.PageIndex = e.NewPageIndex;

    //    pageindex = e.NewPageIndex;

        GridView1.DataBind();
    }
    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        
          this.SerchCount.Text = e.AffectedRows.ToString();

    }

⌨️ 快捷键说明

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