using System; using System.IO; using System.Management; using System.Text; using System.Threading; using System.Windows; using XHWK.WKTool.DAL; namespace XHWK.WKTool { /// /// KeyVerification.xaml 的交互逻辑 /// /* 输入code 调认证服务,成功跳登录 并且调用添加历史接口,失败继续输code */ public partial class KeyVerification : Window { private readonly Interface registerController = new Interface(); private int serverReturnCode = 0; public KeyVerification() { InitializeComponent(); Topmost = true; WindowStartupLocation = WindowStartupLocation.CenterScreen; } private void btnEnd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txbKey.Text)) { MessageWindow.Show("密匙未输入"); return; } projectcode = txbKey.Text.Trim(); APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate); } private string projectcode = string.Empty; /// /// 认证服务-调用 /// /// private object InvokeActivationAddServering() { string device = "pcwk"; string mac = GetMacAddress(); serverReturnCode = registerController.ActivationAdd(mac, device, projectcode); return APP.ServerMsg; } /// /// 认证服务-返回结果 /// /// public void InvokeActivationAddServerCompate(object obj) { if (serverReturnCode == 0) { MessageWindow.Show("产品激活成功"); APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate); Dispatcher.Invoke(new Action(() => { Hide(); CreateAMicroLessonWindow win = new CreateAMicroLessonWindow(); //win.Topmost = true; win.Show(); Thread.Sleep(200); Close(); })); } else { MessageWindow.Show(APP.ServerMsg); } } /// /// 激活信息--添加激活历史-调用 /// /// private object InvokeActivationAddHistoryServering() { serverReturnCode = registerController.ActivationAddHistory(); return APP.ServerMsg; } /// /// 激活信息--添加激活历史-返回结果 /// /// public void InvokeActivationAddHistoryServerCompate(object obj) { if (!Directory.Exists(APP.dataPath)) { Directory.CreateDirectory(APP.dataPath); } string ApplicationData = APP.dataPath + "signatureTime.txt"; string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间 System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期 } /// /// 获取本机MAC地址 /// /// 本机MAC地址 public static string GetMacAddress() { try { string strMac = string.Empty; ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if ((bool)mo["IPEnabled"] == true) { strMac = mo["MacAddress"].ToString(); } } moc = null; mc = null; return strMac; } catch { return "unknown"; } } private void close_click(object sender, RoutedEventArgs e) { closeAction(); } private void closeAction() { APP.myloading.Show(); new Thread(o => { Dispatcher.Invoke(new Action(() => { System.Environment.Exit(0); })); }).Start(); } } }