Exemplo n.º 1
0
        /*
         * Create By zzw
         * 插入教师
         * 成功插入返回1,失败返回0,异常返回-1
         */
        public int addProfessor(Professor professor)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();

            professorDB.professors.Add(professor);
            return(professorDB.SaveChanges());
        }
Exemplo n.º 2
0
        /*
         * Create By zzw
         * 列出所有教师
         * 成功插入返回1,失败返回0,异常返回-1
         */
        public List <Professor> listAllProfessor()
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            List <Professor>   listAll     = professorDB.professors.ToList();

            return(listAll);
        }
Exemplo n.º 3
0
        /*
         * Create By zzw
         * 通过教师工号获取教师
         */
        public Professor getProfessorById(string id)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            Professor          professor   = professorDB.professors.Find(id);

            return(professor);
        }
Exemplo n.º 4
0
        /*
         * Create By zzw
         * 删除教师 by id
         * 成功插入返回1,失败返回0,异常返回-1
         */
        public int deleteProfessorById(string id)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            Professor          professor   = professorDB.professors.Find(id);

            professorDB.professors.Remove(professor);
            return(professorDB.SaveChanges());
        }
Exemplo n.º 5
0
        /*
         * Create By zzw
         * 更改密码
         * 成功插入返回true,失败返回false
         */
        public bool changeQuotaById(string id, int quota)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            Professor          professor   = professorDB.professors.Find(id);

            if (professor != null)
            {
                professor.quota = quota;
                professorDB.SaveChanges();
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        /*
         * Create By 高晔
         * 创建和初始化本地数据库
         */
        public static void initLocalDB()
        {
            StudentDBContext studentDB = new StudentDBContext();

            studentDB.students.Find("");
            AdminDBContext adminDB = new AdminDBContext();

            adminDB.admins.Find("");
            DeanDBContext deanDB = new DeanDBContext();

            deanDB.deans.Find("");
            ProfessorDBContext professorDB = new ProfessorDBContext();

            professorDB.professors.Find("");
            SettingDBContext settingDBContext = new SettingDBContext();
            //settingDBContext.settings.Find("");
            MajorDBContext majorDBContext = new MajorDBContext();

            majorDBContext.majors.Find(0);
        }
Exemplo n.º 7
0
        /*
         * Create By zzw
         * 更新教师
         * 成功插入返回true,未查询到返回false
         */
        public bool updateProfessor(string id, string name, string title, string infoURL, int quota, string remark)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            List <Professor>   list        = professorDB.professors.Where(t => t.id == id).ToList();

            if (list.Count <= 0)
            {
                return(false);
            }
            else
            {
                Professor p = list[0];
                p.name    = name;
                p.title   = title;
                p.infoURL = infoURL;
                p.quota   = quota;
                p.remark  = remark;
                professorDB.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 8
0
        ///*
        // * Create By zzw
        // * 删除教师 by ids
        // * 成功插入返回1,失败返回0,异常返回-1
        // */
        //public int deleteProfessorByIds(string[] ids)
        //{
        //    List<Professor> deleteProfessors = new List<Professor>();
        //    ProfessorDBContext professorDB = new ProfessorDBContext();
        //    for (int i = 0; i < ids.Length; i++)
        //    {
        //        Professor professor = professorDB.professors.Find(ids[i]);
        //        deleteProfessors.Add(professor);
        //    }
        //    try
        //    {
        //        professorDB.professors.RemoveRange(deleteProfessors);
        //        return professorDB.SaveChanges();
        //    }
        //    catch (Exception e)
        //    {
        //        //throw e;
        //        //LogUtil.writeLogToFile(e);
        //        return -1;
        //    }
        //}

        /*
         * Create By zzw
         * 更改密码
         * 成功插入返回true,失败返回false
         */
        public bool changePasswordById(string id, string password)
        {
            ProfessorDBContext professorDB = new ProfessorDBContext();
            Professor          professor   = professorDB.professors.Find(id);

            if (professor != null)
            {
                try
                {
                    professor.password = password;
                    professorDB.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    //throw e;
                    //LogUtil.writeLogToFile(e);
                    return(false);
                }
            }
            return(false);
        }