Example #1
0
    private static string sortGroupNodeList()
    {
        output += "sortGroupNodeList\n";

        List <GroupNode> list1 = GroupQuery.getAllPrimaryGroups();
        List <GroupNode> list2 = GroupQuery.getAllSecondaryGroups();
        List <GroupNode> list3 = GroupQuery.getFocusedPublicGroupsByUserId(sampleUser.UserId);
        List <GroupNode> list4 = GroupQuery.getAllInterestLabelsByUserId(sampleUser.UserId);

        /*
         * output += "> 1 \n";
         * foreach (GroupNode node in list1)
         * {
         *  output += "\t" + node.NodeName + "\t" + node.PrimaryGroupId + "\t" + node.IsPrimaryGroup + "\t" + node.Id + "\t" + node.IsInterestLabel + "\n";
         * }
         * output += "> 2 \n";
         * foreach (GroupNode node in list2)
         * {
         *  output += "\t" + node.NodeName + "\t" + node.PrimaryGroupId + "\t" + node.IsPrimaryGroup + "\t" + node.Id + "\t" + node.IsInterestLabel + "\n";
         * }
         * output += "> 3 \n";
         * foreach (GroupNode node in list3)
         * {
         *  output += "\t" + node.NodeName + "\t" + node.PrimaryGroupId + "\t" + node.IsPrimaryGroup + "\t" + node.Id + "\t" + node.IsInterestLabel + "\n";
         * }
         * output += "> 4 \n";
         * foreach (GroupNode node in list4)
         * {
         *  output += "\t" + node.NodeName + "\t" + node.PrimaryGroupId + "\t" + node.IsPrimaryGroup + "\t" + node.Id + "\t" + node.IsInterestLabel + "\n";
         * }
         */

        if (list1 == null || list2 == null || list3 == null || list4 == null)
        {
            output += "Error! 获取List<GroupNode>记录失败!返回值为null。\n";
            errorCount++;
            return(output);
        }

        List <GroupNode> list = GroupQuery.sortGroupNodeList(new List <GroupNode>[] { list1, list2, list3, list4 });

        if (list == null)
        {
            output += "Error! 通过sortGroupNodeList整理List<GroupNode>[]失败!返回值为null。\n";
            errorCount++;
            return(output);
        }

        output += "\nThe Result:\n";
        output += "\t名称\t隶属于\t是否为主\tid\t是否私有\n";
        foreach (GroupNode node in list)
        {
            output += "\t" + node.NodeName + "\t" + node.PrimaryGroupId + "\t" + node.IsPrimaryGroup + "\t" + node.Id + "\t" + node.IsInterestLabel + "\n";
        }

        return(output);
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /*
         * tv0 = new TreeView();
         * TreeNode tn0 = new TreeNode("体育");
         * tn0.ShowCheckBox = true;
         * TreeNode tn01 = new TreeNode("足球");
         * TreeNode tn02 = new TreeNode(@"<span class='iLabel'>篮球</span>");
         *
         * tn0.ChildNodes.Add(tn01);
         * tn0.ChildNodes.Add(tn02);
         * tv0.Nodes.Add(tn0);
         *
         * TableRow tr = new TableRow();
         * TableCell tc = new TableCell();
         * tc.Controls.Add(tv0);
         * tr.Controls.Add(tc);
         * HolderTable.Controls.Add(tr);
         *
         * TreeView tv1 = new TreeView();
         * TreeNode tn1 = new TreeNode("军事");
         *
         * TreeNode tn11 = new TreeNode("亚洲");
         * TreeNode tn12 = new TreeNode("中东");
         * tn1.ChildNodes.Add(tn11);
         * tn1.ChildNodes.Add(tn12);
         * tv1.Nodes.Add(tn1);
         *
         * TableCell tc1 = new TableCell();
         * tc1.Controls.Add(tv1);
         * tr.Controls.Add(tc1);
         */


        user = (User)Session["user"];

        if (user == null)
        {
            Label1.Text           = "对不起,您没有访问该资源的权限";
            Label1.Font.Size      = 18;
            Label1.ForeColor      = Color.Red;
            Label2.Visible        = false;
            DropDownList1.Visible = false;
            Label3.Visible        = false;
            Label4.Visible        = false;
            TextBox1.Visible      = false;
            TextBox2.Visible      = false;
            Button1.Visible       = false;
            Button2.Visible       = false;
            return;
        }

        map    = new Hashtable();
        p2o    = new Hashtable();
        tvs    = new List <TreeView>();
        alltns = new List <TreeNode>();


        Label1.Visible = false;

        List <GroupNode> lists = GroupQuery.sortGroupNodeList(new List <GroupNode>[] { GroupQuery.getAllPrimaryGroups(), GroupQuery.getAllSecondaryGroups(), GroupQuery.getAllInterestLabelsByUserId(user.UserId) });
        List <GroupNode> list2 = GroupQuery.sortGroupNodeList(new List <GroupNode>[] { GroupQuery.getFocusedPublicGroupsByUserId(user.UserId), GroupQuery.getAllInterestLabelsByUserId(user.UserId) });

        List <GroupNode> list3 = GroupQuery.getAllPrimaryGroups();

        //DropDownList1.Items.Clear();

        /*
         * foreach (TreeView tv in tvs)
         * {
         *  tv.Nodes.Clear();
         * }
         * */
        if (!IsPostBack)
        {
            foreach (GroupNode gn in list3)
            {
                if (gn.NodeName != "其他")
                {
                    DropDownList1.Items.Add(new ListItem(gn.NodeName, gn.Id.ToString()));
                }
            }
        }

        TreeNode tmpPrimary = null;

        foreach (GroupNode gn in lists)
        {
            TableRow row = new TableRow();
            if (gn.NodeName == "其他" && gn.IsPrimaryGroup)
            {
                continue;
            }

            TreeNode tn = new TreeNode(gn.NodeName);

            map.Add(tn, gn);
            tn.ShowCheckBox = true;
            if (checkDup(list2, gn))
            {
                tn.Checked = true;
            }

            tn.NavigateUrl = "#";



            if (gn.NodeName == "其他")
            {
                p2o.Add(tmpPrimary, gn);
                continue;
            }
            alltns.Add(tn);
            if (gn.IsPrimaryGroup)
            {
                tmpPrimary = tn;
                TreeView tv = new TreeView();
                tv.Nodes.Add(tn);
                tvs.Add(tv);
                TableCell tc = new TableCell();
                tc.Controls.Add(tv);
                row.Controls.Add(tc);
                HolderTable.Rows.Add(row);
                tmpPrimary.ChildNodes.Clear();
            }
            else
            {
                //if (!IsPostBack)
                //{
                tmpPrimary.ChildNodes.Add(tn);
                if (gn.IsInterestLabel)
                {
                    tn.Text = @"<span class='iLabel'>" + gn.NodeName + @"</span>";
                }
                //}
            }
        }
    }
