public DBInfoTab(DatabaseInfo infoObject) { InitializeComponent(); dbInfoObject = infoObject; visitedNodesManager = new VisitedNodesManager(treeView1); }
/// <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(); }