星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

KeyVerification.xaml.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.Forms;
  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 : Window
  18. {
  19. private readonly Interface registerController = new Interface();
  20. private int serverReturnCode = 0;
  21. public KeyVerification()
  22. {
  23. InitializeComponent();
  24. this.Topmost = true;
  25. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  26. }
  27. private void btnEnd_Click(object sender, RoutedEventArgs e)
  28. {
  29. if (string.IsNullOrWhiteSpace(txbKey.Text))
  30. {
  31. MessageWindow.Show("密匙未输入");
  32. return;
  33. }
  34. projectcode = txbKey.Text;
  35. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate);
  36. }
  37. private string projectcode = string.Empty;
  38. /// <summary>
  39. /// 认证服务-调用
  40. /// </summary>
  41. /// <returns></returns>
  42. private object InvokeActivationAddServering()
  43. {
  44. string device = "pcwk";
  45. string mac = GetMacAddress();
  46. serverReturnCode = registerController.ActivationAdd(mac, device, projectcode);
  47. return APP.ServerMsg;
  48. }
  49. /// <summary>
  50. /// 认证服务-返回结果
  51. /// </summary>
  52. /// <returns></returns>
  53. public void InvokeActivationAddServerCompate(object obj)
  54. {
  55. if (serverReturnCode == 0)
  56. {
  57. MessageWindow.Show("产品激活成功");
  58. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  59. Dispatcher.Invoke(new Action(() =>
  60. {
  61. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  62. //win.Topmost = true;
  63. win.Show();
  64. Hide();
  65. Thread.Sleep(200);
  66. Close();
  67. }));
  68. }
  69. else
  70. {
  71. MessageWindow.Show(APP.ServerMsg);
  72. }
  73. }
  74. /// <summary>
  75. /// 激活信息--添加激活历史-调用
  76. /// </summary>
  77. /// <returns></returns>
  78. private object InvokeActivationAddHistoryServering()
  79. {
  80. serverReturnCode = registerController.ActivationAddHistory();
  81. return APP.ServerMsg;
  82. }
  83. /// <summary>
  84. /// 激活信息--添加激活历史-返回结果
  85. /// </summary>
  86. /// <returns></returns>
  87. public void InvokeActivationAddHistoryServerCompate(object obj)
  88. {
  89. if (!Directory.Exists(APP.dataPath))
  90. {
  91. Directory.CreateDirectory(APP.dataPath);
  92. }
  93. string ApplicationData = APP.dataPath + "signatureTime.txt";
  94. string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  95. System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
  96. }
  97. /// <summary>
  98. /// 获取本机MAC地址
  99. /// </summary>
  100. /// <returns>本机MAC地址</returns>
  101. public static string GetMacAddress()
  102. {
  103. try
  104. {
  105. string strMac = string.Empty;
  106. ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  107. ManagementObjectCollection moc = mc.GetInstances();
  108. foreach (ManagementObject mo in moc)
  109. {
  110. if ((bool)mo["IPEnabled"] == true)
  111. {
  112. strMac = mo["MacAddress"].ToString();
  113. }
  114. }
  115. moc = null;
  116. mc = null;
  117. return strMac;
  118. }
  119. catch
  120. {
  121. return "unknown";
  122. }
  123. }
  124. private void close_click(object sender, RoutedEventArgs e)
  125. {
  126. closeAction();
  127. }
  128. private void closeAction()
  129. {
  130. APP.myloading.Show();
  131. new Thread(o =>
  132. {
  133. Dispatcher.Invoke(new Action(() =>
  134. {
  135. System.Environment.Exit(0);
  136. }));
  137. }).Start();
  138. }
  139. }
  140. }