Esempio n. 1
0
        public IStockItem GetStockItem(string stockItemName)
        {
            IStockItem result = null;

            using (var Conn = new SqlConnection(_connectionString))
            {
                using (var Cmd = new SqlCommand($"SELECT StockItemID, StockItemName from Warehouse.StockItems where StockItemName = @StockItemName", Conn))
                {
                    Cmd.Parameters.Add("@StockItemName", SqlDbType.NVarChar);
                    Cmd.Parameters["@StockItemName"].Value = stockItemName;
                    // Open SQL Connection
                    Conn.Open();

                    // Execute SQL Command
                    SqlDataReader rdr = Cmd.ExecuteReader();

                    // Loop through the results and add to list
                    while (rdr.Read())
                    {
                        result               = new StockItem();
                        result.ID            = rdr.GetInt32(0);
                        result.StockItemName = rdr.GetString(1);
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
 public Buyer(string itemId, int maximumPrice, int numberToBuy, IStockItem stockItem)
 {
     _numberToBuy  = numberToBuy;
     _maximumPrice = maximumPrice;
     _stockItem    = stockItem;
     Snapshot      = BuyerSnapshot.Joining(itemId);
 }
Esempio n. 3
0
        public void SaveItemToStock(IStockItem stockItem)
        {
            bool itemExistInTable = false;

            if (!itemExistInTable)
            {
                try
                {
                    string      specifier        = "F";
                    CultureInfo culture          = CultureInfo.CreateSpecificCulture("en-CA");
                    string      netPriceString   = (stockItem.Net_Price.ToString(specifier, culture));
                    string      quantityString   = (stockItem.StockQuantity.ToString(specifier, culture));
                    string      grossPriceString = (stockItem.Gross_Price.ToString(specifier, culture));
                    // Displays:    00.00

                    sqlConnection.Open();
                    sqlQuery = string.Format("INSERT INTO Shopper2019StockTable (code, name, quantity, unitOfMeasurement, netPrice, vatTax, grossPrice)" +
                                             "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                                             stockItem.Code, stockItem.Name, quantityString, stockItem.UnitOfMeasurements, netPriceString, stockItem.VatValue, grossPriceString);
                    sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Nieoczekiwany błąd, szczegóły : " + ex.ToString());
                }
            }
        }
        public decimal CalculateDiscountToApply(IStockItem stockItem, int quantity)
        {
            var fullPriceForQualifyingQuantity = stockItem.UnitPrice * _qualifyingQuantity;
            var discountForQualifyingQuantity  = fullPriceForQualifyingQuantity * (_percentageDiscount / 100);
            var numberOfTimesToApplyDiscount   = quantity / _qualifyingQuantity;

            return(discountForQualifyingQuantity * numberOfTimesToApplyDiscount);
        }
Esempio n. 5
0
        public void StartBuying(string newItemId, int newItemMaximumPrice, int numberToBuy)
        {
            IStockItem stockItem = _warehouse.GetStockItemFor(newItemId);
            var        buyer     = new Buyer(newItemId, newItemMaximumPrice, numberToBuy, stockItem);

            stockItem.AddStockEventListener(buyer);
            _portfolio.AddBuyer(buyer);
        }
        public void AddItemToBasket(string stockItemSku)
        {
            IBasket    basket = _basketRepository.GetCurrentBasket();
            IStockItem item   = _stockItemRepository.GetItem(stockItemSku);

            basket.AddItem(item);
            _basketRepository.Persist(basket);
        }
Esempio n. 7
0
 public void AddItem(IStockItem item)
 {
     if (_lineItems.ContainsKey(item.SKU))
     {
         _lineItems[item.SKU].Quantity++;
     }
     else
     {
         _lineItems[item.SKU] = new BasketLineItem(item);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Adds an item to the basket
        /// </summary>
        /// <param name="item">An item to add to the basket</param>
        public void AddItemToBasket(IStockItem item)
        {
            if (!Items.TryGetValue(item.ProductCode, out Stack <IStockItem> value))
            {
                var newStack = new Stack <IStockItem>();
                newStack.Push(item);
                Items.Add(item.ProductCode, newStack);
            }
            else
            {
                value.Push(item);
            }

            recalculateTotel = true;
        }
Esempio n. 9
0
        public IStockItem SetValuesToStockItem(string code, string name, decimal quantity, string unitOfMeasurements, decimal netPrice, int vatTaxValue, decimal grossPrice) // grossPrice autoObliczany
        {
            stockItem = container.Resolve <IStockItem>();

            stockItem.Code               = code;
            stockItem.Name               = name;
            stockItem.StockQuantity      = quantity;
            stockItem.UnitOfMeasurements = unitOfMeasurements;
            stockItem.Net_Price          = netPrice;
            stockItem.VatValue           = vatTaxValue;
            //brutto autoobliczane
            stockItem.Gross_Price      = stockItem.Gross_Price = GrossPriceProcessor.GrossPriceCalculate(stockItem.Net_Price, stockItem.VatValue);
            stockItem.TotalGross_Price = TotalPriceValueProcessor.CalculateTotalPriceValue(stockItem.StockQuantity, stockItem.Gross_Price);

            return(stockItem);
        }
Esempio n. 10
0
        public void EditStockItemListElement(List <IStockItem> listName, IStockItem stockItem, int index)
        {
            try
            {
                var item = StockItemList.ElementAt(index);

                item.Code               = stockItem.Code;
                item.Name               = stockItem.Name;
                item.StockQuantity      = stockItem.StockQuantity;
                item.UnitOfMeasurements = stockItem.UnitOfMeasurements;
                item.Net_Price          = stockItem.Net_Price;
                item.VatValue           = stockItem.VatValue;
                item.Gross_Price        = stockItem.Gross_Price;
            }
            catch (Exception)
            {
                MessageBox.Show("Lista jest pusta!");
            }
        }
Esempio n. 11
0
        public ListViewItem LoadStockItemsToStockListView(IStockItem stockItem, int counter)
        {
            if (stockItem != null)
            {
                ListViewItem stockList = new ListViewItem(counter.ToString());

                stockList.SubItems.Add(stockItem.Code);
                stockList.SubItems.Add(stockItem.Name);
                stockList.SubItems.Add(stockItem.StockQuantity.ToString("F"));
                stockList.SubItems.Add(stockItem.Net_Price.ToString("F"));
                stockList.SubItems.Add(stockItem.VatValue.ToString());
                stockList.SubItems.Add(stockItem.Gross_Price.ToString("F"));

                return(stockList);
            }
            else
            {
                return(null);
            }
        }
 public StockItemController(IStockItem stockItem)
 {
     _stockItem = stockItem;
 }
Esempio n. 13
0
 private static void AssertLineQuantity(Basket basket, IStockItem stockItem, int quantity)
 {
     Assert.That(basket.LineItems.Where(l => l.StockItem.SKU == stockItem.SKU).Count(), Is.EqualTo(1));
     Assert.That(basket.LineItems.Single(l => l.StockItem.SKU == stockItem.SKU).Quantity, Is.EqualTo(quantity));
 }
Esempio n. 14
0
 public void AddItemToStockList(IStockItem item)
 {
     StockItemList.Add(item);
 }
Esempio n. 15
0
 public BasketLineItem(IStockItem item)
 {
     StockItem = item;
 }
Esempio n. 16
0
 public void Setup()
 {
     _mockStockItemA = GenerateMockStockItem("MockSkuA", 10);
     _mockStockItemB = GenerateMockStockItem("MockSkuB", 3);
 }
 public static void SetNewStockRoom(IStockItem aStockItem)
 {
     newStockItem = aStockItem;
 }