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

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

            this.Title = "个人资料管理中心-" + curDbInfoTab.dbInfoObject.DatabaseFilePath;
            this.Cursor = Cursors.AppStarting;
            //profiler发现,GetTreeFromDB()需要花费大量的时间,因此,将其移到独立的线程中去完成
            tbInfo.Text = "从数据库中装载数据……";
            Task tsk = new Task(() =>
            {
                curDbInfoTab.treeView1.EFConnectionString = EFConnectString;

                String treeXML = curDbInfoTab.treeView1.LoadTreeXMLFromDB();

                Action afterFetchTreeXML = () =>
                {

                    curDbInfoTab.treeView1.LoadFromXmlString(treeXML);
                    curDbInfoTab.treeView1.ShowNode(curDbInfoTab.dbInfoObject.LastVisitNodePath);
                    //绑定树节点集合到查找窗体
                    findNodesWindow.SetTree(curDbInfoTab.treeView1);
                    curDbInfoTab.visitedNodesManager = new VisitedNodesManager(curDbInfoTab.treeView1);

                    MenuItem mnuChangeTextColor = curDbInfoTab.treeView1.ContextMenu.Items[curDbInfoTab.treeView1.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()
        {
            //绑定显示数据源
            findNodesWindow = new FindNodes(treeView1);
            ConfigArgus argu = null;
            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;
                }

            }

            if (string.IsNullOrEmpty(SystemConfig.configArgus.DBFileName))
            {
                SystemConfig.configArgus.DBFileName = "infocenter.sdf";
            }
            //创建连接字符串
            DALConfig.ConnectString = DALConfig.getConnectionString(SystemConfig.configArgus.DBFileName);

            this.Title = "个人资料管理中心-" + SystemConfig.configArgus.DBFileName;
            this.Cursor = Cursors.AppStarting;
            //profiler发现,GetTreeFromDB()需要花费大量的时间,因此,将其移到独立的线程中去完成
            tbInfo.Text = "从数据库中装载数据……";
            Task tsk = new Task(() =>
            {
                String treeXML = MainTreeRepository.GetTreeFromDB();
                Action afterFetchTreeXML = () =>
                {
                    treeView1.LoadFromXmlString(treeXML);
                    if (argu != null)
                    {
                        treeView1.ShowNode(argu.LastVisitNodePath);
                    }

                    visitedNodesManager = new VisitedNodesManager(treeView1);

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

                    ColorBrushList brushList = new ColorBrushList(mnuChangeTextColor);
                    brushList.BrushChanged += brushList_BrushChanged;
                    tbInfo.Text = "就绪。";
                    Cursor = null;

                };
                Dispatcher.BeginInvoke(afterFetchTreeXML);
            });

            tsk.Start();
        }