Esempio n. 1
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;
        }
        /// <summary>
        /// 完成系统初始化功能
        /// </summary>
        private void Init()
        {
            //设置NodeFactory的主窗体引用,以便让它创建节点对象时,一并将主窗体引用传给节点
            //从而允许节点调用主窗体的功能,此句代码必须在装入全树节点前完成,否则,节点的DataItem对象
            //将无法引用到主窗体
            NodeFactory._mainWindow = this;

            ConfigArgus argu = new ConfigArgus();

            tbVersionInfo.Text = String.Format("PersonalInfoForWPF ver: {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();
                //用于保存有效的数据库文件对象
                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;
                    LoadCurrentTabDataFromDB();
                }
                else
                {
                    tbInfo.Text = "未能找到上次打开的数据库,请从系统功能菜单中选择打开命令打开一个资料库";
                }
            }
            else
            {
                tbInfo.Text = "请从系统功能菜单中选择打开命令打开一个资料库";
            }

            //响应用户点击不同选项卡的操作
            DBtabContainer.SelectionChanged += DBtabContainer_SelectionChanged;
            //关闭选项卡时,激发此事件
            DBtabContainer.TabPageClosed += DBtabContainer_TabPageClosed;
        }