Exemplo n.º 1
0
        private bool Equals(StockListItem obj)
        {
            var isDiscountsEqual = Discount?.Equals(obj.Discount) ?? obj.Discount == null;

            return(systemId.Equals(obj.systemId) &&
                   Quantity == obj.Quantity &&
                   Product.SystemId == obj.Product.SystemId && isDiscountsEqual &&
                   EnumStringConverter.PrintEnum(PurchaseWay).Equals(EnumStringConverter.PrintEnum(obj.PurchaseWay)));
        }
Exemplo n.º 2
0
 public object[] GetDiscountValuesArray()
 {
     return(new object[]
     {
         discountCode,
         EnumStringConverter.PrintEnum(discountType),
         startDate,
         EndDate,
         DiscountAmount,
         Percentages.ToString()
     });
 }
Exemplo n.º 3
0
        private bool Equals(LotteryTicket obj)
        {
            StockSyncher handler = StockSyncher.Instance;

            return(obj.IntervalStart == IntervalStart &&
                   obj.IntervalEnd == IntervalEnd &&
                   obj.LotteryNumber == LotteryNumber &&
                   obj.myID == myID &&
                   EnumStringConverter.PrintEnum(obj.myStatus).Equals(EnumStringConverter.PrintEnum(myStatus)) &&
                   obj.UserID == UserID
                   );
        }
Exemplo n.º 4
0
 public object[] GetTicketValuesArray()
 {
     return(new object[]
     {
         myID,
         LotteryNumber,
         IntervalStart,
         IntervalEnd,
         Cost,
         EnumStringConverter.PrintEnum(myStatus),
         UserID
     });
 }
Exemplo n.º 5
0
 public override string ToString()
 {
     if (EnumStringConverter.PrintEnum(discountType) == EnumStringConverter.PrintEnum(DiscountTypeEnum.Hidden))
     {
         return("type is: hidden");
     }
     if (Percentages)
     {
         return("DiscountAmount: " + DiscountAmount + "%" +
                " Start Date: " + startDate.Date.ToString("d") + " End Date: " + EndDate.Date.ToString("d") + " type is: visible");
     }
     return("DiscountAmount: " + DiscountAmount +
            " Start Date: " + startDate.Date.ToString("d") + " End Date: " + EndDate.Date.ToString("d") + " type is: visible");
 }
Exemplo n.º 6
0
        public LotteryTicket GetLotteryTicket(string ticketid)
        {
            dbConnection.CheckInput(ticketid);
            using (var dbReader = dbConnection.SelectFromTableWithCondition("LotteryTicket", "*", "myID = '" + ticketid + "'"))
            {
                while (dbReader.Read())
                {
                    LotteryTicket lotty = new LotteryTicket(dbReader.GetString(0), dbReader.GetString(1),
                                                            dbReader.GetDouble(2), dbReader.GetDouble(3), dbReader.GetDouble(4), dbReader.GetInt32(6));
                    lotty.myStatus = EnumStringConverter.GetLotteryStatusString(dbReader.GetString(5));
                    return(lotty);
                }
            }

            return(null);
        }
Exemplo n.º 7
0
        public Discount AddDiscountToProduct(string productName, DateTime startDate, DateTime endDate,
                                             int discountAmount, string discountType, bool presenteges)
        {
            try
            {
                MarketLog.Log("StoreCenter", "trying to add discount to product in store");
                MarketLog.Log("StoreCenter", "check if store exists");
                CheckIfStoreExistsAndActiveDiscount();
                MarketLog.Log("StoreCenter", " store exists");
                MarketLog.Log("StoreCenter", " check if has premmision to edit products");
                _storeManager.CanDeclareDiscountPolicy();
                MarketLog.Log("StoreCenter", " has premmission");
                MarketLog.Log("StoreCenter", " check if product name exists in the store " + _storeName);
                Product product = DataLayerInstance.GetProductByNameFromStore(_storeName, productName);
                CheckifProductExistsDiscount(product);
                MarketLog.Log("StoreCenter", "check if dates are OK");
                CheckIfDatesOK(startDate, endDate);
                MarketLog.Log("StoreCenter", "check that discount amount is OK");
                CheckPresentegesAndAmountOK(discountAmount, presenteges, product);
                StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, product.Name);
                MarketLog.Log("StoreCenter", "check that the product don't have another discount");
                CheckHasNoExistsDiscount(stockListItem);
                Discount discount = new Discount(EnumStringConverter.GetdiscountTypeEnumString(discountType), startDate,
                                                 endDate, discountAmount, presenteges);
                stockListItem.Discount = discount;
                DataLayerInstance.AddDiscount(discount);
                DataLayerInstance.EditStockInDatabase(stockListItem);
                MarketLog.Log("StoreCenter", "discount added successfully");
                string[] coupon = { discount.discountCode };
                answer = new StoreAnswer(DiscountStatus.Success, "discount added successfully", coupon);
                return(discount);
            }
            catch (StoreException exe)
            {
                answer = new StoreAnswer((StoreEnum)exe.Status, exe.GetErrorMessage());
            }
            catch (DataException e)
            {
                answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage());
            }
            catch (MarketException)
            {
                answer = new StoreAnswer(StoreEnum.NoPermission, "you have no premmision to do that");
            }

            return(null);
        }
