星火微课系统客户端
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, InvokeActivationAddHistoryServerCompate);
  72. Dispatcher.Invoke
  73. (
  74. () =>
  75. {
  76. Hide();
  77. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  78. //win.Topmost = true;
  79. win.Show();
  80. Thread.Sleep(200);
  81. Close();
  82. }
  83. );
  84. }
  85. else
  86. {
  87. MessageWindow.Show(App.ServerMsg);
  88. }
  89. }
  90. /// <summary>
  91. /// 激活信息--添加激活历史-调用
  92. /// </summary>
  93. /// <returns>
  94. /// </returns>
  95. private object InvokeActivationAddHistoryServering()
  96. {
  97. _serverReturnCode = _registerController.ActivationAddHistory();
  98. return App.ServerMsg;
  99. }
  100. /// <summary>
  101. /// 激活信息--添加激活历史-返回结果
  102. /// </summary>
  103. /// <returns>
  104. /// </returns>
  105. public void InvokeActivationAddHistoryServerCompate(object obj)
  106. {
  107. if (!Directory.Exists(App.DataPath))
  108. {
  109. Directory.CreateDirectory(App.DataPath);
  110. }
  111. string applicationData = App.DataPath + "signatureTime.txt";
  112. string currentTime = DateTime.Now.ToLongDateString(); //当前时间
  113. File.WriteAllText(applicationData, currentTime, Encoding.Default); //存放签名验证日期
  114. }
  115. /// <summary>
  116. /// 获取本机MAC地址
  117. /// </summary>
  118. /// <returns>
  119. /// 本机MAC地址
  120. /// </returns>
  121. public static string GetMacAddress()
  122. {
  123. try
  124. {
  125. string strMac = string.Empty;
  126. ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  127. ManagementObjectCollection moc = mc.GetInstances();
  128. foreach (var o in moc)
  129. {
  130. var mo = (ManagementObject)o;
  131. if ((bool)mo["IPEnabled"])
  132. {
  133. strMac = mo["MacAddress"].ToString();
  134. }
  135. }
  136. return strMac;
  137. }
  138. catch
  139. {
  140. return "unknown";
  141. }
  142. }
  143. private void close_click(object sender, RoutedEventArgs e)
  144. {
  145. CloseAction();
  146. }
  147. private void CloseAction()
  148. {
  149. App.myloading.Show();
  150. new Thread(o => { Dispatcher.Invoke(() => { Environment.Exit(0); }); }).Start();
  151. }
  152. }
  153. }