private void SearchView() { if (this.rankedDocsIndex == null) { return; } this.docListViewer.Items.Clear(); for (int k = 0; k < this.rankedDocsIndex.Count; ++k) { ListItemUserControl bt = new ListItemUserControl(this.rankedDocsIndex[k].FileIndex); this.docListViewer.Items.Add(bt); } }
/// <summary> /// Imports XML to UI. /// </summary> /// <param name="xmlImportList"></param> public void ImportData(List <SpotifySearchPO> xmlImportList) { if (xmlImportList == null || xmlImportList.Count == 0) { return; } // Populate UI with result user control list. ListItemUserControl[] listItems = new ListItemUserControl[xmlImportList.Count]; if (_viewMain.FlowPanelObject.Controls.Count > 0) { _viewMain.FlowPanelObject.Controls.Clear(); } for (int i = 0; i < listItems.Length; i++) { listItems[i] = new ListItemUserControl { Width = _viewMain.FlowPanelObject.Width, Icon = Resources.spotify_icon_01, IconBackGround = Color.Black }; if (!string.IsNullOrEmpty(listItems[i].Title)) { listItems[i].Title = xmlImportList[i].Title; } if (!string.IsNullOrEmpty(listItems[i].Message)) { listItems[i].Message = xmlImportList[i].Message; } this._viewMain.FlowPanelObject.Controls.Add(listItems[i]); } }
/// <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); } }