Exemplo n.º 8
0
        public LinkedList <LotteryTicket> GetAllTickets(string systemid)
        {
            dbConnection.CheckInput(systemid);
            LinkedList <LotteryTicket> result = new LinkedList <LotteryTicket>();

            using (var dbReader = dbConnection.SelectFromTableWithCondition("LotteryTicket", "*", "LotteryID = '" + systemid + "'"))
            {
                while (dbReader.Read())
                {
                    LotteryTicket lottery = new LotteryTicket(dbReader.GetString(0), dbReader.GetString(1),
                                                              dbReader.GetDouble(2), dbReader.GetDouble(3), dbReader.GetDouble(4), dbReader.GetInt32(6));
                    lottery.myStatus = EnumStringConverter.GetLotteryStatusString(dbReader.GetString(5));
                    result.AddLast(lottery);
                }
            }
            return(result);
        }
Exemplo n.º 9
0
        public object[] GetStockListItemArray()
        {
            object discountCode = "null";

            if (Discount != null)
            {
                discountCode = Discount.discountCode;
            }

            return(new[]
            {
                systemId,
                Product.SystemId,
                Quantity,
                discountCode,
                EnumStringConverter.PrintEnum(PurchaseWay)
            });
        }
Exemplo n.º 10
0
        public Discount GetDiscount(string discountCode)
        {
            dbConnection.CheckInput(discountCode);
            Discount discount = null;

            using (var discountReader =
                       dbConnection.SelectFromTableWithCondition("Discount", "*", "DiscountCode = '" + discountCode + "'"))
            {
                while (discountReader.Read())
                {
                    discount = new Discount(discountCode,
                                            EnumStringConverter.GetdiscountTypeEnumString(discountReader.GetString(1)),
                                            discountReader.GetDateTime(2)
                                            , discountReader.GetDateTime(3)
                                            , discountReader.GetInt32(4),
                                            Boolean.Parse(discountReader.GetString(5)));
                }
            }

            return(discount);
        }
Exemplo n.º 11
0
        private string GetProductStockInformation(string productID, bool showAll)
        {
            StockListItem stockListItem = storeLogic.GetStockListItembyProductID(productID);

            if (stockListItem == null)
            {
                MarketLog.Log("storeCenter", "product not exists");
                throw new StoreException(StoreEnum.ProductNotFound, "product " + productID + " does not exist in Stock");
            }
            if (stockListItem.PurchaseWay == PurchaseEnum.Lottery && !showAll)
            {
                LotterySaleManagmentTicket managmentTicket =
                    storeLogic.GetLotteryByProductID((productID));
                StockListItem sli = storeLogic.GetStockListItembyProductID(productID);
                if ((managmentTicket.EndDate < MarketYard.MarketDate) ||
                    (managmentTicket.StartDate > MarketYard.MarketDate) ||
                    ((managmentTicket.TotalMoneyPayed == managmentTicket.ProductNormalPrice) && sli.Quantity == 0))
                {
                    return("");
                }
            }
            Discount totalDiscount  = stockListItem.CalcTotalDiscount(_storeName);
            string   discountString = " Discount: {";
            string   product        = stockListItem.Product.ToString();

            if (totalDiscount != null)
            {
                discountString += totalDiscount;
            }
            else
            {
                discountString += "null";
            }
            discountString += "}";
            string purchaseWay = " Purchase Way: " + EnumStringConverter.PrintEnum(stockListItem.PurchaseWay);
            string quanitity   = " Quantity: " + stockListItem.Quantity;
            string result      = product + discountString + purchaseWay + quanitity;

            return(result);
        }
Exemplo n.º 12
0
        public StockListItem GetStockListItembyProductID(string productid)
        {
            dbConnection.CheckInput(productid);
            Product       product       = GetProductID(productid);
            StockListItem stockListItem = null;

            using (var dbReader = dbConnection.SelectFromTableWithCondition("Stock", "*", "ProductSystemID = '" + productid + "'"))
            {
                while (dbReader.Read())
                {
                    stockListItem = new StockListItem(dbReader.GetInt32(2), product,
                                                      GetDiscount(dbReader.GetString(3)), EnumStringConverter.GetPurchaseEnumString(dbReader.GetString(4)),
                                                      dbReader.GetString(0));
                    return(stockListItem);
                }
            }

            return(stockListItem);
        }