/// <summary> /// Method that is called when a new selection is made in the ComboBox. This updates the content of the Input Texts /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listFavoriteItems_SelectedIndexChanged(object sender, EventArgs e) { if (this.listFavoriteItems.SelectedItem != null) { Models.FavouriteItem obj = (Models.FavouriteItem) this.listFavoriteItems.SelectedItem; this.editFavoriteAddressInput.Text = obj.Address; this.editFavoriteNameInput.Text = obj.Name; } }
/// <summary> /// Method that is called when the accessButton is being clicked: redirects the currentPage of the MainWindow to the favorite and closes the current form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void accessButton_Click(object sender, EventArgs e) { if (this.listFavoriteItems.SelectedItem != null) { Models.FavouriteItem obj = (Models.FavouriteItem) this.listFavoriteItems.SelectedItem; this.MainWindow.LoadAddressFromOutside(obj.Address); this.Close(); } }
/// <summary> /// Overrides the Equals method to check for attribute equality /// </summary> /// <param name="obj">The object to which we want to compare the current instance</param> /// <returns><seealso cref="bool"/>: Boolean telling wether or not this instance equals the one passed as a parameter</returns> public override bool Equals(object obj) { if (typeof(FavouriteItem).IsInstanceOfType(obj)) { FavouriteItem FavItemObj = (FavouriteItem)obj; if (this.Address == FavItemObj.Address && this.Name == FavItemObj.Name) { return(true); } else { return(false); } } return(false); }
/// <summary> /// Method that is called when the deleteButton is being clicked: deletes the currently selected favorite /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteButton_Click(object sender, EventArgs e) { if (this.listFavoriteItems.SelectedItem != null) { Models.FavouriteItem obj = (Models.FavouriteItem) this.listFavoriteItems.SelectedItem; int objIndex = this.FavoritesController.ListOfFavoriteItems().IndexOf(obj); this.FavoritesController.DeleteFavourite(objIndex); if (objIndex >= 0 && objIndex < this.listFavoriteItems.Items.Count) { this.listFavoriteItems.Items.RemoveAt(objIndex); this.listFavoriteItems.Text = ""; this.editFavoriteAddressInput.Text = ""; this.editFavoriteNameInput.Text = ""; } } }
/// <summary> /// Method that is called when the editButton is being clicked: redirects the currentPage of the MainWindow to the favorite and closes the current form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editFavoriteAddressLabel_Click(object sender, EventArgs e) { if (this.listFavoriteItems.SelectedItem != null) { Models.FavouriteItem obj = (Models.FavouriteItem) this.listFavoriteItems.SelectedItem; int objIndex = this.FavoritesController.ListOfFavoriteItems().IndexOf(obj); obj.Address = this.editFavoriteAddressInput.Text; obj.Name = this.editFavoriteNameInput.Text; this.FavoritesController.UpdateFavorite(obj, objIndex); this.listFavoriteItems.Text = obj.ToString(); if (objIndex >= 0 && objIndex < this.listFavoriteItems.Items.Count) { this.listFavoriteItems.Items.RemoveAt(objIndex); this.listFavoriteItems.Items.Insert(objIndex, obj); } // this.LoadFavoritesInComboBox(); } }