private void btnSua_Click(object sender, EventArgs e)
 {
     nh.MaNhanHieu  = txtMaNhanHieu.Text;
     nh.TenNhanHieu = txtTenNhanHieu.Text;
     if (dtNH.Rows.Count == 0)
     {
         MessageBox.Show("Không còn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (txtMaNhanHieu.Text == "")
     {
         MessageBox.Show("Chưa chọn dòng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (txtTenNhanHieu.Text.Trim().Length == 0)
     {
         MessageBox.Show("chưa nhập tên nhãn hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     try {
         NhanHieuDB db = new NhanHieuDB();
         if (db.UpdateNhanHieu(nh))
         {
             MessageBox.Show("Sửa Thành công ", "Thông báo", MessageBoxButtons.OK);
         }
     } catch {
         MessageBox.Show("Sửa Thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     LoadData();
     ResetValue();
 }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string MaNhanHieu = txtMaNhanHieu.Text;

            if (dtNH.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanHieu.Text == "")
            {
                MessageBox.Show("Hãy chọn một dòng để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn có muốn xoá không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                NhanHieuDB db = new NhanHieuDB();
                try {
                    if (db.DeleteNhanHieu(MaNhanHieu))
                    {
                        MessageBox.Show("Delete Thành công", "Thông báo", MessageBoxButtons.OK);
                    }
                } catch {
                    MessageBox.Show("Delete thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    db.CheckDelete();
                }

                LoadData();
                ResetValue();
            }
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            nh.MaNhanHieu  = txtMaNhanHieu.Text;
            nh.TenNhanHieu = txtTenNhanHieu.Text;
            NhanHieuDB db = new NhanHieuDB();

            if (txtMaNhanHieu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Hãy nhập Mã!!!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNhanHieu.Focus();
                return;
            }
            if (txtTenNhanHieu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Hãy nhập Tên!!!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenNhanHieu.Focus();
                return;
            }

            if (db.checkDuplicate(txtMaNhanHieu.Text.Trim()))
            {
                MessageBox.Show("Mã này đã tồn tại !!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNhanHieu.Focus();
                return;
            }
            try {
                if (db.InsertNhanHieu(nh))
                {
                    MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK);
                }
            } catch {
                MessageBox.Show("Thêm mới thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNhanHieu.Focus();
            }
            LoadData();
            ResetValue();
            btnXoa.Enabled        = true;
            btnThem.Enabled       = true;
            btnSua.Enabled        = true;
            btnDong.Enabled       = true;
            btnLuu.Enabled        = false;
            txtMaNhanHieu.Enabled = false;
        }