/// <summary> /// btnImportSearch click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImportSearch_Click(object sender, EventArgs e) { if (fileBrowserDialog != null) { fileBrowserDialog.Filter = @"xml files (*.xml)|*.xml"; if (this.fileBrowserDialog.ShowDialog() == DialogResult.OK) { string fileNameAndPath = fileBrowserDialog.FileName; FileImportHelper helper = new FileImportHelper(); if (helper.DetermineIfSelectedXmlIsValid(fileNameAndPath)) { SpotifySearchPresenter p = new SpotifySearchPresenter(this); p.ImportData(XMLImportList(fileNameAndPath)); KeepTopMostAndBringToFront(); } else { MessageBox.Show( @"The selected file is not compatible for import. SpotifySearch *.xml files only. See manual for more details.", @"File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); KeepTopMostAndBringToFront(); } } } }
/// <summary> /// btnExportSearch click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExportSearch_Click(object sender, EventArgs e) { SpotifySearchPresenter p = new SpotifySearchPresenter(this); p.CollectSpotifySearchViewList(SpotifySearchPOListFromUI()); p.ExportData(); KeepTopMostAndBringToFront(); }
/// <summary> /// Load Results based on user selection /// </summary> private void LoadResults() { // Clear panel for each subsequent search. if (this.flwSearchResultsFlowPanel.Controls.Count > 0) { this.flwSearchResultsFlowPanel.Controls.Clear(); } string searchQuery = this.rtxtArtistSongEntry.Text; // SearchType.* from user SearchType searchType; if (this.rbtnArtistSearch.Checked) { searchType = SearchType.artist; } else { searchType = SearchType.track; } // Search Limit from user int searchLimit = Convert.ToInt16(cbxMaxSearch.SelectedValue); string artistsJson = string.Empty; try { artistsJson = Api.Search($"{searchQuery}", searchType, searchLimit, 0); } catch (Exception e) { MessageBox.Show(@"Invalid search parameters or user not authenticated. Relaunch app and sign into Spotify via the web browser that launches on application startup. If you receive error again please contact admin @ 1-888-555-5555. Error Message: " + e.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.btnSearch.Enabled = false; this.btnSearch.BackColor = Color.DimGray; } SpotifySearchPresenter p = new SpotifySearchPresenter(this); switch (searchType) { case SearchType.artist: p.ProcessStringJsonIntoSpotifyArtistsModel(artistsJson); break; case SearchType.track: p.ProcessStringJsonIntoSpotifyTracksModel(artistsJson); break; default: // leave method if cannot process MessageBox.Show(@"Could not process Json"); return; } // Populate UI with result user control list. ListItemUserControl[] listItems = new ListItemUserControl[] { }; if (searchType == SearchType.artist && ArtistsResults != null) { listItems = new ListItemUserControl[ArtistsResults.Artists.Items.Count]; } if (searchType == SearchType.track && TracksResults != null) { listItems = new ListItemUserControl[TracksResults.Tracks.Items.Count]; } for (int i = 0; i < listItems.Length; i++) { listItems[i] = new ListItemUserControl { Width = flwSearchResultsFlowPanel.Width, Icon = Resources.spotify_icon_01, IconBackGround = Color.Black }; switch (searchType) { case SearchType.artist: if (ArtistsResults != null) { listItems[i].Title = ArtistsResults.Artists.Items[i].Name; listItems[i].Message = $"Artist Spotify ID: {ArtistsResults.Artists.Items[i].Id}" + Environment.NewLine + "Click to view metadata."; } break; case SearchType.track: if (TracksResults != null) { listItems[i].Title = TracksResults.Tracks.Items[i].Name; listItems[i].Message = $"Track Spotify ID: {TracksResults.Tracks.Items[i].Id}" + Environment.NewLine + "Click to view metadata."; } break; } if (flwSearchResultsFlowPanel.Controls.Count < 0) { flwSearchResultsFlowPanel.Controls.Clear(); } else { this.flwSearchResultsFlowPanel.Controls.Add(listItems[i]); } } if (flwSearchResultsFlowPanel.Controls.Count == 0) { MessageBox.Show(@"No results found. Please modify search text and / or parameters and try again.", @"Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } }