public void removeStoreDiscount(int discountID, Store store) { DiscountComponent d = DBDiscount.getInstance().getDiscountByID(discountID); DBDiscount.getInstance().removeDiscount(d); store.removeDiscount(discountID); }
public void addReliantDiscountTotalAmount(double percentage, String duration, int amount) { ReliantDiscount r = new ReliantDiscount(percentage, duration, amount, store.getStoreID()); DBDiscount.getInstance().addDiscount(r); store.addDiscount(r); }
public void addStoreVisibleDiscount(double percentage, string duration) { VisibleDiscount v = new VisibleDiscount(percentage, duration, "StoreVisibleDiscount", store.getStoreID()); DBDiscount.getInstance().addDiscount(v); store.addDiscount(v); }
public static DBDiscount getInstance() { if (instance == null) { instance = new DBDiscount(); } return(instance); }
public void addReliantDiscountSameProduct(double percentage, String duration, int numOfProducts, Product product) { ReliantDiscount r = new ReliantDiscount(percentage, duration, numOfProducts, product, store.getStoreID()); DBDiscount.getInstance().addDiscount(r); store.addDiscount(r); product.setReliantDiscountSameProduct(r); }
public DiscountComponent(double percentage, string duration, int storeId) { this.id = DBDiscount.getInstance().getNextDiscountID(); this.percentage = percentage; this.duration = stringToDate(duration); this.complexCondition = false; this.storeId = storeId; this.isPartOfComplex = false; }
public void addProductVisibleDiscount(Product product, double percentage, string duration) { Store store = product.getStore(); VisibleDiscount discount = new VisibleDiscount(percentage, duration, "ProductVisibleDiscount", store.getStoreID()); store.addDiscount(discount); discount.setProduct(product); product.setDiscount(discount); DBDiscount.getInstance().addDiscount(discount); }
public void init() { try { //SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { connection.Open(); var products = connection.Query <Product>("SELECT * FROM [dbo].[Product]"); if (products.Count() == 0) { connection.Close(); return; } foreach (Product product in products) { // if(product.discountID != -1) // product.discount = DBDiscount.getInstance().getDiscount(product.discountID); productList.AddFirst(product); Discount d = DBDiscount.getInstance().getProductDiscount(product.getStore().getStoreID(), product.getProductID()); if (d != null) { if (d is VisibleDiscount) { VisibleDiscount v = (VisibleDiscount)d; product.setDiscount(v); } if (d is ReliantDiscount) { ReliantDiscount r = (ReliantDiscount)d; product.setReliantDiscountSameProduct(r); } } if (product.getProductID() > nextProductID) { nextProductID = product.getProductID(); } } connection.Close(); } } catch (Exception e) { connection.Close(); throw e; } nextProductID++; }
public static void initWitOutRead() { DBProduct.getInstance().init(); DBSession.getInstance().init(); DBDiscount.getInstance().init(); DBSubscribedUser.getInstance().init(); DBStore.getInstance().init(); DBSubscribedUser.getInstance().updateShoppingBasket(); DBNotifications.getInstance().init(); PaymentService.getInstance().connectToSystem(); DeliveryService.getInstance().connectToSystem(); ConsistencySystem.getInstance().connectToSystem(); NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance()); }
public void addComplexDiscount(List <DiscountComponent> list, string type, double percentage, string duration) { DiscountComposite composite = new DiscountComposite(list, type, percentage, duration, store.getStoreID()); foreach (DiscountComponent d in list) { store.removeDiscoutFromList(d.getId()); DBDiscount.getInstance().setIsPartOfComplex(d.getId(), true); d.setIsPartOfComplex(true); } DBDiscount.getInstance().addDiscount(composite); store.addDiscount(composite); //DBDiscount.getInstance().addDiscount(composite); }
public static void initTestWitOutRead() { testsMode = true; SystemLogger.configureLogs(); DBProduct.getInstance().initTests(); DBSession.getInstance().initTests(); DBDiscount.getInstance().initTests(); DBSubscribedUser.getInstance().initTests(); DBStore.getInstance().initTests(); DBNotifications.getInstance().initTests(); PaymentService.getInstance().connectToSystem(); DeliveryService.getInstance().connectToSystem(); ConsistencySystem.getInstance().connectToSystem(); NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance()); DomainBridge.getInstance().addAdmin("u1", "123"); }
public Store getStore(int storeId) { foreach (Store s in stores) { if (s.getStoreID() == storeId) { return(s); } } ///////////////////////////////////////////////////// try { // SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { connection.Open(); LinkedList <Store> newStores = new LinkedList <Store>(); var StoreResult = connection.Query <StoreEntry>("SELECT * FROM [dbo].[Stores] WHERE storeId=@storeId ", new { storeId = storeId }); var StoreRoleResult = connection.Query <StoreRoleEntry>("SELECT * FROM [dbo].[StoreRoles] WHERE storeId=@storeId ", new { storeId = storeId }); var ContractResult = connection.Query <Contract>("SELECT * FROM [dbo].[Contracts] WHERE storeId = @storeId", new { storeId = storeId }); var pendingResult = connection.Query <string>("SELECT userName FROM [dbo].[PendingOwners] WHERE storeId = @storeId", new { storeId = storeId }).AsList(); var policyEntries = connection.Query <PolicyEntry>("SELECT * FROM [dbo].[PurchasePolicy] WHERE storeID=@storeId", new { storeID = storeId }); connection.Close(); StoreEntry se = StoreResult.ElementAt(0); Store s = new Store(se.getStoreId(), se.getName(), se.getDescription()); foreach (Contract c in ContractResult) { s.getContracts().AddFirst(c); } foreach (string pending in pendingResult) { s.getPending().AddFirst(pending); } LinkedList <Product> lst = DBProduct.getInstance().getAllProducts(); foreach (Product p in lst) { if (p.getStoreID() == s.getStoreID()) { s.addProduct(p); } } s.setPolicyList(parsePolicy(policyEntries)); foreach (StoreRoleEntry element in StoreRoleResult) { if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 1) { SubscribedUser appointedBy = null; try { appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy()); } catch (Exception) { } SubscribedUser user = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName()); StoreOwner so = new StoreOwner(appointedBy, user, s); s.addStoreRoleFromInitOwner(so); storeRole.AddLast(so); } else if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 0) { SubscribedUser appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy()); SubscribedUser user = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName()); Permissions p = new Permissions(false, false, false); if (element.getEditDiscount() == 1) { p.setEditDiscount(true); } if (element.getEditPolicy() == 1) { p.setEditPolicy(true); } if (element.getEditProduct() == 1) { p.setEditProduct(true); } StoreManager sm = new StoreManager(appointedBy, s, user, p); s.addStoreRoleFromInitManager(sm); storeRole.AddLast(sm); } } stores.AddLast(s); LinkedList <DiscountComponent> discountList = DBDiscount.getInstance().getStoreDiscountsList(storeId); s.setDiscountList(discountList); return(s); } } catch (Exception e) { connection.Close(); SystemLogger.getErrorLog().Error("Connection error in function getStore in DB Store store id " + storeId); throw new ConnectionException(); } /////////////////////////////////////////////////// }
public DiscountComponent() { this.id = DBDiscount.getNextDiscountID(); }