MainWindow.xaml.cs
3.06 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
using HHECS.Application.Licenses;
using HHECS.Infrastructure.CommonHelper;
using Newtonsoft.Json;
using System;
using System.Windows;
namespace HHECS.LicenseTools
{
public partial class MainWindow
{
public string MK { get; set; } = "areyouok";
readonly LicenseModel licenseModel = new();
public MainWindow()
{
InitializeComponent();
Init();
this.DataContext = licenseModel;
}
private void Init()
{
var dict = EnumHelper.EnumListDic<LicenseType>();
cbx_Role.ItemsSource = dict;
cbx_Role.DisplayMemberPath = "Key";
cbx_Role.SelectedValuePath = "Value";
cbx_Role.SelectedIndex = 0;
dt_ExpireTime.SelectedDateTime = DateTime.Now.AddYears(1);
}
private void btn_ClearData_Click(object sender, System.Windows.RoutedEventArgs e)
{
txt_MachineCode.Text = "";
txt_Custom.Text = "";
cbx_Role.SelectedIndex = 0;
dt_ExpireTime.SelectedDateTime = DateTime.Now.AddYears(1);
}
private void btn_ClearLicense_Click(object sender, RoutedEventArgs e)
{
txt_License.Text = "";
}
private void BtnCreate_Click(object sender, System.Windows.RoutedEventArgs e)
{
licenseModel.LastUseTime = DateTime.Now;
licenseModel.ExpireTime = (DateTime)dt_ExpireTime.SelectedDateTime;
licenseModel.CustomMachineCode = txt_MachineCode.Text;
switch ((int)cbx_Role.SelectedValue)
{
case 0: licenseModel.CustomRole = LicenseType.Trial; break;
case 1: licenseModel.CustomRole = LicenseType.Free; break;
default: licenseModel.CustomRole = LicenseType.Trial; break;
}
licenseModel.CustomName = txt_Custom.Text;
var result = EncodeHelper.AES(JsonConvert.SerializeObject(licenseModel), "areyouok");
if (string.IsNullOrWhiteSpace(result))
{
MessageBox.Show($"生成失败");
return;
}
txt_License.Text = result;
}
private void btn_Check_Click(object sender, RoutedEventArgs e)
{
var result = EncodeHelper.AESDecrypt(txt_License.Text, "areyouok");
if (string.IsNullOrWhiteSpace(result))
{
MessageBox.Show($"验证失败:{result}");
return;
}
LicenseModel model = JsonConvert.DeserializeObject<LicenseModel>(result);
txt_MachineCode.Text = model.CustomMachineCode;
txt_Custom.Text = model.CustomName;
cbx_Role.SelectedValue = model.CustomRole.GetIndexInt();
dt_ExpireTime.SelectedDateTime = model.ExpireTime;
}
private void btn_Get_Click(object sender, RoutedEventArgs e)
{
try
{
Clipboard.SetDataObject(txt_License.Text);
}
catch (Exception)
{
}
}
}
}