private void btnThem_Click(object sender, EventArgs e) { try { if (txtMa.Text == "") { MessageBox.Show("Bạn chưa nhập mã thể loại, nhập lại"); } else if (txtTen.Text == "") { MessageBox.Show("Bạn chưa nhập tên thể loại, xin nhập lại"); } else { int dem = 0; foreach (DataRow row in dtTheloai.Rows) { var check = row["maThL"].ToString().Trim(); if (txtMa.Text.Trim() == check) { dem++; break; } } if (dem == 0) { theloai.InsertTheLoai(txtMa.Text, txtTen.Text, txtGhiChu.Text); MessageBox.Show("Thêm thể loại thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show("Mã thể loại đã tồn tại, nhập lại", "cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception) { MessageBox.Show("khong them được thể loại, thử lại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }