public List <BookForListShort> searchBooksSimple(String text) { List <BookForListShort> booksList = new List <BookForListShort>(); SqlCommand cmd = new SqlCommand(string.Format("select ID_KSIAZKA, K_TYTUL from Ksiazki where K_TYTUL like '%{0}%'", text), connection); connection.Open(); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) // czytamy wiersze danych do momentu ich skonczenia { BookForListShort b = new BookForListShort(); b.Id = Int32.Parse(rdr["ID_KSIAZKA"].ToString()); b.tytul = rdr["K_TYTUL"].ToString(); booksList.Add(b); } } if (rdr != null) { rdr.Close(); } if (connection != null) { connection.Close(); } return(booksList); }
public List <BookForListShort> searchBooksAdvanced(String query, Boolean titleDesc, String authors, String publisher, int binding, int pages, int pagesSearchType, String isbn) { List <BookForListShort> booksList = new List <BookForListShort>(); string commandBegin = "select ID_KSIAZKA, K_TYTUL from Ksiazki"; string command = string.Format("{0} where (K_TYTUL like '%{1}%'", commandBegin, query); if (titleDesc) { command += string.Format("or K_OPIS like '%{0}%')", query); } else { command += ")"; } if (!String.IsNullOrWhiteSpace(authors)) { command += string.Format("and K_AUTORZY like '%{0}%'", authors); } if (!String.IsNullOrWhiteSpace(publisher)) { command += string.Format("and K_WYDAWNICTWO like '%{0}%'", publisher); } if (binding != 0) { if (binding == 1) { command += "and K_OPRAWA like 'miękka'"; } else if (binding == 2) { command += "and K_OPRAWA like 'twarda'"; } } if (pages != -1) { if (pagesSearchType == 0) { command += string.Format("and K_ILOSC_STRON < {0}", pages); } else if (pagesSearchType == 1) { command += string.Format("and K_ILOSC_STRON = {0}", pages); } else if (pagesSearchType == 2) { command += string.Format("and K_ILOSC_STRON > {0}", pages); } } if (!String.IsNullOrWhiteSpace(isbn)) { command = string.Format("{0} where K_ISBN like '{1}'", commandBegin, isbn); isbn = isbn.Replace("-", ""); command += string.Format("or K_ISBN like '{0}'", isbn); } SqlCommand cmd = new SqlCommand(command, connection); connection.Open(); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) // czytamy wiersze danych do momentu ich skonczenia { BookForListShort b = new BookForListShort(); b.Id = Int32.Parse(rdr["ID_KSIAZKA"].ToString()); b.tytul = rdr["K_TYTUL"].ToString(); booksList.Add(b); } } if (rdr != null) { rdr.Close(); } if (connection != null) { connection.Close(); } return(booksList); }