private void lbResultados_SelectedIndexChanged(object sender, EventArgs e) { contador = 0; int idlivro = 0; if (lastindex == -1 || lbResultados.SelectedIndex != lastindex) { try { lastindex = lbResultados.SelectedIndex; var livro = lbResultados.SelectedItem.ToString(); Regex regexLivro = new Regex("Título [(]nº[.](\\d+)[)]"); Match matchLivro = regexLivro.Match(livro); if (matchLivro.Success) { idlivro = Convert.ToInt32(matchLivro.Groups[1].Value); } ConsoleApplication.Classes.Db_Utils db = new ConsoleApplication.Classes.Db_Utils(); StringBuilder mensagem = new StringBuilder(); var livros = db.FindBook($"@Livro {idlivro}", 3); Mostrarlivro(livros); } catch { } } }
private void btPesquisar_Click(object sender, EventArgs e) { var pesquisa = ""; LimparPesquisa(); if (cbCategoria.SelectedIndex <= 0) { pesquisa = tbPesquisa.Text; } else if (cbCategoria.SelectedIndex == 1) { pesquisa = $"@Autor {tbPesquisa.Text}"; } else if (cbCategoria.SelectedIndex == 2) { pesquisa = $"@Titulo {tbPesquisa.Text}"; } ConsoleApplication.Classes.Db_Utils db = new ConsoleApplication.Classes.Db_Utils(); StringBuilder mensagem = new StringBuilder(); var livros = db.FindBook(pesquisa, 3); if (livros.Count == 1 && livros.FirstOrDefault().IdLivro == -1) { mensagem.Append($"Comando não reconhecido!\n"); mensagem.Append($"Você pode usar @Título , @Autor ou fazer uma pesquisa geral\n"); LimparPesquisa(); MessageBox.Show("Nenhum Livro Encontrado", "Resultado da Pesquisa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (livros.Count == 0) { LimparPesquisa(); MessageBox.Show("Nenhum Livro Encontrado", "Resultado da Pesquisa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (livros.Count == 1) { Mostrarlivro(livros); } else { for (int i = 0; i < livros.Count; i++) { lbResultados.Items.Add($"\nTítulo (nº.{livros.ElementAt(i).IdLivro}): {livros.ElementAt(i).Titulo}\n"); } } tbPesquisa.Focus(); timer1.Stop(); timer1.Start(); }