public bool suaBook(DTO_SACH book)
        {
            try
            {
                // Mở kết nối
                _conn.Open();

                // Query string
                string SQL = $"UPDATE sach " +
                             $"SET TenSach = '{book.TENSACH}', TacGia = '{book.TACGIA}', " +
                             $"id_TheLoai = {book.ID_THELOAI}, NamXuatBan = {book.NAMXUATBAN}, NhaXuatBan = '{book.NHAXUATBAN}', TriGia = {book.TRIGIA}," +
                             $" TinhTrang = '{book.TINHTRANG}', SoLuong = 0 " +
                             $"WHERE ID = { book.ID }";

                // Command
                MySqlCommand cmd = new MySqlCommand(SQL, _conn);

                // Query và kiểm tra
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch {}
            finally
            {
                // Đóng kết nối
                _conn.Close();
            }
            return(false);
        }
        public bool themBook(DTO_SACH book)
        {
            try
            {
                // Mở kết nối
                _conn.Open();

                // Query string
                string SQL = $"INSERT INTO sach (id, TenSach, TacGia, id_TheLoai, NamXuatBan, NhaXuatBan, TriGia, TinhTrang, SoLuong) " +
                             $"VALUES ({book.ID}, '{book.TENSACH}', '{book.TACGIA}', {book.ID_THELOAI}, {book.NAMXUATBAN}, '{book.NHAXUATBAN}', {book.TRIGIA}, '{book.TINHTRANG}', {book.SOLUONG})";
                // Command
                MySqlCommand cmd = new MySqlCommand(SQL, _conn);

                // Query và kiểm tra
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch {}
            finally
            {
                // Đóng kết nối
                _conn.Close();
            }
            return(false);
        }
 private void btnTiepNhan_Click(object sender, EventArgs e)
 {
     if (txtMaSach.Text != "" && txtTenSach.Text != "" && txtTheLoai.Text != "" && txtTacGia.Text != "" && txtNamXuatBan.Text != "" && txtNhaXuatBan.Text != "" && txtTriGia.Text != "")
     {
         // Tạo DTo
         DTO_SACH book = new DTO_SACH(int.Parse(txtMaSach.Text), txtTenSach.Text, txtTacGia.Text, int.Parse(txtTheLoai.Text), int.Parse(txtNamXuatBan.Text), txtNhaXuatBan.Text, int.Parse(txtTriGia.Text), "Het Hang", 0);
         // Them
         if (bllBook.themBook(book))
         {
             MessageBox.Show("Thêm thành công");
             this.TestDelegate.Invoke("OK");
         }
         else
         {
             MessageBox.Show("Thêm không thành công. Vui lòng kiểm tra lại");
         }
     }
     else
     {
         MessageBox.Show("Xin hãy nhập đầy đủ");
     }
 }
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (datagridDanhSachSach.SelectedRows.Count > 0)
            {
                // Lấy row hiện tại
                DataGridViewRow row = datagridDanhSachSach.SelectedRows[0];

                // Tạo DTo
                DTO_SACH book = new DTO_SACH(int.Parse(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()
                                             , row.Cells[2].Value.ToString(), int.Parse(row.Cells[3].Value.ToString())
                                             , int.Parse(row.Cells[4].Value.ToString()), row.Cells[5].Value.ToString()
                                             , int.Parse(row.Cells[6].Value.ToString()), row.Cells[7].Value.ToString()
                                             , int.Parse(row.Cells[8].Value.ToString())); // Vì ID tự tăng nên để ID số gì cũng dc
                PL_Book_Edit EditForm = new PL_Book_Edit(book);
                EditForm.EditDelegate = TestListen;
                EditForm.Show();
            }
            else
            {
                MessageBox.Show("Hãy chọn độc giả muốn sửa");
            }
        }
Beispiel #5
0
 private void btnLuuLai_Click(object sender, EventArgs e)
 {
     if (txtMaSach.Text != "" && txtTenSach.Text != "" && txtTheLoai.Text != "" && txtTacGia.Text != "" &&
         txtNamXuatBan.Text != "" && txtNhaXuatBan.Text != "" && txtTriGia.Text != "")
     {
         // Tạo DTo
         DTO_SACH book = new DTO_SACH(int.Parse(txtMaSach.Text), txtTenSach.Text, txtTacGia.Text,
                                      int.Parse(txtTheLoai.Text), int.Parse(txtNamXuatBan.Text), txtNhaXuatBan.Text, int.Parse(txtTriGia.Text), txtTrangThai.Text, 0);
         // Them
         if (bllsach.suaSach(book))
         {
             MessageBox.Show("Sửa thành công");
             this.EditDelegate.Invoke("OK");
         }
         else
         {
             MessageBox.Show("Sửa không thành công. Vui lòng kiểm tra lại");
         }
     }
     else
     {
         MessageBox.Show("Xin hãy nhập đầy đủ");
     }
 }
 public bool suaBook(DTO_SACH book)
 {
     return(dalBook.suaBook(book));
 }
 public bool themBook(DTO_SACH book)
 {
     return(dalBook.themBook(book));
 }
Beispiel #8
0
 public bool suaSach(DTO_SACH book)
 {
     return(dalsach.suaSach(book));
 }
Beispiel #9
0
 public bool themSach(DTO_SACH book)
 {
     return(dalsach.themSach(book));
 }
 public PL_Book_Edit(DTO_SACH book)
 {
     InitializeComponent();
     Edit = book;
 }