narsil/Tanshu.Accounts.PointOfSale/Program.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.BI;
namespace Tanshu.Accounts.PointOfSale
{
static class Program
{
private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string userName;
bool isAuthenticated;
using (LoginForm login = new LoginForm())
{
login.ShowDialog();
isAuthenticated = login.UserName(out userName);
}
if (isAuthenticated)
{
SetThreadPrincipal(userName);
Application.Run(new MainForm());
log.Warn(string.Format("User Logout: {0}", CurrentUser.user.Name));
}
else
{
log.Warn(string.Format("User Login Failed: '{0}'", userName));
}
}
static void SetThreadPrincipal(string userName)
{
log.Warn(string.Format("User Login: '{0}'", userName));
if (userName.Contains(":"))
userName = userName.Substring(userName.IndexOf(":") + 1);
AccountsPrincipal principal = AccountsPrincipal.CreateAccountsPrincipal(new Tanshu.Accounts.BI.MembershipBI().GetRolesForUser(userName),
new MembershipBI().GetUserFromName(userName));
// bind the generic principal to the thread
Thread.CurrentPrincipal = principal;
}
}
}