private void lbSearchResults_SelectedIndexChanged(object sender, EventArgs e) { if (lbSearchResults.SelectedIndex > -1 && lbSearchResults.SelectedIndex < lbSearchResults.Items.Count) { SongSearchResult ssr = (SongSearchResult)lbSearchResults.Items[lbSearchResults.SelectedIndex]; UpdateSearchDisplayer(ssr.autoNumber, ssr.songNumber); } }
public static List <SongSearchResult> Search(List <string> searchTerms) { if (searchTerms.Count < 1) { throw (new ApplicationException("No search terms")); } // Double check sql string p = ",./<>?[]\\{}|!@#$%^&*()-=_+:;'\""; foreach (string str in searchTerms) { if (str.IndexOfAny(p.ToCharArray()) != -1) { throw (new ApplicationException("Malformed sql passed to Search")); } } // Build the query string query = "SELECT \"SongVerses\".\"AutoNumber\", \"Songs\".\"Number\", \"SongVerses\".\"Verse\", \"SongVerses\".\"OrderNum\", \"SongVerses\".\"IsChorus\" " + "FROM \"SongVerses\" INNER JOIN \"Songs\" ON \"SongVerses\".\"AutoNumber\" = \"Songs\".\"AutoNumber\" WHERE "; foreach (string s in searchTerms) { query += "(\"Verse\" LIKE '%" + s + "%') AND "; } query = query.Remove(query.Length - 4); query += "ORDER BY \"Number\""; // Query the database List <SongSearchResult> lResult = new List <SongSearchResult>(); using (FBirdTask t = new FBirdTask()) { t.CommandText = query; t.ExecuteReader(); int cutoff = 100; while (t.DR.Read() && cutoff > 0) { cutoff--; SongSearchResult ssr = new SongSearchResult(); ssr.autoNumber = t.GetInt32(0); ssr.songNumber = t.GetInt32(1); ssr.verseData = t.GetString(2); ssr.isAtStart = t.GetInt32(3) == 0; ssr.isChorus = t.GetBoolean(4); ssr.verseData = SongProject.RemoveVerseFormatting(ssr.verseData); ssr.searchResult = ssr.verseData; lResult.Add(ssr); } } return(lResult); }
private void lbSearchResults_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index > -1 && e.Index < lbSearchResults.Items.Count) { // Init brushes int padding = 3; SolidBrush brushNormal = new SolidBrush(Color.FromArgb(223, 223, 223)); SolidBrush brushSelected = new SolidBrush(Color.FromArgb(255, 204, 91)); Rectangle textr = new Rectangle(padding + e.Bounds.X, padding + e.Bounds.Y, e.Bounds.Width - padding * 2, e.Bounds.Height - padding * 2); // Background if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(brushSelected, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); } else { e.Graphics.FillRectangle(brushNormal, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); } // Build the display string SongSearchResult ssr = (SongSearchResult)lbSearchResults.Items[e.Index]; string s = ssr.songNumber + ". "; if (!ssr.isAtStart) { s += "..."; } s += ssr.verseData; // Measure and paint highlights StringFormat sf = new StringFormat(); sf.SetMeasurableCharacterRanges(SearchHelper.FindCharacterRanges(s, SearchHelper.BreakSearchTerms(txtFulltextSearch.Text))); foreach (Region rg in e.Graphics.MeasureCharacterRanges(s, lbSearchResults.Font, textr, sf)) { e.Graphics.FillRegion(new SolidBrush(Color.FromArgb(100, Color.Yellow)), rg); } // Text if (ssr.score > 600) { e.Graphics.DrawString(s, lbSearchResults.Font, new SolidBrush(Color.FromArgb(80, 80, 80)), textr, sf); } else { e.Graphics.DrawString(s, lbSearchResults.Font, Brushes.Black, textr, sf); } } }
private void lbSearchResults_MeasureItem(object sender, MeasureItemEventArgs e) { if (e.Index > -1 && e.Index < lbSearchResults.Items.Count) { // Build the display string SongSearchResult ssr = (SongSearchResult)lbSearchResults.Items[e.Index]; string s = ssr.songNumber + ". "; if (!ssr.isAtStart) { s += "..."; } s += ssr.verseData; int padding = 3; int h = (int)e.Graphics.MeasureString(s, lbSearchResults.Font, lbSearchResults.Width - padding * 2).Height; e.ItemHeight = h + padding * 2; } }
private void lbSearchResults_DoubleClick(object sender, EventArgs e) { if (lbSearchResults.SelectedIndex == -1) { return; } // Start the song SongSearchResult ssr = (SongSearchResult)lbSearchResults.SelectedItem; int autoNumber = ssr.autoNumber; dvSongs.RowFilter = "AutoNumber = " + autoNumber; if (dvSongs.Count > 0) { currentSong = (PresenterDataset.SongsRow)dvSongs[0].Row; StartProject(true); } }