You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.9 KiB

2 years ago
using formula_manage.UserClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2 years ago
using System.Text.RegularExpressions;
2 years ago
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SUNLIGHT_CDKEY
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
2 years ago
int d, y, m;
public MainWindow()
{
InitializeComponent();
2 years ago
T_Y.Text = DateTime.Now.ToString("yyyy");
T_M.Text = DateTime.Now.ToString("MM");
T_D.Text = DateTime.Now.ToString("dd");
}
private void AlphanumericValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex(@"[^a-eA-E0-9]+$");
e.Handled = regex.IsMatch(e.Text.ToUpper());
}
private void validation_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space) e.Handled = true;
}
2 years ago
private void Tb_KeyFloating_D(object sender, TextCompositionEventArgs e)//输入事件
{
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
2 years ago
d = int.Parse(T_D.Text);
if (d > 30)
{
T_D.Text = "30";
}
2 years ago
}
private void Tb_KeyFloating_Y(object sender, TextCompositionEventArgs e)//输入事件
{
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
2 years ago
y = int.Parse(T_Y.Text);
if (y > 2099)
{
T_Y.Text = "2099";
}
2 years ago
}
private void Tb_KeyFloating_M(object sender, TextCompositionEventArgs e)//输入事件
2 years ago
{
2 years ago
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
2 years ago
m = int.Parse(T_M.Text);
if (m > 12)
{
T_M.Text = "12";
}
}
private void DURATION_DropDownClosed(object sender, EventArgs e)
{
2 years ago
T_Y.Text = DateTime.Now.ToString("yyyy");
T_M.Text = DateTime.Now.ToString("MM");
T_D.Text = DateTime.Now.ToString("dd");
d = int.Parse(T_D.Text);
y = int.Parse(T_Y.Text);
m = int.Parse(T_M.Text);
if (DURATION.Text == "1")
{
2 years ago
m += 1;
}
else if (DURATION.Text == "2")
{
2 years ago
m += 2;
}
else if (DURATION.Text == "3")
{
2 years ago
m += 3;
}
else if (DURATION.Text == "6")
{
2 years ago
m += 6;
}
else if (DURATION.Text == "12")
{
2 years ago
y += 1;
}
else if (DURATION.Text == "FOREVER")
{
2 years ago
y = 2099;
2 years ago
m = 12;
d = 30;
2 years ago
}
if (m > 12)
{
m = m-12;
y += 1;
}
2 years ago
T_Y.Text=y.ToString();
T_M.Text=m.ToString();
T_D.Text=d.ToString();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
2 years ago
string a;
string b, my, mm, md;
2 years ago
d = int.Parse(T_D.Text);
y = int.Parse(T_Y.Text);
m = int.Parse(T_M.Text);
sn_id.Text = sn_id.Text.ToUpper();
if (sn_id.Text.Length < 6)//id字节长度大于6有效
2 years ago
{
sn_id.BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0));
2 years ago
return;
}
else
{
sn_id.BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));
}
2 years ago
a= sn_id.Text.Substring(5, 1)+ sn_id.Text.Substring(0, 1)+ sn_id.Text.Substring(4, 1) + sn_id.Text.Substring(1, 1) + sn_id.Text.Substring(3, 1)+ sn_id.Text.Substring(2, 1);
2 years ago
my = Convert.ToString(Convert.ToInt32(2255 - y), 16).ToUpper();
mm = Convert.ToString(Convert.ToInt32(255 - m), 16).ToUpper();
2 years ago
md = Convert.ToString(Convert.ToInt32(255 - d), 16).ToUpper();
2 years ago
b=my+mm+md;
2 years ago
2 years ago
cdk.Text = a + b + CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(a+b), true);
}
2 years ago
}
}