package com.java1234.action;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import com.java1234.dao.ClassDao;
import com.java1234.dao.GradeDao;
import com.java1234.dao.StudentDao;
import com.java1234.model.Class;
import com.java1234.model.Grade;
import com.java1234.util.DbUtil;
import com.java1234.util.NavUtil;
import com.java1234.util.ResponseUtil;
import com.java1234.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;
public class ClassAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private DbUtil dbUtil=new DbUtil();
private ClassDao classDao=new ClassDao();
private GradeDao gradeDao=new GradeDao();
private StudentDao studentDao=new StudentDao();
private List<Class> classList=new ArrayList<Class>();
private List<Grade> gradeList=new ArrayList<Grade>();
private String mainPage;
private String navCode;
private String classId;
private Class c;
private String s_gradeId;
public List<Class> getClassList() {
return classList;
}
public void setClassList(List<Class> classList) {
this.classList = classList;
}
public String getMainPage() {
return mainPage;
}
public void setMainPage(String mainPage) {
this.mainPage = mainPage;
}
public String getNavCode() {
return navCode;
}
public void setNavCode(String navCode) {
this.navCode = navCode;
}
public List<Grade> getGradeList() {
return gradeList;
}
public void setGradeList(List<Grade> gradeList) {
this.gradeList = gradeList;
}
public String getClassId() {
return classId;
}
public void setClassId(String classId) {
this.classId = classId;
}
public Class getC() {
return c;
}
public void setC(Class c) {
this.c = c;
}
public String getS_gradeId() {
return s_gradeId;
}
public void setS_gradeId(String s_gradeId) {
this.s_gradeId = s_gradeId;
}
public String list(){
Connection con=null;
try{
con=dbUtil.getCon();
classList=classDao.classList(con,null);
navCode=NavUtil.getNavgation("班级信息管理", "班级维护");
mainPage="class/classList.jsp";
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return SUCCESS;
}
public String delete(){
Connection con=null;
try{
con=dbUtil.getCon();
JSONObject resultJson=new JSONObject();
boolean exist=studentDao.existStudentByClassId(con, classId);
if(exist){
resultJson.put("error", "班级下面有学生,不能删除!");
}else{
classDao.classDelete(con, classId);
resultJson.put("success", true);
}
ResponseUtil.write(resultJson, ServletActionContext.getResponse());
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
public String preSave(){
Connection con=null;
try{
con=dbUtil.getCon();
gradeList=gradeDao.gradeList(con);
if(StringUtil.isNotEmpty(classId)){
c=classDao.getClassById(con, classId);
navCode=NavUtil.getNavgation("系统管理", "班级修改");
}else{
navCode=NavUtil.getNavgation("系统管理", "班级添加");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mainPage="class/classSave.jsp";
return SUCCESS;
}
public String save(){
Connection con=null;
try{
con=dbUtil.getCon();
if(StringUtil.isNotEmpty(classId)){
c.setClassId(Integer.parseInt(classId));
classDao.classUpdate(con, c);
}else{
classDao.classAdd(con, c);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.getCon();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "save";
}
public String getClassByGradeId(){
Connection con=null;
try{
con=dbUtil.getCon();
Class s_class=new Class();
s_class.setGradeId(Integer.parseInt(s_gradeId));
List<Class> classList=classDao.classList(con,s_class);
JSONArray jsonArray=JSONArray.fromObject(classList);
ResponseUtil.write(jsonArray, ServletActionContext.getResponse());
}catch(Exception e){
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}
最近下载更多
微信网友_6248713511227392 LV11
2022年12月5日
wanglinddad LV55
2022年2月25日
sterbj LV6
2022年1月10日
微信网友_5767418331975680 LV1
2021年12月30日
xsszjx LV4
2021年9月30日
yjp233 LV6
2021年5月28日
ericxu1116 LV24
2021年5月24日
and123456 LV11
2021年5月11日
Eruvin LV3
2021年5月7日
Lcovde LV19
2021年4月5日
最近浏览更多
微信网友_7826662819680256
2025年12月24日
暂无贡献等级
1516299986 LV9
2025年4月16日
ma406805131 LV19
2024年12月4日
李俊客家话 LV1
2024年10月24日
wangming32 LV1
2024年7月15日
WBelong LV8
2024年3月8日
颜菜菜 LV2
2024年1月4日
black8angel LV4
2023年12月22日
uni-code_0123 LV1
2023年11月29日
fesfefe LV13
2023年9月26日

