Exemplo n.º 1
0
        /// <summary>
        /// 从数据库中为当前激活的选项卡装入信息
        /// </summary>
        /// <param name="argu"></param>
        public void LoadCurrentTabDataFromDB()
        {
            //绑定显示数据源
            if (findNodesWindow == null)
            {
                findNodesWindow = new FindNodes();
            }

            //创建连接字符串
            String EFConnectString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);

            //this.Title = "我的信息基地-" + curDbInfoTab.dbInfoObject.DatabaseFilePath;
            this.Title  = "我的信息基地";
            this.Cursor = Cursors.AppStarting;
            //profiler发现,GetTreeFromDB()需要花费大量的时间,因此,将其移到独立的线程中去完成
            tbInfo.Text = "从数据库中装载数据……";
            foreach (SuperTreeView treeView in curDbInfoTab.InnerTreeViewList)
            {
                Task tsk = new Task(() =>
                {
                    treeView.EFConnectionString = EFConnectString;

                    String treeXML = treeView.LoadTreeXMLFromDB();

                    Action afterFetchTreeXML = () =>
                    {
                        treeView.LoadFromXmlString(treeXML);
                        treeView.ShowNode(curDbInfoTab.dbInfoObject.LastVisitNodePath);


                        //绑定树节点集合到查找窗体
                        findNodesWindow.SetTree(curDbInfoTab.OutLineViewObj.SuperTree);
                        curDbInfoTab.visitedNodesManager = new VisitedNodesManager(treeView);



                        MenuItem mnuChangeTextColor = treeView.ContextMenu.Items[treeView.ContextMenu.Items.Count - 1] as MenuItem;

                        ColorBrushList brushList = new ColorBrushList(mnuChangeTextColor);
                        brushList.BrushChanged  += brushList_BrushChanged;
                        tbInfo.Text = "就绪。";
                        Cursor      = null;
                        ////设置己从数据库中装入标记
                        curDbInfoTab.HasBeenLoadedFromDB = true;
                    };
                    Dispatcher.BeginInvoke(afterFetchTreeXML);
                });

                tsk.Start();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 完成系统初始化功能
        /// </summary>
        private void Init()
        {
            //设置NodeFactory的主窗体引用,以便让它创建节点对象时,一并将主窗体引用传给节点
            //从而允许节点调用主窗体的功能,此句代码必须在装入全树节点前完成,否则,节点的DataItem对象
            //将无法引用到主窗体
            NodeFactory._mainWindow = this;
            //DBInfoTab._mainWindow = this;
            SuperWPFRichTextBox._mainWindow = this;
            EditorToolBar._mainWindow       = this;
            //订阅事件
            AddLabelEventManager addLabelEventManager = new AddLabelEventManager();

            addLabelEventManager.Register(this);
            RemoveLabelEventManager removeLabelEventManager = new RemoveLabelEventManager();

            removeLabelEventManager.Register(this);


            ConfigArgus argu = new ConfigArgus();

            tbVersionInfo.Text = String.Format("版本: {0} ", ConfigArgus.version);
            //如果找到了配置文件
            if (File.Exists(SystemConfig.ConfigFileName))
            {
                tbInfo.Text = "正在加载配置文件……";
                //定位到上次访问的节点
                try
                {
                    argu = DeepSerializer.BinaryDeserialize(SystemConfig.ConfigFileName) as ConfigArgus;
                }
                catch (Exception)
                {
                    argu = null;
                }

                if (argu != null)
                {
                    SystemConfig.configArgus = argu;
                    //设置树节点的默认字体大小
                    TreeViewIconsItem.TreeNodeDefaultFontSize = argu.TreeNodeDefaultFontSize;
                }
                findNodesWindow = new FindNodes();

                //labelWindow = new LabelWindow();

                //用于保存有效的数据库文件对象
                List <DatabaseInfo> validDBInfos = new List <DatabaseInfo>();
                //创建数据库选项卡
                foreach (var dbinfo in argu.DbInfos)
                {
                    if (File.Exists(dbinfo.DatabaseFilePath))
                    {
                        DBInfoTab tab = new DBInfoTab(dbinfo);
                        DBtabContainer.Add(System.IO.Path.GetFileName(dbinfo.DatabaseFilePath), tab);
                        validDBInfos.Add(dbinfo);
                    }
                }
                bool allDBAreOk = (argu.DbInfos.Count == validDBInfos.Count);
                if (!allDBAreOk)
                {
                    argu.DbInfos = validDBInfos;
                }
                if (DBtabContainer.Items.Count != 0)
                {
                    //设置当前激活的卡片
                    if (argu.ActiveDBIndex < DBtabContainer.Items.Count && allDBAreOk)
                    {
                        DBtabContainer.SelectedIndex = argu.ActiveDBIndex;
                    }
                    else
                    {
                        argu.ActiveDBIndex           = 0;
                        DBtabContainer.SelectedIndex = 0;
                    }

                    curDbInfoTab            = (DBtabContainer.Items[argu.ActiveDBIndex] as TabItem).Content as DBInfoTab;
                    curDbInfoTab.EditorTool = EditorTool;
                    //显示程序退出时最后一次展现的数据库信息选项卡内部的选项卡视图
                    curDbInfoTab.InnerTabControl.SelectedIndex = curDbInfoTab.dbInfoObject.LastTabViewIndex;

                    LoadCurrentTabDataFromDB();
                }
                else
                {
                    tbInfo.Text = "未能找到上次打开的数据库,请从系统功能菜单中选择打开命令打开一个资料库";
                }
            }
            else
            {
                tbInfo.Text = "请从系统功能菜单中选择打开命令打开一个资料库";
            }
            //响应用户点击不同选项卡的操作,此处添加事件处理程序而不是在xaml文件中添加可以避免在初始化时执行一次。
            DBtabContainer.SelectionChanged += DBtabContainer_SelectionChanged;
            //关闭选项卡时,激发此事件
            DBtabContainer.TabPageClosed += DBtabContainer_TabPageClosed;
        }