private void simpleButton_Register_Click(object sender, System.EventArgs e) { #if SoftwareRegister SoftwareRegisterForm softwareRegisterForm = new SoftwareRegisterForm(); softwareRegisterForm.StartPosition = FormStartPosition.CenterScreen; softwareRegisterForm.ShowDialog(); string getSn = SoftwareRegisterForm.GetSn; DataProtector dp = new DataProtector(DataProtector.Store.USE_MACHINE_STORE); try { byte[] dataToDecrypt = Convert.FromBase64String(getSn); byte[] key = Encoding.ASCII.GetBytes(DataProtector.SetRegisterKeyString()); string getRetrivedSn = Encoding.ASCII.GetString(dp.RegisterSnDecrypt(dataToDecrypt,key)); string getInitSn = new DataProtector().InitInfoDecryp(getRetrivedSn); string getRetrivedProvince = getInitSn.Substring(0,getInitSn.IndexOf(",",0)); string getRetrivedUser = getInitSn.Substring(getInitSn.IndexOf("#",0)+1,getInitSn.IndexOf("@",0)-getInitSn.IndexOf("#",0)-1); if ( getRetrivedProvince.Equals(CPTT.SystemFramework.Util.PROVINCE_INFO) ) { try { RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software",true); RegistryKey winSysDataKey = softwareKey.CreateSubKey("WindowsDataSystem"); RegistryKey ctppKey = winSysDataKey.CreateSubKey("Corporation"); if ( getRetrivedUser.Equals(CPTT.SystemFramework.Util.IS_AGENT_INFO) ) { ctppKey.SetValue("CreateDate",(object)DateTime.Now.Date); ctppKey.SetValue("RegisterUser",(object)0); ctppKey.SetValue("RegisterDays",(object)254); MessageBox.Show("序列号更新成功!\n您已经成为VIP用户,将享有软件所提供的服务,感谢您使用本软件,祝您使用愉快!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); } else { if ( ctppKey.GetValue("RegisterUser") == null ) { ctppKey.SetValue("CreateDate",(object)DateTime.Now); ctppKey.SetValue("RegisterUser",(object)1); ctppKey.SetValue("RegisterDays",(object)1); MessageBox.Show("序列号更新成功!\n感谢您使用本软件,祝您使用愉快!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); } else { MessageBox.Show("该序列号所扮演的角色不比当前系统注册角色新,序列号更新失败!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Information); return; } } } catch(Exception ex) { MessageBox.Show("注册时出现未知错误,请与供应商联系!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Warning); CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); return; } } else MessageBox.Show("您所填写的序列号是非法序列号,请与供应商联系!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Warning); } catch(Exception ex) { MessageBox.Show("您所填写的序列号是非法序列号,请与供应商联系!","系统信息!", MessageBoxButtons.OK,MessageBoxIcon.Warning); CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE); return; } #endif }