Beispiel #1
0
    private void BindTree()
    {
        DataTable dt     = UserDeptSelectBus.GetDeptInfoByCompanyCD(ShowType, OprtType);
        DataTable Userdt = null;

        if (!string.IsNullOrEmpty(ShowType) && Convert.ToInt32(ShowType) > 1)
        {
            string isShowLizhi = "0";
            if (this.RblIsShowLizhi.Checked)
            {
                isShowLizhi = "1";
            }
            Userdt = UserDeptSelectBus.GetUserInfo(ShowType, OprtType, isShowLizhi);
        }
        //根节点
        TreeNode rootNode = new TreeNode();

        rootNode.Text  = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyName + "组织机构";
        rootNode.Value = "0";
        if (dt != null && dt.Rows.Count > 0)
        {
            DataRow[] rows = dt.Select("SuperDeptID IS NULL");
            if (rows.Length > 0)
            {
                TreeNode childNode = null;
                for (int i = 0; i < rows.Length; i++)
                {
                    childNode = new TreeNode();
                    if (ShowType == "1" && OprtType == "2")
                    {
                        if (rows[i]["SuperDeptID"] == DBNull.Value)
                        {
                            /* Edit by ellen at 2010-08-23 16:18 */
                            if (rows[i]["subflag"].ToString() == "0")
                            {
                                childNode.Value       = rows[i]["ID"].ToString();
                                childNode.Text        = rows[i]["DeptName"].ToString();
                                childNode.NavigateUrl = string.Format("javascript:void('{0},{1}');", childNode.Text, childNode.Value);
                                childNode.ToolTip     = "部门";
                            }
                            else
                            {
                                childNode.Value       = rows[i]["ID"].ToString();
                                childNode.Text        = rows[i]["DeptName"].ToString();
                                childNode.NavigateUrl = "javascript:void(0);";
                                childNode.ToolTip     = "分公司";
                            }
                        }
                    }
                    else
                    {
                        childNode.Value       = rows[i]["ID"].ToString();
                        childNode.Text        = rows[i]["DeptName"].ToString();
                        childNode.NavigateUrl = "javascript:void(0);";
                    }
                    if (!string.IsNullOrEmpty(ShowType) && Convert.ToInt32(ShowType) > 1)
                    {
                        TreeNode Usernode = null;
                        if (Userdt != null && Userdt.Rows.Count > 0)
                        {
                            string    UserExprssion = "DeptID='" + childNode.Value + "'";
                            DataRow[] UserRow       = Userdt.Select(UserExprssion);
                            if (UserRow.Length > 0)
                            {
                                for (int j = 0; j < UserRow.Length; j++)
                                {
                                    Usernode       = new TreeNode();
                                    Usernode.Value = UserRow[j]["ID"].ToString();
                                    Usernode.Text  = UserRow[j]["EmployeesName"].ToString();

                                    if (ShowType == "2" && OprtType == "2")
                                    {
                                        Usernode.NavigateUrl = string.Format("javascript:void('{0},{1}');", Usernode.Text, Usernode.Value);
                                    }
                                    else
                                    {
                                        Usernode.NavigateUrl = string.Format("javascript:void(0);");
                                    }
                                    childNode.ChildNodes.Add(Usernode);
                                }
                            }
                        }
                    }
                    rootNode.ChildNodes.Add(childNode);
                    BindChildNode(childNode.Value, childNode, dt, Userdt);
                }
            }
        }
        UserDeptTree.Nodes.Add(rootNode);
    }
    /// <summary>
    /// 初期表示部门员工数据
    /// </summary>
    /// <param name="flag"></param>
    private void InitUserDept(string flag, string TypeID)
    {
        StringBuilder deptUserInfo = new StringBuilder();
        //获取部门信息
        DataTable dtDept = UserDeptSelectBus.GetDeptInfo(TypeID);

        //部门信息存在的时候
        if (dtDept != null && dtDept.Rows.Count > 0)
        {
            //获取员工信息
            DataTable dtUser = UserDeptSelectBus.GetUserInfo();
            deptUserInfo.AppendLine("<table id='dtDeptUser'>");
            //遍历部门,设置部门对应人员
            for (int i = 0; i < dtDept.Rows.Count; i++)
            {
                //获取部门名称
                string deptName = (string)dtDept.Rows[i]["DeptName"];
                //获取部门ID
                int deptID = (int)dtDept.Rows[i]["ID"];
                //显示部门
                deptUserInfo.AppendLine("<tr><td>" + deptName + "</td><td>");
                //员工信息
                StringBuilder deptUser = new StringBuilder(string.Empty);
                //获取部门下的员工


                string Expression = "DeptID='" + deptID.ToString() + "'";

                DataRow[] drDeptUser = dtUser.Select(Expression);
                //遍历部门的所有员工
                for (int j = 0; j < drDeptUser.Length; j++)
                {
                    //获取员工数据
                    DataRow drUserTemp = (DataRow)drDeptUser[j];
                    //获取用户ID
                    int employeesID = (int)drUserTemp["ID"];
                    //获取用户名
                    string employeesName = (string)drUserTemp["EmployeesName"];
                    if (!string.IsNullOrEmpty(employeesName))
                    {
                        if (TypeID == ConstUtil.TYPE_DANX_CODE)
                        {
                            deptUser.AppendLine("<input type='radio' name='select' id='chk_" + deptID.ToString() + "_" + employeesID.ToString() + "'  value='" + ConstUtil.DEPT_EMPLOY_SELECT_EMPLOY
                                                + employeesID.ToString() + "|" + employeesName + "'>" + employeesName);
                        }
                        else if (TypeID == ConstUtil.TYPE_DUOX_CODE)
                        {
                            deptUser.AppendLine("<input type='checkbox' id='chk_" + deptID.ToString() + "_" + employeesID.ToString() + "'  value='" + ConstUtil.DEPT_EMPLOY_SELECT_EMPLOY
                                                + employeesID.ToString() + "|" + employeesName + "'>" + employeesName);
                        }
                    }
                }
                //设置部门下的员工信息
                deptUserInfo.AppendLine(deptUser.ToString());
                deptUserInfo.AppendLine("</td></tr>");
            }
            deptUserInfo.AppendLine("</table>");
        }
        //设置员工部门信息
        divDeptUser.InnerHtml = deptUserInfo.ToString() + divDeptUser.InnerHtml;
    }