예제 #1
0
파일: FileSystem.cs 프로젝트: q4472/FarmSib
        private string RenderFileTreeNode(FileTreeNode node, bool isRoot, bool isLast)
        {
            StringBuilder html     = new StringBuilder();
            ArrayList     children = GetChildNodes(node);
            String        line     = (isRoot) ? " FsNodeIsRoot" : (isLast) ? " FsNodeIsLast" : " IsMiddleFsNode";
            String        expand   = (node.NodeName == "file") ? " FsNodeExpandIsLeaf" : (isRoot) ? " FsNodeExpandIsOpen" : " FsNodeExpandIsClosed";
            //String expand = (children.Count == 0) ? " FsNodeExpandIsLeaf" : (isRoot) ? " FsNodeExpandIsOpen" : " FsNodeExpandIsClosed";
            String path  = WebUtility.HtmlEncode(node.Path.ToString().Replace('\\', '/'));
            String descr = WebUtility.HtmlEncode(node.NodeDescr);

            html.AppendFormat("<div class='FsNode {0} {1}' data-node-name='{2}' data-path='{3}' >", line, expand, node.NodeName, path);
            {
                html.Append("<div class='FsNodeExpand'></div>");
                html.AppendFormat("<div class='FsNodeContent'>{0}</div>", descr);
                html.Append("<div class='FsNodeContainer'>");
                {
                    for (int i = 0; i < children.Count; i++)
                    {
                        FileTreeNode child = (FileTreeNode)children[i];
                        isLast = (i == (children.Count - 1));
                        html.Append(RenderFileTreeNode(child, false, isLast));
                    }
                }
                html.Append("</div>");
            }
            html.Append("</div>");
            return(html.ToString());
        }
예제 #2
0
파일: FileSystem.cs 프로젝트: q4472/FarmSib
        public FileTreeNode(String path, FileTreeNode parent, String nodeName = "dir")
        {
            String[] parts = path.Split('\\');
            String   descr = parts[parts.Length - 1];

            this.Id        = Guid.NewGuid();
            this.ParentId  = (parent == null) ? new Guid() : parent.Id;
            this.NodeName  = nodeName;
            this.NodeDescr = descr;
            this.Path      = path;
        }
예제 #3
0
파일: FileSystem.cs 프로젝트: q4472/FarmSib
        private ArrayList GetChildNodes(FileTreeNode node)
        {
            ArrayList nodes = new ArrayList();

            foreach (object o in this.Nodes)
            {
                FileTreeNode n = (FileTreeNode)o;
                if (n.ParentId != new Guid())
                {
                    if (n.ParentId == node.Id)
                    {
                        nodes.Add(n);
                    }
                }
            }
            return(nodes);
        }
예제 #4
0
파일: FileSystem.cs 프로젝트: q4472/FarmSib
 private void LoadDirInfo(DataSet ds, FileTreeNode parentNode = null)
 {
     if (ds != null)
     {
         DataTable dirs = ds.Tables["Directories"];
         // первая строка это родительский каталог
         DataRow pDir     = dirs.Rows[0];
         String  pDirName = (String)pDir["name"];
         pDirName = ((pDirName == "") ? "\\" : pDirName);
         // добавляем в список
         FileTreeNode pDirNode = new FileTreeNode(pDirName, parentNode, "dir");
         this.Nodes.Add(pDirNode);
         dirs.Rows[0].Delete();
         // остальные строки это вложенные каталоги
         // сортируем в алфавитном порядке
         DataView dv = dirs.DefaultView;
         dv.Sort = "name";
         // добавляем в список
         foreach (DataRowView drv in dv)
         {
             String       cDirName = (String)drv["name"];
             FileTreeNode cDirNode = new FileTreeNode(cDirName, pDirNode, "dir");
             this.Nodes.Add(cDirNode);
         }
         // файлы
         DataTable files = ds.Tables["Files"];
         // сортируем в алфавитном порядке
         dv      = files.DefaultView;
         dv.Sort = "name";
         // добавляем в список
         foreach (DataRowView drv in dv)
         {
             String       cFileName = (String)drv["name"];
             FileTreeNode cFileNode = new FileTreeNode(cFileName, pDirNode, "file");
             this.Nodes.Add(cFileNode);
         }
     }
 }
예제 #5
0
파일: FileSystem.cs 프로젝트: q4472/FarmSib
        public string ToHtml()
        {
            string html = "";
            // ищем root
            FileTreeNode rootNode = null;

            foreach (object node in this.Nodes)
            {
                if (((FileTreeNode)node).ParentId == new Guid())
                {
                    rootNode = (FileTreeNode)node;
                    break;
                }
            }
            if (rootNode == null)
            {
                html = "<div>Root node is not found.</div>";
            }
            else
            {
                html = RenderFileTreeNode(rootNode, true, true);
            }
            return(html);
        }