Exemplo n.º 1
0
        private void CutNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.treeView1.IsInEditMode)
            {
                curDbInfoTab.treeView1.SelectedItem.EndEdit();
            }
            //如果己经有被剪切的节点,则取消它的下划线状态
            if (cutNode != null && cutNode != curDbInfoTab.treeView1.SelectedItem)
            {
                cutNode.Strikethrough = false;
            }
            cutNode = curDbInfoTab.treeView1.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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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.Add(System.IO.Path.GetFileName(dbInfo.DatabaseFilePath), tab);
            DBtabContainer.SelectedIndex           = DBtabContainer.Items.Count - 1;
            SystemConfig.configArgus.ActiveDBIndex = DBtabContainer.Items.Count - 1;

            curDbInfoTab = tab;
            //Note: 新加选项卡,会激发DBtabContainer的SelectedIndexChanged事件,在事件响应代码DBtabContainer_SelectionChanged()
            //中完成了从数据库中装载数据的工作,无需显示调用LoadCurrentTabDataFromDB();方法
        }
Exemplo n.º 4
0
        private void DBtabContainer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //初始化时,此方法不做任何事,仅设置默认标题
            if (DBtabContainer.SelectedIndex == -1)
            {
                this.Title = MainWindowDefaultTitle;
                return;
            }
            //当TabControl的TabItem中放置有ComboBox控件时,ComboBox的SelectionChanged事件会触发
            //TabControl的SelectionChanged事件,虽然可以通过在下层控件的事件响应过程中添加
            //e.Handled = true阻止这一过程,但还是在此屏蔽掉此事件的响应代码,以免有漏网之鱼
            if (e.AddedItems.Count == 1 && e.AddedItems[0].GetType().Name != "TabItem")
            {
                return;
            }

            curDbInfoTab = (DBtabContainer.Items[DBtabContainer.SelectedIndex] as TabItem).Content as DBInfoTab;
            this.Title   = "个人资料管理中心-" + curDbInfoTab.dbInfoObject.DatabaseFilePath;
            if (curDbInfoTab.HasBeenLoadedFromDB == false)
            {
                //从数据库中装入数据
                LoadCurrentTabDataFromDB();
            }
            else
            {
                String EFConnectString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);
                curDbInfoTab.treeView1.EFConnectionString = EFConnectString;
                findNodesWindow.SetTree(curDbInfoTab.treeView1);
                curDbInfoTab.RefreshDisplay();
            }
            //切换选项卡时,恢复状态栏默认显示文本
            if (cutNode == null)
            {
                ShowInfo("就绪");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 将指定选项卡的数据保存到数据库中
        /// </summary>
        /// <param name="infoTab"></param>
        private void SaveDbTabDataToDB(DBInfoTab infoTab)
        {
            TreeViewIconsItem selectedItem = infoTab.treeView1.SelectedItem;
            DatabaseInfo      info         = infoTab.dbInfoObject;

            if (selectedItem != null)
            {
                info.LastVisitNodePath = selectedItem.Path;
                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.Show(ex.ToString()); }));
                    }
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 将指定选项卡的数据保存到数据库中
 /// </summary>
 /// <param name="infoTab"></param>
 private void SaveDbTabDataToDB(DBInfoTab infoTab)
 {
     TreeViewIconsItem selectedItem = infoTab.treeView1.SelectedItem;
     DatabaseInfo info = infoTab.dbInfoObject;
     if (selectedItem != null)
     {
         info.LastVisitNodePath = selectedItem.Path;
         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.Show(ex.ToString()); }));
             }
         }
     }
 }
