alielie
2026-09-10 9ec80cafc23f5ee3278cacce3c9f86f4087b435a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using CommunityToolkit.Mvvm.ComponentModel;
using OpenTap;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using UILib;
 
namespace OpenTapEditor
{
    /// <summary>
    /// ChildSeqPanel.xaml 的交互逻辑
    /// </summary>
    [ObservableObject]
    public partial class ChildSeqPanel : UserControl
    {
        public event EventHandler SequencePropertyChanged;
 
        public event EventHandler<TestStepList> selectedSequenceChanged;
        public event EventHandler<TestStepList> SelectedSequenceChanged
        {
            add
            {
                selectedSequenceChanged += value;
            }
 
            remove
            {
                selectedSequenceChanged -= value;
            }
        }
 
        [ObservableProperty]
        private ObservableCollection<TestStepList> sequences;
 
        [ObservableProperty]
        private TestStepList selectedSequence;
 
        private TestPlan plan;
 
        public void SetPlan(TestPlan plan)
        {
            this.plan = plan;
            Sequences = plan.Sequences;
            SelectedSequence = Sequences[0];
        }
 
        public ChildSeqPanel()
        {
            this.DataContext = this;
            InitializeComponent();
        }
 
        private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MenuItem item = (MenuItem)sender;
            if (item.Tag.ToString() == "添加")
            {
                Sequences.Add(new TestStepList { SequenceName = DateTime.Now.ToString("yyyyMMddHHmmssfff"), Parent = this.plan });
                SequencePropertyChanged?.Invoke(this, new EventArgs());
                return;
            }
            if (item.Tag.ToString() == "删除")
            {
                if (SelectedSequence.SequenceName == TestPlan.MAIN_SEQ_NAME)
                {
                    return;
                }
                Sequences.Remove(SelectedSequence);
                SequencePropertyChanged?.Invoke(this, new EventArgs());
                return;
            }
        }
 
        private bool SequenceNamePreSubmit(object sender, object value, object source)
        {
            if (Sequences.FirstOrDefault(s => s.SequenceName == value.ToString() && s != source) != null)
            {
                MessageBox.Show("名称不能重复");
                return false;
            }
            return true;
        }
 
        private void SequenceNameSubmited(EditBox box, object oldValue, object newValue)
        {
            SequencePropertyChanged?.Invoke(this, new EventArgs());
        }
 
        partial void OnSelectedSequenceChanged(TestStepList value)
        {
            selectedSequenceChanged?.Invoke(this, value);
        }
    }
}