|
using LB_SmartVisionCommon;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Diagnostics;
|
using System.IO;
|
using System.Linq;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
using System.Threading;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Data;
|
using System.Windows.Documents;
|
using System.Windows.Forms;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using System.Windows.Media.Imaging;
|
using System.Windows.Navigation;
|
using System.Windows.Shapes;
|
using MessageBox = System.Windows.Forms.MessageBox;
|
|
namespace LB_SmartVisionLoginUI
|
{
|
/// <summary>
|
/// MainWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class MainWindow : Window
|
{
|
/// <summary>
|
/// 调用Windows的API库user32.dll中的消息发送机制,可实现跨程序数据发送
|
/// </summary>
|
/// <param name="hwnd"></param>
|
/// <param name="wMsg"></param>
|
/// <param name="wParam"></param>
|
/// <param name="lParam"></param>
|
/// <returns></returns>
|
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
|
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
|
/// <summary>
|
/// 当前登录的用户名,也需要共享给整个工程
|
/// </summary>
|
public static string userName;//
|
/// <summary>
|
/// 用户密码
|
/// </summary>
|
private static string userPassword;
|
/// <summary>
|
/// 是否退出
|
/// </summary>
|
public bool isQuit = false;
|
/// <summary>
|
/// 当前用户
|
/// </summary>
|
public bool correctUser = false;
|
/// <summary>
|
/// 是否登出
|
/// </summary>
|
public bool login_on_off = false;
|
|
|
private MainWindow()
|
{
|
InitializeComponent();
|
correctUser = false;
|
}
|
|
private static MainWindow instanceLoginandConfirmation = null;
|
/// <summary>
|
///
|
/// </summary>
|
/// <returns></returns>
|
public static MainWindow InstanceLoginandConfirmation()
|
{
|
if (instanceLoginandConfirmation == null)
|
{
|
instanceLoginandConfirmation = new MainWindow();
|
}
|
return instanceLoginandConfirmation;
|
}
|
|
/// <summary>
|
/// 关闭
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void test_Close(object sender, MouseButtonEventArgs e)
|
{
|
correctUser = false;
|
isQuit = true;
|
this.Close();
|
}
|
|
/// <summary>
|
/// 最小化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void test_Min(object sender, MouseButtonEventArgs e)
|
{
|
this.WindowState = WindowState.Minimized;
|
}
|
|
private void Btn_Cancel_Click(object sender, RoutedEventArgs e)
|
{
|
this.Close();
|
try
|
{
|
Process[] processes = System.Diagnostics.Process.GetProcesses(); //获得所有进程
|
foreach (Process p in processes)
|
{
|
if (p.ProcessName == "ShockPadMeasurementSystem" && p.StartTime < DateTime.Now.AddMilliseconds(-300))
|
{
|
p.Kill();
|
}
|
}
|
}
|
catch { }
|
}
|
|
private void Btn_KeyBoard_Click(object sender, RoutedEventArgs e)
|
{
|
System.Diagnostics.Process.Start(@"C:\WINDOWS\system32\osk.exe");
|
}
|
|
private void Btn_Login_Click(object sender, RoutedEventArgs e)
|
{
|
login_on_off = true;
|
loginon();
|
// 在此处添加事件处理程序实现。
|
if (correctUser)//如果用户名密码正确,合法登录,则获得当前用户名和级别。同时关闭登录窗体
|
{
|
userName = this.Txt_UserName.Text.Trim().ToLower();
|
userPassword = this.Txt_UserPassWord.Password;
|
//closeLoginFrm();
|
this.Hide();
|
}
|
}
|
|
private void loginon()
|
{
|
if (!UserManager.Instance.Login(this.Txt_UserName.Text.Trim(), this.Txt_UserPassWord.Password))
|
{
|
MessageBox.Show("请输入正确的用户名和密码.",
|
"登录失败!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
correctUser = false;
|
return;
|
}
|
else// Valid user, pass the authentication
|
{
|
userName = this.Txt_UserName.Text.Trim();
|
userPassword = this.Txt_UserPassWord.Password;
|
correctUser = true;
|
isQuit = false;
|
}
|
}
|
/// <summary>
|
/// 关闭
|
/// </summary>
|
public void closeLoginFrm()
|
{
|
this.ShowInTaskbar = false;//点击登录后去掉任务栏图标
|
instanceLoginandConfirmation = null;
|
this.Close();
|
}
|
|
private void Txt_UserPassWord_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
{
|
if (e.Key== Key.Enter)
|
{
|
login_on_off = true;
|
loginon();
|
// 在此处添加事件处理程序实现。
|
if (correctUser)
|
{
|
userName = this.Txt_UserName.Text.Trim().ToLower();
|
userPassword = this.Txt_UserPassWord.Password;
|
isQuit = false;
|
//closeLoginFrm();
|
}
|
}
|
else if (e.Key == Key.Escape)
|
{
|
correctUser = false;
|
isQuit = true;
|
this.Close();
|
}
|
}
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
{
|
this.Txt_UserName.Text = "";
|
this.Txt_UserPassWord.Password = "";
|
}
|
}
|
}
|