using ButcherFactory.BO.Utils; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WinFormControl; namespace ButcherFactory.Login { public partial class Login : Form { public Login() { InitializeComponent(); userNameBox.Text = AppContext.User.Name; pwdBox.Text = "123"; if (!string.IsNullOrEmpty(AppContext.User.Name)) pwdBox.Focus(); } private Point mousePoint = new Point(); private void Login_MouseDown(object sender, MouseEventArgs e) { this.mousePoint.X = e.X; this.mousePoint.Y = e.Y; } private void Login_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.Top = Control.MousePosition.Y - mousePoint.Y; this.Left = Control.MousePosition.X - mousePoint.X; } } private async void loginBtn_Click(object sender, EventArgs e) { var username = userNameBox.Text.Trim(); var pwd = pwdBox.Text; if (string.IsNullOrEmpty(username)) throw new Exception("请输入用户名"); if (LoginUtil.TestConnection(1000)) { LoginUtil.InitRpcFacade(); await Task.Factory.StartNew(() => LoginUtil.Login(username, pwd)); } else { if (AppContext.User.Name != username && LoginUtil.EncodePwd(pwd) != AppContext.User.Password) throw new Exception("请输入用户名"); } var form = FormUtil.CreateFrom(); if (form == null) throw new Exception("权限不符"); form.FormClosing += delegate { SubFormClosing(); LoginUtil.LoginOut(); }; form.Show(); Hide(); } void SubFormClosing() { foreach (Form form in Application.OpenForms) { if (form is Login) { form.Show(); return; } } } private void exitBtn_Click(object sender, EventArgs e) { Application.Exit(); } private void pictureBox1_Click(object sender, EventArgs e) { if (new SettingForm().ShowDialog() == DialogResult.OK) LoginUtil.ReInitRpcFacade(); } private void userNameBox_Click(object sender, EventArgs e) { LoginUtil.InitRpcFacade(); var keyBoard = new NumberPad(); if (keyBoard.ShowDialog() == true) { string errorInfo; userNameBox.Text = LoginUtil.GetUserNameByCode(keyBoard.Result, out errorInfo); if (string.IsNullOrEmpty(userNameBox.Text)) throw new Exception("工号输入错误"); if (!string.IsNullOrEmpty(errorInfo)) MessageBox.Show(errorInfo); } } } }