private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "" || dtDate.Text == "" || txtPhone.Text == "" || txtAddress.Text == "" || rdFemale.Checked == false && rdMale.Checked == false) { MessageBox.Show("Điền đầy đủ thông tin !"); } else { tbHocSinh add = new tbHocSinh(); add.hocSinh_Name = txtName.Text; add.hocSinh_NgaySinh = Convert.ToDateTime(dtDate.Text); add.hocSinh_Phone = txtPhone.Text; add.hocSinh_Address = txtAddress.Text; if (rdMale.Checked) { add.hocSinh_Gender = true; } else { add.hocSinh_Gender = false; } db.tbHocSinhs.InsertOnSubmit(add); db.SubmitChanges(); MessageBox.Show("Đã thêm thành công !"); getdata(); } }
//---------Nút Xóa Học sinh--------- private void btnRemove_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in grvList.Rows) { bool isSelected = Convert.ToBoolean(row.Cells[0].Value); if (isSelected) { int id_hs = Convert.ToInt32(row.Cells[1].Value.ToString()); tbHocSinh del = (from hs in db.tbHocSinhs where hs.hocSinh_Id == id_hs select hs).SingleOrDefault(); db.tbHocSinhs.DeleteOnSubmit(del); db.SubmitChanges(); } } MessageBox.Show("xoa thanh cong"); getDuLieuHocSinhConLai(); }