Beispiel #1
0
        /// <summary>
        /// 更换数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChangeDB(object sender, ExecutedRoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            openFileDialog.RestoreDirectory = true;

            openFileDialog.Filter = "sqlserver ce 4.0数据库(*.sdf)|*.sdf";
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                String DBFileName      = openFileDialog.FileName;
                bool   IsDBAlreadyOpen = false;
                foreach (var item in DBtabContainer.Items)
                {
                    if (((item as TabItem).Content as DBInfoTab).dbInfoObject.DatabaseFilePath == DBFileName)
                    {
                        IsDBAlreadyOpen = true;
                        break;
                    }
                }


                if (IsDBAlreadyOpen)
                {
                    MessageBox.ShowInformation("此资料库己被打开");
                    return;
                }
                AddNewDbInfoTabAndLoadData(DBFileName);
            }
        }
        /// <summary>
        /// 添加文件
        /// </summary>
        private void AddFiles()
        {
            WinForm.OpenFileDialog openFileDialog = new WinForm.OpenFileDialog();
            openFileDialog.Multiselect = true;
            String info = "";

            if (openFileDialog.ShowDialog() == WinForm.DialogResult.OK)
            {
                foreach (var FileName in openFileDialog.FileNames)
                {
                    FileInfo fi = new FileInfo(FileName);
                    if (fi.Length > 5 * 1024 * 1024)
                    {
                        MessageBoxResult result = MessageBox.Show("要加入的文件:“" + System.IO.Path.GetFileName(FileName) + "”大小为:" + FileUtils.FileSizeFormater(fi.Length) + ",将大文件加入数据库会导致程序性能下降,点击“是”添加此文件,点击“否”跳过此文件", "加入大文件", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                        if (result == MessageBoxResult.No)
                        {
                            continue;
                        }
                    }


                    DBFileInfo fileInfo = new DBFileInfo()
                    {
                        AddTime  = DateTime.Now,
                        FilePath = FileName,
                        FileSize = fi.Length
                    };
                    //不加入重复的文件
                    if (_dataObject.AttachFiles.IndexOf(fileInfo) != -1)
                    {
                        continue;
                    }
                    //当加入文件时,有可能因为另一进程也使用此文件而导致加载失败
                    try
                    {
                        accessObj.AddFile(_dataObject.Path, fileInfo, System.IO.File.ReadAllBytes(FileName));
                        _dataObject.AttachFiles.Add(fileInfo);
                        info = string.Format("正在加入文件{0}", System.IO.Path.GetFileName(FileName));

                        if (_dataObject.MainWindow != null)
                        {
                            _dataObject.MainWindow.ShowInfo(info);
                        }
                    }

                    catch (IOException ex)
                    {
                        MessageBox.ShowInformation(ex.Message);
                    }
                    if (_dataObject.MainWindow != null)
                    {
                        _dataObject.MainWindow.ShowInfo("文件添加完毕");
                    }
                }
            }

            RaiseFileCountChangedEvent();
        }
Beispiel #3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.MessageBoxWindow = ((WPFMessageBoxView.MessageBox)(target));

            #line 9 "..\..\MessageBox.xaml"
                this.MessageBoxWindow.Closing += new System.ComponentModel.CancelEventHandler(this.MessageBoxWindow_Closing);

            #line default
            #line hidden

            #line 10 "..\..\MessageBox.xaml"
                this.MessageBoxWindow.Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded);

            #line default
            #line hidden

            #line 11 "..\..\MessageBox.xaml"
                this.MessageBoxWindow.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Window_MouseDown);

            #line default
            #line hidden
                return;

            case 2:
                this.Scale = ((System.Windows.Media.ScaleTransform)(target));
                return;

            case 3:
                this.DetailsExpander = ((System.Windows.Controls.Expander)(target));
                return;

            case 4:
                this.DetailsText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 5:
                this.ButtonsPanel = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 6:
                this.ImagePlaceholder = ((System.Windows.Controls.Image)(target));
                return;

            case 7:
                this.MessageLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.MessageText = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #4
0
        private void CopyDB(object sender, ExecutedRoutedEventArgs e)
        {
            String currentDir         = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            String DBTemplateFileName = "";

            if (File.Exists(currentDir + "\\MyDB.sdf"))
            {
                DBTemplateFileName = currentDir + "\\MyDB.sdf";
            }
            else
            {
                if (File.Exists(currentDir + "\\template\\MyDB.sdf"))
                {
                    DBTemplateFileName = currentDir + "\\template\\MyDB.sdf";
                }
                else
                {
                    MessageBox.ShowInformation("数据库模板文件:templateDB.sdf未找到");
                    return;
                }
            }


            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.Title            = "创建新资料库";
            DateTime now            = DateTime.Now;
            String   fileDateString = now.Year + "_" + now.Month + "_" + now.Day + "_" + now.Hour + "_" + now.Minute;

            saveFileDialog.FileName   = "MyDB_" + fileDateString + ".sdf";
            saveFileDialog.Filter     = "sqlserver ce 4.0数据库(*.sdf)|*.sdf";
            saveFileDialog.DefaultExt = "sdf";

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bool IsDBAlreadyOpen = false;
                foreach (var item in DBtabContainer.Items)
                {
                    if (((item as TabItem).Content as DBInfoTab).dbInfoObject.DatabaseFilePath == saveFileDialog.FileName)
                    {
                        IsDBAlreadyOpen = true;
                        break;
                    }
                }
                if (IsDBAlreadyOpen)
                {
                    MessageBox.ShowInformation("不能选择正在使用的资料库文件名");
                    return;
                }
                //复制数据库
                File.Copy(DBTemplateFileName, saveFileDialog.FileName, true);
                AddNewDbInfoTabAndLoadData(saveFileDialog.FileName);
            }
        }
