private void btnAccept_Click(object sender, EventArgs e) { try { int selectedrowindex = dgvView.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dgvView.Rows[selectedrowindex]; //MessageBox.Show(selectedRow.Cells[0].Value.ToString()); if (selectedRow.Cells[0].Value != null && selectedRow.Cells[0].Value.ToString() != string.Empty) { string value = selectedRow.Cells[0].Value.ToString(); bool result = bus.UpdateLoanStatusByLoanID(value, 1); string BookID = selectedRow.Cells[2].Value.ToString(); BUS.InventoryBUS invBUS = new BUS.InventoryBUS(); invBUS.UpdateInventoryStatusByBookID(BookID, 0); if (result) { LoadData(); MessageBox.Show("Update Loan Table successful!!!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Update Loan Table fail!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { } }
private void btnDelete_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(); int selectedrowindex = dgvSearch.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dgvSearch.Rows[selectedrowindex]; if (selectedRow.Cells[0].Value != null && selectedRow.Cells[0].Value.ToString() != string.Empty) { string value = (string)selectedRow.Cells[0].Value; bool result = false; switch (TypeOfSearch) { case 0: BUS.BookTitleBUS bkTitle = new BUS.BookTitleBUS(); result = bkTitle.DeleteBookTitle(value); break; case 1: BUS.AuthorBUS author = new BUS.AuthorBUS(); result = author.DeleteAuthor(value); break; case 2: BUS.CategoryBUS cate = new BUS.CategoryBUS(); result = cate.DeleteCategory(value); break; case 3: BUS.UserBUS user = new BUS.UserBUS(); result = user.DeleteUser(value); break; case 4: BUS.BookBUS bk = new BUS.BookBUS(); result = bk.DeleteAuthor(value); break; case 5: BUS.InventoryBUS inven = new BUS.InventoryBUS(); result = inven.DeleteInventory(value); break; } if (result) { LoadData(); MessageBox.Show(this, "Delete Successful", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Delete Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(this, "Can not delete null cells", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadData() { switch (TypeOfSearch) { case 0: this.Text = "Book Title"; break; case 1: this.Text = "Author"; break; case 2: this.Text = "Category"; break; case 3: this.Text = "User"; break; case 4: this.Text = "Book"; break; case 5: this.Text = "Inventory"; break; } switch (TypeOfSearch) { case 0: BUS.BookTitleBUS bkTitle = new BUS.BookTitleBUS(); //BUS._MultiTableBUS bus = new BUS._MultiTableBUS(); bsItem.DataSource = bkTitle.GetAllBookTitleByDataSet(); //bsItem.DataSource = bus.SelectBookTitleWithTitleOrAuthorNameOrCategoryName("", "", ""); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; this.dgvSearch.Columns["AuthorID"].Visible = true; this.dgvSearch.Columns["CategoryID"].Visible = true; break; case 1: BUS.AuthorBUS author = new BUS.AuthorBUS(); bsItem.DataSource = author.GetAllAuthorByDataSet(); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; break; case 2: BUS.CategoryBUS cate = new BUS.CategoryBUS(); bsItem.DataSource = cate.getAllCategoryByDataSet(); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; break; case 3: BUS.UserBUS user = new BUS.UserBUS(); bsItem.DataSource = user.getAllUserByDataSet(); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; break; case 4: BUS.BookBUS bk = new BUS.BookBUS(); bsItem.DataSource = bk.getAllBookIDByDataSet(); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; break; case 5: BUS.InventoryBUS inven = new BUS.InventoryBUS(); bsItem.DataSource = inven.getAllInventoryByDataSet(); dgvSearch.DataSource = bsItem; bnItemList.BindingSource = bsItem; break; } int width = 0; foreach (DataGridViewColumn col in dgvSearch.Columns) { width += col.Width; } width += dgvSearch.RowHeadersWidth; dgvSearch.ClientSize = new Size(width + 2, dgvSearch.ClientSize.Height); if (this.Role == 1 && this.TypeOfSearch != 4 && this.TypeOfSearch != 0 && this.TypeOfSearch != 5) { btnNew.Enabled = false; btnDelete.Enabled = false; } }