예제 #1
0
        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();
            }
        }