PrivacyInfoVM.cs
1.72 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
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Configuration;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.DAQClient.ViewModel
{
public partial class PrivacyInfoVM : ObservableObject
{
public Window Owner { get; set; }
[ObservableProperty]
private bool isEnable = false;
[ObservableProperty]
private string btnContent;
/// <summary>
/// 超时时间(秒)
/// </summary>
private readonly int Seconds = 30;
[RelayCommand]
public void OK()
{
try
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["PrivacyInfoStatus"].Value = bool.TrueString;
config.Save();
ConfigurationManager.RefreshSection("appSettings"); //刷新
Owner.DialogResult = true;
}
catch (Exception ex)
{
MessageBox.Error($"操作失败:{ex.Message}");
}
}
[RelayCommand]
public void Cancel()
{
Owner.Close();
}
public void Reload()
{
Application.Current.Dispatcher.InvokeAsync(async () =>
{
IsEnable = false;
for (int i = 0; i < Seconds; i++)
{
var index = Seconds - i;
BtnContent = $"同意({index}S)";
await Task.Delay(1000);
}
BtnContent = "同意";
IsEnable = true;
});
}
}
}