コード例 #1
0
ファイル: TreeViewController.cs プロジェクト: hiyouth/R2.RRDL
 //// NodeId: id, NodeInfo: nodeInfo, XmlUrl: temp.xmlUrl 
 public ActionResult OperateTreeNode(string modeType, string _modeType, string nodeId, string nodeInfo, string xmlUrl)
 {
     using (RRDLEntities db = new RRDLEntities())
     {
         Tree tree = new Tree();
         TreeNode treeNode = null;
         switch (modeType)
         {
             case "rename":
                 string id = nodeId;
                 string name = nodeInfo;
                 treeNode = tree.GetTreeNodeById(Int32.Parse(id));
                 treeNode.Title = name;
                 tree.UpdateTreeNode(treeNode);
                 returnStr = "ok&" + treeNode.ParentId;
                 break;
             case "delete":
                 returnStr = DeleteNode(_modeType, nodeId, xmlUrl);                        
                 break;
             case "insert":
                 //List<NodeInfo> nodeList = this.GetListFromJson(nodeInfo);
                 //returnStr = this.InserNode(_modeType, nodeId, xmlUrl, nodeList);
                 //bool flag = true;
                 Tree tree2 = new Tree(db);
                 List<TreeNode> list = tree2.GetTreeNodeChild(Int32.Parse(nodeId));
                 //for (int i = 0; i < list.Count;i++ )
                 //{
                 //    if(list[i].Ariticle != null){
                 //        flag = false; 
                 //    }
                 //}
                 //if (flag)
                 //{
                     treeNode = new TreeNode(Int32.Parse(nodeId), "新建节点");
                     tree.AddTreeNode(treeNode);
                     returnStr = "ok";
                 //}
                 //else {
                 //    returnStr = "该节点下存在文章,不能添加文件夹!";
                 //}
                 break;
         }
         return Content(returnStr);
     }
 }
コード例 #2
0
ファイル: TreeOfNodes.cs プロジェクト: KirilToshev/Projects
    static void Main()
    {
        Tree<int> myTestTree = new Tree<int>();
        Node<int> node2 = new Node<int>(2);
        Node<int> node4 = new Node<int>(4);
        Node<int> node3 = new Node<int>(3);
        Node<int> node5 = new Node<int>(5);
        Node<int> node0 = new Node<int>(0);
        Node<int> node1 = new Node<int>(1);
        Node<int> node6 = new Node<int>(6);
        Node<int> node7 = new Node<int>(7);
        // Node<int> node8 = new Node<int>(8);

        myTestTree.AddTreeNode(node2, node4);
        myTestTree.AddTreeNode(node3, node2);
        myTestTree.AddTreeNode(node5, node0);
        myTestTree.AddTreeNode(node3, node5);
        myTestTree.AddTreeNode(node5, node6);
        myTestTree.AddTreeNode(node5, node1);
        myTestTree.AddTreeNode(node1, node7);
        // myTestTree.AddTreeNode(node7, node8);

        DFSPrint(myTestTree.Root, "");
        // a) Root Node
        Console.WriteLine("Tree root = {0}", myTestTree.Root.Value);

        // b) All leaf nodes
        Console.Write("Leaf nodes: ");
        foreach (var node in myTestTree.NodeList)
        {
            if (node.Value.SubNodes.Count == 0)
            {
                Console.Write("{0} ", node.Value.Value);
            }
        }
        Console.WriteLine();

        // c) All middle nodes
        Console.Write("Leaf middle nodes: ");
        foreach (var node in myTestTree.NodeList)
        {
            if (node.Value.SubNodes.Count != 0 && node.Value.HasParent == true)
            {
                Console.Write("{0} ", node.Value.Value);
            }
        }
        Console.WriteLine();

        // d) The longest path in the tree
        Console.WriteLine("The longes path is = {0}",DFSFindLongestPath(myTestTree.Root));

        // e) All paths with given sum S of their nodes
        //List<Node<int>> pathList = BFSPathSum(myTestTree.Root, 8);
        //foreach (Node<int> node in pathList)
        //{
        //    Console.Write("{0} -> ", node.Value);
        //}
    }
