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="student"></param>
 public void  Change(Student student)
 {
     using (var dbcontext = new srContext())
     {
         var stu = dbcontext.Student.FirstOrDefault(u => u.Sno == student.Sno);
         var sch = dbcontext.Schoolroll.FirstOrDefault(u => u.Sno == student.Sno);
         stu.Sphone     = student.Sphone;
         stu.Saddress   = student.Saddress;
         sch.Department = student.Schoolroll.Department;
         sch.Major      = student.Schoolroll.Major;
         sch.Class      = student.Schoolroll.Class;
         sch.Type       = student.Schoolroll.Type;
         sch.Length     = student.Schoolroll.Length;
         dbcontext.SaveChanges();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 增加一个学生
        /// </summary>
        /// <param name="student"></param>
        /// <returns></returns>
        public bool Addstudent(Student student)
        {
            var infor = student;

            infor.Spassword         = "******";
            infor.Schoolroll.School = "西安建筑科技大学";
            infor.Schoolroll.Sno    = student.Sno;
            var str = Check(student);

            if (str == null)
            {
                using (var db = new srContext())
                {
                    if (db.Student.FirstOrDefault(u => u.Sno == infor.Sno) != null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (infor.Ssex == "男" || infor.Ssex == "女")
                        {
                            db.Student.Add(infor);
                            db.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }

            else
            {
                return(false);
            }
        }