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 bool check() { BUS.AuthorBUS auBUS = new BUS.AuthorBUS(); BUS.CategoryBUS cateBUS = new BUS.CategoryBUS(); if (!auBUS.IsAuthorExisted(txtAuthorID.Text)) { MessageBox.Show(this, "The New Book Title is invalid. Please checked it and try again!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!cateBUS.IsCategoryIDExisted(txtCategoryID.Text)) { MessageBox.Show(this, "The New Book Title is invalid. Please checked it and try again!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
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; } }