Beispiel #1
0
        private void AddCaseProc()
        {
            NewCase = new NewCaseModel();

            _AddCaseWindow       = new AddCaseWindow();
            _AddCaseWindow.Owner = Application.Current.MainWindow;
            _AddCaseWindow.ShowDialog();
        }
Beispiel #2
0
        /// <summary> 按钮点击事件 </summary>
        private void ButtonClickFunc(object obj)
        {
            string buttonName = obj as string;

            // Todo :增加案例
            if (buttonName == "AddCase")
            {
                AddCaseWindow addWindow = new AddCaseWindow();
                var           result    = addWindow.ShowDialog();

                if (result.HasValue && result.Value)
                {
                    CaseModel model = new CaseModel();
                    model.CaseName   = addWindow.ViewModel.CaseName;
                    model.CasePath   = addWindow.ViewModel.CasePath;
                    model.FolderPath = CaseNotifyService.LocalCaseFolder;
                    CaseNotifyService.Instance.CreateCase(model);
                    var c = new CaseViewModel(model);
                    this.CaseSource.Add(c);
                    this.CurrentCase = c;
                }
            }

            // Todo :打开案例
            else if (buttonName == "OpenCase")
            {
                if (_caseSource == null)
                {
                    return;
                }

                foreach (var item in CaseSource)
                {
                    item.IsOpen = false;
                }

                if (this.CurrentCase != null)
                {
                    this.CurrentCase.IsOpen = true;
                }

                if (_lastCase != null)
                {
                    // Todo :保存上一次案例
                    CaseNotifyService.Instance.OnSaveCase(_lastCase.Model);
                }

                // Todo :加载本次案例
                CaseNotifyService.Instance.OnCaseChanged(CurrentCase == null ? null : CurrentCase.Model);

                _lastCase = CurrentCase;
            }

            // Todo :删除案例
            else if (buttonName == "DeleteCase")
            {
                bool result = MessageWindow.ShowDialog("删除无法恢复,确定要删除?");

                if (!result)
                {
                    return;
                }

                if (CurrentCase == _lastCase)
                {
                    _lastCase = null;
                }

                CaseNotifyService.Instance.DeleteCase(CurrentCase.Model);

                this.CaseSource.Remove(CurrentCase);

                // Todo :默认打开第一个
                this.ButtonClickFunc("ShowDefault");
            }

            // Todo :重命名
            else if (buttonName == "ReNameCase")
            {
            }

            // Todo :保存案例
            else if (buttonName == "SaveCase")
            {
                this.SaveCase();
            }

            // Todo 整理文件
            else if (buttonName == "ClearOrder")
            {
                this.SaveCase();

                // Todo :整理到同级别
                CaseNotifyService.Instance.ClearOrder(CurrentCase.Model);

                this.ButtonClickFunc("OpenCase");
            }

            // Todo :重新加载
            else if (buttonName == "RefreshLoad")
            {
                this.SaveCase();

                // Todo :整理到同级别
                CaseNotifyService.Instance.RefreshLoad(CurrentCase.Model);

                this.ButtonClickFunc("OpenCase");
            }

            // Todo :显示默认
            else if (buttonName == "ShowDefault")
            {
                if (this.CaseSource == null || this.CaseSource.Count == 0)
                {
                    this.CurrentCase = null;
                }
                else
                {
                    // Todo :默认打开第一个
                    this.CurrentCase = this.CaseSource[0];
                }
            }

            // Todo :打开案例
            else if (buttonName == "OpenOutCase")
            {
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.Title = "请选择案例文件";

                string format = "案例文件(*{0}) | *{0}| 所有文件(*.*) | *.*";

                dialog.Filter = string.Format(format, CaseNotifyService.extend);

                var result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                string path = Path.GetDirectoryName(dialog.FileName);

                this.SaveCase();

                var caseModel = CaseNotifyService.Instance.LoadCase(path);

                CaseViewModel model = new CaseViewModel(caseModel);

                this.CaseSource.Add(model);

                this.CurrentCase = model;
            }

            // Todo :另存为
            else if (buttonName == "SaveOutCase")
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();

                var result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                string path = dialog.SelectedPath;

                this.SaveCase();

                CaseNotifyService.Instance.SaveOutLoad(CurrentCase.Model, path);
            }

            // Todo :移动路径
            else if (buttonName == "MoveFolder")
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();

                var result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                string path = dialog.SelectedPath;

                if (this.CurrentCase == null)
                {
                    return;
                }

                this.SaveCase();

                CaseNotifyService.Instance.MoveFolderLoad(CurrentCase.Model, path);

                this.RefreshCurrent(this.CurrentCase.Model);
            }

            // Todo :合并案例
            else if (buttonName == "MergeCase")
            {
                var models = this.CaseSource.Select(l => l.Model).ToList();

                models.Remove(this.CurrentCase.Model);

                if (models == null || models.Count == 0)
                {
                    return;
                }

                MergeCaseWindow merge = new MergeCaseWindow(models);

                var result = merge.ShowDialog();

                if (result == null || result.Value == false)
                {
                    return;
                }

                var selection = merge.SelectItems();

                if (selection == null || selection.Count == 0)
                {
                    return;
                }

                Predicate <List <CaseModel> > match = l =>
                {
                    foreach (var item in selection)
                    {
                        if (item.CasePath.Contains(this.CurrentCase.CasePath) || this.CurrentCase.CasePath.Contains(item.CasePath))
                        {
                            return(false);
                        }
                    }

                    return(true);
                };

                if (!match(selection))
                {
                    this.Message = "不满足合并要求,合并路径不能有父子关系!";
                    return;
                }

                this.SaveCase();

                CaseNotifyService.Instance.MergeCases(CurrentCase.Model, selection);

                this.RefreshCurrent(this.CurrentCase.Model);
            }

            // Todo :文件设置
            else if (buttonName == "FileSet")
            {
                SettingCaseWindow window = new SettingCaseWindow(ItemType.MatchFile);
                window.ShowDialog();

                this.ButtonClickFunc("OpenCase");
            }

            // Todo :类型设置
            else if (buttonName == "TypeSet")
            {
                SettingCaseWindow window = new SettingCaseWindow(ItemType.FileType);
                window.ShowDialog();

                this.ButtonClickFunc("OpenCase");
            }
        }