private void btnThem_Click(object sender, EventArgs e) { try { if (txtMaDG.Text == "") { MessageBox.Show("Bạn chưa nhập mã độc giả, nhập lại!"); } else if (txtTenDG.Text == "") { MessageBox.Show("Bạn chưa nhập tên độc giả, nhập lại!"); } else if (txtNgayHetHan.Text == "") { MessageBox.Show("Bạn chưa nhập ngày hết hạn, nhập lại!"); } else if (txtNgayCap.Text == "") { MessageBox.Show("Bạn chưa nhập ngày cấp, nhập lại"); } else if (txtNgaySinh.Text == "") { MessageBox.Show("Bạn chưa nhập ngày sinh, nhập lại"); } else { int dem = 0; foreach (DataRow row in dtDocGia.Rows) { var check = row["maDG"].ToString().Trim(); if (txtMaDG.Text.Trim() == check) { dem++; break; } } if (dem == 0) { Boolean x = true; if (cbGioiTinh.SelectedValue.ToString().Equals("Nu")) { x = x && false; } docgia.InsertDocGia(txtMaDG.Text, txtTenDG.Text, x, txtNgaySinh.Text, cbMaDT.SelectedValue.ToString(), txtNgayCap.Text, txtNgayHetHan.Text); MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show("Mã Độc Giả đã tồn tại, nhập lại", "cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception) { MessageBox.Show("không thêm được độc giả, thử lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }