Esempio n. 1
0
        /// <summary>
        /// 新建笔记页对象。
        /// knowledgeBase是目标知识库
        /// </summary>
        /// <param name="knowledgeBase"></param>
        /// <param name="noteName"></param>
        /// <returns></returns>
        public static Note newNote(KnowledgeBase knowledgeBase, String noteName)
        {
            // 若knowledgeBase有效则新建笔记页对象
            if (null != knowledgeBase)
            {
                Note note = new Note(noteName, knowledgeBase.getRecordLocation());

                // 若目标知识库中不存在同名的笔记页对象,则添加
                String path = note.getRecordLocation();
                if (!knowledgeBase.existNote(path))
                {
                    creatFile(path);
                    knowledgeBase.addNote(note);
                    return(note);
                }
                // 否则提示用户“已重名”
                else
                {
                    MessageBox.Show("已重名");
                    return(null);
                }
            }
            else
            {
                MessageBox.Show("请先选中知识库");
                return(null);
            }
        }
Esempio n. 2
0
        private void newNote()
        {
            TreeNode node;

            if ((node = list_treeView.SelectedNode) != null)
            {
                Tip notepage = new Tip("请输入笔记页名称");
                notepage.ShowDialog();
                if (nodeName.Equals(""))
                {
                    return;
                }

                ClosePreForm();                                  //嵌入窗体前判断当前容器中是否有窗口没关掉
                NodeForm nodeForm = new NodeForm();
                nodeForm.edit_richTextBox.Dock = DockStyle.Fill; //设置富文本框的填充
                int           index = node.Index;
                KnowledgeBase kb    = KBM.getKB(index);
                Note          note;
                if ((note = FileManagement.newNote(kb, nodeName)) != null)
                {
                    addSonNode(node, nodeName);
                    OpenForm(nodeForm, nodeName);
                    bindingNoteForm(nodeForm, note);
                }
            }
        }
