星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KeyVerification.xaml.cs 4.9KB

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