private void btnLuuSV_Click(object sender, EventArgs e) { if (txtMssv.Text == "" || txtHoTen.Text == "" || txtNoiSinh.Text == "" || txtLop.Text == "" || txtSDT.Text == "" || txtEmail.Text == "") { if (string.IsNullOrEmpty(txtMssv.Text.Trim())) { txtMssv.BorderColor = Color.Red; txtMssv.PlaceholderText = "bạn chưa nhập mssv"; txtMssv.PlaceholderForeColor = Color.Red; } if (string.IsNullOrEmpty(txtHoTen.Text.Trim())) { txtHoTen.BorderColor = Color.Red; txtHoTen.PlaceholderText = "bạn chưa nhập họ tên"; txtHoTen.PlaceholderForeColor = Color.Red; } if (string.IsNullOrEmpty(txtNoiSinh.Text.Trim())) { txtNoiSinh.BorderColor = Color.Red; txtNoiSinh.PlaceholderText = "bạn chưa nhập nơi sinh"; txtNoiSinh.PlaceholderForeColor = Color.Red; } if (string.IsNullOrEmpty(txtLop.Text.Trim())) { txtLop.BorderColor = Color.Red; txtLop.PlaceholderText = "bạn chưa nhập lớp"; txtLop.PlaceholderForeColor = Color.Red; } if (string.IsNullOrEmpty(txtSDT.Text.Trim())) { txtSDT.BorderColor = Color.Red; txtSDT.PlaceholderText = "bạn chưa nhập SDT"; txtSDT.PlaceholderForeColor = Color.Red; } if (string.IsNullOrEmpty(txtEmail.Text.Trim())) { txtEmail.BorderColor = Color.Red; txtEmail.PlaceholderText = "bạn chưa nhập Email"; txtEmail.PlaceholderForeColor = Color.Red; } } else { if (flagLuu == 0) { SINH_VIEN sinhvien = sinhVienBLL.Get(x => x.Mssv.Trim() == txtMssv.Text.Trim()); if (sinhvien == null) { sinhvien = new SINH_VIEN(); sinhvien.Mssv = txtMssv.Text; sinhvien.HoTen = txtHoTen.Text; sinhvien.NgaySinh = dtpkNgaySinh.Value; sinhvien.GioiTinh = cbGioiTinh.Text; sinhvien.NoiSinh = txtNoiSinh.Text; sinhvien.SDT = txtSDT.Text; sinhvien.Lop = txtLop.Text; sinhvien.DonVi = cbDonVi.Text; sinhvien.Khoa = cbKhoa.Text; sinhvien.Email = txtEmail.Text; List <USER> us = db.USERs.ToList(); int iduser = us.Last().IDuser; sinhvien.IDuser = iduser; sinhVienBLL.Add(sinhvien); MessageBox.Show("Thêm Thành Công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowSinhVien(sinhVienBLL.DsSinhVien().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList()); pn_Sort.Visible = true; pn_ThemSua.Visible = false; btnLuuSV.Visible = false; btnThemKQ.Enabled = true; } else { MessageBox.Show("Mssv không được trùng !!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); loadntnTT(); } } else { try { SINH_VIEN sv = sinhVienBLL.Get(x => x.Mssv.Trim() == txtMssv.Text.Trim()); sv.HoTen = txtHoTen.Text; sv.NgaySinh = dtpkNgaySinh.Value; sv.GioiTinh = cbGioiTinh.Text; sv.NoiSinh = txtNoiSinh.Text; sv.SDT = txtSDT.Text; sv.Lop = txtLop.Text; sv.DonVi = cbDonVi.Text; sv.Khoa = cbKhoa.Text; sv.Email = txtEmail.Text; sinhVienBLL.Edit(sv); MessageBox.Show("Sửa Thành Công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowSinhVien(sinhVienBLL.DsSinhVien().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList()); pn_Sort.Visible = true; pn_ThemSua.Visible = false; btnLuuSV.Visible = false; btnThemKQ.Enabled = true; } catch (NullReferenceException) { MessageBox.Show("Sửa thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); loadntnTT(); } } } }
private void dtgv_SV_CellContentClick(object sender, DataGridViewCellEventArgs e) { string name = dtgv_SV.Columns[e.ColumnIndex].Name; if (name == "Xem") { editbtnxem(); bindingSV(); } if (name == "Sua") { DataGridViewRow row = this.dtgv_SV.Rows[e.RowIndex]; if (listPQ_SV.Select(x => x.Role).ToArray().First() == "admin") { if (row.Cells["DonVi"].Value.ToString() == listPQ_SV.Select(x => x.DonVi).ToArray().First()) { loadbtnSua(); cbDonVi.Enabled = false; cbDonVi.Text = listPQ_SV.Select(x => x.DonVi).ToArray().First().ToString(); } else { pn_ThemSua.Visible = false; pn_Sort.Visible = true; MessageBox.Show("bạn không được quyền sửa"); } } else { loadbtnSua(); } } if (name == "Xoa") { DialogResult dr = MessageBox.Show("Bạn chắc chắn muốn xóa hóa đơn này?", "Xác nhận xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { //try //{ //} //catch //{ // MessageBox.Show("Xóa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); //} var getmssv = dtgv_SV["Mssv", e.RowIndex].Value.ToString(); SINH_VIEN sv = Mydb.GetInstance().SINH_VIEN.Where(p => p.Mssv == getmssv).SingleOrDefault(); USER user = Mydb.GetInstance().USERs.Where(p => p.IDuser == sv.IDuser).SingleOrDefault(); //DIEM diem = Mydb.GetInstance().DIEMs.Where(p => p.Mssv == sv.Mssv).SingleOrDefault(); //THAMGIA_CHUONGTRINH TGCT = Mydb.GetInstance().THAMGIA_CHUONGTRINH.Where(p => p.Mssv == sv.Mssv).SingleOrDefault(); //THUCHIEN_TIEUCHUAN THTC = Mydb.GetInstance().THUCHIEN_TIEUCHUAN.Where(p => p.Mssv == sv.Mssv).SingleOrDefault(); //THOIDIEM_SV_THAMGIA TDSV = Mydb.GetInstance().THOIDIEM_SV_THAMGIA.Where(p => p.Mssv == sv.Mssv).SingleOrDefault(); //KQ_THEO_TIEUCHI KQ = Mydb.GetInstance().KQ_THEO_TIEUCHI.Where(p => p.Mssv == sv.Mssv).SingleOrDefault(); Mydb.GetInstance().USERs.Remove(user); Mydb.GetInstance().DIEMs.Remove(Mydb.GetInstance().DIEMs.Single(p => p.Mssv == getmssv)); Mydb.GetInstance().THAMGIA_CHUONGTRINH.Remove(Mydb.GetInstance().THAMGIA_CHUONGTRINH.Single(p => p.Mssv == getmssv)); Mydb.GetInstance().THUCHIEN_TIEUCHUAN.Remove(Mydb.GetInstance().THUCHIEN_TIEUCHUAN.Single(p => p.Mssv == getmssv)); Mydb.GetInstance().THOIDIEM_SV_THAMGIA.Remove(Mydb.GetInstance().THOIDIEM_SV_THAMGIA.Single(p => p.Mssv == getmssv)); Mydb.GetInstance().KQ_THEO_TIEUCHI.Remove(Mydb.GetInstance().KQ_THEO_TIEUCHI.Single(p => p.Mssv == getmssv)); sinhVienBLL.Delete(sv); MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("sinh viên vẫn được giữ nguyên"); } ShowSinhVien(sinhVienBLL.DsSinhVien().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList()); } }