Esempio n. 3
0
        private void importNote()
        {
            TreeNode node;

            if ((node = list_treeView.SelectedNode) != null)
            {
                int           index = node.Index;
                KnowledgeBase kb    = KBM.getKB(index);
                FileManagement.importNoteDialog(KBM, kb);
                updateTree();
            }
        }
        /// <summary>
        /// 判断一个知识库对象(KnowledgeBase)是否已经存在于当前知识库列表(knowledgeBases)中
        /// </summary>
        /// <param name="knowledgeBase"></param>
        /// <returns></returns>
        public Boolean existKB(KnowledgeBase knowledgeBase)
        {
            String kbLocation = knowledgeBase.getRecordLocation();

            foreach (KnowledgeBase kb in knowledgeBases)
            {
                if (kb.getRecordLocation().Equals(kbLocation))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// 创建新知识库管理器实例。
        /// </summary>
        /// <param name="konwledgeBaseManagement"></param>
        /// <param name="KBname"></param>
        /// <returns></returns>
        public static Boolean newKB(KonwledgeBaseManagement konwledgeBaseManagement, String KBname)
        {
            KnowledgeBase kb = new KnowledgeBase(getRecordLocation(), KBname);

            if (!konwledgeBaseManagement.existKB(kb))
            {
                konwledgeBaseManagement.addKnowledgeBase(kb);
                return(true);
            }
            else
            {
                MessageBox.Show("已存在知识库");
                return(false);
            }
        }
Esempio n. 6
0
        public static KonwledgeBaseManagement loadKnowledgeBaseManagement()
        {
            // 知识库管理器
            KonwledgeBaseManagement konwledgeBaseManagement;

            // 获得当前工作路径
            String path = getRecordLocation();

            // 如果存在持久化存储的知识库管理器实例,则加载
            if (File.Exists(getRecordLocation() + @"\KBM.xml"))
            {
                XMLTransformation xMLTransformation = new XMLTransformation();
                konwledgeBaseManagement = xMLTransformation.deserialization(path, "KBM");
            }
            // 若不存在,则新建知识库管理器实例
            else
            {
                konwledgeBaseManagement = new KonwledgeBaseManagement();

                // 在当前工作路径下新建知识库
                // 测试名?
                KnowledgeBase kb = new KnowledgeBase(getRecordLocation() + @"\默认知识库");

                // 在当前工作路径中,添加与新建的知识库对应的文件夹
                if (!Directory.Exists(kb.getRecordLocation()))
                {
                    Directory.CreateDirectory(kb.getRecordLocation());
                }

                // 新建笔记页
                // 测试代码?
                Note note1 = new Note("默认笔记", kb.getRecordLocation());

                // 在新建知识库路径中,创建与新建的笔记页对应的富文本文件
                // 若对应文件已存在,则将其删除以便新建
                if (!File.Exists(note1.getRecordLocation()))
                {
                    File.Delete(note1.getRecordLocation());
                }
                creatFile(note1.getRecordLocation());
                kb.addNote(note1);

                // 添加新建的知识库实例到当前知识库管理器中
                konwledgeBaseManagement.addKnowledgeBase(kb);
            }
            return(konwledgeBaseManagement);
        }
Esempio n. 7
0
        /// <summary>
        /// 初始化指定路径为知识库,并将其返回
        /// </summary>
        /// <param name="selectedPath"></param>
        /// <returns></returns>
        private static KnowledgeBase newKB(String selectedPath)
        {
            // 新建了一个知识库实例
            KnowledgeBase knowledgeBase = new KnowledgeBase(selectedPath);

            // 将该路径中所有符合格式(.rtf)的文件都添加到该知识库中作为笔记页
            DirectoryInfo TheFolder = new DirectoryInfo(selectedPath);

            foreach (FileInfo fi in TheFolder.GetFiles())
            {
                if (fi.Name.EndsWith(Note.getFormat()))
                {
                    Note note = new Note(fi.Name, knowledgeBase.getRecordLocation());
                    knowledgeBase.addNote(note);
                }
            }

            return(knowledgeBase);
        }
Esempio n. 8
0
        /// <summary>
        /// 导出知识库。
        /// GUI代码。
        /// </summary>
        /// <param name="knowledgeBase"></param>
        public static void exportKB(KnowledgeBase knowledgeBase)
        {
            // 创建文件夹浏览器并获得导出目标路径
            String selectedPath  = showFolderBrowserDialog("导出笔记");
            String directoryPath = selectedPath + @"\" + knowledgeBase.getName();

            // 若该路径下存在与该知识库同名的文件夹,询问是否替换
            if (Directory.Exists(directoryPath))
            {
                int answer = (int)MessageBox.Show("知识库中已有名为" + knowledgeBase.getName() + "的文件夹,是否替换", "替换提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                if (6 == answer)//返回值 是6 否7 取消2
                {
                    Directory.Delete(directoryPath);
                    Directory.CreateDirectory(directoryPath);
                    knowledgeBase.copyNotes(directoryPath);
                }
            }
            // 若不存在,则复制知识库对应的文件夹到目标文件夹
            else
            {
                Directory.CreateDirectory(directoryPath);
                knowledgeBase.copyNotes(directoryPath);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 导入笔记页面对话框
 /// GUI代码 切割
 /// </summary>
 /// <param name="konwledgeBaseManagement"></param>
 /// <param name="knowledgeBase"></param>
 public static void importNoteDialog(KonwledgeBaseManagement konwledgeBaseManagement, KnowledgeBase knowledgeBase)
 {
     if (null != knowledgeBase)
     {
         // 可以选择数个希望导入的笔记页文件
         String[] fileNames = showOpenFileDialog();
         if (null != fileNames)
         {
             importNote(fileNames, konwledgeBaseManagement, knowledgeBase);
         }
     }
     else
     {
         MessageBox.Show("请先选择知识库");
     }
 }
Esempio n. 10
0
        /// <summary>
        /// 导入笔记页到指定的知识库中。
        /// 切割部分另设方法
        /// </summary>
        /// <param name="fileNames"></param>
        /// <param name="konwledgeBaseManagement"></param>
        /// <param name="knowledgeBase"></param>
        private static void importNote(String[] fileNames, KonwledgeBaseManagement konwledgeBaseManagement, KnowledgeBase knowledgeBase)
        {
            // 不会用到的初始值?
            int index = fileNames[0].LastIndexOf(@"\") + 1;

            //
            for (int i = 0; i < fileNames.Length; i++)
            {
                // 判断将要添加的笔记页是否已存在于目标知识库中
                index = konwledgeBaseManagement.existNote(fileNames[i]);

                // 若不存在,尝试添加:
                if (-1 == index)
                {
                    // (以下应分割为单独的方法):

                    // 获取笔记页名
                    String name = fileNames[i].Substring(index, fileNames[i].Length - index);

                    //新建笔记页对象
                    Note note = new Note(name, knowledgeBase.getRecordLocation());

                    // 添加该笔记页到指定的知识库中
                    knowledgeBase.addNote(note);

                    // 若目标知识库对应文件夹中已存在同名文件,
                    // 询问用户的选择
                    if (File.Exists(note.getRecordLocation()))
                    {
                        int answer = (int)MessageBox.Show("知识库中已有名为" + note.getName() + "的文件,是否替换", "替换提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                        if (6 == answer)//返回值 是6 否7 取消2
                        {
                            File.Delete(note.getRecordLocation());
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // 若不存在,将该笔记页文件复制到目标知识库对应的文件夹中
                    File.Copy(fileNames[i], note.getRecordLocation());//另存
                }
                else
                {
                    MessageBox.Show("该笔记已经在" + konwledgeBaseManagement.getKB(index).getName() + "存在");
                }
            } // for循环的结束
        }
 /// <summary>
 /// 向知识库列表(knowledgeBases)中添加新的知识库(KnowledgeBase)对象
 /// </summary>
 /// <param name="kb"></param>
 public void addKnowledgeBase(KnowledgeBase kb)
 {
     knowledgeBases.Add(kb);
 }