Example #1
0
        }//BooKsDelete


        // user defined functions

        void DeleteBookByID()
        {
            if (CheckIfBookExists())
            {
                try
                {
                    SqlConnection con = new SqlConnection(strcon);
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    SqlCommand cmd = new SqlCommand("DELETE from tbl_book WHERE book_id='" + BooksID.Text.Trim() + "'", con);

                    cmd.ExecuteNonQuery();
                    con.Close();
                    Response.Write("<script>alert('" + BooksName.Text.Trim() + "' + ' is successfully deleted.' ); </script>");
                    GridBooKs.DataBind();
                    ClearForm();
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('" + ex.Message + "');</script>");
                }

            }
            else
            {
                Response.Write("<script>alert('Invalid Book ID');</script>");
            }
        }//DeleteByID
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                FillAuthorPublisherValues();
            }

            GridBooKs.DataBind();           
        }//PageLoad
Example #3
0
        }//CheckBool

        void AddNewBook()
        {
            try
            {
                string genres = "";
                foreach (int i in ListBoxGenre.GetSelectedIndices())
                {
                    genres = genres + ListBoxGenre.Items[i] + ",";
                }
                // genres = Adventure,Self Help,
                genres = genres.Remove(genres.Length - 1);

                string filepath = "~/book_inventory/bookinventory.jpg";
                string filename = Path.GetFileName(FileUploadBooK.PostedFile.FileName);
                FileUploadBooK.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 tbl_book(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", BooksID.Text.Trim());
                cmd.Parameters.AddWithValue("@book_name", BooksName.Text.Trim());
                cmd.Parameters.AddWithValue("@genre", genres);
                cmd.Parameters.AddWithValue("@author_name", DropDownAuthor.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@publisher_name", DropDownPublisher.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@publish_date", PublishDate.Text.Trim());
                cmd.Parameters.AddWithValue("@language", DropDownLanguage.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@edition", BooKsEdition.Text.Trim());
                cmd.Parameters.AddWithValue("@book_cost", BooKsCost.Text.Trim());
                cmd.Parameters.AddWithValue("@no_of_pages", BooKsPages.Text.Trim());
                cmd.Parameters.AddWithValue("@book_description", BooKsDescription.Text.Trim());
                cmd.Parameters.AddWithValue("@actual_stock", BooKsActualStock.Text.Trim());
                cmd.Parameters.AddWithValue("@current_stock", BooKsActualStock.Text.Trim());
                cmd.Parameters.AddWithValue("@book_img_link", filepath);

                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Book added successfully.');</script>");
                GridBooKs.DataBind();
                ClearForm();

            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }//AddNewBook
Example #4
0
        }//DeleteByID

        void UpdateBookByID()
        {

            if (CheckIfBookExists())
            {
                try
                {

                    int actual_stock = Convert.ToInt32(BooKsActualStock.Text.Trim());
                    int current_stock = Convert.ToInt32(BooKsCurrentStock.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;
                            BooKsCurrentStock.Text = "" + current_stock;
                        }
                    }

                    string genres = "";
                    foreach (int i in ListBoxGenre.GetSelectedIndices())
                    {
                        genres = genres + ListBoxGenre.Items[i] + ",";
                    }
                    genres = genres.Remove(genres.Length - 1);

                    string filepath = "~/book_inventory/bookinventory.jpg";
                    string filename = Path.GetFileName(FileUploadBooK.PostedFile.FileName);
                    if (filename == "" || filename == null)
                    {
                        filepath = global_filepath;

                    }
                    else
                    {
                        FileUploadBooK.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 tbl_book 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='" + BooksID.Text.Trim() + "'", con);

                    cmd.Parameters.AddWithValue("@book_name", BooksName.Text.Trim());
                    cmd.Parameters.AddWithValue("@genre", genres);
                    cmd.Parameters.AddWithValue("@author_name", DropDownAuthor.SelectedItem.Value);
                    cmd.Parameters.AddWithValue("@publisher_name", DropDownPublisher.SelectedItem.Value);
                    cmd.Parameters.AddWithValue("@publish_date", PublishDate.Text.Trim());
                    cmd.Parameters.AddWithValue("@language", DropDownLanguage.SelectedItem.Value);
                    cmd.Parameters.AddWithValue("@edition", BooKsEdition.Text.Trim());
                    cmd.Parameters.AddWithValue("@book_cost", BooKsCost.Text.Trim());
                    cmd.Parameters.AddWithValue("@no_of_pages", BooKsPages.Text.Trim());
                    cmd.Parameters.AddWithValue("@book_description", BooKsDescription.Text.Trim());
                    cmd.Parameters.AddWithValue("@actual_stock", actual_stock.ToString());
                    cmd.Parameters.AddWithValue("@current_stock", current_stock.ToString());
                    cmd.Parameters.AddWithValue("@book_img_link", filepath);


                    cmd.ExecuteNonQuery();
                    con.Close();
                    GridBooKs.DataBind();
                    Response.Write("<script>alert('" + BooksName.Text.Trim() + "' + ' is successfully Updated.' ); </script>");
                    ClearForm();
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('" + ex.Message + "');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Invalid Book ID');</script>");
            }
        }//UpdateByID