private void btnView_Click(object sender, EventArgs e) { frmBookViewer frm = new frmBookViewer(); this.Hide(); frm.ListBooksOrFilter(false); if (frm.ShowDialog(this) == DialogResult.OK) { this.Show(); } }
public BookHandler(Books BookInfo, frmBookViewer.SaveOrUpdateDelete saveOrUpdateDelete, string old_ISBN, out bool success) { if (saveOrUpdateDelete == frmBookViewer.SaveOrUpdateDelete.Save) { qry = "INSERT INTO Books (Title,Author,ISBN,Year,Pages,Price,In_Stock,Hired_Out,pic)" + "VALUES (@Title,@Author,@ISBN,@Year,@Pages,@Price,@In_Stock,@Hired_Out,@pic)"; } else if (saveOrUpdateDelete == frmBookViewer.SaveOrUpdateDelete.Update) { qry = "UPDATE Books SET Title = @Title,Author = @Author,ISBN = @ISBN,Year = @Year," + "Pages = @Pages,Price = @Price,In_Stock = @In_Stock,Hired_Out = @Hired_Out, pic = @pic WHERE ISBN = @OLD_ISBN"; } else { qry = "DELETE FROM Books WHERE ISBN = @ISBN"; } using (MySqlConnection Connection = new MySqlConnection(MyConString)) { success = false; try { MySqlCommand cmd = new MySqlCommand(qry, Connection); cmd.Parameters.Add(new MySqlParameter("@Title", (object)BookInfo.Title)); cmd.Parameters.Add(new MySqlParameter("@Author", (object)BookInfo.Author)); cmd.Parameters.Add(new MySqlParameter("@ISBN", (object)BookInfo.ISBN)); cmd.Parameters.Add(new MySqlParameter("@Year", (object)BookInfo.Year)); cmd.Parameters.Add(new MySqlParameter("@Pages", (object)BookInfo.Pages)); cmd.Parameters.Add(new MySqlParameter("@Price", (object)BookInfo.Price)); cmd.Parameters.Add(new MySqlParameter("@In_Stock", (object)BookInfo.In_Stock)); cmd.Parameters.Add(new MySqlParameter("@Hired_Out", (object)BookInfo.Hired_Out)); cmd.Parameters.Add(new MySqlParameter("@pic", (object)BookInfo.pic)); cmd.Parameters.Add(new MySqlParameter("@OLD_ISBN", (object)old_ISBN)); Connection.Open(); cmd.ExecuteNonQuery(); success = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Connection.Close(); } } }