Beispiel #1
0
        /// <summary>
        /// Method that the background worker executes
        /// </summary>
        /// <param name="sender">object sender</param>
        /// <param name="e">do work event</param>
        private void WorkerOnDoWork(object sender, DoWorkEventArgs e)
        {
            ProgressBarVisibility = Visibility.Visible;
            ButtonVisibility      = Visibility.Collapsed;
            Random rng = new Random();

            for (int i = 1; i < 22; i++)
            {
                Thread.Sleep(100);

                if (i == 21)
                {
                    // 100% if all passed
                    // Notify about an item being purchased
                    storagedata.Notify(ShoppingBasket);
                    StorageList = storagedata.GetAllSelectedIngredientStorageItems(LoggedGuest.ID).ToList();

                    // Write to file the changes
                    ReadWriteToFile rwf = new ReadWriteToFile();
                    rwf.WriteShoppingFile(ShoppingBasket);

                    // Delete item from the shopping basket after 2 seconds
                    shoppingData.DeleteShoppingBasket(ShoppingBasket.ShoppingBasketID);
                    ShoppingBasketList = shoppingData.GetAllSelectedShoppingBasketItems(LoggedGuest.ID).ToList();
                    // allShoppingListWindow.DataGridShoppingList.UnselectAll();

                    bgWorker.ReportProgress(100);
                }

                bgWorker.ReportProgress(100 / 20 * i);
            }

            _isRunning = false;

            // Cancel the asynchronous operation if still in progress
            if (bgWorker.IsBusy)
            {
                bgWorker.CancelAsync();
            }
        }
        /// <summary>
        /// Method for deleting the selected item from the list
        /// </summary>
        public void DeleteExecute()
        {
            tblIngredient ing = ingrediantsData.FindIngredient(ItemAmount.IngredientID);

            try
            {
                MessageBoxResult dialogDelete = Xceed.Wpf.Toolkit.MessageBox.Show($"Da li zelite da obrisete ovaj sastojak iz liste?\n\nSastojak: {ing.IngredientName}", "Obrisi sastojak", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                if (dialogDelete == MessageBoxResult.Yes)
                {
                    if (ItemAmount != null)
                    {
                        shoppingData.DeleteShoppingBasket(ItemAmount.ShoppingBasketID);
                        IngrediantAmountList = shoppingData.GetAllSelectedShoppingBasketItems(LoggedGuest.ID);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxResult dialog = Xceed.Wpf.Toolkit.MessageBox.Show("Trenutno je nemoguce obrisati sastojak..." + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }