コード例 #1
0
ファイル: GongGaoModify.aspx.cs プロジェクト: cnbin/HLB
    private void BindTree(TreeNodeCollection Nds, int IDStr)
    {
        //Andy  20130925
        ArrayList listName = null;

        if (Request.QueryString["Condition"] != null && Request.QueryString["Condition"].ToString() != "")
        {
            listName = new ArrayList(Request.QueryString["Condition"].ToString().Split(','));
        }
        string DepartmentID = "";
        string SuperiorID   = ZWL.Common.PublicMethod.GetSessionValue("DepartmentID");;

        while (SuperiorID != "0")
        {
            DepartmentID = SuperiorID;
            SuperiorID   = GetSuperiorDepartmentID(SuperiorID);
        }

        SqlConnection Conn = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());


        //SqlConnection Conn = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());
        Conn.Open();

        // SqlCommand MyCmd = new SqlCommand("select * from ERPBuMen where DirID=" + IDStr.ToString() + " order by ID asc", Conn);
        //SqlCommand MyCmd = new SqlCommand("select * from hx_vERPBuMen where DirID=" + IDStr.ToString() + " and CHARINDEX('" + ZWL.Common.PublicMethod.GetSessionValue("DepartmentID") + "',p_depart_ids)>0 order by ID asc", Conn);
        SqlCommand MyCmd;

        if (ZWL.Common.PublicMethod.GetSessionValue("UserName") == "admin")
        {
            MyCmd = new SqlCommand("select * from hx_vERPBuMen where DirID=" + IDStr.ToString() + " and CHARINDEX('" + DepartmentID + "',p_depart_ids)>0 order by ID asc", Conn);
        }
        else
        {
            MyCmd = new SqlCommand("select * from hx_vERPBuMen where DirID=" + IDStr.ToString() + " and CHARINDEX('," + ZWL.Common.PublicMethod.GetSessionValue("DepartmentID") + ",',p_depart_ids)>0 order by ID asc", Conn);
        }

        SqlDataReader MyReader = MyCmd.ExecuteReader();

        while (MyReader.Read())
        {
            TreeNode OrganizationNode = new TreeNode();
            OrganizationNode.Text  = MyReader["BuMenName"].ToString();
            OrganizationNode.Value = MyReader["ID"].ToString();
            int strId = int.Parse(MyReader["ID"].ToString());
            OrganizationNode.ImageUrl     = "~/images/user_group.gif";
            OrganizationNode.SelectAction = TreeNodeSelectAction.Expand;
            //OrganizationNode.Expanded = true;
            //string ChildID = ZWL.DBUtility.DbHelperSQL.GetSHSLInt("select top 1 ID from ERPBuMen where DirID=" + MyReader["ID"].ToString() + " order by ID asc");
            //if (ChildID.Trim() != "0")
            //{
            HaveChild = HaveChild + "|" + MyReader["BuMenName"].ToString() + "|";
            //}
            //OrganizationNode.ToolTip = MyReader["BuMenName"].ToString();
            //OrganizationNode.Collapse();

            /////////////////////////////////////////////////////////////////////////////////////////////////////
            //在当前节点下加入用户
            //SqlConnection Conn1 = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());

            SqlConnection Conn1 = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());
            Conn1.Open();
            SqlCommand MyCmd1 = new SqlCommand("select * from ERPUser "
                                               + "where Department = '" + MyReader["BuMenName"].ToString() + "' or Department like '%," + MyReader["BuMenName"].ToString()
                                               + "' or Department like '" + MyReader["BuMenName"].ToString() + ",%' or Department like '%," + MyReader["BuMenName"].ToString() + ",%' order by ID asc"
                                               , Conn1);
            SqlDataReader MyReader1 = MyCmd1.ExecuteReader();
            while (MyReader1.Read())
            {
                TreeNode UserNode = new TreeNode();

                //Andy 20130925 选中文本框中传过来的用户
                if (listName != null)
                {
                    if (listName.Contains(MyReader1["UserName"].ToString()))
                    {
                        UserNode.Checked = true;
                    }
                }

                //UserNode.Text = MyReader1["UserName"].ToString();
                UserNode.Text         = MyReader1["TrueName"].ToString();
                UserNode.Value        = MyReader1["ID"].ToString();
                UserNode.ImageUrl     = OnLinePic(MyReader1["ID"].ToString());
                UserNode.ToolTip      = MyReader1["UserName"].ToString();
                UserNode.SelectAction = TreeNodeSelectAction.Expand;

                OrganizationNode.ChildNodes.Add(UserNode);
            }

            MyReader1.Close();
            Conn1.Close();


            /////////////////////////////////////////////////////////////////////////////////////////////////////



            Nds.Add(OrganizationNode);
            //递归循环
            BindTree(Nds[Nds.Count - 1].ChildNodes, strId);
        }


        readTreeNode(this.ListTreeView.Nodes);
        MyReader.Close();
        Conn.Close();
    }
