星火微课系统客户端
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.7KB

4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 XHWK.WKTool.DAL;
  8. using XHWK.WKTool.Skin;
  9. namespace XHWK.WKTool
  10. {
  11. /// <summary>
  12. /// KeyVerification.xaml 的交互逻辑
  13. /// </summary>
  14. /*
  15. 输入code 调认证服务,成功跳登录 并且调用添加历史接口,失败继续输code
  16. */
  17. public partial class KeyVerification : Window
  18. {
  19. private readonly XHApi registerController = new XHApi();
  20. private int serverReturnCode = 0;
  21. public KeyVerification()
  22. {
  23. InitializeComponent();
  24. Topmost = true;
  25. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  26. Console.WriteLine("初始化KeyVerification");
  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.Trim();
  36. APP.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 = "pcwk";
  46. string mac = GetMacAddress();
  47. serverReturnCode = registerController.ActivationAdd(mac, device, projectcode);
  48. return APP.ServerMsg;
  49. }
  50. /// <summary>
  51. /// 认证服务-返回结果
  52. /// </summary>
  53. /// <returns></returns>
  54. public void InvokeActivationAddServerCompate(object obj)
  55. {
  56. if (serverReturnCode == 0)
  57. {
  58. MessageWindow.Show("产品激活成功");
  59. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  60. Dispatcher.Invoke(new Action(() =>
  61. {
  62. Hide();
  63. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  64. //win.Topmost = true;
  65. win.Show();
  66. Thread.Sleep(200);
  67. Close();
  68. }));
  69. }
  70. else
  71. {
  72. MessageWindow.Show(APP.ServerMsg);
  73. }
  74. }
  75. /// <summary>
  76. /// 激活信息--添加激活历史-调用
  77. /// </summary>
  78. /// <returns></returns>
  79. private object InvokeActivationAddHistoryServering()
  80. {
  81. serverReturnCode = registerController.ActivationAddHistory();
  82. return APP.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. }