private void deleteItemHandler()
 {
     try
     {
         DisplayItem selectedItem = ListOfItems[ListOfItems.CurrentIndex];
         _db.TableItem.DeleteItem((long)selectedItem.ID);
         ListOfItems.RemoveAt(ListOfItems.CurrentIndex);
         _messageBox.OpenMessageBox($"{selectedItem.VareNavn} blev slettet fra databasen");
     }
     catch (Exception exception)
     {
         _messageBox.OpenMessageBox("Noget gik galt! Check Debug for fejlmeddelelse");
         Debug.WriteLine(exception.Message);
     }
 }
        public StoreSectionViewModel(DatabaseService database, IMessageBox mb)
        {
            try
            {
                _db         = database;
                _messageBox = mb;
            }
            catch (Exception e)
            {
                _messageBox.OpenMessageBox("Noget gik galt! Check Debug for fejlmeddelelse");
                Debug.WriteLine(e.Message);
            }
            ShapeCollection = new ObservableCollection <SectionShape>();
            ListOfItems     = new DisplayItems();

            WindowLoadedCommand = new RelayCommand(windowLoadedHandler);
            SelectCurrentStoreSectionCommand = new RelayCommand <SectionShape>(selectCurrentStoreSectionHandler);
            DeleteStoreSectionCommand        = new RelayCommand(deleteStoreSectionHandler, () => _selectedStoreSection != 0);
            EditStoreSectionCommand          = new RelayCommand(editStoreSectionHandler, () => _selectedStoreSection != 0);
            SearchItemsCommand              = new RelayCommand(searchItemsHandler);
            AddItemToSectionCommand         = new RelayCommand(addItemToSectionHandler, () => _selectedStoreSection != 0);
            RemoveItemFromSectionCommand    = new RelayCommand(removeItemFromSectionHandler, () => _selectedStoreSection != 0);
            AddStoreSectionCommand          = new RelayCommand(AddStoreSectionDialogOkButtonHandler, () => CheckValidName(NewlyCreatedStoreSectionName));
            CancelStoreSectionCommand       = new RelayCommand(AddStoreSectionDialogCancelButtonHandler);
            EditStoreSectionDialogOKCommand = new RelayCommand(editStoreSectionButtonOKHandler, () => CheckValidName(NewSectionName));
        }
Ejemplo n.º 3
0
 private void editItemGroupHandler()
 {
     try
     {
         _db.TableItemGroup.UpdateItemGroup(PreviousItemGroupName, ItemGroupName);
         ItemGroup temp = new ItemGroup(ItemGroupName, ListOfItemGroups[ListOfItemGroups.CurrentIndex].ItemGroupParentID, ListOfItemGroups[ListOfItemGroups.CurrentIndex].ItemGroupID);
         ListOfItemGroups.RemoveAt(ListOfItemGroups.CurrentIndex);
         ListOfItemGroups.Add(temp);
         _messageBox.OpenMessageBox($"Varegruppens navn er blevet opdateret til {ItemGroupName}");
         ItemGroupName = "";
         ComboBoxIndex = -1;
     }
     catch (Exception e)
     {
         _messageBox.OpenMessageBox("Noget gik galt! Check debug for fejlmeddelelse");
         Debug.WriteLine(e.Message);
     }
 }
        public static void SearchItem(IDatabaseService db, string searchstring, DisplayItems listofItems, IMessageBox messageBox)
        {
            try
            {
                var searchList = db.TableItem.SearchItems(searchstring);
                listofItems.Clear();
                listofItems.Populate(searchList);

                if (searchList.Count == 0)
                {
                    messageBox.OpenMessageBox($"Fandt ingen varer med navnet {searchstring}");
                }
            }
            catch (Exception exception)
            {
                messageBox.OpenMessageBox("Noget gik galt! Check Debug for fejlmeddelelse");
                Debug.WriteLine(exception.Message);
            }
        }
        private void addItemToSectionHandler()
        {
            foreach (DisplayItem item in SelectedItemsList)
            {
                int findValue = ItemsInSectionList.FindIndex(currentItem => currentItem.ItemID == item.ID);

                if (findValue == -1)
                {
                    _db.TableItemSectionPlacement.PlaceItem(item.ID, _selectedStoreSection);
                }
                else
                {
                    _messageBox.OpenMessageBox("Varen " + item.VareNavn + " findes i sektionen i forvejen");
                }
            }

            ItemsInSectionList = _db.TableItemSectionPlacement.ListItemsInSection(_selectedStoreSection);
        }
        public ItemViewModel(IDatabaseService db, IMessageBox mb)
        {
            try
            {
                _db           = db;
                _messageBox   = mb;
                ListOfItems   = new DisplayItems();
                ComboBoxIndex = -1;
                bool dummybool = false;
                DeleteItemCommand = new RelayCommand(deleteItemHandler, () => ListOfItems.CurrentIndex >= 0);
                CreateItemCommand = new RelayCommand(addItemHandler, () => ComboBoxIndex != -1);
                EditItemCommand   = new RelayCommand(() => MessageBox.Show("Not Implemented"), () => dummybool == true);
                SearchItemCommand = new RelayCommand(searchItemHandler, () => dummybool == false);

                ListOfItems.Populate(_db.TableItem.SearchItems(""));
            }
            catch (Exception e)
            {
                _messageBox.OpenMessageBox("Noget gik galt! Check Debug for fejlmeddelelse");
                Debug.WriteLine(e.Message);
            }
        }