123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System;
- using System.IO;
- using System.Windows;
- using System.Windows.Forms;
- using Aitex.Core.RT.Key;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Clipboard = System.Windows.Forms.Clipboard;
-
- namespace Aitex.Core.Backend
- {
- public partial class LicenseView : UserControl
- {
- PeriodicJob _thread;
- public LicenseView()
- {
- InitializeComponent();
- this.VisibleChanged += LicenseView_VisibleChanged;
- _thread = new PeriodicJob(500, OnTimer, "LicenseView Update", false, true);
- }
- void LicenseView_VisibleChanged(object sender, EventArgs e)
- {
- if (Visible)
- _thread.Start();
- else
- _thread.Pause();
- }
-
- bool OnTimer()
- {
- try
- {
- Invoke(new Action(() =>
- {
- textMachineCode.Text = KeyManager.Instance.LocalMachineCode;
- textLastDate.Text = KeyManager.Instance.ExpireDateTime.ToString();
- textLeftDays.Text = KeyManager.Instance.LeftDays.ToString();
- textRegisterDate.Text = KeyManager.Instance.LastRegisterDateTime.ToString();
- textRegisterDays.Text = KeyManager.Instance.LastRegisterDays.ToString();
- textPlcDateTime.Text = KeyManager.Instance.CurrentDateTime.ToString();
- }));
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return true;
- }
- private void LicenseView_Load(object sender, EventArgs e)
- {
- }
- private void btnRegister_Click(object sender, EventArgs e)
- {
- string inputKey = textKey.Text.Trim();
- if (string.IsNullOrEmpty(inputKey))
- return;
- string reason;
- if (!KeyManager.Instance.Register(inputKey, out reason))
- {
- System.Windows.MessageBox.Show(reason, "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
- return;
- }
- System.Windows.MessageBox.Show(reason, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- private void btnCopy_Click(object sender, EventArgs e)
- {
- string key = textMachineCode.Text.Trim();
- if (!string.IsNullOrEmpty(key))
- {
- Clipboard.SetDataObject(key);
- System.Windows.MessageBox.Show("机器码已经复制到剪贴板", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- }
- private void btnExport_Click(object sender, EventArgs e)
- {
- string key = textMachineCode.Text.Trim();
- if (string.IsNullOrEmpty(key))
- return;
-
- System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
- sfd.DefaultExt = ".code";
- sfd.Filter = ".code|*.*";
- sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- sfd.FileName = string.Format("jet_machine_code_{0}.code", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
- if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
- return;
- try
- {
- byte[] myByte = System.Text.Encoding.UTF8.GetBytes(key);
- using (FileStream fsWrite = new FileStream(sfd.FileName, FileMode.OpenOrCreate))
- {
- fsWrite.Write(myByte, 0, myByte.Length);
- }
- System.Windows.MessageBox.Show(string.Format("机器码导出到文件\r\n{0}\r\n成功",sfd.FileName), "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- private void btnPaste_Click(object sender, EventArgs e)
- {
- if (!Clipboard.ContainsText())
- return;
- textKey.Text = Clipboard.GetText();
- }
- private void btnImport_Click(object sender, EventArgs e)
- {
- System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
- ofd.DefaultExt = ".code";
- ofd.Filter = ".code|*.*";
- ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- //ofd.FileName = string.Format("machine_code_{0}.code", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
- if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
- return;
- try
- {
- using (FileStream fsSource = new FileStream(ofd.FileName,
- FileMode.Open, FileAccess.Read))
- {
- // Read the source file into a byte array.
- byte[] bytes = new byte[fsSource.Length];
-
- fsSource.Read(bytes, 0, (int) fsSource.Length);
- textKey.Text = System.Text.Encoding.UTF8.GetString(bytes);
-
- }
- System.Windows.MessageBox.Show("导入注册码成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- }
- }
|