private void SelectButton_Click(object sender, RoutedEventArgs e) { //Actually creating new list item ShoppingListItem newListItem = new ShoppingListItem() { ItemName = item.ItemName, List = (sender as RadioButton).DataContext as ShoppingList, Priority = item.Priority, Price = item.Price, Quantity = item.Quantity, Units = item.Units, Tag = item.Tag, Status = item.Status, Note = item.Note, }; App.ViewModel.MoveItemToAnotherList(list, (sender as RadioButton).DataContext as ShoppingList, item); VisualStateManager.GoToState(this, "CollapsedVisualState", true); }
/// <summary> /// Update item quantity /// </summary> /// <param name="item">Instance of item to be updated</param> /// <param name="newQuantity">New item quantity</param> public void UpdateItemQuantity(ShoppingListItem item, int? newQuantity) { float oldlPrice = item.Price; int? oldQuantity = item.Quantity; //Converting old item price to new (with corresponding item quantity) if (oldQuantity != null && oldQuantity != 0 && oldlPrice != 0.0) oldlPrice = oldlPrice / (float)oldQuantity; if (newQuantity != null) item.Price = oldlPrice * (float)newQuantity; else item.Price = oldlPrice; item.Quantity = newQuantity; item.ModifiedDate = DateTime.Now; item.List.ModifiedDate = DateTime.Now; item.List.SortItemsCollection(); listDB.SubmitChanges(); }
/// <summary> /// Update list item status /// </summary> /// <param name="item">Instance of list item to be updated</param> /// <param name="status">New list item status</param> public void UpdateItemStatus(ShoppingListItem item, bool status) { item.Status = status ? 1 : 0; item.ModifiedDate = DateTime.Now; item.List.ModifiedDate = DateTime.Now; //After updating list item status it's necessary to sort items collection item.List.SortItemsCollection(); //Submit all changes to database listDB.SubmitChanges(); }
/// <summary> /// Set current item status to 'Picked' /// </summary> /// <param name="item">Instance of item to be picked</param> public void PickItem(ShoppingListItem item) { item.Status = 2; listDB.SubmitChanges(); item.List.FilterItemsCollection(); }
/// <summary> /// Update item priority /// </summary> /// <param name="item">Instance of item to be updated</param> /// <param name="priority">New item priority</param> public void UpdateItemPriority(ShoppingListItem item, int newPriority) { item.Priority = newPriority; item.ModifiedDate = DateTime.Now; item.List.ModifiedDate = DateTime.Now; item.List.SortItemsCollection(); listDB.SubmitChanges(); }
/// <summary> /// Delete item from list permanently /// </summary> /// <param name="delItem">Item to be deleted permanently</param> public void DeleteListItem(ShoppingListItem delItem) { IEnumerable<ShoppingListItemsStores> itemsStores = listDB.ItemsStores.Where(i => i.ItemID == delItem.ItemID); if (itemsStores != null) listDB.ItemsStores.DeleteAllOnSubmit(itemsStores); delItem.List.ModifiedDate = DateTime.Now; delItem.List.ListItems.Remove(delItem); delItem.List.FilterItemsCollection(); listDB.ListItems.DeleteOnSubmit(delItem); listDB.SubmitChanges(); }
/// <summary> /// Move item to another list /// </summary> /// <param name="oldList">Instance of old item list</param> /// <param name="newList">Instance of new item list</param> /// <param name="listItem">Instance of item to be moved</param> public void MoveItemToAnotherList(ShoppingList oldList, ShoppingList newList, ShoppingListItem listItem) { oldList.ListItems.Remove(listItem); oldList.ModifiedDate = DateTime.Now; //Filter list items collection with adding new item to list oldList.FilterItemsCollection(); listItem.List = newList; newList.ListItems.Add(listItem); newList.ModifiedDate = DateTime.Now; //Filter list items collection with adding new item to list newList.FilterItemsCollection(); //Submiting all changes to database //listDB.ListItems.InsertOnSubmit(newListItem); listDB.SubmitChanges(); }
/// <summary> /// Change item status. If status was 'Unchecked' -> change to 'Checked', /// else if status was 'Checked' -> change to 'Unchecked' /// </summary> /// <param name="currentList">Instance of list containing item to be changed</param> /// <param name="item">Instance of item to be updated</param> public void ChangeItemStatus(ShoppingList currentList, ShoppingListItem item) { ShoppingListItem itemInDB = listDB.ListItems.Where(i => i.ItemID == item.ItemID).FirstOrDefault(); if (itemInDB.Status == 0) itemInDB.Status = 1; else itemInDB.Status = 0; itemInDB.ModifiedDate = DateTime.Now; currentList.ModifiedDate = DateTime.Now; currentList.SortItemsCollection(); listDB.SubmitChanges(); }
/// <summary> /// Adding new list item to list /// </summary> /// <param name="currentList">Instance of list to which add new item</param> /// <param name="newListItem">Instance of new item to be added</param> public void AddNewListItem(ShoppingList currentList, ShoppingListItem newListItem) { newListItem.CreatedDate = DateTime.Now; newListItem.ModifiedDate = DateTime.Now; currentList.ListItems.Add(newListItem); currentList.ModifiedDate = DateTime.Now; //Filter list items collection with adding new item to list currentList.FilterItemsCollection(); //Submiting all changes to database listDB.ListItems.InsertOnSubmit(newListItem); listDB.SubmitChanges(); }
/// <summary> /// Activate List Selector Control /// </summary> public void ActivateListSelector(ShoppingList list, ShoppingListItem item) { this.listSelector = new ListSelectorControl(); listSelector.list = list; listSelector.item = item; listSelector.CollapsedVisualState.Storyboard.Completed +=new EventHandler(ListSelect_Completed); //Actually activating the dialog LayoutRoot.Children.Add(listSelector); listSelector.Activate(); ApplicationBar.IsVisible = false; }
//Button 'add' click event handler private void Button_Add_Click(object sender, RoutedEventArgs e) { //Check is the new item name string empty. //If 'no' - creating new list item with this name and adding it //to the current shopping list if (newListItemName.Text.Trim() != String.Empty) { ShoppingList currentList = this.GetCurrentShoppingList(); if (currentList != null) { //Checking whether item is already exist in current list var itemNames = from ShoppingListItem item in currentList.ListItems select item.ItemName; string newItemName = newListItemName.Text.Trim(); //If NOT exist - adding new item if (!itemNames.Contains(newItemName)) { //Actually creating new list item ShoppingListItem newListItem = new ShoppingListItem() { ItemName = newItemName, List = currentList, Priority = null, Price = 0F, Quantity = null, Units = string.Empty, Tag = string.Empty, Status = 0, Note = string.Empty, }; //Adding new list item to the database and updating current list's entries App.ViewModel.AddNewListItem(currentList, newListItem); } //If EXIST - checking/unchecking existing item else { ShoppingListItem exItem = currentList.ListItems.FirstOrDefault(i => i.ItemName == newItemName); if (exItem != null) { App.ViewModel.ChangeItemStatus(currentList, exItem); //Implementation 'ResetQuantity' Application Setting if (App.Settings.ResetQuantitySettings) App.ViewModel.UpdateItemQuantity(exItem, null); } } } //Erasing 'new item's name' TextBox newListItemName.Text = ""; } else MessageBox.Show("Please, input correct list's item name" + "\n\n" + "*Note: Name must not be empty", "Information", MessageBoxButton.OK); }
private void ApplicationBarIconButtonSave_Click(object sender, EventArgs e) { int? quantity = null; if (this.itemQuantity.Text != string.Empty) quantity = Convert.ToInt32(this.itemQuantity.Text); int? priority = null; if (this.itemPriority.Text != string.Empty) priority = Convert.ToInt32(this.itemPriority.Text); float price = 0.00F; price = (float)Convert.ToDouble(this.itemPrice.Text); if (totalItemsPrice.Visibility == System.Windows.Visibility.Visible) price = (float)Convert.ToDouble(this.totalItemsPrice.Text); if (bCopyMode) { ShoppingList list = App.ViewModel.ShoppingLists.Where(l => l.ListID == this.listID).FirstOrDefault(); //Actually creating new list item ShoppingListItem newListItem = new ShoppingListItem() { ItemName = itemName.Text, List = list, Priority = priority, Price = price, Quantity = quantity, Units = itemUnits.Text, Tag = itemTag.Text, Status = 0, Note = itemNote, }; App.ViewModel.AddNewListItem(list, newListItem); } else { App.ViewModel.UpdateListItem(this.listID, this.itemID, this.itemName.Text, quantity, this.itemUnits.Text, price, this.itemTag.Text, priority, this.itemNote); } NavigationService.GoBack(); }