Exemplo n.º 7
0
        private void PasteNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.treeView1.IsInEditMode)
            {
                curDbInfoTab.treeView1.SelectedItem.EndEdit();
            }
            if (cutNode == null || cutNodeSourceTab == null)
            {
                return;
            }
            TreeViewIconsItem selectedNode = curDbInfoTab.treeView1.SelectedItem as TreeViewIconsItem;
            if (selectedNode == cutNode)
            {
                return;
            }
            String newPath = "";

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

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

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

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

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

                //保存目标树结构
                curDbInfoTab.treeView1.SaveToDB();
                //将源树保存到数据库中
                cutNodeSourceTab.treeView1.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.treeView1.SelectedItem != null)
            {
                 curDbInfoTab.treeView1.SelectedItem.IsExpanded = true;
            }
        }
Exemplo n.º 8
0
        /// <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;
        }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
        private void DBtabContainer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //初始化时,此方法不做任何事,仅设置默认标题
            if (DBtabContainer.SelectedIndex == -1)
            {
                this.Title = MainWindowDefaultTitle;
                return;
            }
            //当TabControl的TabItem中放置有ComboBox控件时,ComboBox的SelectionChanged事件会触发
            //TabControl的SelectionChanged事件,虽然可以通过在下层控件的事件响应过程中添加
            //e.Handled = true阻止这一过程,但还是在此屏蔽掉此事件的响应代码,以免有漏网之鱼
            if (e.AddedItems.Count == 1 && e.AddedItems[0].GetType().Name != "TabItem")
            {
                return;
            }

            curDbInfoTab = (DBtabContainer.Items[DBtabContainer.SelectedIndex] as TabItem).Content as DBInfoTab;
            this.Title = "个人资料管理中心-" + curDbInfoTab.dbInfoObject.DatabaseFilePath;
            if (curDbInfoTab.HasBeenLoadedFromDB == false)
            {
                //从数据库中装入数据
                LoadCurrentTabDataFromDB();
            }
            else
            {
                String EFConnectString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);
                curDbInfoTab.treeView1.EFConnectionString = EFConnectString;
                findNodesWindow.SetTree(curDbInfoTab.treeView1);
                curDbInfoTab.RefreshDisplay();
            }
            //切换选项卡时,恢复状态栏默认显示文本
            if (cutNode == null)
            {
                ShowInfo("就绪");
            }
        }
Exemplo n.º 11
0
 private void CutNode(object sender, ExecutedRoutedEventArgs e)
 {
     if (curDbInfoTab.treeView1.IsInEditMode)
     {
         curDbInfoTab.treeView1.SelectedItem.EndEdit();
     }
     //如果己经有被剪切的节点,则取消它的下划线状态
     if (cutNode != null && cutNode != curDbInfoTab.treeView1.SelectedItem)
     {
         cutNode.Strikethrough = false;
     }
     cutNode = curDbInfoTab.treeView1.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);
 }
Exemplo n.º 12
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.Add(System.IO.Path.GetFileName(dbInfo.DatabaseFilePath), tab);
            DBtabContainer.SelectedIndex = DBtabContainer.Items.Count - 1;
            SystemConfig.configArgus.ActiveDBIndex = DBtabContainer.Items.Count - 1;

            curDbInfoTab = tab;
            //Note: 新加选项卡,会激发DBtabContainer的SelectedIndexChanged事件,在事件响应代码DBtabContainer_SelectionChanged()
            //中完成了从数据库中装载数据的工作,无需显示调用LoadCurrentTabDataFromDB();方法
        }
Exemplo n.º 13
0
        /// <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;
        }
Exemplo n.º 14
0
        private void PasteNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.treeView1.IsInEditMode)
            {
                curDbInfoTab.treeView1.SelectedItem.EndEdit();
            }
            if (cutNode == null || cutNodeSourceTab == null)
            {
                return;
            }
            TreeViewIconsItem selectedNode = curDbInfoTab.treeView1.SelectedItem as TreeViewIconsItem;

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

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

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

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

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


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

                //保存目标树结构
                curDbInfoTab.treeView1.SaveToDB();
                //将源树保存到数据库中
                cutNodeSourceTab.treeView1.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.treeView1.SelectedItem != null)
            {
                curDbInfoTab.treeView1.SelectedItem.IsExpanded = true;
            }
        }