public static ShoppingCart Factory(string storeId, string machineId, int companyId, string deviceSn, bool isNew = false)
        {
            string key = KeyFactory.MachineKeyFactory(companyId, storeId, machineId, deviceSn);

            if (shoppingCartCache.ContainsKey(key) && !isNew)
            {
#if (Local != true)
                shoppingCartCache.JsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings();
                shoppingCartCache.JsonSerializerSettings.Converters.Add(new BarcodeConverter());
#endif
                var shoppingCart = shoppingCartCache.Get(key);
                return(shoppingCart);
            }
            else
            {
                shoppingCartCache.Remove(key);
#if (Local != true)
                OnlineCache onlineCache = new OnlineCache();
#endif
#if (Local)
                OnlineCache onlineCache = Salesclerk.onlineCache;
#endif

                var machineInfo = onlineCache.Get(key);
                if (machineInfo != null)
                {
                    var shoppingCart = new ShoppingCart();
                    shoppingCart.MachineInformation = machineInfo;
                    shoppingCart.NewAndResetOrderSN();
                    shoppingCartCache.Set(key, shoppingCart);
                    return(shoppingCart);
                }
                else
                {
                    goto TheSaleException;
                }
            }

TheSaleException:
            throw new SaleException("400", "未登录或者未授权,不允许操作!");
        }
Example #2
0
        public override void Execute(Protocol.Clients.PosStoreClient posStoreClient, Protocol.RequestInfos.PosStorePackageInfo package)
        {
            var jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings();

            jsonSerializerSettings.Converters.Add(new BarcodeConverter());
            var shoppingcart = package.Read <ShoppingCart>(jsonSerializerSettings);

            if (shoppingcart != null)
            {
                var    shoppingCartCache = new ShoppingCartCache();
                string key = KeyFactory.MachineKeyFactory(shoppingcart.MachineInformation.CompanyToken, shoppingcart.MachineInformation.StoreId, shoppingcart.MachineInformation.MachineSn, shoppingcart.MachineInformation.DeviceSn);
                shoppingCartCache.Set(key, shoppingcart);
            }
        }
 public override void Excute(PosStoreServer server, PosStoreSession session, PosStoreRequestInfo requestInfo)
 {
     try
     {
         var jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings();
         jsonSerializerSettings.Converters.Add(new BarcodeConverter());
         var shoppingcart = requestInfo.Read <ShoppingCart>(jsonSerializerSettings);
         if (shoppingcart != null)
         {
             var    shoppingCartCache = new ShoppingCartCache();
             string key = KeyFactory.MachineKeyFactory(shoppingcart.MachineInformation.CompanyId, shoppingcart.MachineInformation.StoreId, shoppingcart.MachineInformation.MachineSn, shoppingcart.MachineInformation.DeviceSn);
             shoppingCartCache.Set(key, shoppingcart);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }