2014-11-02 08:03:31 +00:00
|
|
|
|
using NHibernate;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Configuration;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
|
|
|
|
public class Cache
|
|
|
|
|
{
|
|
|
|
|
private static IList<ProductGroup> cache = null;
|
|
|
|
|
private static Dictionary<int, PrintLocation> locations = new Dictionary<int, PrintLocation>();
|
2014-11-10 11:06:49 +00:00
|
|
|
|
private static Dictionary<Guid, IList<Modifier>> modifiers = new Dictionary<Guid, IList<Modifier>>();
|
2014-11-02 08:03:31 +00:00
|
|
|
|
private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
|
|
|
|
|
2014-11-06 10:39:11 +00:00
|
|
|
|
private static IList<Role> roles = null;
|
|
|
|
|
|
|
|
|
|
private static bool _log = false;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
public static IList<ProductGroup> ProductGroups()
|
|
|
|
|
{
|
|
|
|
|
if (cache == null)
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new ProductGroupBI())
|
|
|
|
|
{
|
|
|
|
|
var list = bi.SaleList();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
NHibernateUtil.Initialize(item.Products);
|
|
|
|
|
}
|
|
|
|
|
cache = list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
public static PrintLocation BasePrinter
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!locations.ContainsKey(location.GetHashCode()))
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new PrintLocationBI())
|
|
|
|
|
{
|
|
|
|
|
var loc = bi.Get(x => x.Location == location && x.ProductGroup == null);
|
|
|
|
|
locations.Add(location.GetHashCode(), loc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return locations[location.GetHashCode()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static PrintLocation KotPrinter(Guid productGroupID)
|
|
|
|
|
{
|
|
|
|
|
if (!locations.ContainsKey(location.GetHashCode() ^ productGroupID.GetHashCode()))
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new PrintLocationBI())
|
|
|
|
|
{
|
|
|
|
|
var loc = bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
|
|
|
|
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
|
|
|
|
locations.Add(location.GetHashCode() ^ productGroupID.GetHashCode(), loc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return locations[location.GetHashCode() ^ productGroupID.GetHashCode()];
|
|
|
|
|
}
|
2014-11-10 11:06:49 +00:00
|
|
|
|
public static IList<Modifier> ProductGroupModifiers(Guid productGroupID)
|
|
|
|
|
{
|
|
|
|
|
if (!modifiers.ContainsKey(productGroupID))
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new ProductGroupModifierBI())
|
|
|
|
|
{
|
|
|
|
|
var list = bi.List(productGroupID);
|
|
|
|
|
modifiers.Add(productGroupID, list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return modifiers[productGroupID];
|
|
|
|
|
}
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public static IList<Role> UserRoles(Guid userID)
|
|
|
|
|
{
|
|
|
|
|
if (roles == null)
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new UserBI())
|
|
|
|
|
{
|
|
|
|
|
roles = bi.Roles(userID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return roles;
|
|
|
|
|
}
|
|
|
|
|
public static void ClearRoles()
|
|
|
|
|
{
|
|
|
|
|
roles = null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 08:03:31 +00:00
|
|
|
|
public static void Invalidate()
|
|
|
|
|
{
|
|
|
|
|
cache = null;
|
|
|
|
|
locations = new Dictionary<int, PrintLocation>();
|
2014-11-10 11:06:49 +00:00
|
|
|
|
modifiers = new Dictionary<Guid, IList<Modifier>>();
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public static bool Log
|
|
|
|
|
{
|
|
|
|
|
get { return _log; }
|
|
|
|
|
set { _log = value; }
|
|
|
|
|
}
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|