using System; using System.Collections.Generic; using Tanshu.Accounts.Entities; namespace Tanshu.Accounts.Repository { public class Cache { private static IList _productGroups = null; private static Dictionary> _modifiers = new Dictionary>(); private static string _machine = Environment.MachineName; private static string _location = null; private static Dictionary _locations = new Dictionary(); private static bool _log = false; public static string Location { get { if (string.IsNullOrEmpty(_location)) { var loc = MachineLocationBI.Get(_machine); if (loc != null) _location = loc.Location; } return _location; } } public static PrintLocation BasePrinter { get { if (string.IsNullOrEmpty(Location)) throw new ArgumentException("No location for Machine"); if (!_locations.ContainsKey(Location.GetHashCode())) { var loc = PrintLocationBI.Get(Location); _locations.Add(Location.GetHashCode(), loc); } return _locations[Location.GetHashCode()]; } } public static PrintLocation KotPrinter(Guid productGroupID) { if (string.IsNullOrEmpty(Location)) throw new ArgumentException("No location for Machine"); if (!_locations.ContainsKey(Location.GetHashCode() ^ productGroupID.GetHashCode())) { var loc = PrintLocationBI.Get(Location, productGroupID); _locations.Add(Location.GetHashCode() ^ productGroupID.GetHashCode(), loc); } return _locations[Location.GetHashCode() ^ productGroupID.GetHashCode()]; } public static IList ProductGroups() { if (_productGroups == null) { var list = ProductGroupBI.SaleList(); _productGroups = list; foreach (var item in _productGroups) { for (var i = item.Products.Count - 1; i >= 0; i--) { if (item.Products[i].HasHappyHour) { var product = item.Products[i]; product.HasHappyHour = false; item.Products.Insert(i + 1, new Product() { ProductID = product.ProductID, Name = product.FullName, Units = product.Units, ProductGroup = product.ProductGroup, Vat = product.Vat, ServiceTax = product.ServiceTax, ServiceCharge = product.ServiceCharge, IsScTaxable = product.IsScTaxable, Price = product.Price, HasHappyHour = true, IsActive = product.IsActive, IsNotAvailable = product.IsNotAvailable, SortOrder = product.SortOrder, Quantity = product.Quantity }); } } } } return _productGroups; } public static IList ProductGroupModifiers(Guid productGroupID) { if (!_modifiers.ContainsKey(productGroupID)) { var list = ModifierBI.List(productGroupID); _modifiers.Add(productGroupID, list); } return _modifiers[productGroupID]; } public static void Invalidate() { _productGroups = null; _machine = Environment.MachineName; _location = null; _locations = new Dictionary(); _modifiers = new Dictionary>(); } public static bool Log { get { return _log; } set { _log = value; } } } }