From fdc719fba911eca98e1b052c5dde4dda1dc0aa14 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 29 Nov 2024 15:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9winform=20=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HIR-Activate/Form1.Designer.cs | 224 ++++++++++++++++++++++++++++++--- HIR-Activate/Form1.cs | 87 ++++++++++--- 2 files changed, 277 insertions(+), 34 deletions(-) diff --git a/HIR-Activate/Form1.Designer.cs b/HIR-Activate/Form1.Designer.cs index 86d1830..4ed19ed 100644 --- a/HIR-Activate/Form1.Designer.cs +++ b/HIR-Activate/Form1.Designer.cs @@ -34,30 +34,47 @@ btn_activate = new Button(); label2 = new Label(); 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(); // // label1 // label1.AutoSize = true; 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.Size = new Size(138, 21); label1.TabIndex = 0; - label1.Text = "选择项目激活文件"; + label1.Text = "项目授权申请文件"; // // txtFilePath // - txtFilePath.Location = new Point(167, 55); + txtFilePath.Location = new Point(173, 48); txtFilePath.Name = "txtFilePath"; txtFilePath.ReadOnly = true; - txtFilePath.Size = new Size(462, 23); + txtFilePath.Size = new Size(462, 32); txtFilePath.TabIndex = 1; // // btn_select // 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.Size = new Size(100, 33); btn_select.TabIndex = 2; @@ -68,7 +85,7 @@ // btn_activate // 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.Size = new Size(307, 57); btn_activate.TabIndex = 3; @@ -80,7 +97,7 @@ // label2.AutoSize = true; 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.Size = new Size(106, 21); label2.TabIndex = 4; @@ -88,27 +105,185 @@ // // txtActivateFilePath // - txtActivateFilePath.Location = new Point(167, 131); + txtActivateFilePath.Location = new Point(191, 245); txtActivateFilePath.Name = "txtActivateFilePath"; txtActivateFilePath.ReadOnly = true; - txtActivateFilePath.Size = new Size(591, 23); + txtActivateFilePath.Size = new Size(459, 32); 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 // AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 542); - Controls.Add(txtActivateFilePath); - Controls.Add(label2); - Controls.Add(btn_activate); - Controls.Add(btn_select); - Controls.Add(txtFilePath); - Controls.Add(label1); + ClientSize = new Size(825, 750); + Controls.Add(groupBox2); + Controls.Add(groupBox1); Name = "Form1"; Text = "HIR 激活码"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox2.PerformLayout(); ResumeLayout(false); - PerformLayout(); } #endregion @@ -119,5 +294,20 @@ private Button btn_activate; private Label label2; 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; } } diff --git a/HIR-Activate/Form1.cs b/HIR-Activate/Form1.cs index 5062b14..a617e8a 100644 --- a/HIR-Activate/Form1.cs +++ b/HIR-Activate/Form1.cs @@ -1,5 +1,6 @@ using IRaCIS.Core.Infrastructure.Encryption; using Newtonsoft.Json; +using System.Diagnostics; namespace HIR_Activate { @@ -10,6 +11,8 @@ namespace HIR_Activate InitializeComponent(); } + private TrialAuthorizationInfo authorizationInfo; + private void btn_select_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) @@ -20,12 +23,54 @@ namespace HIR_Activate 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(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) { + if (textMonths.Text.Length == 0) + { + MessageBox.Show("Ȩʱɼļ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + authorizationInfo.PurchaseDuration = Convert.ToInt32(textMonths.Text); + } + string filePath = txtFilePath.Text; - var fileName=Path.GetFileNameWithoutExtension(filePath); + var fileName = Path.GetFileNameWithoutExtension(filePath); if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath)) { MessageBox.Show("ѡһЧļ·", "", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -34,22 +79,7 @@ namespace HIR_Activate try { - // ȡļ - string authorizationCode = File.ReadAllText(filePath); - // Base64 - byte[] base64DecodedBytes = Convert.FromBase64String(authorizationCode); - string decodedText = System.Text.Encoding.UTF8.GetString(base64DecodedBytes); - - var authorizationInfo = JsonConvert.DeserializeObject(decodedText); - - if (authorizationInfo == null) - { - MessageBox.Show("ܽĿȨ룡", "", MessageBoxButtons.OK, MessageBoxIcon.Error); - - return; - } - else { //һڼ authorizationInfo.ActiveDeadLineDate = DateTime.Now.Date.AddDays(8).AddSeconds(-1); @@ -66,16 +96,39 @@ namespace HIR_Activate txtActivateFilePath.Text = licensePath; + btnOpen.Enabled = true; + MessageBox.Show($"֤ɳɹ", "ɹ", MessageBoxButtons.OK, MessageBoxIcon.Information); } - + } catch (Exception ex) { 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