//end of menu events //add book private void btn_add_Click(object sender, EventArgs e) { if (tb_name.Text == "" || tb_publisher.Text == "" || tb_price.Text == "" || tb_quantity.Text == "") { MessageBox.Show("All fields are mandatory"); } else { try { con = DatabaseConnection.connectDB(); con.Open(); SqlCommand cmd = new SqlCommand("Insert into book values('" + tb_bookId.Text + "','" + tb_name.Text + "','" + cb_edition.Text + "','" + tb_publisher.Text + "','" + date_of_purchase.Text + "','" + tb_price.Text + "','" + tb_quantity.Text + "','" + tb_quantity.Text + "')", con); int result = cmd.ExecuteNonQuery(); if (result == 1) { MessageBox.Show("New Book Added!!"); tb_bookId.Text = Increment.bookIncrement().ToString(); tb_name.Text = ""; cb_edition.Text = "1"; tb_publisher.Text = ""; tb_price.Text = ""; tb_quantity.Text = ""; date_of_purchase.Value = DateTime.Today; } else { MessageBox.Show("Something Went Wrong!!"); } con.Close(); } catch (SqlException ex) { MessageBox.Show(ex.Message); } } }
//Page Load private void NewBook_Load(object sender, EventArgs e) { menu_user.Text = ""; menu_user.Text = global.user; tb_bookId.Text = Increment.bookIncrement().ToString(); }