Esempio n. 1
0
        /// <summary>
        /// 按学号删除学生
        /// </summary>
        /// <param name="value"></param>
        public void Delete(string value)
        {
            SchoolrollMethod roll = new SchoolrollMethod();

            using (var dbcontext = new srContext())
            {
                var student    = dbcontext.Student.FirstOrDefault(u => u.Sno == value);
                var schoolroll = dbcontext.Schoolroll.FirstOrDefault(u => u.Sno == value);
                var cerlist    = new List <Certificate>();
                var cetlists   = new List <Cet>();
                var scorelist  = new List <Score>();
                foreach (var infor in dbcontext.Certificate)
                {
                    if (infor.Sno == value)
                    {
                        cerlist.Add(infor);
                    }
                }
                foreach (var infor in dbcontext.Cet)
                {
                    if (infor.Sno == value)
                    {
                        cetlists.Add(infor);
                    }
                }
                foreach (var infor in dbcontext.Score)
                {
                    if (infor.Sno == value)
                    {
                        scorelist.Add(infor);
                    }
                }
                if (cerlist != null)
                {
                    foreach (var infor in cerlist)
                    {
                        dbcontext.Certificate.Remove(infor);
                    }
                }
                if (cetlists != null)
                {
                    foreach (var infor in cetlists)
                    {
                        dbcontext.Cet.Remove(infor);
                    }
                }
                if (scorelist != null)
                {
                    foreach (var infor in scorelist)
                    {
                        dbcontext.Score.Remove(infor);
                    }
                }
                dbcontext.Schoolroll.Remove(schoolroll);
                dbcontext.Student.Remove(student);
                dbcontext.SaveChanges();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取一个学生信息
        /// </summary>
        /// <param name="no"></param>
        /// <returns></returns>
        public Student FindStudent(string no)
        {
            var student = new Student();

            using (var dbcontext = new srContext())
            {
                student = dbcontext.Student.FirstOrDefault(u => u.Sno == no);
            }
            var schoolroll = new Schoolroll();
            var function   = new SchoolrollMethod();

            schoolroll         = function.GetRoll(no);
            student.Schoolroll = schoolroll;
            return(student);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取所有学生信息
        /// </summary>
        /// <returns></returns>
        public List <Student> ReadDB()
        {
            List <Student> students   = new List <Student>();
            var            schoolroll = new Schoolroll();
            var            function   = new SchoolrollMethod();

            using (var dbcontext = new srContext())
            {
                foreach (var value in dbcontext.Student)
                {
                    schoolroll       = function.GetRoll(value.Sno);
                    value.Schoolroll = schoolroll;
                    students.Add(value);
                }
            }
            return(students);
        }