public static void TestTree() { using (var db = new RRDLEntities()) { TreeNode rootNode = new TreeNode(null, "测试Root"); rootNode.Title = "测试Root"; Tree tree = TreeSet.CreateNewTree(rootNode, "R2Team知识"); TreeNode level1 = new TreeNode(rootNode.Id,"level1"); //TreeNode treeNode=tree.GetTreeNodeById(tree.RootNode.Id); // level1.ParentId = treeNode; tree.AddTreeNode(level1); TreeNode level2 = new TreeNode(level1.Id,"level2"); tree.AddTreeNode(level2); TreeNode level3 = new TreeNode(level2.Id,"level3"); tree.AddTreeNode(level3); TreeNode level4 = new TreeNode(level2.Id, "level3-1"); tree.AddTreeNode(level4); //Tree tree = new Tree("R2Team知识"); tree.GetTreeNodePath(level4); } }
public static Tree CreateNewTree(TreeNode rootNode, string rootPrefix) { // TreeNodeRepository treeRepository = new TreeNodeRepository(); TreeRootPrefixRepository prefixRepository = new TreeRootPrefixRepository(); rootNode.ParentId = null; rootNode.Deepth = 1; //treeRepository.Add(rootNode); TreeRootPrefix prefix = new TreeRootPrefix(rootPrefix, rootNode,DateTime.Now); prefixRepository.Add(prefix); return new Tree(); }
//// 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); } }
public TreeRootPrefix(string prefix,TreeNode rootNode,DateTime dateTime) { this.Prefix = prefix; this.RootNode = rootNode; this.CreateTime = dateTime; }
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"; } }
//当数据源为SQL时调用 //ModeType: "view", IsLoadLeaf: isLoadLeaf, NodeId: pId, XmlUrl: xmlUrl //public ActionResult GetTreeByRootId(string ModeType, string IsLoadLeaf, string NodeId) //{ // Tree tree = new Tree("开发技术"); // string result = ""; // if (NodeId != "") // { // int rootId = Int32.Parse(NodeId); // List<TreeNode> list = tree.GetTreeNodeChild(rootId); // result = JsonConvert.SerializeObject(list); // } // else // { // //"[{\"Ariticle\":null,\"Id\":6,\"Title\":\"Html\",\"Deepth\":2,\"ParentId\":1,\"IsLeaf\":true}] // result = "[{\"Ariticle\":\"null\",\"Id\":\"" + tree.RootNode.Id + "\",\"Title\":\"" + tree.RootNode.Title + "\",\"Deepth\":\"" + tree.RootNode.Deepth + "\",\"ParentId\":\"null\",\"IsLeaf\":\"" + tree.RootNode.IsLeaf + "\"}]"; // //result = JsonConvert.SerializeObject(result); // } // // List<TreeNode> // return Content(result); //} public string AddAriticle(string title, string userId, string visibility, string tag, string content, string treeNodeParentId) { Ariticle ariticle = new Ariticle(); //添加标题 ariticle.Title = title; //添加内容 //ariticle.UGC = System.Web.HttpUtility.UrlDecode(content); content = System.Web.HttpUtility.UrlDecode(content); content = content.Replace("CodeReplacePlus", "+"); ariticle.UGC = content; //ariticle.UGC = content; //添加标签 string[] tlist = tag.Split(new char[] { ',' }); List<AriticleTag> Tags = new List<AriticleTag>(); AriticleTag ariticletag = new AriticleTag(); for (int i = 0; i < tlist.Length; i++) { ariticletag = new AriticleTag(); ariticletag.Title = tlist[i]; // ariticletag.Article = ariticle; Tags.Add(ariticletag); } ariticle.Tags = Tags; //创建一个新节点 TreeNode treeNode = new TreeNode(Int32.Parse(treeNodeParentId), title); //创建不可见分组信息数组 string[] inlist = visibility.Split(new char[] { ';' }); List<int> visiblityGroup = new List<int>(); for (int i = 0; i < inlist.Length - 1; i++) { visiblityGroup.Add(Int32.Parse(inlist[i])); } AriticleService ariticleService = new AriticleService(); ariticleService.NewAriticle(ariticle, visiblityGroup,userId,treeNode); return "success"; }
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"; } }