Ejemplo n.º 1
0
 //根据用户名,查询用户是否存在
 public static Teacher SelectTeacherByUserName(string userName)
 {
     using (ExamDBEntities db = new ExamDBEntities()) {
         Teacher teacher = db.Teachers.SingleOrDefault(t => t.TeacherLoginName == userName);
         return(teacher);
     }
 }
Ejemplo n.º 2
0
 public static List <Student> SelectAllStudent()
 {
     using (ExamDBEntities db = new ExamDBEntities())
     {
         return(db.Students.ToList());
     }
 }
Ejemplo n.º 3
0
        public static bool UpdateStudentInfo(Student s)
        {
            try
            {
                ////查询出来一个student
                //Student stu = StudentServer.SelectStudentByID(s.StuID);
                //ExamDBEntities db = new ExamDBEntities();
                //db.Entry(stu).State = EntityState.Modified;
                ////逐个更新
                //stu.StuName = s.StuName;
                //stu.StuLoginName = s.StuLoginName;
                //stu.StuSex = s.StuSex;
                //stu.StuGrade = s.StuGrade;
                //stu.StuEmail = s.StuEmail;
                //stu.StuLoginPwd = s.StuLoginPwd;
                //stu.StuPhone = s.StuPhone;

                //查询出来一个student
                Student        stu = StudentServer.SelectStudentByID(s.StuID);
                ExamDBEntities db  = new ExamDBEntities();
                //这也可以实现对象的快速修改,推荐用这个方法
                db.Entry(s).State = EntityState.Modified;    //直接将传入的对象,设置修改装填
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 public static Student SelectStudentByID(int id)
 {
     using (ExamDBEntities db = new ExamDBEntities())
     {
         Student stu = db.Students.SingleOrDefault(s => s.StuID == id);
         return(stu);
     }
 }
Ejemplo n.º 5
0
 public static Student SelectStudentByName(string name)
 {
     using (ExamDBEntities db = new ExamDBEntities())
     {
         Student s = db.Students.FirstOrDefault(stu => stu.StuLoginName == name);
         return(s);
     }
 }
Ejemplo n.º 6
0
 public static bool AddStudent(Student s)
 {
     using (ExamDBEntities db = new ExamDBEntities())
     {
         try
         {
             db.Entry(s).State = EntityState.Added;//也可以不加,因为Add时,会自动修改状态
             db.Students.Add(s);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Ejemplo n.º 7
0
 public static bool DeleteStudentByID(int id)
 {
     try
     {
         //获取要删除的学生信息
         Student        s  = StudentServer.SelectStudentByID(id);
         ExamDBEntities db = new ExamDBEntities();
         //将要删除的学生对象状态,修改为删除。
         db.Entry(s).State = EntityState.Deleted;
         db.Students.Remove(s);//Remove删除
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
 public BestSellingProductsDataSource(ExamDBEntities context)
 {
     this._context = context;
 }