Exemplo n.º 1
0
        //双击目录树结点打开文件或者文件夹
        private void treeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            TreeNode tn = treeView.SelectedNode;

            if (tn.Tag.ToString() == "1") //打开文件夹
            {
                Stack <TreeNode> s = new Stack <TreeNode>();
                s.Push(tn);
                currentRoot = category.search(rootNode, tn.Text, FCB.FOLDER);

                //更新路径
                nowPath = "";
                while (tn.Parent != null)
                {
                    s.Push(tn.Parent);
                    tn = tn.Parent;
                }
                nowPath = "";
                while (s.Count() != 0)
                {
                    nowPath += "> " + s.Pop().Text;
                }
                textBoxSearch.Text = nowPath;

                //刷新新目录下的界面
                fileFormInit(currentRoot);
            }
            else if (tn.Tag.ToString() == "0") //打开文件
            {
                NoteForm file = new NoteForm(tn.Text.Replace(".txt", ""), this);
                file.Show();
            }
        }
Exemplo n.º 2
0
        //更新所有日志信息,将所有的内容写入到本地
        public void updateLog()
        {
            if (File.Exists(Application.StartupPath + "\\CategoryInfo.txt"))
            {
                File.Delete(Application.StartupPath + "\\CategoryInfo.txt");
            }
            Category.Node         temp = new Category.Node();
            string                path = Application.StartupPath;
            Queue <Category.Node> q    = new Queue <Category.Node>();

            q.Enqueue(category.root);

            while (q.Count() != 0)
            {
                temp = q.Dequeue();
                temp = temp.firstChild;
                while (temp != null)
                {
                    q.Enqueue(temp);
                    writeCategory(temp);
                    temp = temp.nextBrother;
                }
            }

            writeBitMap();
            writeMyDisk();
        }
Exemplo n.º 3
0
 //判断控件内按钮点击
 public void MyControlButtonClick(object sender, EventArgs e)
 {
     if (sender.GetType().ToString() == "System.Windows.Forms.Button")
     {
         Button bt = (Button)sender;                      //当前点击的按钮
         if (bt.Tag.ToString() == "0")                    //文件
         {
             NoteForm file = new NoteForm(bt.Text, this); //弹出记事本窗口
             file.Show();
         }
         else if (bt.Tag.ToString() == "1")                       //文件夹
         {
             currentRoot = category.search(rootNode, bt.Text, 1); //更改当前根节点
             nowPath     = nowPath + "> " + bt.Text;              //更改当前路径
             fileFormInit(currentRoot);                           //更新界面元素
         }
     }
     else
     {
         string filename = fileWindow.contextMenuStrip_FileChoose.SourceControl.Text;
         string type     = fileWindow.contextMenuStrip_FileChoose.SourceControl.Tag.ToString();
         if (((ToolStripMenuItem)sender).Name == "打开ToolStripMenuItem")
         {
             if (type == "0") //文件
             {
                 NoteForm file = new NoteForm(filename, this);
                 file.Show();
             }
             else if (type == "1")//文件夹
             {
                 currentRoot = category.search(rootNode, filename, 1);
                 nowPath     = nowPath + "> " + filename;
                 fileFormInit(currentRoot);
             }
         }
         else if (((ToolStripMenuItem)sender).Name == "删除ToolStripMenuItem")
         {
             if (type == "0")
             {
                 delete(filename, 0);
             }
             else if (type == "1")
             {
                 delete(filename, 1);
             }
         }
     }
 }
Exemplo n.º 4
0
        public MainForm()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            FCB root = new FCB("root", FCB.FOLDER, "", 1);

            rootNode      = new Category.Node(root);
            currentRoot   = rootNode;
            category.root = rootNode;

            /*恢复文件管理系统*/
            readFormDisk();        //读取目录信息文件
            readBitMap();          //读取位图文件
            readMyDisk();          //读取虚拟磁盘文件

            InitializeComponent();
        }