Beispiel #5
0
        private void DeleteNode(object sender, ExecutedRoutedEventArgs e)
        {
            if (curDbInfoTab.CurrentTreeView.IsInEditMode)
            {
                curDbInfoTab.CurrentTreeView.SelectedItem.EndEdit();
            }



            //删除多级节点时询问用户
            TreeViewIconsItem selectedNode = curDbInfoTab.CurrentTreeView.SelectedItem as TreeViewIconsItem;

            if (selectedNode != null && curDbInfoTab.CurrentTreeView.GetChildren(selectedNode).Count > 0)
            {
                MessageBoxResult result = MessageBox.Show("您将要删除一个包含有下级信息的节点,删除操作不可恢复,真的进行吗?", "删除节点", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }


            curDbInfoTab.CurrentTreeView.DeleteNode(selectedNode);
            //保存树结构
            curDbInfoTab.SaveTreeToDB();

            //此时可能出现一个WPF中的bug,当删除树窗口中最后一个节点时,会导致树窗口内部卡死,添加的节点实际存在但无法显示在树窗口中,于是在此处重新添加视图,以避开此bug
            if (curDbInfoTab.CurrentTreeView.Nodes.Count == 0)
            {
                //findNodesWindow.ShouldExit = true;
                //Close();
                //Process.Start(Assembly.GetEntryAssembly().Location);
                if (curDbInfoTab.CurrentTreeView.TreeNodeType == "InfoNode")
                {
                    curDbInfoTab.OutLineViewObj = new OutLineView(curDbInfoTab);
                    curDbInfoTab.OutLineViewObj.SuperTree.EFConnectionString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);
                    curDbInfoTab.InnerTabControl.SelectedIndex = 1;
                    curDbInfoTab.InnerTabControl.SelectedIndex = 0;
                }
                if (curDbInfoTab.CurrentTreeView.TreeNodeType == "LabelNode")
                {
                    curDbInfoTab.LabelViewObj = new LabelView(curDbInfoTab);
                    curDbInfoTab.LabelViewObj.SuperTree.EFConnectionString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath);

                    curDbInfoTab.InnerTabControl.SelectedIndex = 0;
                    curDbInfoTab.InnerTabControl.SelectedIndex = 1;
                }
            }
        }
        /// <summary>
        /// 失去焦点时,更新数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void richTextBox1_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            UpdateDataObjectInMemory();

            Thread thread = new Thread(() =>
            {
                try
                {
                    accessObj.UpdateDataInfoObject(_dataObject);
                }
                catch (Exception ex)
                {
                    Dispatcher.Invoke(new Action(() => { MessageBox.ShowInformation(ex.ToString()); }));
                }
            });

            thread.Start();
        }
        /// <summary>
        ///  刷新数据库中的内容
        /// </summary>
        private void UpdateDb()
        {
            UpdateDataObjectInMemory();
            Task task = new Task(() =>
            {
                try
                {
                    accessObj.UpdateDataInfoObject(_dataObject);

                    Dispatcher.Invoke(new Action(() => { MessageBox.ShowInformation("数据己保存"); }));
                }
                catch (Exception ex)
                {
                    Dispatcher.Invoke(new Action(() => { MessageBox.ShowInformation(ex.ToString()); }));
                }
            });

            task.Start();
        }
Beispiel #8
0
        private void ShowConfigWin(object sender, ExecutedRoutedEventArgs e)
        {
            ConfigWin win    = new ConfigWin();
            bool?     result = win.ShowDialog();

            if (curDbInfoTab.CurrentTreeView.IsInEditMode)
            {
                curDbInfoTab.CurrentTreeView.SelectedItem.EndEdit();
            }
            if (result.Value && SystemConfig.configArgus.IsArgumentsValueChanged)
            {
                DeepSerializer.BinarySerialize(SystemConfig.configArgus, SystemConfig.ConfigFileName);

                MessageBox.Show("参数修改,请重新启动程序", "重启");

                findNodesWindow.ShouldExit = true;
                Close();
                Process.Start(Assembly.GetEntryAssembly().Location);
            }
        }
Beispiel #9
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()); }));
                    }
                }
            }
        }
Beispiel #10
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;
            }
        }