using System; using System.Collections.Generic; using System.Linq; using System.Text; using Tanshu.Accounts.Repository; using System.Threading; using Tanshu.Accounts.Contracts; using Tanshu.Common.KeyboardControl; namespace Tanshu.Accounts.PointOfSale { class KeyboardLogin : ILogin { public bool LoginUser() { return LoginUser(true); } bool LoginUser(bool setThreadPrincipal) { using (LoginForm login = new LoginForm(new KeyboardControl())) { string userName; login.ShowDialog(); bool authenticated = login.UserName(out userName); if (authenticated && setThreadPrincipal) SetThreadPrincipal(userName); return authenticated; } } public bool LogoutUser() { Session.User = null; return true; } static void SetThreadPrincipal(string userName) { if (userName.Contains(":")) userName = userName.Substring(userName.IndexOf(":") + 1); using (var bi = new UserBI()) Session.User = bi.Get(x => x.Name == userName); } } }