private void Button_ImportLicense_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog open = new Microsoft.Win32.OpenFileDialog(); open.Title = "请选择要导入的License文件"; open.Filter = "石蚁License文件|*.key"; open.RestoreDirectory = true; if ((bool)open.ShowDialog().GetValueOrDefault()) { LicenseFile = open.FileName; StoneAnt.License.Model.LicenseModel m = new StoneAnt.License.Model.LicenseModel(); if (new StoneAnt.License.Verify.Term().VerfyLicense(LicenseFile, out m)) { if (DateTime.Now.Subtract(m.CreationDate).Days > 7 || DateTime.Now.Subtract(m.CreationDate).Days < 0) { MessageBox.Show("许可有误或已过期,请联系开发商", "错误"); } else { Helper.DataDefinition.CommonParameters.LicenseModel = m; new Helper.License.FillLicense().CalculatePeriodOfValidity(); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "License.key")) { File.Copy(AppDomain.CurrentDomain.BaseDirectory + "License.key", AppDomain.CurrentDomain.BaseDirectory + "License.key.bak", true); } try { File.Copy(LicenseFile, AppDomain.CurrentDomain.BaseDirectory + "License.key", true); } catch (Exception) { MessageBox.Show("注册失败,请勿重复注册", "错误"); return; } AuthorizeLabel(); if (new ViewModel.Security.LicenseConsole().RegisterInDB(m.Key)) { new Helper.License.PCRegister().Register(); MessageBox.Show("许可验证成功,感谢支持石蚁软件\n重启软件后生效", "通知"); } else { MessageBox.Show("注册失败,请联系开发商", "错误"); } } } else { MessageBox.Show("许可有误或已过期,请联系开发商", "错误"); } } }
public void CheckLicense(string LicenseFile) { string KeyInDB = ""; Helper.DataDefinition.CommonParameters.LicenseModel = new StoneAnt.License.Model.LicenseModel(); if (new ViewModel.Security.LicenseConsole().ReadKeyFromDB(out KeyInDB)) { if (KeyInDB != "") //数据库存在key { if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "License.key")) //存在license文件 { StoneAnt.License.Model.LicenseModel m = new StoneAnt.License.Model.LicenseModel(); if (new StoneAnt.License.Verify.Term().VerfyLicense(LicenseFile, out m)) //验证License文件 { if (KeyInDB == m.Key) //验证License文件与数据库Key { if (new PCRegister().CheckRegistrationInformation()) //验证系统信息 { Helper.DataDefinition.CommonParameters.LicenseModel = m; CalculatePeriodOfValidity(); return; } else//许可匹配,电脑不匹配 { Helper.DataDefinition.CommonParameters.IsLockApp = true; System.Windows.MessageBox.Show("感谢使用石蚁科技ERP产品,请支持正版。\n请使用管理员帐号登陆并导入许可文件以继续使用。", "代码:004"); } } else//许可与DB数据不匹配 { System.Windows.MessageBox.Show("许可有误,请联系开发商,错误代码:003", "错误"); } } else//许可验证不通过 { System.Windows.MessageBox.Show("许可损坏,请联系开发商,错误代码:002", "错误"); } } else//找不到许可文件 { System.Windows.MessageBox.Show("许可丢失,请联系开发商,错误代码:001", "错误"); } } } Helper.DataDefinition.CommonParameters.IsLockAdminLogin = true; Helper.DataDefinition.CommonParameters.PeriodOfValidity = -1; }