2016-01-04 05:22:01 +00:00
|
|
|
|
using System;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-01-04 05:22:01 +00:00
|
|
|
|
using NHibernate;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
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
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
private static IList<ProductGroup> _productGroups = null;
|
|
|
|
|
private static Dictionary<Guid, IList<Modifier>> _modifiers = new Dictionary<Guid, IList<Modifier>>();
|
|
|
|
|
private static string _machine = Environment.MachineName;
|
|
|
|
|
private static string _location = null;
|
|
|
|
|
private static Dictionary<int, PrintLocation> _locations = new Dictionary<int, PrintLocation>();
|
|
|
|
|
private static IList<Role> _roles = null;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
private static bool _log = false;
|
2016-01-04 05:22:01 +00:00
|
|
|
|
|
|
|
|
|
public static string Location
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
get
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
if (string.IsNullOrEmpty(_location))
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
using (var bi = new MachineLocationBI())
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
var loc = bi.Get(x => x.Machine == _machine);
|
|
|
|
|
if (loc != null)
|
|
|
|
|
_location = loc.Location;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
return _location;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static PrintLocation BasePrinter
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
if (string.IsNullOrEmpty(Location))
|
|
|
|
|
throw new ArgumentException("No location for Machine");
|
|
|
|
|
if (!_locations.ContainsKey(Location.GetHashCode()))
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new PrintLocationBI())
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
var loc = bi.Get(x => x.Location == Location && x.ProductGroup == null);
|
|
|
|
|
_locations.Add(Location.GetHashCode(), loc);
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
return _locations[Location.GetHashCode()];
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static PrintLocation KotPrinter(Guid productGroupID)
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
if (string.IsNullOrEmpty(Location))
|
|
|
|
|
throw new ArgumentException("No location for Machine");
|
|
|
|
|
if (!_locations.ContainsKey(Location.GetHashCode() ^ productGroupID.GetHashCode()))
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new PrintLocationBI())
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
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()];
|
|
|
|
|
}
|
|
|
|
|
public static IList<ProductGroup> ProductGroups()
|
|
|
|
|
{
|
|
|
|
|
if (_productGroups == null)
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new ProductGroupBI())
|
|
|
|
|
{
|
|
|
|
|
var list = bi.SaleList();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
NHibernateUtil.Initialize(item.Products);
|
|
|
|
|
}
|
|
|
|
|
_productGroups = list;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
return _productGroups;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
}
|
2014-11-10 11:06:49 +00:00
|
|
|
|
public static IList<Modifier> ProductGroupModifiers(Guid productGroupID)
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
if (!_modifiers.ContainsKey(productGroupID))
|
2014-11-10 11:06:49 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new ProductGroupModifierBI())
|
|
|
|
|
{
|
|
|
|
|
var list = bi.List(productGroupID);
|
2016-01-04 05:22:01 +00:00
|
|
|
|
_modifiers.Add(productGroupID, list);
|
2014-11-10 11:06:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
return _modifiers[productGroupID];
|
2014-11-10 11:06:49 +00:00
|
|
|
|
}
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public static IList<Role> UserRoles(Guid userID)
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
if (_roles == null)
|
2014-11-06 10:39:11 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new UserBI())
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
_roles = bi.Roles(userID);
|
2014-11-06 10:39:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
return _roles;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public static void ClearRoles()
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
_roles = null;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
}
|
2014-11-02 08:03:31 +00:00
|
|
|
|
public static void Invalidate()
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
_productGroups = null;
|
|
|
|
|
_machine = Environment.MachineName;
|
|
|
|
|
_location = null;
|
|
|
|
|
_locations = new Dictionary<int, PrintLocation>();
|
|
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
}
|