コード例 #1
0
        private void BindOrganizationTree()
        {
            OrganizationBLL organizationBLL = new OrganizationBLL();

            IList <RailExam.Model.Organization> organizationList = new List <RailExam.Model.Organization>();

            int railSystemID = 0;

            if (PrjPub.IsServerCenter)
            {
                SystemRoleBLL roleBll = new SystemRoleBLL();
                SystemRole    role    = roleBll.GetRole(PrjPub.CurrentLoginUser.RoleID);
                railSystemID = role.RailSystemID;
            }

            if (PrjPub.IsServerCenter && (PrjPub.CurrentLoginUser.SuitRange == 1 || railSystemID != 0))
            {
                SystemRoleBLL roleBll = new SystemRoleBLL();
                SystemRole    role    = roleBll.GetRole(PrjPub.CurrentLoginUser.RoleID);

                organizationList = organizationBLL.GetOrganizations();

                string strOwnIDs = string.Empty;
                if (railSystemID != 0)
                {
                    IList <RailExam.Model.Organization> organizationList1 = organizationBLL.GetOrganizations(PrjPub.CurrentLoginUser.StationOrgID);
                    foreach (RailExam.Model.Organization organization in organizationList1)
                    {
                        strOwnIDs += strOwnIDs == string.Empty
                                         ? organization.OrganizationId.ToString()
                                         : "," + organization.OrganizationId;
                    }
                }

                if (organizationList.Count > 0)
                {
                    TreeViewNode tvn = null;
                    tvn = new TreeViewNode();
                    //tvn.ID = "0";
                    //tvn.Value = "0";
                    //tvn.Text = PrjPub.GetRailNameBao();
                    //tvn.ToolTip = PrjPub.GetRailNameBao();
                    //tvOrganization.Nodes.Add(tvn);

                    foreach (RailExam.Model.Organization organization in organizationList)
                    {
                        if ((organization.IdPath + "/").IndexOf("/1/") >= 0 && organization.LevelNum != 1 && railSystemID != 0 && railSystemID != organization.RailSystemID)
                        {
                            continue;
                        }

                        if (organization.LevelNum != 1 && strOwnIDs != string.Empty && (organization.IdPath + "/").IndexOf("/1/") < 0 && ("," + strOwnIDs + ",").IndexOf("," + organization.OrganizationId + ",") < 0)
                        {
                            continue;
                        }

                        tvn         = new TreeViewNode();
                        tvn.ID      = organization.OrganizationId.ToString();
                        tvn.Value   = organization.OrganizationId.ToString();
                        tvn.Text    = organization.ShortName;
                        tvn.ToolTip = organization.FullName;



                        try
                        {
                            if (organization.ParentId == 0)
                            {
                                tvn.Expanded = true;
                                tvOrganization.Nodes.Add(tvn);
                            }
                            else
                            {
                                tvOrganization.FindNodeById(organization.ParentId.ToString()).Nodes.Add(tvn);
                            }
                        }
                        catch
                        {
                            tvOrganization.Nodes.Clear();
                            SessionSet.PageMessage = "数据错误!";
                            return;
                        }
                    }
                }

                //Pub.BuildComponentArtTreeView(tvOrganization, (IList)organizationList, "OrganizationId",
                //    "ParentId", "ShortName", "FullName", "OrganizationId", null, null, null);
            }
            else
            {
                string strOrgID;
                if (PrjPub.IsServerCenter)
                {
                    strOrgID = PrjPub.CurrentLoginUser.StationOrgID.ToString();
                }
                else
                {
                    strOrgID = ConfigurationManager.AppSettings["StationID"].ToString();
                }
                int stationID = organizationBLL.GetStationOrgID(Convert.ToInt32(strOrgID));

                organizationList =
                    organizationBLL.GetOrganizations(stationID);

                if (organizationList.Count > 0)
                {
                    TreeViewNode tvn = null;
                    tvn         = new TreeViewNode();
                    tvn.ID      = "0";
                    tvn.Value   = "0";
                    tvn.Text    = PrjPub.GetRailNameBao();
                    tvn.ToolTip = PrjPub.GetRailNameBao();
                    tvOrganization.Nodes.Add(tvn);

                    foreach (RailExam.Model.Organization organization in organizationList)
                    {
                        tvn         = new TreeViewNode();
                        tvn.ID      = organization.OrganizationId.ToString();
                        tvn.Value   = organization.OrganizationId.ToString();
                        tvn.Text    = organization.ShortName;
                        tvn.ToolTip = organization.FullName;

                        if (organization.LevelNum == 2)
                        {
                            tvn.Expanded = true;
                        }

                        try
                        {
                            if (organization.LevelNum == 2)
                            {
                                tvOrganization.FindNodeById("0").Nodes.Add(tvn);
                            }
                            else
                            {
                                tvOrganization.FindNodeById(organization.ParentId.ToString()).Nodes.Add(tvn);
                            }
                        }
                        catch
                        {
                            tvOrganization.Nodes.Clear();
                            SessionSet.PageMessage = "数据错误!";
                            return;
                        }
                    }
                }
            }



            tvOrganization.DataBind();

            if (tvOrganization.Nodes.Count > 0)
            {
                tvOrganization.Nodes[0].Expanded = true;
            }
        }