private void DoGiangVien() { var giangVien = GiangVienController.GetGiangVien(this.msgv); txtMSGV.Text = giangVien.MSGV; txtHoTen.Text = giangVien.HoTen; try { dtpNgaySinh.Value = giangVien.NgaySinh.Value; } catch { dtpNgaySinh.Value = DateTime.Now; } txtQueQuan.Text = giangVien.QueQuan; cbGioiTinh.Text = giangVien.GioiTinh; cbxChuyenNganh.SelectedIndex = chuyenNganhs.IndexOf(chuyenNganhs.Where(x => x.IDChuyenNganh == giangVien.ChuyenNganh).FirstOrDefault()); }
private void btnDelete_Click(object sender, EventArgs e) { if (dtgThongTinGiangVien.SelectedRows.Count <= 0) { MessageBox.Show("Phải chọn giảng viên muốn xóa!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult dr; dr = MessageBox.Show("Bạn có chắc chắn muốn xóa giảng viên không?", "Thông báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { string id = dtgThongTinGiangVien.CurrentRow.Cells[0].Value.ToString(); if (GiangVienController.DeleteGiangVien(id) == false) { MessageBox.Show("Không thể xoá giảng viên này!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } DoDuLieu(); } }
private void DoDuLieu() { dtgThongTinGiangVien.DataSource = GiangVienController.GetAllGiangVien(""); dtgThongTinGiangVien.Refresh(); }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMSGV.Text.Trim())) { txtMSGV.Focus(); this.errorProvider1.SetError(txtMSGV, "Phải nhập mã số giảng viên!"); } else { this.errorProvider1.SetError(txtMSGV, null); DBLapTrinhWin db = new DBLapTrinhWin(); if (this.msgv == null) { GiangVien addOrUpdateGV = new GiangVien() { MSGV = txtMSGV.Text, HoTen = txtHoTen.Text, NgaySinh = DateTime.Parse(dtpNgaySinh.Value.ToString()), QueQuan = txtQueQuan.Text, GioiTinh = cbGioiTinh.Text, ChuyenNganh = ((ChuyenNganhViewModel)cbxChuyenNganh.SelectedItem).IDChuyenNganh, DaXoa = false }; if (addOrUpdateGV.MSGV.Length > 4) { txtMSGV.Focus(); this.errorProvider1.SetError(txtMSGV, "Mã số giảng viên chỉ gồm 4 kí tự!"); return; } else { this.errorProvider1.SetError(txtMSGV, null); } if (GiangVienController.GetGiangVien(txtMSGV.Text) != null) { txtMSGV.Focus(); this.errorProvider1.SetError(txtMSGV, "Mã số giảng viên này đã tồn tại!"); return; } else { this.errorProvider1.SetError(txtMSGV, null); } db.GiangViens.Add(addOrUpdateGV); } else { GiangVien updateGV = db.GiangViens.Where(x => x.MSGV == msgv).SingleOrDefault(); updateGV.HoTen = txtHoTen.Text; updateGV.NgaySinh = dtpNgaySinh.Value; updateGV.QueQuan = txtQueQuan.Text; updateGV.GioiTinh = cbGioiTinh.Text; updateGV.ChuyenNganh = ((ChuyenNganhViewModel)cbxChuyenNganh.SelectedItem).IDChuyenNganh; updateGV.DaXoa = false; } db.SaveChanges(); this.Close(); } }