星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

KeyVerification.xaml.cs 4.6KB

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