コード例 #2
0
ファイル: OnlineUser.aspx.cs プロジェクト: cnbin/HLB
    private void BindTree(TreeNodeCollection Nds, int IDStr)
    {
        //SqlConnection Conn = new SqlConnection(DecryptDBStr(ConfigurationManager.AppSettings["SQLConnectionString"].ToString(),"zhangweilong"));
        SqlConnection Conn = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());

        Conn.Open();

        string DepartmentID = "";
        string SuperiorID   = ZWL.Common.PublicMethod.GetSessionValue("DepartmentID");;

        while (SuperiorID != "0")
        {
            DepartmentID = SuperiorID;
            SuperiorID   = GetSuperiorDepartmentID(SuperiorID);
        }


        SqlCommand MyCmd;

        if (ZWL.Common.PublicMethod.GetSessionValue("UserName") == "admin")
        {
            MyCmd = new SqlCommand("select * from hx_vERPBuMen where DirID=" + IDStr.ToString() + " and CHARINDEX('" + DepartmentID + "',p_depart_ids)>0 order by ID asc", Conn);
        }
        else
        {
            MyCmd = new SqlCommand("select * from hx_vERPBuMen where DirID=" + IDStr.ToString() + " and CHARINDEX('," + ZWL.Common.PublicMethod.GetSessionValue("DepartmentID") + ",',p_depart_ids)>0 order by ID asc", Conn);
        }
        SqlDataReader MyReader = MyCmd.ExecuteReader();

        while (MyReader.Read())
        {
            TreeNode OrganizationNode = new TreeNode();
            OrganizationNode.Text  = MyReader["BuMenName"].ToString();
            OrganizationNode.Value = MyReader["ID"].ToString();
            int strId = int.Parse(MyReader["ID"].ToString());
            OrganizationNode.ImageUrl     = "~/images/user_group.gif";
            OrganizationNode.SelectAction = TreeNodeSelectAction.Expand;
            OrganizationNode.Expanded     = true;

            /////////////////////////////////////////////////////////////////////////////////////////////////////
            //在当前节点下加入用户
            SqlConnection Conn1 = new SqlConnection(ConfigurationManager.AppSettings["SQLConnectionString"].ToString());
            Conn1.Open();
            //SqlCommand MyCmd1 = new SqlCommand("select * from ERPUser where Department like '%" + MyReader["BuMenName"].ToString() + "%' order by ID asc", Conn1);
            SqlCommand    MyCmd1    = new SqlCommand("select * from ERPUser where Department = '" + MyReader["BuMenName"].ToString() + "' order by ID asc", Conn1);
            SqlDataReader MyReader1 = MyCmd1.ExecuteReader();
            while (MyReader1.Read())
            {
                TreeNode UserNode = new TreeNode();
                //UserNode.Text = MyReader1["UserName"].ToString();
                UserNode.Text        = MyReader1["TrueName"].ToString();
                UserNode.Value       = MyReader1["ID"].ToString();
                UserNode.ToolTip     = MyReader1["UserName"].ToString();
                UserNode.ImageUrl    = OnLinePic(MyReader1["ID"].ToString());
                UserNode.NavigateUrl = "../LanEmail/LanEmailAdd.aspx?UserName="******"UserName"].ToString();
                OrganizationNode.ChildNodes.Add(UserNode);
            }
            MyReader1.Close();
            Conn1.Close();
            /////////////////////////////////////////////////////////////////////////////////////////////////////

            Nds.Add(OrganizationNode);

            //递归循环
            BindTree(Nds[Nds.Count - 1].ChildNodes, strId);
        }
        MyReader.Close();
        Conn.Close();
    }