Example #3
0
    private Hashtable map;//通过TreeNode寻找相应的GroupNode

    protected void Page_Load(object sender, EventArgs e)
    {
        user = (User)Session["user"];
        const string TARGET = "mainframe";

        /*
         * TreeView tv0 = new TreeView();
         * TreeNode tn0 = new TreeNode("体育");
         * tn0.NavigateUrl = "Showarticles.aspx";
         * tn0.Target = TARGET;
         *
         * TreeNode tn01 = new TreeNode("足球");
         * TreeNode tn02 = new TreeNode(@"<span class='iLabel'>篮球</span>");
         * tn01.Target = TARGET;
         * tn02.Target = TARGET;
         *
         * tn0.ChildNodes.Add(tn01);
         * tn0.ChildNodes.Add(tn02);
         * tv0.Nodes.Add(tn0);
         *
         * TableRow tr = new TableRow();
         * TableCell tc = new TableCell();
         * tc.Controls.Add(tv0);
         * tr.Controls.Add(tc);
         * HolderTable.Rows.Add(tr);
         *
         * TreeView tv1 = new TreeView();
         * TreeNode tn1 = new TreeNode("军事");
         * tn1.Target = TARGET;
         * TreeNode tn11 = new TreeNode("亚洲");
         * TreeNode tn12 = new TreeNode("中东");
         * tn11.Target = TARGET;
         * tn12.Target = TARGET;
         * tn1.ChildNodes.Add(tn11);
         * tn1.ChildNodes.Add(tn12);
         * tv1.Nodes.Add(tn1);
         *
         * TableRow tr1 = new TableRow();
         * TableCell tc1 = new TableCell();
         * tc1.Controls.Add(tv1);
         * tr1.Controls.Add(tc1);
         * HolderTable.Rows.Add(tr1);
         *
         */

        //针对为注册用户
        if (user == null)
        {
            //首先建立左边的TreeView
            //取得所有主分类
            List <GroupNode> primaryGroups   = GroupQuery.getAllPrimaryGroups();
            List <GroupNode> secondaryGroups = GroupQuery.getAllSecondaryGroups();
            List <GroupNode> list            = GroupQuery.sortGroupNodeList(new List <GroupNode>[] { primaryGroups, secondaryGroups });



            TreeNode tmpPrimaryNode = null;
            foreach (GroupNode gn in list)
            {
                if (gn.IsPrimaryGroup)
                {
                    TreeView tv = new TreeView();
                    TreeNode tn = new TreeNode(gn.NodeName);//根节点
                    tn.Target      = TARGET;
                    tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=1&other=0&pgid=-1";
                    tmpPrimaryNode = tn;
                    tv.Nodes.Add(tn);

                    TableCell tc = new TableCell();
                    tc.Controls.Add(tv);
                    TableRow tr = new TableRow();
                    tr.Controls.Add(tc);

                    HolderTable.Rows.Add(tr);
                }
                else
                {
                    TreeNode tn = new TreeNode(gn.NodeName);//子节点
                    tn.Target = TARGET;
                    if (gn.NodeName == "其他")
                    {
                        tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=0&other=1&pgid=" + gn.PrimaryGroupId;
                    }
                    else
                    {
                        tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=0&other=0&pgid=" + gn.PrimaryGroupId;
                    }
                    tmpPrimaryNode.ChildNodes.Add(tn);
                }
            }
        }
        else//针对已登录用户
        {
            List <GroupNode> primaryGroups   = GroupQuery.getFocusedPublicGroupsByUserId(user.UserId);
            List <GroupNode> secondaryGroups = GroupQuery.getAllInterestLabelsByUserId(user.UserId);
            List <GroupNode> list            = GroupQuery.sortGroupNodeList(new List <GroupNode>[] { primaryGroups, secondaryGroups });

            if (list == null || list.Count == 0)
            {
                Label tmpLabel = new Label();
                tmpLabel.Text = "您还没有任何关注哦!";
                TableCell tc = new TableCell();
                TableRow  tr = new TableRow();
                tc.Controls.Add(tmpLabel);
                tr.Controls.Add(tc);
                HolderTable.Rows.Add(tr);
                return;
            }

            TreeNode tmpPrimaryNode = null;

            foreach (GroupNode gn in list)
            {
                if (gn.IsPrimaryGroup)
                {
                    TreeView tv = new TreeView();
                    TreeNode tn = new TreeNode(gn.NodeName);//根节点
                    tn.Target      = TARGET;
                    tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=1&other=0&pgid=-1";
                    tmpPrimaryNode = tn;
                    tv.Nodes.Add(tn);

                    TableCell tc = new TableCell();
                    tc.Controls.Add(tv);
                    TableRow tr = new TableRow();
                    tr.Controls.Add(tc);

                    HolderTable.Rows.Add(tr);
                }
                else
                {
                    //这里还需要判断是否是兴趣标签
                    TreeNode tn;
                    if (gn.IsInterestLabel)
                    {
                        tn = new TreeNode(@"<span class='iLabel'>" + gn.NodeName + @"</span>");//子节点
                    }
                    else
                    {
                        tn = new TreeNode(gn.NodeName);
                    }

                    tn.Target = TARGET;
                    if (gn.NodeName == "其他")
                    {
                        tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=0&other=1&pgid=" + gn.PrimaryGroupId;
                    }
                    else
                    {
                        tn.NavigateUrl = "Showarticles.aspx?gn=" + gn.Id + "&primary=0&other=0&pgid=" + gn.PrimaryGroupId;
                    }
                    tmpPrimaryNode.ChildNodes.Add(tn);
                }
            }

            //增加其他选项
            TreeView othertv = new TreeView();
            TreeNode othertn = new TreeNode("其他");
            othertn.NavigateUrl = "Showarticles.aspx?gn=-1&primary=1&other=1&pgid=-1";
            othertn.Target      = TARGET;
            othertv.Nodes.Add(othertn);
            TableRow  othertr = new TableRow();
            TableCell othertc = new TableCell();
            othertr.Controls.Add(othertc);
            othertc.Controls.Add(othertv);
            HolderTable.Rows.Add(othertr);
        }

        /*primaryGroups = new List<GroupNode>();
         *  List<GroupNode> temp = GroupQuery.getFocusedPublicGroupsByUserId(user.UserId);
         *  foreach (GroupNode node in temp)
         *  {
         *      if (node.IsPrimaryGroup)
         *          primaryGroups.Add(node);
         *  }*/
    }