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.
149 lines
7.2 KiB
149 lines
7.2 KiB
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Windows;
|
|
|
|
|
|
namespace SunlightCentralizedControlManagement_SCCM_.WindowsView
|
|
{
|
|
/// <summary>
|
|
/// CDKEY.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class CDKEY : Window
|
|
{
|
|
public CDKEY()
|
|
{
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
InitializeComponent();
|
|
}
|
|
|
|
string cpuSerialNumber;
|
|
string biosSerialNumber;
|
|
|
|
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini";
|
|
|
|
private void Window_CDKEY(object sender, RoutedEventArgs e) //打开页面
|
|
{
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取
|
|
string cdk = Configini.IniReadvalue("SN", "SN1"); //读配置文件
|
|
|
|
if (cdk.Length == 16)
|
|
{
|
|
if (CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(cdk.Substring(0, 12)), true) == cdk.Substring(12, 4)) //校验key的crc校验值
|
|
{
|
|
try
|
|
{
|
|
string Y = (2255 - StrToInt.To16Convert10(cdk.Substring(6, 2))).ToString();
|
|
string M = (255 - StrToInt.To16Convert10(cdk.Substring(8, 2))).ToString();
|
|
string D = (255 - StrToInt.To16Convert10(cdk.Substring(10, 2))).ToString();
|
|
sn_time.Text = Properties.Resources.Validtime+ ": " + Y + "-" + M + "-" + D;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
sn_time.Text = Properties.Resources.Validtime + ": --------";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sn_time.Text = Properties.Resources.Validtime + ": --------";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sn_time.Text = Properties.Resources.Validtime + ": --------";
|
|
}
|
|
|
|
// 获取CPU序列号
|
|
cpuSerialNumber = HardwareSN.GetCPUSerialNumber();
|
|
// 获取主板序列号
|
|
biosSerialNumber = HardwareSN.GetBIOSSerialNumber();
|
|
// 获取硬盘序列号
|
|
//string hardDiskSerialNumber = HardwareSN.GetHardDiskSerialNumber();
|
|
// 获取网卡地址
|
|
//string netCardMACAddress = HardwareSN.GetNetCardMACAddress();
|
|
sn_id.Text = MD5check.MD5Encrypt16(cpuSerialNumber + biosSerialNumber);//生成id基于硬件值的md5校验
|
|
|
|
}
|
|
|
|
private void Button_Click_2(object sender, RoutedEventArgs e) //cdk确认按钮
|
|
{
|
|
string id_1;
|
|
id_1 = 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);
|
|
|
|
if (cdk.Text.Length != 16)
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY: 无效注册码", "ERR", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
return;
|
|
}
|
|
|
|
if (id_1 == cdk.Text.Substring(0, 6))
|
|
{
|
|
if (CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(cdk.Text.Substring(0, 12)), true) == cdk.Text.Substring(12, 4)) //校验key的crc校验值
|
|
{
|
|
string Y = (2255 - StrToInt.To16Convert10(cdk.Text.Substring(6, 2))).ToString();
|
|
string M = (255 - StrToInt.To16Convert10(cdk.Text.Substring(8, 2))).ToString();
|
|
string D = (255 - StrToInt.To16Convert10(cdk.Text.Substring(10, 2))).ToString();
|
|
|
|
string YY = DateTime.Now.ToString("yyyy");
|
|
string MM = DateTime.Now.ToString("MM");
|
|
string DD = DateTime.Now.ToString("dd");
|
|
|
|
if (string.Compare(Y, YY) == 0)
|
|
{
|
|
if (string.Compare(M, MM) == 0)
|
|
{
|
|
if (string.Compare(D, DD) >= 0)
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY: "+Properties.Resources.RIS, "KEY", MessageBoxButton.OK, MessageBoxImage.Asterisk);
|
|
sn_time.Text = Properties.Resources.Validtime + ": " + Y + "-" + M + "-" + D;
|
|
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
|
Configini.IniWritevalue("SN", " SN1", cdk.Text);
|
|
Configini.IniWritevalue("SN", " SN2", MD5check.MD5Encrypt16(cpuSerialNumber + biosSerialNumber));
|
|
}
|
|
else if (string.Compare(M, MM) > 0)
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY: " + Properties.Resources.RIS, "KEY", MessageBoxButton.OK, MessageBoxImage.Asterisk);
|
|
sn_time.Text = Properties.Resources.Validtime + ": " + Y + "-" + M + "-" + D;
|
|
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
|
Configini.IniWritevalue("SN", " SN1", cdk.Text);
|
|
Configini.IniWritevalue("SN", " SN2", MD5check.MD5Encrypt16(cpuSerialNumber + biosSerialNumber));
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:" + Properties.Resources.TRCE, "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:" + Properties.Resources.TRCE, "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
}
|
|
else if (string.Compare(Y, YY) > 0)
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:"+Properties.Resources.RIS, "KEY", MessageBoxButton.OK, MessageBoxImage.Asterisk);
|
|
sn_time.Text = Properties.Resources.Validtime + ": " + Y + "-" + M + "-" + D;
|
|
|
|
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
|
Configini.IniWritevalue("SN", " SN1", cdk.Text);
|
|
Configini.IniWritevalue("SN", " SN2", MD5check.MD5Encrypt16(cpuSerialNumber + biosSerialNumber));
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:" + Properties.Resources.TRCE, "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:" + Properties.Resources.void_, "ERR", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("CDKEY:" + Properties.Resources.void_, "ERR", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|