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 btnFind_Click(object sender, EventArgs e) { string mssv = txtMSSV.Text; string name = txtHoTen.Text; string gioitinh = cbGioiTinh.Text; string quequan = txtQueQuan.Text; string chuyennganh = cmbChuyenNganh.Text; string namnhaphoc = txtNamNhapHoc.Text; using (var _context = new DBLapTrinhWin()) { var x = from u in _context.SinhViens where u.Mssv.Contains(mssv) && u.HoTen.Contains(name) && u.GioiTinh.Contains(gioitinh) && u.QueQuan.Contains(quequan) && u.IDChuyenNganh.Contains(chuyennganh) && u.NamNhapHoc.Contains(namnhaphoc) && u.DaXoa == false select new { u.Mssv, u.HoTen, u.NgaySinh, u.GioiTinh, u.QueQuan, u.Khoa, u.IDChuyenNganh, u.NamNhapHoc }; if (x.Count() == 0) { MessageBox.Show("Không có kết quả"); return; } var i = x.First(); dtgThongTinSinhVien.AutoGenerateColumns = true; this.dtgThongTinSinhVien.DataSource = x.ToList(); } }
private void txtGVHD_TextChanged(object sender, EventArgs e) { lstViewGVHD.Items.Clear(); string s = txtGVHD.Text; using (var _context = new DBLapTrinhWin()) { var x = from u in _context.GiangViens where u.MSGV.Contains(s) && u.DaXoa == false select u; foreach (var i in x) { string noi = i.MSGV + ": " + i.HoTen; lstViewGVHD.Items.Add(noi); } } if (s == string.Empty) { this.lstViewGVHD.Visible = false; } else { this.lstViewGVHD.Visible = true; } }
public static bool UpdateStudent(SinhVien student) { using (var _context = new DBLapTrinhWin()) { _context.SinhViens.AddOrUpdate(student); _context.SaveChanges(); return(true); } }
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 SinhVien GetStudent(string studentID) { using (var _context = new DBLapTrinhWin()) { var dbStudent = (from s in _context.SinhViens where s.Mssv == studentID && s.DaXoa == false select s).FirstOrDefault(); return(dbStudent); } }
private void DoDuLieu() { string IDdean = txtIDDeAn.Text.Trim(); string tendean = txtTenDeAn.Text.Trim(); string loaidean = cbType.Text; string idnhom = txtIDNhom.Text.Trim(); string gvhd = txtGVHD.Text.Trim(); string idchuyennganh = txtMaChuyenNganh.Text.Trim(); string idmonhoc = txtMaMonHoc.Text.Trim(); List <string> a = new List <string>(); string type = ""; if (loaidean == cbType.Items[0].ToString()) { type = "0"; } else if (loaidean == cbType.Items[1].ToString()) { type = "1"; } else if (loaidean == cbType.Items[2].ToString()) { type = "2"; } using (var _context = new DBLapTrinhWin()) { var x = (from u in _context.DeAns where u.IDDeAn.Contains(IDdean) && u.TenDeAn.Contains(tendean) && u.Type.Contains(type) && u.IDNhomSV.Contains(idnhom) && u.GiangVien.HoTen.Contains(gvhd) && u.IDDeAn.Contains(idchuyennganh) && u.IDDeAn.Contains(idmonhoc) select new DeAnViewModel { IDDeAn = u.IDDeAn, TenDeAn = u.TenDeAn, TenNhom = u.NhomSinhVien.TenNhom, MoTa = u.MoTa, TenMonHoc = u.MonHoc1.TenMonHoc, LoaiDeAn = u.Type1.LoaiDeAn, StringThanhVien = u.NhomSinhVien.ThanhVien, TenChuyenNganh = u.ChuyenNganh1.TenChuyenNganh, HoTenGV = u.GiangVien.HoTen, DateStart = u.DateStart, DateEnd = u.DateEnd, Diem = u.Diem, TienDo = u.TienDo.HasValue ? (u.TienDo * 100).ToString() + "%" : "0%" }).ToList(); foreach (var deAn in x) { deAn.DanhSachThanhVien = NhomController.GetDanhSachThanhVien(deAn.StringThanhVien); } this.dtgDeAn.DataSource = x; } }
public static GiangVien GetGiangVien(string IDGiangVien) { using (var _context = new DBLapTrinhWin()) { var dbGiangVien = (from s in _context.GiangViens where s.MSGV == IDGiangVien select s).FirstOrDefault(); return(dbGiangVien); } }
public static List <ChuyenNganhViewModel> GetAllChuyenNganh() { using (var _context = new DBLapTrinhWin()) { var model = _context.ChuyenNganhs; var result = model.Select(x => new ChuyenNganhViewModel { IDChuyenNganh = x.IDChuyenNganh, TenChuyenNganh = x.TenChuyenNganh }).ToList(); return(result); } }
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); } }
private void btnFind_Click(object sender, EventArgs e) { using (var _context = new DBLapTrinhWin()) { string msgv = txtMSGV.Text; string name = txtHoTen.Text; string gioitinh = cbGioiTinh.Text; string quequan = txtQueQuan.Text; string chuyennganh = txtChuyenNganh.Text; var x = from u in _context.GiangViens where u.MSGV.Contains(msgv) && u.HoTen.Contains(name) && u.GioiTinh.Contains(gioitinh) && u.QueQuan.Contains(quequan) && u.ChuyenNganh.Contains(chuyennganh) && u.DaXoa == false select new { u.MSGV, u.HoTen, u.NgaySinh, u.GioiTinh, u.QueQuan, u.ChuyenNganh1.TenChuyenNganh }; this.dtgThongTinGiangVien.DataSource = x.ToList(); } }
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); } }
public static List <string> GetDanhSachThanhVien(string s) { List <string> a = new List <string>(); string[] tam = s.Split(','); using (var _context = new DBLapTrinhWin()) { foreach (var i in tam) { var x = (from u in _context.SinhViens where u.Mssv == i select u).First(); string y = x.Mssv + ": " + x.HoTen; a.Add(y); } } return(a); }
private void FrmAddNhomSinhVien_Load(object sender, EventArgs e) { using (var _context = new DBLapTrinhWin()) { var monhoc = from u in _context.MonHocs select new { u.MaMonHoc }; foreach (var x in monhoc) { cbMaMonHoc.Items.Add(x.MaMonHoc.Trim()); } var chuyennganh = from u in _context.ChuyenNganhs select new { u.IDChuyenNganh }; foreach (var x in chuyennganh) { cbMaChuyenNganh.Items.Add(x.IDChuyenNganh.Trim()); } } }
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 List <SinhVienViewModel> GetListStudent() { using (var _context = new DBLapTrinhWin()) { var model = (from t in _context.SinhViens where t.DaXoa == false select t) .Select(x => new SinhVienViewModel { Mssv = x.Mssv, HoTen = x.HoTen, NgaySinh = x.NgaySinh ?? DateTime.MinValue, QueQuan = x.QueQuan, GioiTinh = x.GioiTinh, NamNhapHoc = x.NamNhapHoc, ChuyenNganh = x.ChuyenNganh.TenChuyenNganh }).ToList(); return(model); } }
public static List <GiangVienViewModel> GetAllGiangVien(string searchString) { using (var _context = new DBLapTrinhWin()) { var dbGiangVien = (from s in _context.GiangViens where s.DaXoa == false select s); List <GiangVienViewModel> gv = dbGiangVien.Select(x => new GiangVienViewModel() { MSGV = x.MSGV, HoTen = x.HoTen, NgaySinh = x.NgaySinh.HasValue ? x.NgaySinh.Value : DateTime.MinValue, GioiTinh = x.GioiTinh, QueQuan = x.QueQuan, ChuyenNganh = x.ChuyenNganh1.TenChuyenNganh }).ToList(); return(gv); } }
public void Khoitao() { using (var _context = new DBLapTrinhWin()) { var x = (from u in _context.TienDoes where u.IDDeAn == key select u).FirstOrDefault(); TienDoBaoCao present = new TienDoBaoCao(); present.SoBuoi = x.SoBuoi; txtSoBuoi.Text = (present.SoBuoi).ToString(); if (cbSoBuoi.Items.Count <= 0) { for (int i = 1; i <= present.SoBuoi; i++) { cbSoBuoi.Items.Add(i); } } var m = from u in _context.DeAns where u.IDDeAn == key select u; if (m.Count() != 0) { var n = m.First(); if (!(n.Diem is null)) { txtDiem.Text = n.Diem.ToString(); } if (!(n.DateStart is null || n.DateEnd is null)) { dtpDateStart.Value = DateTime.Parse(n.DateStart.Value.ToString()); dtpDateEnd.Value = DateTime.Parse(n.DateEnd.Value.ToString()); } } } }
private void txtFindMSSV_TextChanged(object sender, EventArgs e) { lstViewThanhVienNhom.Items.Clear(); using (var _context = new DBLapTrinhWin()) { string s = txtFindMSSV.Text; var x = (from u in _context.SinhViens where u.Mssv.Contains(s) && u.DaXoa == false select u); foreach (var i in x) { string noiten = i.Mssv + ": " + i.HoTen; lstViewThanhVienNhom.Items.Add(noiten); } } if (txtFindMSSV.Text == string.Empty) { this.lstViewThanhVienNhom.Visible = false; } else { this.lstViewThanhVienNhom.Visible = true; } }
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(); } }
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 } }
public void TaoDTG() { using (var _context = new DBLapTrinhWin()) { int sobuoi = 0; var x = from u in _context.TienDoes where u.IDDeAn == key select u; if (x.Count() != 0) { if (x.First().SoBuoi != null) { sobuoi = (int)x.First().SoBuoi; } } var sobuoihientai = from u in _context.TienDoes where u.HoanThanh == null && u.IDDeAn == key select u; if (sobuoihientai.Count() == 1) { List <TienDoBaoCao> dtg = new List <TienDoBaoCao>(); for (int j = 0; j < sobuoi; j++) { TienDoBaoCao k = new TienDoBaoCao(); string buoi = "Buổi " + (j + 1).ToString(); k.Buoi = buoi; dtg.Add(k); } dtgTienDo.DataSource = dtg; return; } string xnd = ""; string xlink = ""; string xcheck = ""; if ((x.First().BaoCao != null)) { xnd = x.First().BaoCao; } if ((x.First().LinkTaiLieu != null)) { xlink = x.First().LinkTaiLieu; } if ((x.First().HoanThanh != null)) { xcheck = x.First().HoanThanh; } List <string> noidung = BaoCaoTienDoController.GetDanhSachNoiDungBaoCao(xnd); List <string> link = BaoCaoTienDoController.GetDanhSachLinkTaiLieu(xlink); List <bool> check = BaoCaoTienDoController.GetHoanThanh(xcheck); List <TienDoBaoCao> dtgsource = new List <TienDoBaoCao>(); for (int i = 0; i < sobuoi; i++) { TienDoBaoCao k = new TienDoBaoCao(); string buoi = "Buổi " + (i + 1).ToString(); k.Buoi = buoi; if (i < noidung.Count()) { k.NoiDung = noidung[i]; } if (i < link.Count()) { k.Link = link[i]; } if (i < check.Count()) { k.HoanThanh = check[i]; } dtgsource.Add(k); } dtgTienDo.DataSource = dtgsource; } }
private void btnFind_Click(object sender, EventArgs e) { string IDdean = txtIDDeAn.Text.Trim(); string tendean = txtTenDeAn.Text.Trim(); string loaidean = cbType.Text; string idnhom = txtIDNhom.Text.Trim(); string gvhd = txtGVHD.Text.Trim(); string idchuyennganh = txtMaChuyenNganh.Text.Trim(); string idmonhoc = txtMaMonHoc.Text.Trim(); List <string> a = new List <string>(); string type = ""; if (loaidean == cbType.Items[0].ToString()) { type = "0"; } else if (loaidean == cbType.Items[1].ToString()) { type = "1"; } else if (loaidean == cbType.Items[2].ToString()) { type = "2"; } using (var _context = new DBLapTrinhWin()) { var x = from u in _context.DeAns where u.IDDeAn.Contains(IDdean) && u.TenDeAn.Contains(tendean) && u.Type.Contains(type) && u.IDNhomSV.Contains(idnhom) && u.GiangVien.HoTen.Contains(gvhd) && u.IDDeAn.Contains(idchuyennganh) && u.IDDeAn.Contains(idmonhoc) select new { u.IDDeAn, u.TenDeAn, u.NhomSinhVien.TenNhom, u.MoTa, u.MonHoc1.TenMonHoc, u.Type1.LoaiDeAn, u.NhomSinhVien.ThanhVien, u.ChuyenNganh1.TenChuyenNganh, u.GiangVien.HoTen, u.DateStart, u.DateEnd, u.TienDo, u.Diem }; List <DeAnViewModel> y = new List <DeAnViewModel>(); foreach (var i in x) { DeAnViewModel k = new DeAnViewModel(); k.IDDeAn = i.IDDeAn; k.TenDeAn = i.TenDeAn; k.TenNhom = i.TenNhom; k.MoTa = i.MoTa; k.TenMonHoc = i.TenMonHoc; k.LoaiDeAn = i.LoaiDeAn; k.StringThanhVien = i.ThanhVien; k.TenChuyenNganh = i.TenChuyenNganh; k.HoTenGV = i.HoTen; k.DateStart = i.DateStart; k.DateEnd = i.DateEnd; k.TienDo = i.TienDo.HasValue ? (i.TienDo * 100).ToString() + "%" : "0%"; k.Diem = i.Diem; k.DanhSachThanhVien = NhomController.GetDanhSachThanhVien(k.StringThanhVien); y.Add(k); } this.dtgDeAn.DataSource = y; } }