Exemplo n.º 5
0
        //创建目录树
        public void createTreeView(Category.Node pNode)
        {
            if (pNode == null)      //目录为空, 不需要创建目录树
            {
                return;
            }

            /*文件夹和文本文件分别创建目录树结点*/
            TreeNode tn = new TreeNode();

            if (pNode.fcb.type == FCB.FOLDER)
            {
                tn.Name               = pNode.fcb.fileName;
                tn.Text               = pNode.fcb.fileName;
                tn.Tag                = 1;
                tn.ImageIndex         = 1;
                tn.SelectedImageIndex = 1;
            }
            else if (pNode.fcb.type == FCB.TXTFILE)
            {
                tn.Name               = pNode.fcb.fileName + ".txt";
                tn.Text               = pNode.fcb.fileName + ".txt";
                tn.Tag                = 0;
                tn.ImageIndex         = 0;
                tn.SelectedImageIndex = 0;
            }

            /*只需按照一个左孩子一个右兄弟建立目录树*/
            if (pNode.parent == rootNode)
            {
                treeView.Nodes.Add(tn);
            }
            else
            {
                CallAddNode(treeView, pNode.parent.fcb.fileName, tn);
            }
            createTreeView(pNode.firstChild);
            createTreeView(pNode.nextBrother);
        }
Exemplo n.º 6
0
        //初始化当前结点下的界面
        public void fileFormInit(Category.Node now)
        {
            labelDiskSize.Text  = "当前磁盘大小: " + MyDisk.size.ToString() + "B";
            labelBlockSize.Text = "当前盘块大小: " + MyDisk.blockSize.ToString() + "B";

            if (now.fcb.fileName == "root") //当前目录为root时禁用返回上一层按钮
            {
                buttonBack.Enabled = false;
            }
            else
            {
                buttonBack.Enabled = true;
            }

            textBoxSearch.Text = nowPath;   //更新路径

            string name = now.fcb.fileName;

            //窗体初始化
            this.fileWindow.Init();

            //按照左孩子-右兄弟树的结构, 依次显示该目录下的文件夹/文件
            if (now.firstChild == null)
            {
                return;
            }
            Category.Node temp = new Category.Node();
            temp = now.firstChild;
            fileWindow.showFiles(temp.fcb.fileName, temp.fcb.lastModify, temp.fcb.type, temp.fcb.size);
            temp = temp.nextBrother;
            while (temp != null)
            {
                FCB current = temp.fcb;
                fileWindow.showFiles(temp.fcb.fileName, temp.fcb.lastModify, temp.fcb.type, temp.fcb.size);
                temp = temp.nextBrother;
            }
        }
Exemplo n.º 7
0
        public void writeCategory(Category.Node pNode)
        {
            //当前结点的父结点
            Category.Node parentNode = category.currentRootName(rootNode, pNode.fcb.fileName, pNode.fcb.type);
            string        InfoPath   = Application.StartupPath + "\\CategoryInfo.txt";
            StreamWriter  writer     = File.AppendText(InfoPath);

            writer.WriteLine(parentNode.fcb.fileName); //写入父结点的名字
            writer.WriteLine(pNode.fcb.fileName);      //写入文件的名字
            writer.WriteLine(pNode.fcb.type);          //写入文件的类型
            writer.WriteLine(pNode.fcb.lastModify);    //写入最后修改的时间
            writer.WriteLine(pNode.fcb.size);          //写入文件的大小
            if (pNode.fcb.type == FCB.TXTFILE)         //写入文件的开始位置
            {
                writer.WriteLine(pNode.fcb.start);
            }
            else if (pNode.fcb.type == FCB.FOLDER)            //若为文件夹则写入-1
            {
                writer.WriteLine(-1);
            }
            writer.WriteLine("#");                    //一个结点写完

            writer.Close();
        }
Exemplo n.º 8
0
 //返回上一级目录
 private void buttonBack_Click(object sender, EventArgs e)
 {
     nowPath     = nowPath.Replace("> " + currentRoot.fcb.fileName, "");
     currentRoot = currentRoot.parent;
     fileFormInit(currentRoot);
 }