//takes two string one the keyword and the other the col in the database used to find the search results public void search(string keyWord, string col) { DBSetup(); cmd = "Select * from Manga Where " + col + " Like '%" + keyWord + "%';"; OleDbDataAdapter2.SelectCommand.CommandText = cmd; OleDbDataAdapter2.SelectCommand.Connection = OleDbConnection2; Console.WriteLine(cmd); try { OleDbConnection2.Open(); System.Data.OleDb.OleDbDataReader dr; dr = OleDbDataAdapter2.SelectCommand.ExecuteReader(); int i = 0; manga a1 = new manga(); while (dr.Read()) { //taking id a pulling all data from manga to add to list i = dr.GetInt32(0); a1 = new manga(); a1.selectSingleManga(i); arrL.add(a1); } } catch (Exception ex) { Console.WriteLine(ex); } finally { OleDbConnection2.Close(); } }
//get id from all manga and added them to a list array. public void getAllManga() { DBSetup(); cmd = "SELECT ID FROM Manga;"; OleDbDataAdapter2.SelectCommand.CommandText = cmd; OleDbDataAdapter2.SelectCommand.Connection = OleDbConnection2; //Console.WriteLine(cmd); try { OleDbConnection2.Open(); System.Data.OleDb.OleDbDataReader dr; dr = OleDbDataAdapter2.SelectCommand.ExecuteReader(); int i = 0; manga a1 = new manga(); while (dr.Read()) { //taking id a pulling all data from manga to add to list i = dr.GetInt32(0); a1 = new manga(); a1.selectSingleManga(i); arrL.add(a1); } } catch (Exception ex) { Console.WriteLine(ex); } finally { OleDbConnection2.Close(); } }
//get info from form to update database public void getinfoUpdate() { id = Int32.Parse(idL.Text); name = mNameTB.Text; author = mAuthorTB.Text; getGenres(); up.selectSingleManga(id); type = typeCB.Text; //error message if some information is missing. if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(author) || string.IsNullOrWhiteSpace(genres) || string.IsNullOrWhiteSpace(type)) { MessageBox.Show("Some information is missing"); } else { if (string.IsNullOrWhiteSpace(cover)) { cover = up.mangaCover; } //Double checks with user, id all information is right. DialogResult ans = MessageBox.Show("Is this information right?\n Name:" + name + "\n Author: " + author + "\n Genres: " + genres + "\n Type: " + type + "\n File Loaction: " + cover, "Check", MessageBoxButtons.YesNo); if (ans == DialogResult.Yes) { up.mangaName = name; up.mangaAuthor = author; up.mangaGenre = genres; up.mangaType = type; up.mangaCover = cover; up.updateSingleManga(); //Executes update query updateDataGridView(); frm1.Enabled = true; MessageBox.Show("Data has been updated."); Close(); } else if (ans == DialogResult.No) { genres = null; } } }