void DeleteBookByID() { if (CheckIfBookExists()) { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("DELETE from dbo.book_master_tbl WHERE book_id='" + TextBox_BookId.Text.Trim() + "'", con); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Book Deleted Successfully');</script>"); BookTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } } else { Response.Write("<script>alert('Invalid Member ID');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillAuthorPublisherValues(); } BookTable.DataBind(); }
private void BindUserInfo() { string sql = "select * from bookstat_full"; BookTable.DataSource = SqlHelper.ExecuteDataTable(sql); BookTable.DataBind(); btnAll.Checked = false; txtID.Text = ""; txtKeyword.Text = ""; Label1.Text = BookStatBLL.GetBookOnSaleCount().ToString(); }
protected void txtKeyword_TextChanged(object sender, EventArgs e) { txtID.Text = ""; string sql = "select * from bookstat_full where title like @keyword or category like @keyword or isbn like @keyword or author like @keyword or publisher like @keyword"; BookTable.DataSource = SqlHelper.ExecuteDataTable(sql, new SqlParameter[] { new SqlParameter("keyword", "%" + txtKeyword.Text + "%") }); BookTable.DataBind(); btnAll.Checked = false; }
void AddNewBook() { try { string genres = ""; foreach (int i in ListBox_Genre.GetSelectedIndices()) { genres = genres + ListBox_Genre.Items[i] + ","; } genres = genres.Remove(genres.Length - 1); string filepath = "~/book_inventory/books1.png"; string filename = Path.GetFileName(FileUpload.PostedFile.FileName); FileUpload.SaveAs(Server.MapPath("book_inventory/" + filename)); filepath = "~/book_inventory/" + filename; SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Insert Into dbo.book_master_tbl(book_id,book_name," + "genre,author_name,publisher_name,publish_date,language,edition,book_cost,no_of_pages," + "book_description,actual_stock,current_stock,book_img_link) values(@book_id,@book_name," + "@genre,@author_name,@publisher_name,@publish_date,@language,@edition,@book_cost,@no_of_pages," + "@book_description,@actual_stock,@current_stock,@book_img_link)", con); cmd.Parameters.AddWithValue("@book_id", TextBox_BookId.Text.Trim()); cmd.Parameters.AddWithValue("@book_name", TextBox_BookName.Text.Trim()); cmd.Parameters.AddWithValue("@genre", genres); cmd.Parameters.AddWithValue("@author_name", DropDownList_AuthorName.SelectedItem.Value); cmd.Parameters.AddWithValue("@publisher_name", DropDownList_Publisher.SelectedItem.Value); cmd.Parameters.AddWithValue("@publish_date", TextBox_Date.Text.Trim()); cmd.Parameters.AddWithValue("@language", DropDownList_Language.SelectedItem.Value); cmd.Parameters.AddWithValue("@edition", TextBox_Edition.Text.Trim()); cmd.Parameters.AddWithValue("@book_cost", TextBox_BookCost.Text.Trim()); cmd.Parameters.AddWithValue("@no_of_pages", TextBox_Pages.Text.Trim()); cmd.Parameters.AddWithValue("@book_description", TextBox_BookDescription.Text.Trim()); cmd.Parameters.AddWithValue("@actual_stock", TextBox_ActualStock.Text.Trim()); cmd.Parameters.AddWithValue("@current_stock", TextBox_CurrentStock.Text.Trim()); cmd.Parameters.AddWithValue("@book_img_link", filepath); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Book added successfully.');</script>"); BookTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
protected void txtID_TextChanged(object sender, EventArgs e) { int bookid = 0; if (int.TryParse(txtID.Text, out bookid)) { txtKeyword.Text = ""; string sql = "select * from bookstat_full where id=@bookid"; BookTable.DataSource = SqlHelper.ExecuteDataTable(sql, new SqlParameter[] { new SqlParameter("bookid", bookid) }); BookTable.DataBind(); btnAll.Checked = false; } else { txtID.Text = ""; BindUserInfo(); } }
void UpdateBookByID() { if (CheckIfBookExists()) { try { /*int actual_stock = Convert.ToInt32(TextBox_ActualStock.Text.Trim()); * int current_stock = Convert.ToInt32(TextBox_CurrentStock.Text.Trim()); * * if (global_actual_stock == actual_stock) * { * * } * else * { * if (actual_stock < global_issued_books) * { * Response.Write("<script>alert('Actual Stock value cannot be less than the Issued books');</script>"); * return; * } * else * { * current_stock = actual_stock - global_issued_books; * TextBox_CurrentStock.Text = "" + current_stock; * } * }*/ string genres = ""; foreach (int i in ListBox_Genre.GetSelectedIndices()) { genres = genres + ListBox_Genre.Items[i] + ","; } genres = genres.Remove(genres.Length - 1); string filepath = "~/book_inventory/books1"; string filename = Path.GetFileName(FileUpload.PostedFile.FileName); if (filename == "" || filename == null) { filepath = global_filepath; } else { FileUpload.SaveAs(Server.MapPath("book_inventory/" + filename)); filepath = "~/book_inventory/" + filename; } SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("UPDATE dbo.book_master_tbl set book_name=@book_name, " + "genre=@genre, author_name=@author_name, publisher_name=@publisher_name, publish_date=@publish_date, " + "language=@language, edition=@edition, book_cost=@book_cost, no_of_pages=@no_of_pages, " + "book_description=@book_description, actual_stock=@actual_stock, current_stock=@current_stock, " + "book_img_link=@book_img_link Where book_id='" + TextBox_BookId.Text.Trim() + "'", con); cmd.Parameters.AddWithValue("@book_name", TextBox_BookName.Text.Trim()); cmd.Parameters.AddWithValue("@genre", genres); cmd.Parameters.AddWithValue("@author_name", DropDownList_AuthorName.SelectedItem.Value); cmd.Parameters.AddWithValue("@publisher_name", DropDownList_Publisher.SelectedItem.Value); cmd.Parameters.AddWithValue("@publish_date", TextBox_Date.Text.Trim()); cmd.Parameters.AddWithValue("@language", DropDownList_Language.SelectedItem.Value); cmd.Parameters.AddWithValue("@edition", TextBox_Edition.Text.Trim()); cmd.Parameters.AddWithValue("@book_cost", TextBox_BookCost.Text.Trim()); cmd.Parameters.AddWithValue("@no_of_pages", TextBox_Pages.Text.Trim()); cmd.Parameters.AddWithValue("@book_description", TextBox_BookDescription.Text.Trim()); cmd.Parameters.AddWithValue("@actual_stock", TextBox_ActualStock.Text.Trim()); cmd.Parameters.AddWithValue("@current_stock", TextBox_CurrentStock.Text.Trim()); cmd.Parameters.AddWithValue("@book_img_link", filepath); cmd.ExecuteNonQuery(); con.Close(); BookTable.DataBind(); Response.Write("<script>alert('Book Updated Successfully');</script>"); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } } else { Response.Write("<script>alert('Invalid Book ID');</script>"); } }