星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

KeyVerification.xaml.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.IO;
  3. using System.Management;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using XHWK.WKTool.DAL;
  9. namespace XHWK.WKTool
  10. {
  11. /// <summary>
  12. /// KeyVerification.xaml 的交互逻辑
  13. /// </summary>
  14. /*
  15. 输入code 调认证服务,成功跳登录 并且调用添加历史接口,失败继续输code
  16. */
  17. public partial class KeyVerification
  18. {
  19. private readonly XHApi _registerController = new XHApi();
  20. private int _serverReturnCode;
  21. public KeyVerification()
  22. {
  23. InitializeComponent();
  24. Topmost = true;
  25. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  26. Console.WriteLine(@"初始化KeyVerification");
  27. }
  28. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  29. {
  30. DragMove();
  31. }
  32. private void btnEnd_Click(object sender, RoutedEventArgs e)
  33. {
  34. if (string.IsNullOrWhiteSpace(TxbKey.Text))
  35. {
  36. MessageWindow.Show("密匙未输入");
  37. return;
  38. }
  39. _projectcode = TxbKey.Text.Trim();
  40. if (_projectcode.Length > 8)
  41. {
  42. MessageWindow.Show("密匙输入过长");
  43. TxbKey.Text = _projectcode.Substring(0, 8);
  44. return;
  45. }
  46. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate);
  47. }
  48. private string _projectcode = string.Empty;
  49. /// <summary>
  50. /// 认证服务-调用
  51. /// </summary>
  52. /// <returns>
  53. /// </returns>
  54. private object InvokeActivationAddServering()
  55. {
  56. string device = "pcwk";
  57. string mac = GetMacAddress();
  58. _serverReturnCode = _registerController.ActivationAdd(mac, device, _projectcode);
  59. return APP.ServerMsg;
  60. }
  61. /// <summary>
  62. /// 认证服务-返回结果
  63. /// </summary>
  64. /// <returns>
  65. /// </returns>
  66. public void InvokeActivationAddServerCompate(object obj)
  67. {
  68. if (_serverReturnCode == 0)
  69. {
  70. MessageWindow.Show("产品激活成功");
  71. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering,
  72. InvokeActivationAddHistoryServerCompate);
  73. Dispatcher.Invoke(() =>
  74. {
  75. Hide();
  76. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  77. //win.Topmost = true;
  78. win.Show();
  79. Thread.Sleep(200);
  80. Close();
  81. });
  82. }
  83. else
  84. {
  85. MessageWindow.Show(APP.ServerMsg);
  86. }
  87. }
  88. /// <summary>
  89. /// 激活信息--添加激活历史-调用
  90. /// </summary>
  91. /// <returns>
  92. /// </returns>
  93. private object InvokeActivationAddHistoryServering()
  94. {
  95. _serverReturnCode = _registerController.ActivationAddHistory();
  96. return APP.ServerMsg;
  97. }
  98. /// <summary>
  99. /// 激活信息--添加激活历史-返回结果
  100. /// </summary>
  101. /// <returns>
  102. /// </returns>
  103. public void InvokeActivationAddHistoryServerCompate(object obj)
  104. {
  105. if (!Directory.Exists(APP.DataPath))
  106. {
  107. Directory.CreateDirectory(APP.DataPath);
  108. }
  109. string applicationData = APP.DataPath + "signatureTime.txt";
  110. string currentTime = DateTime.Now.ToLongDateString(); //当前时间
  111. File.WriteAllText(applicationData, currentTime, Encoding.Default); //存放签名验证日期
  112. }
  113. /// <summary>
  114. /// 获取本机MAC地址
  115. /// </summary>
  116. /// <returns>
  117. /// 本机MAC地址
  118. /// </returns>
  119. public static string GetMacAddress()
  120. {
  121. try
  122. {
  123. string strMac = string.Empty;
  124. ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  125. ManagementObjectCollection moc = mc.GetInstances();
  126. foreach (var o in moc)
  127. {
  128. var mo = (ManagementObject)o;
  129. if ((bool)mo["IPEnabled"])
  130. {
  131. strMac = mo["MacAddress"].ToString();
  132. }
  133. }
  134. return strMac;
  135. }
  136. catch
  137. {
  138. return "unknown";
  139. }
  140. }
  141. private void close_click(object sender, RoutedEventArgs e)
  142. {
  143. CloseAction();
  144. }
  145. private void CloseAction()
  146. {
  147. APP.myloading.Show();
  148. new Thread(o => { Dispatcher.Invoke(() => { Environment.Exit(0); }); }).Start();
  149. }
  150. }
  151. }