Esempio n. 1
0
 //// 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);
     }
 }
Esempio n. 2
0
 //The Function Bllew is Added By ZHAOs ,2013年11月14日10:02:13,used to Delete A TreeNode in 目录树管理
 public string DeleteNode(string _modeType, string nodeId, string xmlUrl) {
     // _modeType = "deleteFolder"  ,modeId = "6" ,xmlUrl = ""  传入的参数大致形式如此
     Tree tree = new Tree();
     TreeNode treeNode = tree.GetTreeNodeById(Convert.ToInt32(nodeId));
     string returnStr = "";
     /*
     如果这个节点是叶子节点
         如果是空文件夹  --文件夹(ariticleID为空且isLeaf属性为True),为空文件夹 ===> 可删除
         如果是知识   --不能删除知识  (此时 ariticleID属性不为NULL  且 idLeaf属性为 True即是)
     如果这个节点不是叶子节点(即非空文件夹,里面可能有知识或者 为空不为空的 文件夹)(ariticleID为空且isLeaf属性为false)====> 不能删除
     PS:但是这里不显示知识,所以只可能有 叶子节点文件夹 和 非叶子节点文件夹。
      * 叶子节点文件夹内部一定没有知识,可以直接删除 ===>有知识的情况 以后版本考虑
      * 非叶子节点文件夹内容一定有文件夹或知识,不能删除。
      * 逻辑较简单。
      * 只是只能从叶子节点删起      
      * PS:如果一个父节点其下的所有子节点都被删除,则该父节点的IsLeaf属性变为True
      */
     if (treeNode.IsLeaf == true)
     {   
         //如果是根目录
         if (treeNode.ParentId == null)
         {
             returnStr = "根目录不可删除!";
         }
         else {//若果其父节点下只有这一个子节点,则删除此子节点并把父节点isLeaf属性设为True
             TreeNode parentNode = tree.GetTreeNodeById(Convert.ToInt32(treeNode.ParentId));
             List<TreeNode> parentChildList = tree.GetTreeNodeChild(Convert.ToInt32(treeNode.ParentId));
             if (parentChildList.Count == 1)
             {
                 parentNode.IsLeaf = true;
             }
             tree.UpdateTreeNode(parentNode);//改变父节点isLeaf属性
             tree.Drop(treeNode);//删除子节点
             returnStr = "ok";
         }
         
     }
     else {
         returnStr = "该节点下存在子文件夹或知识,不能删除!";
     }
     return returnStr;
 }