using SchoolClient.Commons;
using SchoolClient.Config;
using SchoolClient.Method;
using System;
using System.IO;
using System.Management;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
namespace XHWK.WKTool
{
///
/// KeyVerification.xaml 的交互逻辑
///
/*
输入code 调认证服务,成功跳登陆 并且调用添加历史接口,失败继续输code
*/
public partial class KeyVerification : Window
{
private readonly RegisterController registerController = new RegisterController();
private int serverReturnCode = 0;
public KeyVerification()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
private void btnEnd_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(txbKey.Text))
{
MessageWindow.Show("密匙未输入");
return;
}
projectcode = txbKey.Text;
Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate);
}
private string projectcode = string.Empty;
///
/// 认证服务-调用
///
///
private object InvokeActivationAddServering()
{
string device = "pc";
string mac = GetMacAddress();
serverReturnCode = registerController.ActivationAdd(mac, device, projectcode);
return Shared.ServerMsg;
}
///
/// 认证服务-返回结果
///
///
public void InvokeActivationAddServerCompate(object obj)
{
if (serverReturnCode == Shared.ServerScuessCode)
{
MessageWindow.Show("产品激活成功");
Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
Dispatcher.Invoke(new Action(() =>
{
LoginWindow win = new LoginWindow();
//win.Topmost = true;
win.Show();
Hide();
Thread.Sleep(200);
Close();
}));
}
else
{
System.Windows.Forms.MessageBox.Show(Shared.ServerMsg, "激活结果:", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);
}
}
///
/// 激活信息--添加激活历史-调用
///
///
private object InvokeActivationAddHistoryServering()
{
serverReturnCode = registerController.ActivationAddHistory(ref Shared.TeachingData);
return Shared.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();
}
}
}