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 Tanshu.Accounts.Entities;
|
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>();
|
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
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var loc = MachineLocationBI.Get(_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
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var loc = PrintLocationBI.Get(Location);
|
|
|
|
|
_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
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var loc = PrintLocationBI.Get(Location, productGroupID);
|
|
|
|
|
_locations.Add(Location.GetHashCode() ^ productGroupID.GetHashCode(), loc);
|
2016-01-04 05:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
return _locations[Location.GetHashCode() ^ productGroupID.GetHashCode()];
|
|
|
|
|
}
|
|
|
|
|
public static IList<ProductGroup> ProductGroups()
|
|
|
|
|
{
|
|
|
|
|
if (_productGroups == null)
|
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var list = ProductGroupBI.SaleList();
|
|
|
|
|
_productGroups = list;
|
2016-04-11 07:01:52 +00:00
|
|
|
|
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;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
item.Products.Insert(i + 1, new Product()
|
|
|
|
|
{
|
2016-04-11 07:01:52 +00:00
|
|
|
|
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
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var list = ModifierBI.List(productGroupID);
|
|
|
|
|
_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
|
|
|
|
}
|
2016-01-04 05:22:01 +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
|
|
|
|
}
|
|
|
|
|
}
|