private async void DeleteSelectedMenuItems(object sender, RoutedEventArgs e) { bool continueSafely = await ConfirmDeletion(); if (continueSafely) { int successes = 0; foreach (object selected in MenuItemSearchResults.SelectedItems) { bool isSuccessful = MenuDBHelper.DeleteMenuItem((MenuItem)selected); if (isSuccessful) { successes++; } } if (successes == MenuItemSearchResults.SelectedItems.Count) { string messageText = resourceLoader.GetString("Message_DatabaseDeleteSuccessful"); MessageDialog successMessage = new MessageDialog(messageText); await successMessage.ShowAsync(); } else { string messageText = resourceLoader.GetString("Message_DatabaseDeleteFailed"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } SearchMenuItems(); } }
private void SearchMenus() { List <Menu> searchResults = MenuDBHelper.SearchMenus(InputMenuNameSearch_Box.Text, InputMenuLocationSearch_Box.Text); MenuSearchResults.ItemsSource = searchResults; MenuResultsCount.Text = resourceLoader.GetString("Heading_Results") + searchResults.Count; MenuResultsCount.Visibility = Visibility.Visible; }
private void SearchMenuItems() { List <MenuItem> searchResults = MenuDBHelper.SearchMenuItems(InputMenuItemSearch_Box.Text, GetTypes(), CostMin.Text, CostMax.Text); MenuItemSearchResults.ItemsSource = searchResults; MenuItemResultsCount.Text = resourceLoader.GetString("Heading_Results") + searchResults.Count; MenuItemResultsCount.Visibility = Visibility.Visible; }
public MenuPage() { InitializeComponent(); currentMenu.Name = newMenuName; currentMenu.Location = newMenuLocation; unsavedChanges = false; OptionsAllCheckBox.IsChecked = true; MenuSearchResults.ItemsSource = MenuDBHelper.SearchMenus(string.Empty, string.Empty); MenuItemSearchResults.ItemsSource = new List <MenuItem>(); // Give it a blank list to get the headers to show. RefreshCurrentMenuInPage(); }
private async void EditMenuItem(object sender, RoutedEventArgs e) { MenuItem editingItem = (MenuItem)MenuItemSearchResults.SelectedItem; EditMenuItem editDialog = new EditMenuItem { NameInput = editingItem.Name, CostInput = editingItem.Cost.ToString(), DescriptionInput = editingItem.Description, TypeInput = editingItem.Type }; await editDialog.ShowAsync(); if (editDialog.MadeChanges) { if (MenuItem.IsMenuItemValid(editDialog.NameInput, editDialog.CostInput, editDialog.TypeInput)) { editingItem.Cost = Convert.ToDecimal(editDialog.CostInput); editingItem.Description = editDialog.DescriptionInput; editingItem.Type = editDialog.TypeInput; bool successfulUpdate = MenuDBHelper.UpdateMenuItem(editingItem); if (successfulUpdate) { string messageText = resourceLoader.GetString("Message_DatabaseUpdateSuccessful"); MessageDialog successMessage = new MessageDialog(messageText); await successMessage.ShowAsync(); SearchMenuItems(); } else { string messageText = resourceLoader.GetString("Message_DatabaseUpdateFailed"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } } else { string messageText = resourceLoader.GetString("Errors_MenuItemInvalid"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } } }
private async void ShowCreateMenuItemDialog(object sender, RoutedEventArgs e) { CreateMenuItem createDialog = new CreateMenuItem(); await createDialog.ShowAsync(); string itemName = createDialog.NameInput; string itemDescription = createDialog.DescriptionInput; string itemCost = createDialog.CostInput; string itemType = createDialog.TypeInput.ToUpper(); if (MenuItem.IsMenuItemValid(itemName, itemCost, itemType)) { MenuItem newItem = new MenuItem(itemName, itemDescription, itemCost, itemType); bool successfulSave = false; if (string.IsNullOrEmpty(MenuDBHelper.SearchMenuItem(newItem).Name)) // check if item already exists in database { successfulSave = MenuDBHelper.AddMenuItem(newItem); } if (successfulSave) { string messageText = resourceLoader.GetString("Message_DatabaseSaveSuccessful"); MessageDialog successMessage = new MessageDialog(messageText); await successMessage.ShowAsync(); } else { string messageText = resourceLoader.GetString("Message_DatabaseSaveFailed"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } } else { string messageText = resourceLoader.GetString("Errors_MenuItemInvalid"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } }
private async void SaveMenuToDatabase(object sender, RoutedEventArgs e) { if (Menu.IsMenuValid(currentMenu)) { bool successfulSave; int menuCount = MenuDBHelper.SearchMenus(currentMenu.Name, string.Empty).Count; if (menuCount == 0) // Menu with this name doesn't exist yet, so we add it { successfulSave = MenuDBHelper.AddMenu(currentMenu); unsavedChanges = !successfulSave; } else // Menu with this name exists, so we update it instead of adding since names are unique { successfulSave = MenuDBHelper.UpdateMenu(currentMenu); unsavedChanges = !successfulSave; } unsavedChanges = !successfulSave; if (successfulSave) { string messageText = resourceLoader.GetString("Message_DatabaseSaveSuccessful"); MessageDialog successMessage = new MessageDialog(messageText); await successMessage.ShowAsync(); } else { string messageText = resourceLoader.GetString("Message_DatabaseSaveFailed"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } } else { string messageText = resourceLoader.GetString("Errors_MenuInvalid"); MessageDialog failureMessage = new MessageDialog(messageText); await failureMessage.ShowAsync(); } }