Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvBookStatus.SelectedCells.Count > 0)
            {
                int             selectedrowindex = this.dgvBookStatus.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow      = this.dgvBookStatus.Rows[selectedrowindex];
                BookStatusBLL   bookStatusBLL    = new BookStatusBLL(Convert.ToInt32(selectedRow.Cells["clmnId"].Value), selectedRow.Cells["clmnName"].Value.ToString());
                DialogResult    result           = MessageBox.Show("Do you want to delete book status: " + selectedRow.Cells["clmnName"].Value + "?", "Warning", MessageBoxButtons.OKCancel);
                switch (result)
                {
                case DialogResult.Cancel:
                    break;

                case DialogResult.OK:

                    if (BookStatusDAL.getBookStatusItem(bookStatusBLL) != null)
                    {
                        MessageBox.Show("Can't delete! Please delete all book has status " + selectedRow.Cells["clmnName"].Value + " before delete this status!", "Error");
                        break;
                    }
                    else
                    {
                        BookStatusDAL.deleteBookStatus(bookStatusBLL);
                        MessageBox.Show("Delete complete!", "Success");
                        this.LoadDataToGridView();
                        break;
                    }
                }
            }
        }
Example #2
0
        private void LoadDataToDataGridView()
        {
            this.dgvBook.Rows.Clear();
            List <BookBLL> bookList = new List <BookBLL>();

            bookList = BookDAL.getBookList(this._bookTitleBLL);
            foreach (BookBLL row in bookList)
            {
                BookTitleBLL bookTitleBLL = new BookTitleBLL();
                bookTitleBLL = BookTitleDAL.getBookTitleItem(row.BookTitleId);
                BookStatusBLL bookStatusBLL = new BookStatusBLL();
                bookStatusBLL = BookStatusDAL.getBookStatusItem(row.BookStatusId);
                this.dgvBook.Rows.Add(row.BookId, bookTitleBLL.Name, bookTitleBLL.BookTitleId, bookStatusBLL.Name, bookStatusBLL.BookStatusId);
            }
        }