示例#1
0
        private void CutNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.CurrentTreeView.IsInEditMode)
            {
                curDbInfoTab.CurrentTreeView.SelectedItem.EndEdit();
            }
            //如果己经有被剪切的节点,则取消它的下划线状态
            if (cutNode != null && cutNode != curDbInfoTab.CurrentTreeView.SelectedItem)
            {
                cutNode.Strikethrough = false;
            }
            cutNode = curDbInfoTab.CurrentTreeView.SelectedItem as TreeViewIconsItem;
            cutNode.Strikethrough = true;
            cutNodeSourceTab      = curDbInfoTab;
            String info = "";

            if (cutNode.HeaderText.Length > 30)
            {
                info = "节点:\"" + cutNode.HeaderText.Substring(0, 30) + "\"己被剪切";
            }
            else
            {
                info = "节点:\"" + cutNode.HeaderText + "\"己被剪切";
            }
            ShowInfo(info);
        }
示例#2
0
 public LabelWindow(MainWindow mainWindow, DBInfoTab curDbInfoTab, InfoNodeAccess access, InfoNodeDataInfo datainfo)
 {
     InitializeComponent();
     labeltree.TreeNodeType = "LabelNode";
     MainWin           = mainWindow;
     this.curDbInfoTab = curDbInfoTab;
     // SelectedInfoNodeDataObj = curDbInfoTab.CurrentTreeView.SelectedItem.NodeData ;
     InfoNodeAccessObj   = access;
     InfoNodeDataInfoObj = datainfo;
     LoadLabelTree();
 }
示例#3
0
        void DBtabContainer_TabPageClosed(object sender, TabPageClosedEventArgs e)
        {
            //保存被关闭的选项卡的数据
            DBInfoTab closedTab = e.ClosedTabItem.Content as DBInfoTab;

            //如果被关闭的是包容有被剪切节点的选项卡,则设置相关的变量为null
            if (cutNodeSourceTab != null && cutNodeSourceTab == closedTab)
            {
                cutNodeSourceTab = null;
                cutNode          = null;
            }
            //从参数中移除本选项卡所对应的DbInfo对象
            int index = SystemConfig.configArgus.DbInfos.IndexOf(closedTab.dbInfoObject);

            if (index != -1)
            {
                SystemConfig.configArgus.DbInfos.RemoveAt(index);
            }
            SaveDbTabDataToDB(closedTab);
        }
示例#4
0
        /// <summary>
        /// 打开指定的数据库文件,创建新选项卡,装入数据,新创建的选项卡成为当前选项卡
        /// </summary>
        /// <param name="DBFileName"></param>
        private void AddNewDbInfoTabAndLoadData(String DBFileName)
        {
            DatabaseInfo dbInfo = new DatabaseInfo()
            {
                DatabaseFilePath  = DBFileName,
                LastVisitNodePath = ""
            };

            SystemConfig.configArgus.DbInfos.Add(dbInfo);

            //添加选项卡
            DBInfoTab tab = new DBInfoTab(dbInfo);

            //DBtabContainer.SelectedIndex = DBtabContainer.Items.Count - 1;
            DBtabContainer.Add(System.IO.Path.GetFileName(dbInfo.DatabaseFilePath), tab);//Note:新添加选项卡,会激发会激发DBtabContainer的SelectedIndexChanged事件,所以此函数内本语句下面的代码是不会执行的。
            DBtabContainer.SelectedIndex           = DBtabContainer.Items.Count - 1;
            SystemConfig.configArgus.ActiveDBIndex = DBtabContainer.Items.Count - 1;
            curDbInfoTab            = tab;
            curDbInfoTab.EditorTool = EditorTool;
            //Note: 新加选项卡,会激发DBtabContainer的SelectedIndexChanged事件,在事件响应代码DBtabContainer_SelectionChanged()
            //中完成了从数据库中装载数据的工作,无需显示调用LoadCurrentTabDataFromDB();方法
        }
示例#5
0
        /// <summary>
        /// 将指定选项卡的数据保存到数据库中
        /// </summary>
        /// <param name="infoTab"></param>
        private void SaveDbTabDataToDB(DBInfoTab infoTab)
        {
            TreeViewIconsItem selectedItem = infoTab.CurrentTreeView.SelectedItem;
            DatabaseInfo      info         = infoTab.dbInfoObject;

            if (selectedItem != null)
            {
                if (infoTab.CurrentTreeView == infoTab.OutLineViewObj.SuperTree || infoTab.CurrentTreeView == infoTab.LabelViewObj.SuperTree)
                {
                    info.LastVisitNodePath = selectedItem.Path;
                    if (infoTab.CurrentTreeView == infoTab.OutLineViewObj.SuperTree)
                    {
                        infoTab.dbInfoObject.LastTabViewIndex = 0;
                    }
                    if (infoTab.CurrentTreeView == infoTab.LabelViewObj.SuperTree)
                    {
                        infoTab.dbInfoObject.LastTabViewIndex = 1;
                    }
                }

                IDataAccess accessobj = selectedItem.NodeData.AccessObject;
                IDataInfo   infoObj   = selectedItem.NodeData.DataItem;
                if (accessobj != null)
                {
                    try
                    {
                        infoObj.RefreshMe();
                        accessobj.UpdateDataInfoObject(infoObj);
                    }
                    catch (Exception ex)
                    {
                        Dispatcher.Invoke(new Action(() => { MessageBox.ShowInformation(ex.ToString()); }));
                    }
                }
            }
        }
示例#6
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;
        }
示例#7
0
        private void PasteNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.CurrentTreeView.IsInEditMode)
            {
                curDbInfoTab.CurrentTreeView.SelectedItem.EndEdit();
            }
            if (cutNode == null || cutNodeSourceTab == null)
            {
                return;
            }
            TreeViewIconsItem selectedNode = curDbInfoTab.CurrentTreeView.SelectedItem as TreeViewIconsItem;

            if (selectedNode == cutNode)
            {
                return;
            }
            String newPath = "";

            if (selectedNode == null)//如果目标选项卡中没有选中任何节点,则默认添加到根节点
            {
                newPath = "/" + cutNode.HeaderText + "/";
            }
            else
            {
                newPath = selectedNode.Path + cutNode.HeaderText + "/";
            }

            if (curDbInfoTab.CurrentTreeView.IsNodeExisted(newPath))
            {
                MessageBox.ShowInformation("在此处粘贴将导致两个节点拥有相同的路径,因此,请在其他地方粘贴");
                return;
            }
            //在同一数据库中粘贴
            if (curDbInfoTab == cutNodeSourceTab)
            {
                //先移除被剪切的子树
                curDbInfoTab.CurrentTreeView.CutNode(cutNode);
                curDbInfoTab.CurrentTreeView.PasteNode(cutNode, selectedNode);

                curDbInfoTab.OnNodeMove(NodeMoveType.NodePaste);
            }
            else
            {
                //在不同的数据库中粘贴
                String sourcePath = cutNode.Path;
                String targetPath = "";
                if (selectedNode != null)
                {
                    targetPath = selectedNode.Path;
                }
                else
                {
                    targetPath = "/";
                }

                //先移除源树中被剪切的子树
                cutNodeSourceTab.CurrentTreeView.CutNode(cutNode);


                //将剪切的节点子树追加到当前节点
                curDbInfoTab.CurrentTreeView.PasteNodeCrossDB(cutNode, selectedNode);

                //保存目标树结构
                curDbInfoTab.CurrentTreeView.SaveToDB();
                //将源树保存到数据库中
                cutNodeSourceTab.CurrentTreeView.SaveToDB();

                //更新所有粘贴节点的数据存取对象
                String EFConnectionString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);
                if (selectedNode != null)
                {
                    UpdateDataAcessObject(selectedNode, EFConnectionString);
                }
                else
                {
                    UpdateDataAcessObject(cutNode, EFConnectionString);
                }

                //更新数据库中内容
                NodeMoveBetweenDBManager nodeMoveManager = new NodeMoveBetweenDBManager(cutNodeSourceTab.dbInfoObject.DatabaseFilePath, curDbInfoTab.dbInfoObject.DatabaseFilePath);
                nodeMoveManager.MoveNodeBetweenDB(sourcePath, targetPath);
            }
            //取消删除线显示
            cutNode.Strikethrough = false;
            cutNode          = null;
            cutNodeSourceTab = null;
            if (curDbInfoTab.CurrentTreeView.SelectedItem != null)
            {
                curDbInfoTab.CurrentTreeView.SelectedItem.IsExpanded = true;
            }
        }
示例#8
0
        private void DBtabContainer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //打开数据库,首次选择节点时,附加栏选项卡的SelectionChanged事件被触发,此处用于屏蔽此路由事件,也可在事件源屏蔽。
            if (e.Source.GetType().Name == "DBInfoTab")
            {
                return;
            }
            //初始化时,此方法不做任何事,仅设置默认标题,下面语句无法执行
            if (DBtabContainer.SelectedIndex == -1)
            {
                this.Title = MainWindowDefaultTitle;
                return;
            }
            if (e.AddedItems.Count == 1 && e.AddedItems[0].GetType().Name != "TabItem")
            {
                return;
            }
            //初始化时,此方法不做任何事,仅设置默认标题
            if (e.OriginalSource.GetType().Name == "InfoTabControl")
            {
                //if (e.RemovedItems.Count <= 0)
                //{

                curDbInfoTab            = (DBtabContainer.Items[DBtabContainer.SelectedIndex] as TabItem).Content as DBInfoTab;
                curDbInfoTab.EditorTool = EditorTool;
                curDbInfoTab.InnerTabControl.SelectedIndex = curDbInfoTab.dbInfoObject.LastTabViewIndex;

                this.Title = MainWindowDefaultTitle;
                if (curDbInfoTab.HasBeenLoadedFromDB == false)
                {
                    //从数据库中装入数据
                    LoadCurrentTabDataFromDB();
                    curDbInfoTab.HasBeenLoadedFromDB = true;
                }
                //return;
                //}
            }
            //TabControl的SelectionChanged事件,虽然可以通过在下层控件的事件响应过程中添加
            //e.Handled = true阻止这一过程,但还是在此屏蔽掉此事件的响应代码,以免有漏网之鱼
            if (e.AddedItems.Count == 1 && e.AddedItems[0].GetType().Name != "TabItem")
            {
                return;
            }
            // this.Title = "我的信息基地-" + curDbInfoTab.dbInfoObject.DatabaseFilePath;
            this.Title = "我的信息基地";
            if (curDbInfoTab.HasBeenLoadedFromDB == false)
            {
                //从数据库中装入数据
                LoadCurrentTabDataFromDB();
                curDbInfoTab.HasBeenLoadedFromDB = true;
            }
            else
            {
                String EFConnectString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);
                curDbInfoTab.CurrentTreeView.EFConnectionString = EFConnectString;
                findNodesWindow.SetTree(curDbInfoTab.OutLineViewObj.SuperTree);
                curDbInfoTab.RefreshDisplay();
            }
            //切换选项卡时,恢复状态栏默认显示文本
            if (cutNode == null)
            {
                ShowInfo("就绪");
            }
        }