| | using System; |
| | using System.Drawing; |
| | using System.Windows.Forms; |
| |
|
| | namespace KSTools.Licensing |
| | { |
| | |
| | |
| | |
| | |
| | public partial class LicenseActivationDialog : Form |
| | { |
| | |
| | |
| | |
| | public string LicenseCode { get; private set; } |
| | |
| | private TextBox txtLicenseCode; |
| | private TextBox txtHardwareId; |
| | private Button btnActivate; |
| | private Button btnCancel; |
| | private Button btnCopyHardwareId; |
| | private Label lblInstructions; |
| | private Label lblHardwareId; |
| | private Label lblLicenseCode; |
| | private PictureBox picIcon; |
| | |
| | |
| | |
| | |
| | |
| | public LicenseActivationDialog(string hardwareId) |
| | { |
| | InitializeComponent(); |
| | txtHardwareId.Text = hardwareId; |
| | |
| | |
| | this.StartPosition = FormStartPosition.CenterScreen; |
| | this.FormBorderStyle = FormBorderStyle.FixedDialog; |
| | this.MaximizeBox = false; |
| | this.MinimizeBox = false; |
| | this.ShowInTaskbar = false; |
| | } |
| | |
| | |
| | |
| | |
| | private void InitializeComponent() |
| | { |
| | this.txtLicenseCode = new TextBox(); |
| | this.txtHardwareId = new TextBox(); |
| | this.btnActivate = new Button(); |
| | this.btnCancel = new Button(); |
| | this.btnCopyHardwareId = new Button(); |
| | this.lblInstructions = new Label(); |
| | this.lblHardwareId = new Label(); |
| | this.lblLicenseCode = new Label(); |
| | this.picIcon = new PictureBox(); |
| | |
| | ((System.ComponentModel.ISupportInitialize)(this.picIcon)).BeginInit(); |
| | this.SuspendLayout(); |
| | |
| | |
| | |
| | |
| | this.picIcon.Location = new Point(12, 12); |
| | this.picIcon.Size = new Size(48, 48); |
| | this.picIcon.SizeMode = PictureBoxSizeMode.StretchImage; |
| | |
| | |
| | |
| | |
| | |
| | this.lblInstructions.AutoSize = false; |
| | this.lblInstructions.Location = new Point(76, 12); |
| | this.lblInstructions.Size = new Size(380, 60); |
| | this.lblInstructions.Text = "歡迎使用 KSTools!\n\n" + |
| | "請將下方的硬體 ID 提供給管理員以取得授權碼,\n" + |
| | "然後在下方輸入授權碼進行啟用。"; |
| | this.lblInstructions.Font = new Font("Microsoft JhengHei", 9F, FontStyle.Regular); |
| | |
| | |
| | |
| | |
| | this.lblHardwareId.AutoSize = true; |
| | this.lblHardwareId.Location = new Point(12, 85); |
| | this.lblHardwareId.Size = new Size(68, 15); |
| | this.lblHardwareId.Text = "硬體 ID:"; |
| | this.lblHardwareId.Font = new Font("Microsoft JhengHei", 9F, FontStyle.Bold); |
| | |
| | |
| | |
| | |
| | this.txtHardwareId.Location = new Point(12, 105); |
| | this.txtHardwareId.Size = new Size(350, 25); |
| | this.txtHardwareId.ReadOnly = true; |
| | this.txtHardwareId.BackColor = Color.LightGray; |
| | this.txtHardwareId.Font = new Font("Consolas", 9F, FontStyle.Regular); |
| | |
| | |
| | |
| | |
| | this.btnCopyHardwareId.Location = new Point(370, 105); |
| | this.btnCopyHardwareId.Size = new Size(75, 25); |
| | this.btnCopyHardwareId.Text = "複製"; |
| | this.btnCopyHardwareId.UseVisualStyleBackColor = true; |
| | this.btnCopyHardwareId.Click += new EventHandler(this.btnCopyHardwareId_Click); |
| | |
| | |
| | |
| | |
| | this.lblLicenseCode.AutoSize = true; |
| | this.lblLicenseCode.Location = new Point(12, 145); |
| | this.lblLicenseCode.Size = new Size(68, 15); |
| | this.lblLicenseCode.Text = "授權碼:"; |
| | this.lblLicenseCode.Font = new Font("Microsoft JhengHei", 9F, FontStyle.Bold); |
| | |
| | |
| | |
| | |
| | this.txtLicenseCode.Location = new Point(12, 165); |
| | this.txtLicenseCode.Size = new Size(433, 25); |
| | this.txtLicenseCode.Font = new Font("Consolas", 10F, FontStyle.Regular); |
| | this.txtLicenseCode.CharacterCasing = CharacterCasing.Upper; |
| | this.txtLicenseCode.MaxLength = 50; |
| | this.txtLicenseCode.TextChanged += new EventHandler(this.txtLicenseCode_TextChanged); |
| | this.txtLicenseCode.KeyPress += new KeyPressEventHandler(this.txtLicenseCode_KeyPress); |
| | |
| | |
| | |
| | |
| | this.btnActivate.Location = new Point(280, 210); |
| | this.btnActivate.Size = new Size(80, 30); |
| | this.btnActivate.Text = "啟用"; |
| | this.btnActivate.UseVisualStyleBackColor = true; |
| | this.btnActivate.Enabled = false; |
| | this.btnActivate.Font = new Font("Microsoft JhengHei", 9F, FontStyle.Bold); |
| | this.btnActivate.Click += new EventHandler(this.btnActivate_Click); |
| | |
| | |
| | |
| | |
| | this.btnCancel.Location = new Point(370, 210); |
| | this.btnCancel.Size = new Size(80, 30); |
| | this.btnCancel.Text = "取消"; |
| | this.btnCancel.UseVisualStyleBackColor = true; |
| | this.btnCancel.DialogResult = DialogResult.Cancel; |
| | |
| | |
| | |
| | |
| | this.AcceptButton = this.btnActivate; |
| | this.CancelButton = this.btnCancel; |
| | this.ClientSize = new Size(467, 260); |
| | this.Controls.Add(this.btnCancel); |
| | this.Controls.Add(this.btnActivate); |
| | this.Controls.Add(this.txtLicenseCode); |
| | this.Controls.Add(this.lblLicenseCode); |
| | this.Controls.Add(this.btnCopyHardwareId); |
| | this.Controls.Add(this.txtHardwareId); |
| | this.Controls.Add(this.lblHardwareId); |
| | this.Controls.Add(this.lblInstructions); |
| | this.Controls.Add(this.picIcon); |
| | this.Font = new Font("Microsoft JhengHei", 9F, FontStyle.Regular); |
| | this.Text = "KSTools 授權啟用"; |
| | |
| | ((System.ComponentModel.ISupportInitialize)(this.picIcon)).EndInit(); |
| | this.ResumeLayout(false); |
| | this.PerformLayout(); |
| | } |
| | |
| | |
| | |
| | |
| | private void btnCopyHardwareId_Click(object sender, EventArgs e) |
| | { |
| | try |
| | { |
| | Clipboard.SetText(txtHardwareId.Text); |
| | MessageBox.Show("硬體 ID 已複製到剪貼簿!", "複製成功", |
| | MessageBoxButtons.OK, MessageBoxIcon.Information); |
| | } |
| | catch (Exception ex) |
| | { |
| | MessageBox.Show($"複製失敗:{ex.Message}", "錯誤", |
| | MessageBoxButtons.OK, MessageBoxIcon.Error); |
| | } |
| | } |
| | |
| | |
| | |
| | |
| | private void txtLicenseCode_TextChanged(object sender, EventArgs e) |
| | { |
| | |
| | string licenseCode = txtLicenseCode.Text.Trim(); |
| | |
| | |
| | bool isValidFormat = licenseCode.StartsWith("KS") && licenseCode.Length >= 8 && licenseCode.Length <= 20; |
| | |
| | btnActivate.Enabled = isValidFormat; |
| | |
| | |
| | if (string.IsNullOrEmpty(licenseCode)) |
| | { |
| | txtLicenseCode.ForeColor = Color.Black; |
| | } |
| | else if (isValidFormat) |
| | { |
| | txtLicenseCode.ForeColor = Color.Green; |
| | } |
| | else |
| | { |
| | txtLicenseCode.ForeColor = Color.Red; |
| | } |
| | } |
| | |
| | |
| | |
| | |
| | private void txtLicenseCode_KeyPress(object sender, KeyPressEventArgs e) |
| | { |
| | |
| | if (!char.IsLetterOrDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) |
| | { |
| | e.Handled = true; |
| | } |
| | } |
| | |
| | |
| | |
| | |
| | private void btnActivate_Click(object sender, EventArgs e) |
| | { |
| | string licenseCode = txtLicenseCode.Text.Trim().ToUpper(); |
| | |
| | if (string.IsNullOrEmpty(licenseCode)) |
| | { |
| | MessageBox.Show("請輸入授權碼!", "輸入錯誤", |
| | MessageBoxButtons.OK, MessageBoxIcon.Warning); |
| | txtLicenseCode.Focus(); |
| | return; |
| | } |
| | |
| | if (!licenseCode.StartsWith("KS")) |
| | { |
| | MessageBox.Show("授權碼格式錯誤!授權碼必須以 'KS' 開頭。", "格式錯誤", |
| | MessageBoxButtons.OK, MessageBoxIcon.Warning); |
| | txtLicenseCode.Focus(); |
| | return; |
| | } |
| | |
| | |
| | var confirmResult = MessageBox.Show( |
| | $"確定要使用授權碼 '{licenseCode}' 進行啟用嗎?\n\n" + |
| | $"授權碼將與此電腦的硬體 ID 綁定,無法轉移到其他電腦使用。", |
| | "確認啟用", |
| | MessageBoxButtons.YesNo, |
| | MessageBoxIcon.Question); |
| | |
| | if (confirmResult == DialogResult.Yes) |
| | { |
| | this.LicenseCode = licenseCode; |
| | this.DialogResult = DialogResult.OK; |
| | this.Close(); |
| | } |
| | } |
| | |
| | |
| | |
| | |
| | protected override void OnLoad(EventArgs e) |
| | { |
| | base.OnLoad(e); |
| | |
| | |
| | txtLicenseCode.Focus(); |
| | |
| | |
| | this.ShowTips(); |
| | } |
| | |
| | |
| | |
| | |
| | private void ShowTips() |
| | { |
| | var tips = "使用提示:\n\n" + |
| | "1. 請將上方的硬體 ID 提供給系統管理員\n" + |
| | "2. 管理員會為您生成專屬的授權碼\n" + |
| | "3. 在授權碼輸入框中輸入完整的授權碼\n" + |
| | "4. 授權碼格式:KS + 數字字母組合\n" + |
| | "5. 每個授權碼只能在一台電腦上使用\n\n" + |
| | "如有問題請聯絡技術支援。"; |
| | |
| | |
| | } |
| | } |
| | } |