Esempio n. 1
0
        void getBookByID()
        {
            try
            {
                SqlConnection con = new SqlConnection(strcon);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlCommand cmd = new SqlCommand($"SELECT * FROM book_master_tb1 WHERE book_id='{BookIDText.Text.Trim()}';", con);

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                con.Close();
                if (dt.Rows.Count >= 1)
                {
                    BookNameText.Text                    = dt.Rows[0]["book_name"].ToString();
                    PublishDateText.Text                 = dt.Rows[0]["publish_date"].ToString();
                    EditionText.Text                     = dt.Rows[0]["edition"].ToString();
                    BookCostText.Text                    = dt.Rows[0]["book_cost"].ToString().Trim();
                    PagesText.Text                       = dt.Rows[0]["no_of_pages"].ToString().Trim();
                    BookDescriptionText.Text             = dt.Rows[0]["book_description"].ToString();
                    ActualStockText.Text                 = dt.Rows[0]["actual_stock"].ToString().Trim();
                    CurrentStockText.Text                = dt.Rows[0]["current_stock"].ToString().Trim();
                    IssueBooksText.Text                  = "" + (Convert.ToInt32(dt.Rows[0]["actual_stock"].ToString()) - Convert.ToInt32(dt.Rows[0]["current_stock"].ToString()));
                    LanguageDropDownList.SelectedValue   = dt.Rows[0]["language"].ToString();
                    PublisherDropDownList.SelectedValue  = dt.Rows[0]["publisher_name"].ToString();
                    AuthorNameDropDownList.SelectedValue = dt.Rows[0]["author_name"].ToString();
                    GenreList.ClearSelection();
                    string[] Datagenre = dt.Rows[0]["genre"].ToString().Trim().Split(',');
                    for (int DatagenreLength = 0; DatagenreLength < Datagenre.Length; DatagenreLength++)
                    {
                        for (int genrelistCount = 0; genrelistCount < GenreList.Items.Count; genrelistCount++)
                        {
                            if (GenreList.Items[genrelistCount].ToString() == Datagenre[DatagenreLength])
                            {
                                GenreList.Items[genrelistCount].Selected = true;
                            }
                        }
                    }


                    global_actual_stock  = Convert.ToInt32(dt.Rows[0]["actual_stock"].ToString());
                    global_current_stock = Convert.ToInt32(dt.Rows[0]["current_stock"].ToString());
                    global_issued_books  = global_actual_stock - global_current_stock;
                    global_filepath      = dt.Rows[0]["book_img_link"].ToString();
                }
                else
                {
                    Response.Write("<script>alert('BookID is not available');</script");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script language='javascript'>alert('" + ex.Message + "');</script");
            }
        }