12 changed files with 294 additions and 2 deletions
@ -0,0 +1,20 @@ |
|||
<Window x:Class="SunlightCentralizedControlManagement_SCCM_.WindowsView.CDKEY" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.WindowsView" |
|||
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" |
|||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" |
|||
mc:Ignorable="d" Loaded="Window_CDKEY" BorderBrush="White" Background="#FFEFEFEF" |
|||
Title="CDKEY" Height="190" Width="500" MaxHeight="190" MaxWidth="500" ResizeMode="NoResize"> |
|||
<Grid> |
|||
<TextBlock HorizontalAlignment="Left" Height="20" Margin="20,55,0,0" TextWrapping="Wrap" Text="CDKEY:" VerticalAlignment="Top" Width="70" FontSize="16"/> |
|||
<TextBlock HorizontalAlignment="Left" Height="20" Margin="20,25,0,0" Text="SN:" VerticalAlignment="Top" Width="70" FontSize="16"/> |
|||
<TextBox x:Name="sn_id" HorizontalAlignment="Left" Height="30" Margin="90,20,0,0" VerticalAlignment="Top" Width="360" Background="#FFE6E6E6" IsReadOnly="True" IsTabStop="False" Focusable="False"/> |
|||
<TextBox x:Name="cdk" HorizontalAlignment="Left" Height="30" Margin="90,55,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="360"/> |
|||
<Button Content="OK" HorizontalAlignment="Right" Height="30" Margin="0,90,50,0" VerticalAlignment="Top" Width="85" Background="#7F673AB7" Click="Button_Click_2"/> |
|||
<TextBox x:Name="sn_time" HorizontalAlignment="Left" Height="30" Margin="90,90,0,0" VerticalAlignment="Top" Width="250" Background="{x:Null}" IsReadOnly="True" IsTabStop="False" Focusable="False" BorderBrush="{x:Null}"/> |
|||
|
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,149 @@ |
|||
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); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue