public static SuspendList Factory(string storeId, string machineSn, int companyId, string path) { SuspendList result = null; try { var fileName = string.Format(FileFormat, storeId, machineSn, companyId); var filePath = Path.Combine(path, fileName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(filePath)) { using (StreamReader sr = new StreamReader(filePath)) { JsonSerializer serializer = new JsonSerializer(); JsonReader reader = new JsonTextReader(sr); result = serializer.Deserialize <SuspendList>(reader); } } } catch (Exception) { } if (result == null) { result = new SuspendList(storeId, machineSn); } return(result); }
public static IEnumerable <IBarcode> Read(ShoppingCart cart, string id) { try { List <IBarcode> result = null; var fileName = string.Format("SaleDetails{0}.JSON", id); var filePath = Path.Combine(MachinesSettings.CachePath, fileName); if (File.Exists(filePath)) { using (StreamReader sr = new StreamReader(filePath)) { var json = sr.ReadToEnd(); result = JsonConvert.DeserializeObject <List <IBarcode> >(json, new BarcodeConverter()); } } if (result != null && result.Count() > 0) { cart.Clear(); cart.OrderList = result; cart.ResetProduct(SaleStatus.Normal); } var suspendList = SuspendList.Factory(cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId, MachinesSettings.CachePath); suspendList.RemoveAll(o => o.Id == id); suspendList.Save(MachinesSettings.CachePath, cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId); File.Delete(filePath); return(result); } catch (Exception ex) { throw; } }
public static SuspendList Remove(ShoppingCart cart, string id) { try { var suspendList = SuspendList.Factory(cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId, MachinesSettings.CachePath); var fileName = string.Format("SaleDetails{0}.JSON", id); var filePath = Path.Combine(MachinesSettings.CachePath, fileName); suspendList.RemoveAll(o => o.Id == id); suspendList.Save(MachinesSettings.CachePath, cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId); File.Delete(filePath); return(suspendList); } catch (Exception ex) { throw; } }
public static void Suspend(ShoppingCart cart) { try { var statistics = cart.GetSaleStatistics(); var details = new SuspendDetails() { Id = KeyFactory.SuspendKeyFactory(cart.MachineInformation.CompanyId, cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.DeviceSn), Amount = statistics.Receivable, Count = statistics.Num, SuspendDate = DateTime.Now, OrderSN = cart.OrderSN }; var suspendList = SuspendList.Factory(cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId, MachinesSettings.CachePath); suspendList.Add(details); suspendList.Save(MachinesSettings.CachePath, cart.MachineInformation.StoreId, cart.MachineInformation.MachineSn, cart.MachineInformation.CompanyId); Save(cart, MachinesSettings.CachePath, details.Id); cart.Clear(); } catch (Exception ex) { throw; } }