屠宰场客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7 KiB

using ButcherManage.BO.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WinFormControl;
namespace ButcherManage.Login
{
/// <summary>
/// Login.xaml 的交互逻辑
/// </summary>
public partial class Login : Window
{
public Login()
{
InitializeComponent();
#if DEBUG
pwdInput.Password = "123";
#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)
{
var username = userNameInput.Text.Trim();
var pwd = pwdInput.Password;
if (string.IsNullOrEmpty(username))
throw new Exception("请输入用户名");
if (LoginUtil.TestConnection(1000))
{
await Task.Factory.StartNew(() => LoginUtil.Login(username, pwd));
}
else
{
if (!AppContext.ConnectInfo.LocalOffline)
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();
}
private void ExistBtn_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
}
private void UserNameTextBoxClick(object sender, MouseButtonEventArgs e)
{
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;
}
}
}