diff --git a/MainWindow.xaml b/MainWindow.xaml index 5460b33..661d58b 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -215,5 +215,10 @@ + + + + + diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 57763fc..f7534db 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -1,4 +1,5 @@ using formula_manage.SQLModels; +using formula_manage.UserClass; using formula_manage.ViewModel; using formula_manage.Windows; using GalaSoft.MvvmLight; @@ -14,6 +15,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Forms; using System.Windows.Threading; using System.Xml.Linq; @@ -61,6 +63,42 @@ namespace formula_manage.ViewModel string TEXT_SQLUSER; string TEXT_SQLPASWOR; string Connstr_SC; + string SN_ID; + string SN_KEY; + + private void CDkey_() + { + string id_1 = SN_ID.Substring(5, 1) + SN_ID.Substring(0, 1) + SN_ID.Substring(4, 1) + SN_ID.Substring(1, 1) + SN_ID.Substring(3, 1) + SN_ID.Substring(2, 1); + if ((id_1 == SN_KEY.Substring(0, 6)) && (SN_KEY.Length == 16)) + { + if (CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(SN_KEY.Substring(0, 12)), true) == SN_KEY.Substring(12, 4)) //校验key的crc校验值 + { + string Y = (2255 - StrToInt.To16Convert10(SN_KEY.Substring(6, 2))).ToString(); + string M = (255 - StrToInt.To16Convert10(SN_KEY.Substring(8, 2))).ToString(); + string D = (255 - StrToInt.To16Convert10(SN_KEY.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) + { + CDKEY cDKEY = new CDKEY(); + cDKEY.ShowDialog();//实例化并置顶打开窗口 + } + else if (string.Compare(M, MM) < 0) + { + CDKEY cDKEY = new CDKEY(); + cDKEY.ShowDialog();//实例化并置顶打开窗口 + } + else if (string.Compare(D, DD) < 0) + { + CDKEY cDKEY = new CDKEY(); + cDKEY.ShowDialog();//实例化并置顶打开窗口 + } + } + } + } private async void Sql_() { @@ -70,6 +108,9 @@ namespace formula_manage.ViewModel TEXT_SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3"); TEXT_SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4"); TEXT_SQLPASWOR = Configini.IniReadvalue("SQL_SERVER", "SQL5"); + SN_ID = Configini.IniReadvalue("SN", "SN2"); + SN_KEY = Configini.IniReadvalue("SN", "SN1"); + if (TEXT_SQMOD == "0") //判断连接方式 { Connstr_SC = "server=" + TEXT_SQLIP + ";database=" + TEXT_SQLNAME + ";Trusted_Connection=SSPI"; @@ -173,22 +214,33 @@ namespace formula_manage.ViewModel /// public void CountDown() { - DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick { - Interval = TimeSpan.FromSeconds(0.5) + Interval = TimeSpan.FromSeconds(1) }; - timer.Tick += Tick_Event; - timer.Start(); + timer1s.Tick += Tick_Event_1S; + timer1s.Start(); + DispatcherTimer timer1h = new DispatcherTimer//初始化循环,每1h调用一次Tick + { + Interval = TimeSpan.FromSeconds(3600) + }; + timer1h.Tick += Tick_Event_1h; + timer1h.Start(); //设置定时器 // disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法 // disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。 // disTimer.Start();//计时开始 } - void Tick_Event(object sender, EventArgs e)//Tick_Event周期执行事件 + void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件 { Sys_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } + void Tick_Event_1h(object sender, EventArgs e)//Tick_Event周期执行事件 + { + CDkey_(); + + } } public class Product //stuff_Product diff --git a/Windows/CDKEY.xaml.cs b/Windows/CDKEY.xaml.cs index b2d4efc..7b53c66 100644 --- a/Windows/CDKEY.xaml.cs +++ b/Windows/CDKEY.xaml.cs @@ -40,6 +40,14 @@ namespace formula_manage.Windows private void Window_CDKEY(object sender, RoutedEventArgs e) //打开页面 { + UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);//生效配置读取 + cdk.Text = Configini.IniReadvalue("SN", "SN1"); //读配置文件 + + 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(); + sn_time.Text = "CDkeyDueTime: " + Y + "-" + M + "-" + D; + // 获取CPU序列号 cpuSerialNumber = HardwareSN.GetCPUSerialNumber(); // 获取主板序列号 @@ -57,7 +65,7 @@ namespace formula_manage.Windows 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 (id_1 == cdk.Text.Substring(0, 6)) + if ((id_1 == cdk.Text.Substring(0, 6)) && (cdk.Text.Length == 16)) { if (CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(cdk.Text.Substring(0, 12)), true) == cdk.Text.Substring(12, 4)) //校验key的crc校验值 { @@ -75,16 +83,16 @@ namespace formula_manage.Windows { if (string.Compare(D, DD) >= 0) { - System.Windows.MessageBox.Show("CDKEY:OK"); + System.Windows.MessageBox.Show("CDKEY: OK","KEY",MessageBoxButton.OK,MessageBoxImage.Asterisk); sn_time.Text = "CDkeyDueTime: " + 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) + else if (string.Compare(M, MM) > 0) { - System.Windows.MessageBox.Show("CDKEY:OK"); + System.Windows.MessageBox.Show("CDKEY: OK", "KEY", MessageBoxButton.OK, MessageBoxImage.Asterisk); sn_time.Text = "CDkeyDueTime: " + Y + "-" + M + "-" + D; UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath); @@ -93,17 +101,17 @@ namespace formula_manage.Windows } else { - System.Windows.MessageBox.Show("CDKEY:overdue"); + System.Windows.MessageBox.Show("CDKEY: Overdue", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { - System.Windows.MessageBox.Show("CDKEY:overdue"); + System.Windows.MessageBox.Show("CDKEY: Overdue", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } else if (string.Compare(Y, YY) > 0) { - System.Windows.MessageBox.Show("CDKEY:OK"); + System.Windows.MessageBox.Show("CDKEY: OK", "KEY", MessageBoxButton.OK, MessageBoxImage.Asterisk); sn_time.Text = "CDkeyDueTime: " + Y + "-" + M + "-" + D; UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath); @@ -112,9 +120,17 @@ namespace formula_manage.Windows } else { - System.Windows.MessageBox.Show("CDKEY:overdue"); - } + System.Windows.MessageBox.Show("CDKEY: Overdue","WARNING",MessageBoxButton.OK,MessageBoxImage.Warning); + } } + else + { + System.Windows.MessageBox.Show("CDKEY: Linvalid", "ERR", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + else + { + System.Windows.MessageBox.Show("CDKEY: Linvalid","ERR" , MessageBoxButton.OK,MessageBoxImage.Error); } }