public partial class bkrentSearch : Form
{
public bkrentSearch()
{
InitializeComponent();
}
private SqlConnection con()
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Book;User Id=sa;Password=123;");
return con;
}
SqlDataAdapter adapJoin;
DataView dv;
DataSet ds;
private void bkrentSearch_Load(object sender, EventArgs e)
{
ds = new DataSet();
adapJoin = new SqlDataAdapter("select * from Books inner join bkrent on books.bk_id = bkrent.bk_id where bkrent_status = 1", con());
adapJoin.Fill(ds, "joinbook");
dv = new DataView(ds.Tables["joinbook"]);
dataGridView3.AutoGenerateColumns = false;
dataGridView3.DataSource = dv;
for (int i = 0; i < dataGridView3.Rows.Count; i++)
{
if (Convert.ToInt16(ds.Tables["joinbook"].Rows[i]["bkrent_status"]) == 1)
{
dataGridView3.Rows[i].Cells[4].Value = "หนังสือยังไม่ถูกเช่า";
}
else dataGridView3.Rows[i].Cells[4].Value = "หนังสือถูกเช่าไป";
}
}
private void button8_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
dv.RowFilter = "bkrent_id like '%" + txtSend.Text + "%'";
}
else if (radioButton2.Checked)
{
dv.RowFilter = "bk_name like '%" + txtSend.Text + "%'";
}
else dv.RowFilter = "";
}
int i = 0;
private void dataGridView3_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
i = e.RowIndex;
if (i >= 0 && i < dv.Count)
{
Rent.BkrentID = dv[i]["bkrent_id"].ToString();
Rent.BkID = dv[i]["bk_id"].ToString();
this.Close();
}
}
}
}