Repository navigation
Expand file tree
/
Copy pathProfileManagementWindow.xaml.cs
More file actions
157 lines (136 loc) · 5.96 KB
/
Copy pathProfileManagementWindow.xaml.cs
File metadata and controls
157 lines (136 loc) · 5.96 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace WpfApp1
{
/// <summary>
/// ProfileManagementWindow.xaml 的交互逻辑
/// </summary>
public partial class ProfileManagementWindow : Window
{
public ObservableCollection<BroadcastProfile> Profiles { get; private set; }
public BroadcastProfile SelectedProfile { get; private set; }
public ProfileManagementWindow(ObservableCollection<BroadcastProfile> profiles)
{
InitializeComponent();
// 使用传入的方案集合
Profiles = profiles;
ProfilesListView.ItemsSource = Profiles;
// 选择当前活动的方案
var activeProfile = Profiles.FirstOrDefault(p => p.IsActive);
if (activeProfile != null)
{
ProfilesListView.SelectedItem = activeProfile;
}
else if (Profiles.Count > 0)
{
ProfilesListView.SelectedItem = Profiles[0];
}
}
private void NewProfileButton_Click(object sender, RoutedEventArgs e)
{
// 弹出输入框获取新方案名称
var inputDialog = new InputDialog("新建方案", "请输入方案名称:", "新方案");
if (inputDialog.ShowDialog() == true)
{
string profileName = inputDialog.Answer;
// 检查名称是否已存在
if (Profiles.Any(p => p.Name == profileName))
{
MessageBox.Show("方案名称已存在,请使用其他名称。", "命名冲突", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 创建新方案
var newProfile = BroadcastProfile.CreateDefault(profileName);
Profiles.Add(newProfile);
ProfilesListView.SelectedItem = newProfile;
}
}
private void RenameProfileButton_Click(object sender, RoutedEventArgs e)
{
var selectedProfile = ProfilesListView.SelectedItem as BroadcastProfile;
if (selectedProfile == null)
{
MessageBox.Show("请先选择一个方案。", "未选择方案", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 弹出输入框获取新名称
var inputDialog = new InputDialog("重命名方案", "请输入新的方案名称:", selectedProfile.Name);
if (inputDialog.ShowDialog() == true)
{
string newName = inputDialog.Answer;
// 检查名称是否已存在
if (Profiles.Any(p => p.Name == newName && p != selectedProfile))
{
MessageBox.Show("方案名称已存在,请使用其他名称。", "命名冲突", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 更新方案名称
selectedProfile.Name = newName;
}
}
private void DeleteProfileButton_Click(object sender, RoutedEventArgs e)
{
var selectedProfile = ProfilesListView.SelectedItem as BroadcastProfile;
if (selectedProfile == null)
{
MessageBox.Show("请先选择一个方案。", "未选择方案", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 不允许删除最后一个方案
if (Profiles.Count <= 1)
{
MessageBox.Show("不能删除唯一的方案。", "操作取消", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 确认删除
var result = MessageBox.Show($"确定要删除方案 \"{selectedProfile.Name}\" 吗?", "确认删除",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
// 如果删除的是当前激活的方案,激活其他方案
if (selectedProfile.IsActive && Profiles.Count > 1)
{
var nextProfile = Profiles.FirstOrDefault(p => p != selectedProfile);
if (nextProfile != null)
{
nextProfile.IsActive = true;
}
}
// 删除方案
Profiles.Remove(selectedProfile);
}
}
private void ActivateProfileButton_Click(object sender, RoutedEventArgs e)
{
var selectedProfile = ProfilesListView.SelectedItem as BroadcastProfile;
if (selectedProfile == null)
{
MessageBox.Show("请先选择一个方案。", "未选择方案", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 如果选择的方案已经是活动的,则不需要操作
if (selectedProfile.IsActive)
{
MessageBox.Show($"方案 \"{selectedProfile.Name}\" 已经是当前活动方案。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 确认激活
var result = MessageBox.Show($"确定要激活方案 \"{selectedProfile.Name}\" 吗?这将使用该方案的广播设置。", "确认激活",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
// 设置选中的方案为活动,并关闭窗口
foreach (var profile in Profiles)
{
profile.IsActive = (profile == selectedProfile);
}
SelectedProfile = selectedProfile;
DialogResult = true;
}
}
}
}