修改winform 界面

master
hang 2024-11-29 15:20:33 +08:00
parent 7905b6f572
commit fdc719fba9
2 changed files with 277 additions and 34 deletions

View File

@ -34,30 +34,47 @@
btn_activate = new Button(); btn_activate = new Button();
label2 = new Label(); label2 = new Label();
txtActivateFilePath = new TextBox(); txtActivateFilePath = new TextBox();
label3 = new Label();
textMonths = new TextBox();
groupBox1 = new GroupBox();
textYears = new TextBox();
textTrialCode = new TextBox();
textCompany = new TextBox();
label7 = new Label();
label5 = new Label();
label4 = new Label();
groupBox2 = new GroupBox();
btnOpen = new Button();
textTrialCode2 = new TextBox();
textCompany2 = new TextBox();
label6 = new Label();
label8 = new Label();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); label1.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label1.Location = new Point(12, 57); label1.Location = new Point(18, 50);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(138, 21); label1.Size = new Size(138, 21);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "选择项目激活文件"; label1.Text = "项目授权申请文件";
// //
// txtFilePath // txtFilePath
// //
txtFilePath.Location = new Point(167, 55); txtFilePath.Location = new Point(173, 48);
txtFilePath.Name = "txtFilePath"; txtFilePath.Name = "txtFilePath";
txtFilePath.ReadOnly = true; txtFilePath.ReadOnly = true;
txtFilePath.Size = new Size(462, 23); txtFilePath.Size = new Size(462, 32);
txtFilePath.TabIndex = 1; txtFilePath.TabIndex = 1;
// //
// btn_select // btn_select
// //
btn_select.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); btn_select.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
btn_select.Location = new Point(650, 49); btn_select.Location = new Point(656, 42);
btn_select.Name = "btn_select"; btn_select.Name = "btn_select";
btn_select.Size = new Size(100, 33); btn_select.Size = new Size(100, 33);
btn_select.TabIndex = 2; btn_select.TabIndex = 2;
@ -68,7 +85,7 @@
// btn_activate // btn_activate
// //
btn_activate.Font = new Font("Microsoft YaHei UI", 15F, FontStyle.Regular, GraphicsUnit.Point, 134); btn_activate.Font = new Font("Microsoft YaHei UI", 15F, FontStyle.Regular, GraphicsUnit.Point, 134);
btn_activate.Location = new Point(230, 236); btn_activate.Location = new Point(227, 318);
btn_activate.Name = "btn_activate"; btn_activate.Name = "btn_activate";
btn_activate.Size = new Size(307, 57); btn_activate.Size = new Size(307, 57);
btn_activate.TabIndex = 3; btn_activate.TabIndex = 3;
@ -80,7 +97,7 @@
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); label2.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label2.Location = new Point(12, 133); label2.Location = new Point(30, 247);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(106, 21); label2.Size = new Size(106, 21);
label2.TabIndex = 4; label2.TabIndex = 4;
@ -88,27 +105,185 @@
// //
// txtActivateFilePath // txtActivateFilePath
// //
txtActivateFilePath.Location = new Point(167, 131); txtActivateFilePath.Location = new Point(191, 245);
txtActivateFilePath.Name = "txtActivateFilePath"; txtActivateFilePath.Name = "txtActivateFilePath";
txtActivateFilePath.ReadOnly = true; txtActivateFilePath.ReadOnly = true;
txtActivateFilePath.Size = new Size(591, 23); txtActivateFilePath.Size = new Size(459, 32);
txtActivateFilePath.TabIndex = 5; txtActivateFilePath.TabIndex = 5;
// //
// label3
//
label3.AutoSize = true;
label3.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label3.Location = new Point(33, 185);
label3.Name = "label3";
label3.Size = new Size(122, 21);
label3.TabIndex = 7;
label3.Text = "授权时长(月)";
//
// textMonths
//
textMonths.Location = new Point(191, 186);
textMonths.Name = "textMonths";
textMonths.Size = new Size(100, 32);
textMonths.TabIndex = 8;
textMonths.TextChanged += textMonths_TextChanged;
//
// groupBox1
//
groupBox1.Controls.Add(textYears);
groupBox1.Controls.Add(textTrialCode);
groupBox1.Controls.Add(textCompany);
groupBox1.Controls.Add(label7);
groupBox1.Controls.Add(label5);
groupBox1.Controls.Add(label4);
groupBox1.Controls.Add(btn_select);
groupBox1.Controls.Add(label1);
groupBox1.Controls.Add(txtFilePath);
groupBox1.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134);
groupBox1.Location = new Point(19, 15);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(778, 297);
groupBox1.TabIndex = 16;
groupBox1.TabStop = false;
groupBox1.Text = "授权申请信息";
//
// textYears
//
textYears.Location = new Point(173, 235);
textYears.Name = "textYears";
textYears.ReadOnly = true;
textYears.Size = new Size(100, 32);
textYears.TabIndex = 21;
//
// textTrialCode
//
textTrialCode.Location = new Point(173, 165);
textTrialCode.Name = "textTrialCode";
textTrialCode.ReadOnly = true;
textTrialCode.Size = new Size(462, 32);
textTrialCode.TabIndex = 20;
//
// textCompany
//
textCompany.Location = new Point(173, 108);
textCompany.Name = "textCompany";
textCompany.ReadOnly = true;
textCompany.Size = new Size(462, 32);
textCompany.TabIndex = 19;
//
// label7
//
label7.AutoSize = true;
label7.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label7.Location = new Point(28, 234);
label7.Name = "label7";
label7.Size = new Size(122, 21);
label7.TabIndex = 18;
label7.Text = "购买时长(年)";
//
// label5
//
label5.AutoSize = true;
label5.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label5.Location = new Point(28, 107);
label5.Name = "label5";
label5.Size = new Size(74, 21);
label5.TabIndex = 17;
label5.Text = "单位名称";
//
// label4
//
label4.AutoSize = true;
label4.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label4.Location = new Point(28, 167);
label4.Name = "label4";
label4.Size = new Size(74, 21);
label4.TabIndex = 16;
label4.Text = "项目编号";
//
// groupBox2
//
groupBox2.Controls.Add(btnOpen);
groupBox2.Controls.Add(textTrialCode2);
groupBox2.Controls.Add(textCompany2);
groupBox2.Controls.Add(label6);
groupBox2.Controls.Add(label8);
groupBox2.Controls.Add(btn_activate);
groupBox2.Controls.Add(label2);
groupBox2.Controls.Add(textMonths);
groupBox2.Controls.Add(txtActivateFilePath);
groupBox2.Controls.Add(label3);
groupBox2.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134);
groupBox2.Location = new Point(19, 341);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(778, 397);
groupBox2.TabIndex = 17;
groupBox2.TabStop = false;
groupBox2.Text = "激活生成信息";
//
// btnOpen
//
btnOpen.Enabled = false;
btnOpen.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
btnOpen.Location = new Point(656, 244);
btnOpen.Name = "btnOpen";
btnOpen.Size = new Size(100, 33);
btnOpen.TabIndex = 25;
btnOpen.Text = "打开目录";
btnOpen.UseVisualStyleBackColor = true;
btnOpen.Click += btnOpen_Click;
//
// textTrialCode2
//
textTrialCode2.Location = new Point(191, 117);
textTrialCode2.Name = "textTrialCode2";
textTrialCode2.ReadOnly = true;
textTrialCode2.Size = new Size(462, 32);
textTrialCode2.TabIndex = 24;
//
// textCompany2
//
textCompany2.Location = new Point(191, 60);
textCompany2.Name = "textCompany2";
textCompany2.ReadOnly = true;
textCompany2.Size = new Size(462, 32);
textCompany2.TabIndex = 23;
//
// label6
//
label6.AutoSize = true;
label6.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label6.Location = new Point(30, 59);
label6.Name = "label6";
label6.Size = new Size(74, 21);
label6.TabIndex = 22;
label6.Text = "单位名称";
//
// label8
//
label8.AutoSize = true;
label8.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
label8.Location = new Point(30, 119);
label8.Name = "label8";
label8.Size = new Size(74, 21);
label8.TabIndex = 21;
label8.Text = "项目编号";
//
// Form1 // Form1
// //
AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 542); ClientSize = new Size(825, 750);
Controls.Add(txtActivateFilePath); Controls.Add(groupBox2);
Controls.Add(label2); Controls.Add(groupBox1);
Controls.Add(btn_activate);
Controls.Add(btn_select);
Controls.Add(txtFilePath);
Controls.Add(label1);
Name = "Form1"; Name = "Form1";
Text = "HIR 激活码"; Text = "HIR 激活码";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@ -119,5 +294,20 @@
private Button btn_activate; private Button btn_activate;
private Label label2; private Label label2;
private TextBox txtActivateFilePath; private TextBox txtActivateFilePath;
private Label label3;
private TextBox textMonths;
private GroupBox groupBox1;
private TextBox textYears;
private TextBox textTrialCode;
private TextBox textCompany;
private Label label7;
private Label label5;
private Label label4;
private GroupBox groupBox2;
private TextBox textTrialCode2;
private TextBox textCompany2;
private Label label6;
private Label label8;
private Button btnOpen;
} }
} }

