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;
                        }
                }
            }
        }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     BookStatusBLL bookStatusBLL = new BookStatusBLL();
     bookStatusBLL.Name = this.txtBookStatusName.Text;
     if (bookStatusBLL.Name == "")
     {
         MessageBox.Show("Book status name is not null!", "Notice");
         return;
     }
     BookStatusDAL.addBookStatus(bookStatusBLL);
     MessageBox.Show("Add success!", "Success");
     this.LoadDataToGridView();
 }
Esempio n. 3
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);
     }
 }
 public static BookStatusBLL getBookStatusItem(BookStatusBLL bookStatusBLL)
 {
     String sql = "SELECT * FROM [tinhtrangsach] WHERE matinhtrangsach=" + bookStatusBLL.BookStatusId;
         DataTable dt = BookStatusDAL._condb.getDataTable(sql);
         if (dt.Rows.Count > 0)
         {
             DataRow row = dt.Rows[0];
             return new BookStatusBLL(Int32.Parse(row["matinhtrangsach"].ToString()), row["tentinhtrangsach"].ToString());
         }
         else
         {
             return null;
         }
 }
        public static List<BookStatusBLL> getBookStatusList()
        {
            String sql = "SELECT * FROM [tinhtrangsach]";
                DataTable dt = BookStatusDAL._condb.getDataTable(sql);
                List<BookStatusBLL> bookStatusBLLList = new List<BookStatusBLL>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        BookStatusBLL bookStatusBLL = new BookStatusBLL(Int32.Parse(row["matinhtrangsach"].ToString()), row["tentinhtrangsach"].ToString());
                        bookStatusBLLList.Add(bookStatusBLL);

                    }
                    return bookStatusBLLList;
                }
                else
                {
                    return null;
                }
        }
        private void btnSave_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), this.txtBookStatusName.Text);

                if (bookStatusBLL.Name == "")
                {
                    MessageBox.Show("Book status name is not null!", "Notice");
                    return;
                }
                BookStatusDAL.updateBookStatus(bookStatusBLL);
                MessageBox.Show("Update success!", "Success");
                this.LoadDataToGridView();
            }
        }
 private void LoadDataToGridView()
 {
     this.dgvBookStatus.Rows.Clear();
     BookStatusBLL bookStatusBLL = new BookStatusBLL();
     List<BookStatusBLL> bookStatusArr = new List<BookStatusBLL>();
     bookStatusArr = BookStatusDAL.getBookStatusList();
     foreach (BookStatusBLL row in bookStatusArr)
     {
         this.dgvBookStatus.Rows.Add(row.BookStatusId, row.Name);
     }
     this.GetSelectedValue();
     this.dgvBookStatus.CellClick += new DataGridViewCellEventHandler(dgvBookStatus_CellClick);
 }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string key = this.txtSearch.Text;
            if (key == "".Trim())
            {
                MessageBox.Show("Please enter keyword!", "Notice");
                return;
            }
            string catalog = "";
            if (this.cboSearch.SelectedItem.ToString() == "Name")
            {
                catalog = "tentinhtrangsach";
            }
            BookStatusBLL bookStatusBLL = new BookStatusBLL();
            List<BookStatusBLL> bookStatusArr = new List<BookStatusBLL>();
            bookStatusArr = BookStatusDAL.search(catalog, key);
            this.dgvBookStatus.Rows.Clear();
            if (bookStatusArr.Count != null)
            {
                foreach (BookStatusBLL row in bookStatusArr)
                {
                    this.dgvBookStatus.Rows.Add(row.BookStatusId, row.Name);
                }
            }
            this.GetSelectedValue();

            this.dgvBookStatus.CellClick += new DataGridViewCellEventHandler(this.dgvBookStatus_CellClick);
        }
        public static List<BookStatusBLL> search(string key, string value)
        {
            string sql = "SELECT * FROM [tinhtrangsach] WHERE " + key + " LIKE N'%" + value + "%'";
                DataTable dt = BookStatusDAL._condb.getDataTable(sql);
                List<BookStatusBLL> bookStatusBLLList = new List<BookStatusBLL>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        BookStatusBLL bookStatusBLL = new BookStatusBLL(Int32.Parse(row["matinhtrangsach"].ToString()), row["tentinhtrangsach"].ToString());
                        bookStatusBLLList.Add(bookStatusBLL);

                    }
                    return bookStatusBLLList;
                }
                else
                {
                    return null;
                }
        }
Esempio n. 10
0
 public static void deleteBookStatus(BookStatusBLL bookStatusBLL)
 {
     String sql = "DELETE FROM [tinhtrangsach] WHERE matinhtrangsach=" + bookStatusBLL.BookStatusId;
         BookStatusDAL._condb.ExecuteNonQuery(sql);
 }
Esempio n. 11
0
 public static void addBookStatus(BookStatusBLL bookStatusBLL)
 {
     String sql = "INSERT INTO [tinhtrangsach] (tentinhtrangsach) VALUES ( N'" + bookStatusBLL.Name + "')";
         BookStatusDAL._condb.ExecuteNonQuery(sql);
 }
Esempio n. 12
0
 public static void updateBookStatus(BookStatusBLL bookStatusBLL)
 {
     String sql = "UPDATE [tinhtrangsach] SET tentinhtrangsach=N'" + bookStatusBLL.Name + "' WHERE matinhtrangsach=" + bookStatusBLL.BookStatusId;
         BookStatusDAL._condb.ExecuteNonQuery(sql);
 }