using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Configuration;
using System.IO;
using System.Security.Cryptography;
using System.Management;
namespace Uninpho.Tools.components.SomethingSetting
{
public partial class InitInviteFrom : DevExpress.XtraEditors.XtraForm
{
public InitInviteFrom()
{
InitializeComponent();
}
private void InitInviteFrom_Load(object sender, EventArgs e)
{
loadText();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
if (UserInform.userinf.Pow != 0)
{
if (XtraMessageBox.Show("软件已授权,您确定要更改授权码吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
SaveAppConfig("sqssrY", richTextBox1.Text);
}
}
else
{
SaveAppConfig("sqssrY", richTextBox1.Text);
}
}
///
/// 保存配置文件的设定
///
///
///
private void SaveAppConfig(string Key, string Value)
{
string strFilePath = System.Windows.Forms.Application.ExecutablePath;
Configuration objConfig = ConfigurationManager.OpenExeConfiguration(strFilePath);
bool bolExist = false;
foreach (string Item in objConfig.AppSettings.Settings.AllKeys)
{
if (Item == Key)
{
bolExist = true;
break;
}
}
if (bolExist)
{
objConfig.AppSettings.Settings.Remove(Key);
}
objConfig.AppSettings.Settings.Add(Key, Value);
objConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
try
{
UserInform.sqCode = Value;
string[] straa = sqClass.Decrypt(UserInform.sqCode, UserInform.sqkey).Split('灬');
UserInform.sqDate = straa[1];
if (UserInform.CPUID == straa[0])
{
if (straa[1] == "forever")
{
UserInform.userinf.Pow = 1;
UserInform.sqType = "Long";
}
else
{
UserInform.sqType = "Short";
DateTime nowtime = DateTime.Now;
DateTime timeLim = Convert.ToDateTime(straa[1]);
if (nowtime < timeLim)
{
UserInform.userinf.Pow = 1;
}
else
{
UserInform.userinf.Pow = 0;
}
}
}
}
catch
{
UserInform.userinf.Pow = 0;
}
finally
{
loadText();
}
}
private void loadText()
{
mechKey.Text = UserInform.CPUID;
if (UserInform.userinf.Pow == 0)
{
if (UserInform.sqType == "Short")
{
labelControl3.Text = "授权已过期";
}
else
{
labelControl3.Text = "未授权";
}
}
else
{
if (UserInform.sqType == "Short")
{
labelControl3.Text = "已授权,授权期限:" + UserInform.sqDate;
}
else
{
labelControl3.Text = "永久授权";
}
}
richTextBox1.Text = UserInform.sqCode;
}
}
}