private void btnCapNhatAnhSinhVien_Click(object sender, EventArgs e) { try { MemoryStream streamm = new MemoryStream(); pictureBoxSV.Image.Save(streamm, ImageFormat.Jpeg); MyDbContextDataContext myDb = new MyDbContextDataContext(); SinhVien sv = new SinhVien(); sv = myDb.SinhViens.Where(p => p.MaSV == txtMaSV.Text).Single(); sv.MaSV = txtMaSV.Text; sv.TenSV = txtHoTen.Text; sv.MaLop = txtMaLop.Text; sv.HinhAnh = streamm.ToArray(); if (rbNam.Checked == true) { sv.GioiTinh = "Nam"; } else { sv.GioiTinh = "Nữ"; } myDb.SubmitChanges(); HienThiDuLieuLenListView(); MessageBox.Show("Cập Nhật Thành Công"); } catch (Exception) { MessageBox.Show("Cập Nhật Thất Bại!"); } }
private void btnThem_Click_1(object sender, EventArgs e) { try { if (txtMaSV.Text == "" || txtHoTen.Text == "" || txtMaLop.Text == "" || cbKhoa.SelectedIndex == -1) { MessageBox.Show("Vui lòng nhập đầy đủ thông tin"); } else { MemoryStream streamm = new MemoryStream(); pictureBoxSV.Image.Save(streamm, ImageFormat.Jpeg); MyDbContextDataContext myDb = new MyDbContextDataContext(); SinhVien sv = new SinhVien(); sv.MaSV = txtMaSV.Text; sv.TenSV = txtHoTen.Text; sv.MaLop = txtMaLop.Text; sv.HinhAnh = streamm.ToArray(); if (rbNam.Checked == true) { sv.GioiTinh = "Nam"; } else if (rbNu.Checked == true) { sv.GioiTinh = "Nữ"; } myDb.SinhViens.InsertOnSubmit(sv); myDb.SubmitChanges(); HienThiDuLieuLenListView(); MessageBox.Show("Thêm Sinh Viên Thành Công !"); } } catch (Exception) { MessageBox.Show("Lỗi Kết Nối"); } }