HIR-Activate/HIR-Activate/Form1.cs

219 lines
5.6 KiB
C#

using IRaCIS.Core.Infrastructure.Encryption;
using Newtonsoft.Json;
namespace HIR_Activate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_select_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Request Files (*.req)|*.req";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
txtFilePath.Text = openFileDialog.FileName;
}
}
}
private void btn_activate_Click(object sender, EventArgs e)
{
string filePath = txtFilePath.Text;
var fileName=Path.GetFileNameWithoutExtension(filePath);
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
{
MessageBox.Show("请选择一个有效的文件路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
// 读取文件内容
string authorizationCode = File.ReadAllText(filePath);
// 解密 Base64 编码后的数据
byte[] base64DecodedBytes = Convert.FromBase64String(authorizationCode);
string decodedText = System.Text.Encoding.UTF8.GetString(base64DecodedBytes);
var authorizationInfo = JsonConvert.DeserializeObject<TrialAuthorizationInfo>(decodedText);
if (authorizationInfo == null)
{
MessageBox.Show("不能解析该项目授权码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
//一周内激活
authorizationInfo.ActiveDeadLineDate = DateTime.Now.Date.AddDays(8).AddSeconds(-1);
var licenseContent = AesEncryption.Encrypt($"{JsonConvert.SerializeObject(authorizationInfo)}", "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
Console.WriteLine("HIR_System_AES_Key_Info".PadRight(32, '0').Substring(0, 32) + " " + "Trial_AuthorizationEncrypt".PadRight(16, '0').Substring(0, 16));
//var dd = AesEncryption.Decrypt(info, "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
// 保存许可证文件
string licensePath = Path.Combine(Path.GetDirectoryName(filePath), $"{fileName}_Activation_Code.lic");
File.WriteAllText(licensePath, licenseContent);
txtActivateFilePath.Text = licensePath;
MessageBox.Show($"许可证生成成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show($"生成许可证失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
public class TrialAuthorizationInfo
{
public Guid TrialId { get; set; }
public Guid CreateUserId { get; set; }
public string TrialCode { get; set; }
public string HospitalName { get; set; }
public string HospitalCode { get; set; }
public int PurchaseDuration { get; set; }
public List<CriterionType> CriterionTypeList { get; set; }
public DateTime? AuthorizationDeadLineDate { get; set; }
public DateTime? ActiveDeadLineDate { get; set; }
public DateTime? ActiveTime { get; set; }
}
/// <summary>
/// 标准类型
/// </summary>
public enum CriterionType
{
NoCriterion = -1,
//自定义
SelfDefine = 0,
/// <summary>
/// RECIST 1.1
/// </summary>
RECIST1Point1 = 1,
/// <summary>
/// Lugano 2014
/// </summary>
Lugano2014 = 2,
/// <summary>
/// iRECIST1Point1
/// </summary>
IRECIST1Point1 = 3,
/// <summary>
/// RANO-BM
/// </summary>
RANO_BM = 4,
/// <summary>
/// RANO
/// </summary>
RANO = 5,
/// <summary>
/// IWCLL 2018
/// </summary>
IWCLL2018 = 6,
/// <summary>
/// mRECIST HCC
/// </summary>
mRECISTHCC = 7,
/// <summary>
/// Cheson 2007
/// </summary>
Cheson2007 = 8,
/// <summary>
/// IMWG 2016
/// </summary>
IMWG2016 = 9,
/// <summary>
/// PCWG3
/// </summary>
PCWG3 = 10,
/// <summary>
/// mRECIST Mesothelioma
/// </summary>
mRECISTMesothelioma = 11,
/// <summary>
/// RECIL
/// </summary>
RECIL = 12,
/// <summary>
/// RECIST 1.0
/// </summary>
RECIST1Point0 = 13,
/// <summary>
/// WHO
/// </summary>
WHO = 14,
/// <summary>
/// PERCIST
/// </summary>
PERCIST = 15,
/// <summary>
/// Forrest
/// </summary>
Forrest = 16,
/// <summary>
/// RECIST 1.1-BM
/// </summary>
RECIST1Pointt1_MB = 17,
/// <summary>
/// Lugano 2014 Without PET
/// </summary>
Lugano2014WithoutPET = 18,
/// <summary>
/// IVUS定量评估
/// </summary>
IVUS = 19,
/// <summary>
/// OCT定量评估
/// </summary>
OCT = 20,
}
}