package action; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import models.Admin; import models.Course; import models.Course_teacher; import models.Student; import models.Teacher; import org.apache.struts2.ServletActionContext; import service.IAdminService; import com.opensymphony.xwork2.ActionContext; public class AdminAction { private IAdminService adminservice; private HttpServletRequest request; private Teacher newteacher; public Teacher getNewteacher() { return newteacher; } public void setNewteacher(Teacher newteacher) { this.newteacher = newteacher; } private Admin newadmin; private Student newstudent; private Course newcourse; public Course getNewcourse() { return newcourse; } public void setNewcourse(Course newcourse) { this.newcourse = newcourse; } public Student getNewstudent() { return newstudent; } public void setNewstudent(Student newstudent) { this.newstudent = newstudent; } public Admin getNewadmin() { return newadmin; } public void setNewadmin(Admin newadmin) { this.newadmin = newadmin; } public IAdminService getAdminservice() { return adminservice; } public void setAdminservice(IAdminService adminservice) { this.adminservice = adminservice; } public String execute() { ActionContext.getContext().getSession().put("admin", newadmin); if(adminservice.updateAdminInfo(newadmin)){ return "success"; } else return "false"; } public String showallstuInfo(){ List<Student> allstudent=adminservice.getallstuInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allstudent", allstudent); return "success"; } public String admindeletestu(){ String stuid=ServletActionContext.getRequest().getParameter("stuid"); Student deletestudent=new Student(); deletestudent.setStuId(Integer.parseInt(stuid)); if(adminservice.admindeletestu(deletestudent)){ List<Student> allstudent=adminservice.getallstuInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allstudent", allstudent); return "success"; } else return "false"; } public String admingetSelectedStu(){ String stuid=ServletActionContext.getRequest().getParameter("stuid"); int realstuid=Integer.parseInt(stuid); Student selectedstudent=adminservice.admingetSelectedStu(realstuid); if(selectedstudent==null) return "fail"; else{ request=ServletActionContext.getRequest(); request.setAttribute("selectedstudent", selectedstudent); return "success"; } } public String adminEditStu(){ if(adminservice.adminEditStu(newstudent)){ List<Student> allstudent=adminservice.getallstuInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allstudent", allstudent); return "success"; } else return "fail"; } public String adminAddStu(){ if(adminservice.adminAddStu(newstudent)){ return "success"; } else return "fail"; } public String showallcourse(){ List<Course> allcourse=adminservice.getallCourseInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allcourse", allcourse); return "success"; } public String adminDeleteCourse(){ String cid=ServletActionContext.getRequest().getParameter("cid"); Course deletecourse=new Course(); deletecourse.setCId(Integer.parseInt(cid)); if(adminservice.adminDeleteCourse(deletecourse)){ List<Course> allcourse=adminservice.getallCourseInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allcourse", allcourse); return "success"; } else return "fail"; } public String admingetSelectedCourseInfo(){ String cid=ServletActionContext.getRequest().getParameter("cid"); int realcid=Integer.parseInt(cid); Course selectedcouse=adminservice.admingetSelectedCourseInfo(realcid); if(selectedcouse!=null){ request=ServletActionContext.getRequest(); request.setAttribute("selectedcouse", selectedcouse); return "success"; } else return "fail"; } public String adminEditCourse(){ if(adminservice.adminEditCourse(newcourse)){ List<Course> allcourse=adminservice.getallCourseInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allcourse", allcourse); return "success"; } else return "fail"; } public String adminAddCourse(){ if(adminservice.adminAddCourse(newcourse)){ List<Course> allcourse=adminservice.getallCourseInfo(); request=ServletActionContext.getRequest(); request.setAttribute("allcourse", allcourse); return "success"; } else return "fail"; } public String manageTea() { List a = adminservice.manageTeacher(); request = ServletActionContext.getRequest(); // HttpSession session=request.getSession(); request.setAttribute("teacherList", a); return "success"; } public String deleteTea() { // 管理员删除教师 request = ServletActionContext.getRequest(); String tid = (String) request.getParameter("tid"); Teacher a = new Teacher(); a.setTId(Integer.parseInt(tid)); boolean b = adminservice.deleteTeacher(a); if (b) return "success"; return "fail"; } public String adminEditTeacher() { request = ServletActionContext.getRequest(); String tid = (String) request.getParameter("tid"); Teacher a = adminservice.getOneTeacher(Integer.parseInt(tid)); request.setAttribute("teacher", a); return "success"; } public String UpdateTea() { // 管理员更改教师信息 request = ServletActionContext.getRequest(); String tid = (String) request.getParameter("tid"); boolean b = adminservice.adminUpdateTeacher(newteacher); if (b) return "success"; return "fail"; } public String adminAddTeacher() { boolean b = adminservice.adminAddTeacher(newteacher); if (b) return "success"; return "fail"; } public String adminManageCTid() { // 教师授课管理 List a; try { a = adminservice.getAllCT(); } catch (Exception e) { return "fail"; } request = ServletActionContext.getRequest(); request.setAttribute("allCT", a); return "success"; } public String adminDeleteCTid(){ //删除教师授课 request=ServletActionContext.getRequest(); HttpSession session=request.getSession(); String ctid=request.getParameter("ctid"); Course_teacher c=new Course_teacher(); c.setCTId(Integer.parseInt(ctid)); boolean b=adminservice.deleteCT(c); if (b) return "success"; return "fail"; } public String adminManageSCid(){ //学生选课记录管理 List a; try { a = adminservice.getAllSC(); } catch (Exception e) { return "fail"; } request = ServletActionContext.getRequest(); request.setAttribute("allSC", a); return "success"; } public String adminDeleteSC(){ //删除学生选课记录 request=ServletActionContext.getRequest(); HttpSession session=request.getSession(); String stuid=request.getParameter("stuid"); String ctid=request.getParameter("ctid"); boolean b=adminservice.deleteSC(Integer.parseInt(stuid), Integer.parseInt(ctid)); if (b) return "success"; return "fail"; } public String adminEditGrade(){ //编辑学生选课信息 request=ServletActionContext.getRequest(); HttpSession session=request.getSession(); String stuid=request.getParameter("stuid"); String ctid=request.getParameter("ctid"); String grade=request.getParameter("grade"); Student a=adminservice.getStudent(Integer.parseInt(stuid)); session.setAttribute("stuName", a.getStuName()); session.setAttribute("stuid", stuid); session.setAttribute("ctid", ctid); request.setAttribute("grade", grade); return "success"; } public String adminChangeGrade(){ //确认修改学生信息 request=ServletActionContext.getRequest(); HttpSession session=request.getSession(); String stuid=(String)session.getAttribute("stuid"); String ctid=(String)session.getAttribute("ctid"); String grade=(String)request.getParameter("newgrade"); boolean b=adminservice.updateGrade(Integer.parseInt(stuid), Integer.parseInt(ctid), Integer.parseInt(grade)); if (b) return "success"; return "fail"; } }

krispeng LV15
6月1日
571818771 LV3
2024年12月17日
星予宝藏666 LV6
2023年5月27日
海棠花瘦 LV9
2023年5月5日
aaa最代码 LV14
2023年2月27日
LITIANYU084414 LV11
2022年12月30日
weilaizhisheng LV21
2022年12月5日
yut1an LV2
2022年10月31日
hdwangxin LV1
2022年7月7日
bluesky2016 LV15
2022年7月6日

微信网友_7407113009926144 LV1
3月2日
微信网友_7391151377240064
2月19日
暂无贡献等级
ma406805131 LV19
2024年12月26日
571818771 LV3
2024年12月17日
AOAO1234 LV2
2024年12月12日
xuanwomingren
2024年12月9日
暂无贡献等级
liulian666 LV2
2024年7月19日
y_x_happy LV4
2024年6月7日
sunlea LV20
2024年5月17日
阿昌先生 LV13
2024年3月26日