コード例 #3
0
        public string KnowledgeModify(string ariticleJson)
        {
            using (RRDLEntities db = new RRDLEntities())
            {
                AriticleJson ariticlejson = (AriticleJson)JsonConvert.DeserializeObject(ariticleJson, typeof(AriticleJson));

                AriticleService ars = new AriticleService(db);
                Ariticle ariticle = ars.FindById(ariticlejson.Id);

                //添加标题
                ariticle.Title = ariticlejson.title;
                //添加内容
                //ariticle.UGC = System.Web.HttpUtility.UrlDecode(ariticlejson.UGC);
                ariticlejson.UGC = System.Web.HttpUtility.UrlDecode(ariticlejson.UGC);
                ariticlejson.UGC = ariticlejson.UGC.Replace("CodeReplacePlus", "+");
                ariticle.UGC = ariticlejson.UGC;
                //添加标签
                string[] tlist = ariticlejson.tag.Split(new char[] { ',' });
                List<AriticleTag> tagList = new List<AriticleTag>();
                for (int i = 0; i < tlist.Length; i++)
                {
                    AriticleTag ariticletag = new AriticleTag();
                    ariticletag.Title = tlist[i];
                    ariticletag.AriticleId = ariticlejson.Id;
                    // ariticletag.Article = ariticle;
                    tagList.Add(ariticletag);
                }
                AriticleTagRepository tagRepository = new AriticleTagRepository(db);
                tagRepository.UpdateAllRelatedAriticleId(ariticle.Id, tagList);
                //创建一个新节点
                TreeNode treeNode = new TreeNode(Int32.Parse(ariticlejson.treeNodeParentId), ariticlejson.title);
                treeNode.Ariticle = ariticle;
                Tree tree = new Tree(db);
                tree.AddTreeNode(treeNode);
                //删除旧节点
                TreeNode oldtreeNode = tree.SearchByAriticle(ariticle.Id);
                tree.Drop(oldtreeNode);
                //创建不可见分组信息数组
                string[] inlist = ariticlejson.invisibility.Split(new char[] { ';' });
                List<int> invisiblityGroup = new List<int>();
                for (int i = 0; i < inlist.Length - 1; i++)
                {
                    invisiblityGroup.Add(Int32.Parse(inlist[i]));
                }
                //判断是否为管理员或超级管理员修改,审核状态保持已通过审核
                UserService us = new UserService();
                User user = us.FindById(ariticlejson.UserId);
                if (user.AuthorityCategory != EnumUserCategory.Administrator && user.AuthorityCategory != EnumUserCategory.Superman)
                {
                    ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.UnApproved;
                }
                else {
                    ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.Approved;
                }
                ars.UpdateAriticle(ariticle, invisiblityGroup);
                db.SaveChanges();
                return "success";
            }
        }
コード例 #4
0
 public string KnowledgeModify(string title, string userId, string invisibility, string tag, string content, string ariticleId, string treeNodeParentId)
 {
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
       
         //添加标题
         ariticle.Title = title;
         //添加内容
         //ariticle.UGC = System.Web.HttpUtility.UrlDecode(content);
         content = System.Web.HttpUtility.UrlDecode(content);
         content = content.Replace("CodeReplacePlus", "+");
         ariticle.UGC = content;
         //添加标签
         string[] tlist = tag.Split(new char[] { ',' });
         List<AriticleTag> tagList = new List<AriticleTag>();
         for (int i = 0; i < tlist.Length; i++)
         {
             AriticleTag ariticletag = new AriticleTag();
             ariticletag.Title = tlist[i];
             ariticletag.AriticleId = ariticleId;
             // ariticletag.Article = ariticle;
             tagList.Add(ariticletag);
         }
         AriticleTagRepository tagRepository = new AriticleTagRepository(db);
         tagRepository.UpdateAllRelatedAriticleId(ariticle.Id, tagList);
         //创建一个新节点
         TreeNode treeNode = new TreeNode(Int32.Parse(treeNodeParentId), title);
         treeNode.Ariticle = ariticle;
         Tree tree = new Tree(db);
         tree.AddTreeNode(treeNode);
         //删除旧节点
         TreeNode oldtreeNode = tree.SearchByAriticle(ariticle.Id);
         tree.Drop(oldtreeNode);
         //创建不可见分组信息数组
         string[] inlist = invisibility.Split(new char[] { ';' });
         List<int> invisiblityGroup = new List<int>();
         for (int i = 0; i < inlist.Length - 1; i++)
         {
             invisiblityGroup.Add(Int32.Parse(inlist[i]));
         }
         ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.Approved;
         ars.UpdateAriticle(ariticle, invisiblityGroup);
         db.SaveChanges();
         return "success";
     }
 }