private async Task ExecuteLoadShoppingItemsCommand()
        {
            IsBusy = true;

            try
            {
                ShoppingItems.Clear();
                System.Collections.Generic.IEnumerable <ShoppingItem> items;
                if (selectedMode == Mode.Modify)
                {
                    items = await ShoppingListDataStore.GetShoppingItemsAsync(shoppingListId);
                }
                else
                {
                    items = await ShoppingListDataStore.GetShoppingItemsOrderBySortKeyAsync(shoppingListId);
                }
                foreach (ShoppingItem item in items)
                {
                    ShoppingItems.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #2
0
        public void AddItem(string itemName, int quantity)
        {
            if (string.IsNullOrEmpty(itemName) || quantity == 0)
            {
                return;
            }

            double unitPrice = 0;

            if (_pricelist.ContainsKey(itemName.ToLower()))
            {
                unitPrice = _pricelist[itemName.ToLower()];
            }



            ShoppingItems.Add(new ShoppingItem()
            {
                Name      = itemName,
                Quantity  = quantity,
                UnitPrice = unitPrice
            });
        }
        private void TimerOnTick(object sender, EventArgs eventArgs)
        {
            string code = TextBoxBarcode.Text;

            _timer.Stop();
            TextBoxBarcode.Clear();

            WarehouseItem warehouseItemDb;

            try
            {
                warehouseItemDb = DB.GetWarehouseItemById(code);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errore durante la connessione al Database: " + Environment.NewLine + ex.Message,
                                "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (warehouseItemDb == null)
            {
                //L'elemento con quel codice non esiste nel DB

                MessageBoxResult msgBoxResult =
                    MessageBox.Show("Elemento con Id " + code + " non registrato in Magazzino." + Environment.NewLine +
                                    "Desidera registrarlo?", "Informazione", MessageBoxButton.YesNo,
                                    MessageBoxImage.Information, MessageBoxResult.Yes);

                if (msgBoxResult == MessageBoxResult.Yes)
                {
                    AddElementWindow addElementWindow = new AddElementWindow(code)
                    {
                        Owner = this
                    };
                    addElementWindow.ShowDialog();
                    RefreshWarehouse();
                }
            }
            else
            {
                //L'elemento con quel codice ESISTE nel DB
                //Ne controllo la quantità presente

                WarehouseItem selectedWareHouseItem = ShoppingItems.FirstOrDefault(x => x.Id == warehouseItemDb.Id);

                if (selectedWareHouseItem == null)
                {
                    if (warehouseItemDb.Quantity <= 0)
                    {
                        MessageBox.Show("Elemento " + warehouseItemDb.Name + " (ID: " + warehouseItemDb.Id +
                                        ") non disponibile in Magazzino per la quantità desiderata.");
                    }
                    else
                    {
                        warehouseItemDb.Quantity = 1;
                        ShoppingItems.Add(warehouseItemDb);
                        TotalPrice += warehouseItemDb.Price;
                    }
                }
                else
                {
                    if (warehouseItemDb.Quantity < selectedWareHouseItem.Quantity + 1)
                    {
                        MessageBox.Show("Elemento " + warehouseItemDb.Name + " (ID: " + warehouseItemDb.Id +
                                        ") non disponibile in Magazzino per la quantità desiderata.");
                    }
                    else
                    {
                        selectedWareHouseItem.Quantity++;
                        TotalPrice += warehouseItemDb.Price;
                    }
                }
            }
        }