using ButcherFactory.BO.Utils;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using WinFormControl;
|
|
|
|
namespace ButcherFactory.Login
|
|
{
|
|
/// <summary>
|
|
/// Login.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class Login : Window
|
|
{
|
|
public Login()
|
|
{
|
|
InitializeComponent();
|
|
#if DEBUG
|
|
pwdInput.Password = AppContext.ConnectInfo.ServerMode == 0 ? "123" : "bwp2017";
|
|
#endif
|
|
|
|
try
|
|
{
|
|
userNameInput.Text = AppContext.Worker.Name;
|
|
if (!string.IsNullOrEmpty(AppContext.Worker.Name))
|
|
pwdInput.Focus();
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
this.DragMove();
|
|
}
|
|
|
|
private async void LoginBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
loginBtn.IsEnabled = false;
|
|
if (string.IsNullOrEmpty(AppContext.ConnectInfo.SqlConnection))
|
|
throw new Exception("请设置数据库地址!");
|
|
var username = userNameInput.Text.Trim();
|
|
var pwd = pwdInput.Password;
|
|
if (string.IsNullOrEmpty(username))
|
|
throw new Exception("请输入用户名");
|
|
LoginUtil.InitRpcFacade();
|
|
if (LoginUtil.TestConnection(1000))
|
|
{
|
|
await Task.Factory.StartNew(() => LoginUtil.Login(username, pwd, AppContext.ConnectInfo.ServerMode));
|
|
}
|
|
else
|
|
{
|
|
if (AppContext.ConnectInfo.ServerMode == 1)
|
|
throw new Exception("网络错误");
|
|
if (AppContext.Worker.Name != username || string.Join("", LoginUtil.EncodePwd(pwd)) != string.Join("", AppContext.Worker.Password))
|
|
throw new Exception("离线时只能使用上次登录信息登录");
|
|
}
|
|
|
|
var form = FormUtil.CreateFrom();
|
|
if (form == null)
|
|
throw new Exception("权限不符");
|
|
form.FormClosing += delegate
|
|
{
|
|
this.Show();
|
|
};
|
|
|
|
form.Show();
|
|
Hide();
|
|
}
|
|
catch { throw; }
|
|
finally
|
|
{
|
|
loginBtn.IsEnabled = true;
|
|
}
|
|
}
|
|
|
|
private void ExistBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
App.Current.Shutdown();
|
|
}
|
|
|
|
private void UserNameTextBoxClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
LoginUtil.InitRpcFacade();
|
|
var keyBoard = new NumberPad();
|
|
if (keyBoard.ShowDialog() == true)
|
|
{
|
|
if (!LoginUtil.TestConnection(1000))
|
|
{
|
|
if (string.IsNullOrEmpty(AppContext.Worker.Name))
|
|
throw new Exception("请检查网络");
|
|
throw new Exception("离线时无法切换用户");
|
|
}
|
|
userNameInput.Text = LoginUtil.GetWorkerNameByCode(keyBoard.Result);
|
|
}
|
|
}
|
|
|
|
private void PwdTextBoxClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
var keyBoard = new VirtualKeyPad();
|
|
if (keyBoard.ShowDialog() == true)
|
|
pwdInput.Password = keyBoard.Result;
|
|
}
|
|
}
|
|
}
|