View File

@ -1,5 +1,6 @@
using IRaCIS.Core.Infrastructure.Encryption; using IRaCIS.Core.Infrastructure.Encryption;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics;
namespace HIR_Activate namespace HIR_Activate
{ {
@ -10,6 +11,8 @@ namespace HIR_Activate
InitializeComponent(); InitializeComponent();
} }
private TrialAuthorizationInfo authorizationInfo;
private void btn_select_Click(object sender, EventArgs e) private void btn_select_Click(object sender, EventArgs e)
{ {
using (OpenFileDialog openFileDialog = new OpenFileDialog()) using (OpenFileDialog openFileDialog = new OpenFileDialog())
@ -20,12 +23,54 @@ namespace HIR_Activate
txtFilePath.Text = openFileDialog.FileName; txtFilePath.Text = openFileDialog.FileName;
} }
} }
string filePath = txtFilePath.Text;
// 读取文件内容
string authorizationCode = File.ReadAllText(filePath);
// 解密 Base64 编码后的数据
byte[] base64DecodedBytes = Convert.FromBase64String(authorizationCode);
string decodedText = System.Text.Encoding.UTF8.GetString(base64DecodedBytes);
authorizationInfo = JsonConvert.DeserializeObject<TrialAuthorizationInfo>(decodedText);
if (authorizationInfo == null)
{
MessageBox.Show("不能解析该项目授权码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
textCompany.Text = authorizationInfo.HospitalName;
textTrialCode.Text = authorizationInfo.TrialCode;
textCompany2.Text = authorizationInfo.HospitalName;
textTrialCode2.Text = authorizationInfo.TrialCode;
textYears.Text = authorizationInfo.PurchaseDuration.ToString();
textMonths.Text = (authorizationInfo.PurchaseDuration * 12).ToString();
}
} }
private void btn_activate_Click(object sender, EventArgs e) private void btn_activate_Click(object sender, EventArgs e)
{ {
if (textMonths.Text.Length == 0)
{
MessageBox.Show("请输入授权时长再生成激活文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
authorizationInfo.PurchaseDuration = Convert.ToInt32(textMonths.Text);
}
string filePath = txtFilePath.Text; string filePath = txtFilePath.Text;
var fileName=Path.GetFileNameWithoutExtension(filePath); var fileName = Path.GetFileNameWithoutExtension(filePath);
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath)) if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
{ {
MessageBox.Show("请选择一个有效的文件路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("请选择一个有效的文件路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -34,22 +79,7 @@ namespace HIR_Activate
try 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); authorizationInfo.ActiveDeadLineDate = DateTime.Now.Date.AddDays(8).AddSeconds(-1);
@ -66,6 +96,8 @@ namespace HIR_Activate
txtActivateFilePath.Text = licensePath; txtActivateFilePath.Text = licensePath;
btnOpen.Enabled = true;
MessageBox.Show($"许可证生成成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show($"许可证生成成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
@ -76,6 +108,27 @@ namespace HIR_Activate
MessageBox.Show($"生成许可证失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"生成许可证失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void textMonths_TextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(textMonths.Text, @"^\d*$"))
{
MessageBox.Show("请输入有效的整数");
textMonths.Text = ""; // 清空无效输入
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (File.Exists(txtActivateFilePath.Text))
{
string folderPath = Path.GetDirectoryName(txtActivateFilePath.Text); // 替换为你的目录路径
Process.Start("explorer.exe", folderPath);
}
}
} }
public class TrialAuthorizationInfo public class TrialAuthorizationInfo