public bool addProfessor(int UserID, int ProID, string ProName, int ProTitle, string ProInfoUrl, int ProNum, int ProMaxNum)
        {
            Professor p = new Professor();

            p.ProID      = ProID;
            p.ProInfoUrl = ProInfoUrl;
            p.ProMaxNum  = ProMaxNum;
            p.ProName    = ProName;
            p.ProNum     = ProNum;
            p.ProTitle   = ProTitle;
            p.UserID     = UserID;
            SsContext db = new SsContext();

            try
            {
                db.Professors.Add(p);
                db.SaveChanges();
            }catch (Exception e)
            {
                db = null;
                return(false);
            }
            db = null;
            return(true);
        }
        public List <Student> findNoWillStudents()
        {
            SsContext      db = new SsContext();
            List <Student> ps = db.Students.Where(s => s.StuWillChecked == false).ToList();

            return(ps);
        }
 internal string creatSetting(DateTime InfoStart, DateTime InfoEnd, DateTime FirstStart, DateTime FirstEnd, DateTime SecondStart, DateTime SecondEnd)
 {
     try
     {
         SsContext       db   = new SsContext();
         List <Settings> list = db.Settingss.ToList();
         Settings        s;
         if (list.Count == 0)
         {
             s             = new Settings();
             s.FirstEnd    = FirstEnd;
             s.FirstStart  = FirstStart;
             s.InfoEnd     = InfoEnd;
             s.InfoStart   = InfoStart;
             s.SecondEnd   = SecondEnd;
             s.SecondStart = SecondStart;
             db.Settingss.Add(s);
         }
         else
         {
             s             = list[0];
             s.FirstEnd    = FirstEnd;
             s.FirstStart  = FirstStart;
             s.InfoEnd     = InfoEnd;
             s.InfoStart   = InfoStart;
             s.SecondEnd   = SecondEnd;
             s.SecondStart = SecondStart;
         }
         db.SaveChanges();
     }catch (Exception e)
     {
         return(e.Message);
     }
     return("success");
 }
        public List <Student> getStudentByUserID(int id)
        {
            SsContext      db   = new SsContext();
            List <Student> list = db.Students.Where(s => s.UserID == id).ToList();

            return(list);
        }
        public List <Student> findNoFinalWillStudents()
        {
            SsContext      db = new SsContext();
            List <Student> ps = db.Students.Where(s => s.StuFinalWill == 0).ToList();

            return(ps);
        }
        public List <Student> getStudentByStuID(string id)
        {
            SsContext      db   = new SsContext();
            List <Student> list = db.Students.Where(s => s.StuID.Equals(id)).ToList();

            return(list);
        }
        public string updateProfessor(string ProName, int ProID, string ProTitle, int ProMaxNum, string ProInfoUrl, int ProNum)
        {
            SsContext        ss   = new SsContext();
            List <Professor> list = ss.Professors.Where(s => s.ProID == ProID).ToList();

            if (list.Count <= 0)
            {
                return("未知错误");
            }
            Professor p = list[0];

            p.ProID      = ProID;
            p.ProInfoUrl = ProInfoUrl;
            p.ProMaxNum  = ProMaxNum;
            p.ProName    = ProName;
            p.ProNum     = ProNum;
            if (ProTitle.Equals("讲师"))
            {
                p.ProTitle = 0;
            }
            else if (ProTitle.Equals("副教授"))
            {
                p.ProTitle = 1;
            }
            else if (ProTitle.Equals("教授"))
            {
                p.ProTitle = 2;
            }
            ss.SaveChanges();
            return("成功");
        }
 public string deleteProfessorToStudent(int pid, string StuID)
 {
     try
     {
         SsContext          db    = new SsContext();
         ProfessorToStudent ps    = db.ProfessorToStudents.Find(pid, StuID);
         ProfessorToStudent pts   = new ProfessorToStudent();
         List <Professor>   plist = db.Professors.Where(s => s.ProID == pid).ToList();
         if (plist[0].ProNum > 0)
         {
             plist[0].ProNum--;
         }
         if (plist.Count <= 0)
         {
             return("未知错误");
         }
         db.ProfessorToStudents.Remove(ps);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         return("操作失败");
     }
     return("操作成功");
 }
        public List <JiaoWu> getJiaoWuByJId(int id)
        {
            SsContext     db   = new SsContext();
            List <JiaoWu> list = db.JiaoWus.Where(s => s.JiaoWuID == id).ToList();

            return(list);
        }
        public User getUserByUserId(int Id)
        {
            SsContext db = new SsContext();
            User      u  = db.Users.Find(Id);

            return(u);
        }
        public List <Professor> getProfessorByUserId(int id)
        {
            SsContext        db   = new SsContext();
            List <Professor> list = db.Professors.Where(s => s.UserID == id).ToList();

            return(list);
        }
        public List <User> getUsers(int userType)
        {
            SsContext   db   = new SsContext();
            List <User> list = db.Users.Where(s => s.RoleID == userType).ToList();

            return(list);
        }
        public List <JiaoWu> getJiaoWus()
        {
            SsContext     db   = new SsContext();
            List <JiaoWu> list = db.JiaoWus.ToList();

            return(list);
        }
        public List <Professor> findNotFullProfessors()
        {
            SsContext        db = new SsContext();
            List <Professor> ps = db.Professors.Where(s => s.ProNum < s.ProMaxNum).ToList();

            return(ps);
        }
        public List <Professor> findAllProfessors()
        {
            SsContext        db = new SsContext();
            List <Professor> ps = db.Professors.ToList();

            db = null;
            return(ps);
        }
        public List <Student> findAllStudents()
        {
            SsContext      db = new SsContext();
            List <Student> ps = db.Students.ToList();

            db = null;
            return(ps);
        }
        public string getInfoEnd()
        {
            SsContext       db = new SsContext();
            List <Settings> ss = db.Settingss.ToList();

            if (ss.Count > 0)
            {
                Settings s = ss[ss.Count - 1];
                return(s.InfoEnd.ToString());
            }
            return("未设定");
        }
        private Student getStudentBySid(string id)
        {
            SsContext      db    = new SsContext();
            List <Student> plist = db.Students.Where(s => s.StuID == id).ToList();

            if (plist.Count <= 0)
            {
                return(null);
            }
            Student p = plist[0];

            return(p);
        }
        Professor getProfessorByPid(int id)
        {
            SsContext        db    = new SsContext();
            List <Professor> plist = db.Professors.Where(s => s.ProID == id).ToList();

            if (plist.Count <= 0)
            {
                return(null);
            }
            Professor p = plist[0];

            return(p);
        }
        public bool addJiaoWu(string JiaoWuName, int JiaoWuID, int JiaoWuMajorID)
        {
            SsContext db = new SsContext();
            JiaoWu    j  = new JiaoWu();

            j.UserID        = addUser(JiaoWuName, 1, JiaoWuID.ToString());
            j.JiaoWuID      = JiaoWuID;
            j.JiaoWuMajorID = JiaoWuMajorID;
            j.JiaoWuName    = JiaoWuName;
            db.JiaoWus.Add(j);
            db.SaveChanges();
            return(true);
        }
        internal Settings getSetting()
        {
            SsContext       db   = new SsContext();
            List <Settings> list = db.Settingss.ToList();

            if (list.Count > 0)
            {
                return(list[0]);
            }
            else
            {
                return(null);
            }
        }
        public Professor getProfessorByProName(string name)
        {
            SsContext        db   = new SsContext();
            List <Professor> list = db.Professors.Where(s => s.ProName == name).ToList();

            if (list.Count > 0)
            {
                return(list[0]);
            }
            else
            {
                return(null);
            }
        }
        public bool deleteUserById(int id)
        {
            try
            {
                SsContext db = new SsContext();
                User      p  = db.Users.Find(id);

                db.Users.Remove(p);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
        public bool changePassword(int type, string id, string password)
        {
            int       userId;
            SsContext db = new SsContext();

            if (type == 2)
            {
                Professor p = getProfessorByPid(int.Parse(id));
                userId = p.UserID;
            }
            else if (type == 3)
            {
                Student s = getStudentBySid(id);
                userId = s.UserID;
            }
            else if (type == 1)
            {
                if (getJiaoWuByJId(Int32.Parse(id)).Count > 0)
                {
                    userId = getJiaoWuByJId(Int32.Parse(id))[0].UserID;
                }
                else
                {
                    userId = -1;
                }
            }
            else
            {
                userId = int.Parse(id);
            }

            User u = db.Users.Find(userId);

            if (u != null)
            {
                try
                {
                    u.UserPassword = password;
                    db.SaveChanges();
                    return(true);
                }catch (Exception e)
                {
                    return(false);
                }
            }
            return(false);
        }
        internal string batchAddStudents(List <Student> listStudents)
        {
            string         rel = "";
            int            num = 0;
            List <Student> list;
            int            userId;

            try
            {
                SsContext db = new SsContext();
                foreach (Student p in listStudents)
                {
                    list = db.Students.Where(s => s.StuID == p.StuID).ToList();
                    if (list.Count > 0)
                    {
                        num++;
                    }
                    else
                    {
                        userId = addUser(p.StuName, 3, p.StuID.ToString());
                        if (userId != -1)
                        {
                            p.UserID = userId;
                            db.Students.Add(p);
                        }
                    }
                }
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            if (num > 0)
            {
                rel = "error:共操作" + listStudents.Count + "个数据,其中" + num + "个失败,可能存在重复的数据。";
            }
            else
            {
                rel = "success:共操作" + listStudents.Count + "个数据,其中" + num + "个失败。";
            }



            return(rel);
        }
        internal Professor findProfessor(int UserId)
        {
            SsContext        db = new SsContext();
            List <Professor> ps = db.Professors.Where(s => s.UserID == UserId).ToList();
            Professor        p;

            if (ps.Count <= 0)
            {
                p = null;
            }
            else
            {
                p = ps[0];
            }
            db = null;
            return(p);
        }
        public bool addStudent(string StuName, string StuID, int Age, int StuMajorID, string StuTel, string StuMail, bool StuIfWork)
        {
            SsContext db = new SsContext();
            Student   s  = new Student();

            s.UserID     = addUser(StuName, 3, StuID.ToString());
            s.StuID      = StuID;
            s.StuName    = StuName;
            s.Age        = Age;
            s.StuMajorID = StuMajorID;
            s.StuTel     = StuTel;
            s.StuMail    = StuMail;
            s.StuIfWork  = StuIfWork;
            db.Students.Add(s);
            db.SaveChanges();
            return(true);
        }
        public bool saveResumeUrl(string id, string path)
        {
            SsContext      db   = new SsContext();
            List <Student> list = db.Students.Where(s => s.StuID == id).ToList();

            if (list.Count <= 0)
            {
                return(false);
            }
            else
            {
                Student s = list[0];
                s.StuResumeUrl = path;
                db.SaveChanges();
                return(true);
            }
        }
        public bool studentConfirm(string id)
        {
            SsContext      db   = new SsContext();
            List <Student> list = db.Students.Where(s => s.StuID == id).ToList();

            if (list.Count <= 0)
            {
                return(false);
            }
            else
            {
                Student s = list[0];
                s.StuInfoChecked = true;
                db.SaveChanges();
                return(true);
            }
        }
        public List <Student> getSecondWillStudents(int id)
        {
            SsContext        db    = new SsContext();
            List <Professor> plist = db.Professors.Where(s => s.ProID == id).ToList();

            if (plist.Count <= 0)
            {
                return(null);
            }
            Professor      p    = plist[0];
            List <Student> list = db.Students.Where(s => s.StuSecondWill == p.UserID && s.StuSecondWillStates == 0).ToList();

            if (list.Count > 0)
            {
                return(list);
            }
            return(null);
        }