123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.IO;
- using System.Management;
- using System.Text;
- using System.Threading;
- using System.Windows;
-
- using XHWK.WKTool.DAL;
- using XHWK.WKTool.Skin;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// KeyVerification.xaml 的交互逻辑
- /// </summary>
- /*
- 输入code 调认证服务,成功跳登录 并且调用添加历史接口,失败继续输code
- */
-
- public partial class KeyVerification : Window
- {
- private readonly XHApi registerController = new XHApi();
- private int serverReturnCode = 0;
-
- public KeyVerification()
- {
- InitializeComponent();
- Topmost = true;
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
-
- Console.WriteLine("初始化KeyVerification");
- }
-
- private void btnEnd_Click(object sender, RoutedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(txbKey.Text))
- {
- MessageWindow.Show("密匙未输入");
- return;
- }
- projectcode = txbKey.Text.Trim();
- if (projectcode.Length > 8)
- {
- MessageWindow.Show("密匙输入过长");
- txbKey.Text = projectcode.Substring(0, 8);
- return;
- }
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate);
- }
-
- private string projectcode = string.Empty;
-
- /// <summary>
- /// 认证服务-调用
- /// </summary>
- /// <returns>
- /// </returns>
- private object InvokeActivationAddServering()
- {
- string device = "pcwk";
- string mac = GetMacAddress();
- serverReturnCode = registerController.ActivationAdd(mac, device, projectcode);
- return APP.ServerMsg;
- }
-
- /// <summary>
- /// 认证服务-返回结果
- /// </summary>
- /// <returns>
- /// </returns>
- public void InvokeActivationAddServerCompate(object obj)
- {
- if (serverReturnCode == 0)
- {
- MessageWindow.Show("产品激活成功");
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
- Dispatcher.Invoke(new Action(() =>
- {
- Hide();
- CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
- //win.Topmost = true;
- win.Show();
-
- Thread.Sleep(200);
- Close();
- }));
- }
- else
- {
- MessageWindow.Show(APP.ServerMsg);
- }
- }
-
- /// <summary>
- /// 激活信息--添加激活历史-调用
- /// </summary>
- /// <returns>
- /// </returns>
- private object InvokeActivationAddHistoryServering()
- {
- serverReturnCode = registerController.ActivationAddHistory();
- return APP.ServerMsg;
- }
-
- /// <summary>
- /// 激活信息--添加激活历史-返回结果
- /// </summary>
- /// <returns>
- /// </returns>
- public void InvokeActivationAddHistoryServerCompate(object obj)
- {
- if (!Directory.Exists(APP.DataPath))
- {
- Directory.CreateDirectory(APP.DataPath);
- }
- string ApplicationData = APP.DataPath + "signatureTime.txt";
- string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
- System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
- }
-
- /// <summary>
- /// 获取本机MAC地址
- /// </summary>
- /// <returns>
- /// 本机MAC地址
- /// </returns>
- public static string GetMacAddress()
- {
- try
- {
- string strMac = string.Empty;
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection moc = mc.GetInstances();
- foreach (ManagementObject mo in moc)
- {
- if ((bool)mo["IPEnabled"] == true)
- {
- strMac = mo["MacAddress"].ToString();
- }
- }
- moc = null;
- mc = null;
- return strMac;
- }
- catch
- {
- return "unknown";
- }
- }
-
- private void close_click(object sender, RoutedEventArgs e)
- {
- closeAction();
- }
-
- private void closeAction()
- {
- APP.myloading.Show();
- new Thread(o =>
- {
- Dispatcher.Invoke(new Action(() =>
- {
- System.Environment.Exit(0);
- }));
- }).Start();
- }
- }
- }
|