private void search() { string key = this.txtSearch.Text; if (key == "".Trim()) { MessageBox.Show("Please enter keyword!", "Notice"); return; } string catalog = ""; //MessageBox.Show(this.cboSearch.SelectedItem.ToString()); /*if (this.cboSearch.SelectedItem.ToString() == "Certificate") { catalog += "phieumuon.maphieumuon"; //MessageBox.Show(catalog); } else if (this.cboSearch.SelectedItem.ToString() == "Certificate Stt") { catalog += "tinhtrangphieumuon.tentinhtrang"; //MessageBox.Show(catalog); }*/ BackBookBLL bookStatusBLL = new BackBookBLL(); List<BackBookBLL> backbookArr = new List<BackBookBLL>(); backbookArr = BackBookDAL.search(key); this.dgvBook.Rows.Clear(); if (backbookArr != null) { DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn(); checkBoxColumn.HeaderText = ""; checkBoxColumn.Width = 30; checkBoxColumn.Name = "chkBook"; //MessageBox.Show("ok"); int dem = 0; if (this.dgvBook.ColumnCount == 3) { this.dgvBook.Columns.RemoveAt(0); } foreach (BackBookBLL row in backbookArr) { dem++; if (row.Bookstt != 1) { this.dgvBook.Rows.Add(row.Bookid, row.Bookname); this.dgvBook.Columns.Insert(0, checkBoxColumn); } if (backbookArr.Count == dem) { this.txtCertificate.Text = row.Code.ToString(); this.txtReaderName.Text = row.Name; this.txtReaderId.Text = row.ReaderId.ToString(); this.txtDayStart.Text = row.Datestart.ToShortDateString(); this.txtDayEnd.Text = row.Dateend.ToShortDateString(); if(this.dgvBook.RowCount < 1) { this.btnAddVoucher.Enabled = false; } else { this.btnAddVoucher.Enabled = true; } } } } else { this.txtCertificate.Text = ""; this.txtReaderName.Text = ""; this.txtReaderId.Text = ""; this.txtDayStart.Text = ""; this.txtDayEnd.Text = ""; if (this.dgvBook.ColumnCount == 3) { this.dgvBook.Columns.RemoveAt(0); } this.btnAddVoucher.Enabled = false; MessageBox.Show("Sorry! Can't find this certificate"); } }
public static List<BackBookBLL> search(string value) { string sql = "SELECT * FROM [phieumuon] INNER JOIN [sachmuon] ON phieumuon.maphieumuon = sachmuon.maphieumuon INNER JOIN [docgia] ON phieumuon.madocgia = docgia.madocgia INNER JOIN [sach] ON sachmuon.masach = sach.masach INNER JOIN [dausach] ON dausach.madausach = sach.madausach where phieumuon.maphieumuon = " + value; DataTable dt = BackBookDAL._condb.getDataTable(sql); List<BackBookBLL> backbookBLLList = new List<BackBookBLL>(); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { BackBookBLL backbookBLL = new BackBookBLL(Int32.Parse(row["maphieumuon"].ToString()), row["tensach"].ToString(),Int32.Parse(row["masach"].ToString()),Int32.Parse(row["matinhtrangsach"].ToString()),Int64.Parse(row["madocgia"].ToString()), row["tendocgia"].ToString(), DateTime.Parse(row["ngaymuon"].ToString()), DateTime.Parse(row["hantra"].ToString())); backbookBLLList.Add(backbookBLL); } return backbookBLLList; } else { return null; } }