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

📄 singleuserchoose.aspx.cs

📁 商机管理系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class depart_users_singleuserchoose : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    static string sqlstr;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string did = "0";
            if (Request.QueryString["did"] != null)
            {
                did = Request.QueryString["did"];
            }
            CreateDataSet();
            sqlstr = "";
            getTree(did);
            sqlstr += "departid =" + did;
            GridView1.DataSource = getDataSource(sqlstr);
            GridView1.DataBind();
        }
    }
    private void CreateDataSet()
    {
        ds.Clear();
        ds.Dispose();
        string connectstr = MyCommon.getConnectstr();
        SqlConnection myConn = new SqlConnection(connectstr);
        SqlCommand myCmd = new SqlCommand("select departid,parentid,name from depart");
        SqlDataAdapter myDataAdpter = new SqlDataAdapter();
        myCmd.Connection = myConn;
        myDataAdpter.SelectCommand = myCmd;
        myConn.Open();
        myDataAdpter.Fill(ds, "depart");
        myConn.Close();
    }

    private void getTree(string parentid)
    {
        DataView dv = new DataView();
        dv.Table = ds.Tables["depart"];
        dv.RowFilter = "parentid=" + parentid + "";
        string strId;
        foreach (DataRowView drv in dv)
        {
            strId = drv["departid"].ToString();
            sqlstr = sqlstr + "departid =" + strId + " or ";
            getTree(strId);
        }
    }

    private SqlDataSource getDataSource(string str)
    {
        SqlDataSource sds = new SqlDataSource();
        sds.ConnectionString = MyCommon.getConnectstr();
        sds.SelectCommand = "SELECT [user].* FROM [user] where "+str;
        //sds.SelectCommand = "select * from user_depart";
        return sds;
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "if(this!=prev){c=this.style.backgroundColor;this.style.backgroundColor='#D8F3C6'}");//当鼠标停留时更改背景色
        e.Row.Attributes.Add("onmouseout", "if(this!=prev){this.style.backgroundColor=c}");//当鼠标移开时还原背景色
        e.Row.Attributes["style"] = "Cursor:hand";//设置悬浮鼠标指针形状为"小手"

        e.Row.Attributes.Add("onclick", "var a='" + e.Row.Cells[1].Text +"';window.returnValue = a;top.opener='meizz';top.close();");
    }
}

⌨️ 快捷键说明

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