示例#1
0
        private void searchbtn_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();



            if (Namecb.Text != "All" && categorycb.Text == "All" && authorcb.Text == "All")
            {
                dt = lc.searchBookbyTitle(Namecb.SelectedValue.ToString());
            }
            else if (Namecb.Text == "All" && categorycb.Text != "All" && authorcb.Text == "All")
            {
                dt = lc.searchBookbyCategory(categorycb.SelectedValue.ToString());
            }
            else if (Namecb.Text == "All" && categorycb.Text == "All" && authorcb.Text != "All")
            {
                dt = lc.searchBookByAuthor(authorcb.SelectedValue.ToString());
            }
            else if (Namecb.Text != "All" && categorycb.Text != "All" && authorcb.Text == "All")
            {
                dt = lc.searchBookByTitleandCategory(Namecb.SelectedValue.ToString(), categorycb.SelectedValue.ToString());
            }
            else if (Namecb.Text != "All" && categorycb.Text == "All" && authorcb.Text != "All")
            {
                dt = lc.searchBookByTitleandAuthor(Namecb.SelectedValue.ToString(), authorcb.SelectedValue.ToString());
            }
            else if (Namecb.Text == "All" && categorycb.Text != "All" && authorcb.Text != "All")
            {
                dt = lc.searchBookByCategoryandAuthor(categorycb.SelectedValue.ToString(), authorcb.SelectedValue.ToString());
            }
            else if (Namecb.Text != "All" && categorycb.Text != "All" && authorcb.Text != "All")
            {
                dt = lc.searchBookByTitleandCategoryandAuthor(Namecb.SelectedValue.ToString(), categorycb.SelectedValue.ToString(), authorcb.SelectedValue.ToString());
            }
            else
            {
                dt = lc.searchBookAll();
            }



            dataGridView1.DataSource = dt;
            DataGridViewColumn column = dataGridView1.Columns[1];

            column.Width = 200;

            DataGridViewColumn column1 = dataGridView1.Columns[4];

            column1.Width = 160;

            DataGridViewColumn column2 = dataGridView1.Columns[5];

            column2.Width = 180;
        }