private void btnFinish_Click(object sender, EventArgs e) { SetErrorProvider(); if (txtSoBuoi.Text != "" && dtpDateStart.Value > DateTime.Now && dtpDateEnd.Value > dtpDateStart.Value) { using (var _context = new DBLapTrinhWin()) { var x = from u in _context.TienDoes where u.IDDeAn == key select u; if (x.Count() != 0) { x.First().SoBuoi = int.Parse(txtSoBuoi.Text.Trim()); } var y = from u in _context.DeAns where u.IDDeAn == key select u; if (y.Count() != 0) { var z = y.First(); z.DateStart = dtpDateStart.Value; z.DateEnd = dtpDateEnd.Value; z.Diem = txtDiem.Text.Trim(); } _context.SaveChanges(); Khoitao(); TaoDTG(); } } }
private void btnAddNhom_Click(object sender, EventArgs e) { SetErrorProvider(); if (cbLoaiDoAn.Text != "" && txtTenNhom.Text != "" && txtThanhVienNhom.Text != "" && cbMaMonHoc.Text != "" && cbMaChuyenNganh.Text != "") { using (var _context = new DBLapTrinhWin()) { if (cbLoaiDoAn.SelectedIndex == 0) /// Tạo ID nhóm đồ án môn học { string s = "DAMH" + "-" + cbMaMonHoc.Text; var stt = from u in _context.NhomSinhViens where u.IDNhom.Contains(s) select u; int sttcuoicung = stt.Count(); string Stt = NhomController.SoThuTuTiepTheo(sttcuoicung); txtIDNhom.Text = NhomController.CreateIDNhom("DAMH", cbMaMonHoc.Text, Stt); } else if (cbLoaiDoAn.SelectedIndex == 1) /// tạo ID nhóm tiểu luận chuyên ngành { string s = "TLCN" + "-" + cbMaChuyenNganh.Text; var stt = from u in _context.NhomSinhViens where u.IDNhom.Contains(s) select u; int sttcuoicung = stt.Count(); string Stt = NhomController.SoThuTuTiepTheo(sttcuoicung); txtIDNhom.Text = NhomController.CreateIDNhom("TLCN", cbMaChuyenNganh.Text, Stt); } else if (cbLoaiDoAn.SelectedIndex == 2) { string s = "DATN" + "-" + cbMaChuyenNganh.Text; var stt = from u in _context.NhomSinhViens where u.IDNhom.Contains(s) select u; int sttcuoicung = stt.Count(); string Stt = NhomController.SoThuTuTiepTheo(sttcuoicung); txtIDNhom.Text = NhomController.CreateIDNhom("DATN", cbMaChuyenNganh.Text, Stt); } } NhomSinhVien nhom = new NhomSinhVien(); nhom.IDNhom = txtIDNhom.Text; nhom.TenNhom = txtTenNhom.Text; nhom.ThanhVien = txtThanhVienNhom.Text; using (var _context = new DBLapTrinhWin()) { _context.NhomSinhViens.Add(nhom); _context.SaveChanges(); } DangKyNhomThanhCongEventArgs arg = new DangKyNhomThanhCongEventArgs { IdNhom = txtIDNhom.Text }; OnDangKyNhomThanhCong(arg); this.Close(); } }
public static bool UpdateStudent(SinhVien student) { using (var _context = new DBLapTrinhWin()) { _context.SinhViens.AddOrUpdate(student); _context.SaveChanges(); return(true); } }
private void checkboxHoanTat_CheckedChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(cbSoBuoi.Text)) { cbSoBuoi.Focus(); this.errorProvider1.SetError(cbSoBuoi, "Bạn phải chọn số buổi!"); } else { this.errorProvider1.SetError(cbSoBuoi, null); using (var _context = new DBLapTrinhWin()) { var get = (from u in _context.TienDoes where u.IDDeAn == key select u).FirstOrDefault(); string noidung = get.BaoCao; string link = get.LinkTaiLieu; string check = get.HoanThanh; noidung = noidung + rtxtNoiDung.Text + "$"; link = link + txtLinkTaiLieu.Text + ","; check = check + "true" + ","; get.BaoCao = noidung; get.LinkTaiLieu = link; get.HoanThanh = check; _context.SaveChanges(); Khoitao(); TaoDTG(); tienDo = (double)(BaoCaoTienDoController.GetHoanThanh(check).Count() - 1) / int.Parse(txtSoBuoi.Text); tienDo = Math.Round(tienDo, 2); var get1 = (from u in _context.DeAns where u.IDDeAn == key select u).FirstOrDefault(); get1.TienDo = tienDo; _context.SaveChanges(); } } }
public static bool DeleteStudent(string studentID) { using (var _context = new DBLapTrinhWin()) { var dbStudent = (from s in _context.SinhViens where s.Mssv == studentID && s.DaXoa == false select s).FirstOrDefault(); if (dbStudent == null) { return(false); } dbStudent.DaXoa = true; _context.SinhViens.AddOrUpdate(dbStudent); _context.SaveChanges(); return(true); } }
public static bool DeleteGiangVien(string ID) { using (var _context = new DBLapTrinhWin()) { var dbGiangVien = (from s in _context.GiangViens where s.MSGV == ID && s.DaXoa == false select s).FirstOrDefault(); if (dbGiangVien == null) { return(false); } dbGiangVien.DaXoa = true; _context.GiangViens.AddOrUpdate(dbGiangVien); _context.SaveChanges(); return(true); } }
private void btnDangKy_Click(object sender, EventArgs e) { SetErrorProvider(); if (txtIDNhom.Text != "" && txtTenDeAn.Text != "" && txtGVHD.Text != "" && txtMoTa.Text != "" && dtpDateStart.Value > DateTime.Now && dtpDateEnd.Value > dtpDateStart.Value) { string IDnhom = txtIDNhom.Text.Trim(); #region Tên nhóm hoặc giảng viên không tồn tại using (var _context = new DBLapTrinhWin()) { var nhom = from u in _context.NhomSinhViens where u.IDNhom == IDnhom select u; if (nhom.Count() == 0) { MessageBox.Show("Nhóm không tồn tại!"); this.ActiveControl = txtIDNhom; return; } string gvhd = txtGVHD.Text.Trim(); var gv = from u in _context.GiangViens where u.MSGV == gvhd select u; if (gv.Count() == 0) { MessageBox.Show("Giảng viên không tồn tại"); this.ActiveControl = txtGVHD; return; } } #endregion #region Xử lý lưu các thuộc tính vào database List <string> cacthuoctinh = new List <string>(); cacthuoctinh = DeAnController.TachIDNhom(IDnhom); string type = ""; if (cacthuoctinh[0] == "DAMH") { type = "1"; } else if (cacthuoctinh[0] == "TLCN") { type = "2"; } else if (cacthuoctinh[0] == "DATN") { type = "3"; } DeAn DeAnDangKy = new DeAn(); DeAnDangKy.IDDeAn = IDnhom; DeAnDangKy.TenDeAn = txtTenDeAn.Text.Trim(); DeAnDangKy.Type = type; DeAnDangKy.IDNhomSV = IDnhom; DeAnDangKy.GVHD = txtGVHD.Text.Trim(); DeAnDangKy.MoTa = txtMoTa.Text; if (type == "1") { DeAnDangKy.MonHoc = cacthuoctinh[1]; } else { DeAnDangKy.ChuyenNganh = cacthuoctinh[1]; } using (var _context = new DBLapTrinhWin()) { _context.DeAns.Add(DeAnDangKy); _context.SaveChanges(); } txtIDDeAn.Text = IDnhom; TienDo tienDo = new TienDo(); tienDo.IDDeAn = DeAnDangKy.IDDeAn; using (var _context = new DBLapTrinhWin()) { _context.TienDoes.Add(tienDo); _context.SaveChanges(); } MessageBox.Show("Thêm đề án thành công!"); AddDeAnThanhCongEventArgs arg = new AddDeAnThanhCongEventArgs(); OnAddDeAnThanhCong(arg); this.Close(); #endregion } }
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(); } }