package scoreInfo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ClassSvlt extends HttpServlet{
	
public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    	
    String class_id =req.getParameter("id");
    int success = 0;
    String action = req.getParameter("action");
    classp cla = null;
    String message="";
    
     if ("new".equalsIgnoreCase(action)) {
      cla = doNew(req,res);
      
      sendBean(req, res, cla,"/getClass.jsp");
    }  
    
    if ("update".equalsIgnoreCase(action)) {
    	try{		
     	cla = doUpdate(req,res, class_id);
     	sendBean(req,res,cla,"/getClass.jsp");
     	   }
     	  catch(SQLException e){} 
    }
			   
    if ("delete".equalsIgnoreCase(action)) {
    	try{			
      	success = doDelete(class_id);	
      	    }
      	    catch(SQLException e){}				
    	if (success != 1) {
    		doError(req, res, "ClassSvlt: Delete unsuccessful. Rows affected: " + success);
    	} else {
    		res.sendRedirect("http://localhost:8080/test/getClass.jsp");
    	}}
       
    }
    
     public classp doNew(HttpServletRequest req,HttpServletResponse res )
                           throws ServletException,IOException{
      classp cla= new classp();                     	
      String class_id=new String(req.getParameter("id").getBytes("ISO-8859-1"),"GBK");
      String tea_id=req.getParameter("tea_id");
      String cour_id=req.getParameter("cour_id");
      String room_id=req.getParameter("room_id");
      String cour_time=req.getParameter("cour_time");
    
  if(isTrue(req,res,class_id) && hasMoreclass(tea_id,cour_time,req,res) ){  
      cla.setId(class_id);
      cla.setTea_id(tea_id);   
      cla.setCour_id(cour_id);
      cla.setRoom_id(room_id);
      cla.setCour_time(cour_time);
      cla.addClass();
                                     }
      return cla;                	
                           	
                           	}
                           	
 public boolean hasMoreclass(String tea_id,String cour_time,HttpServletRequest req,HttpServletResponse res)
       throws ServletException,IOException{
      	boolean f=true;
      	String temp="";
      	String message="";
      	classp cla=new classp();
      	temp=cla.hasMoreclass(tea_id,cour_time);
      	if (temp=="no")
         f=true;
        else {
        	f=false;
        message="对不起,该教师("+tea_id+")在"+cour_time+"时间已经安排有课"+temp+""	;
        doError(req,res,message);
        	}        	
      	return f;
      	
      	}
      	
   public boolean hasChange(String tea_id,String cour_time,
   HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
   	boolean f=false;
   	String tea_id0=req.getParameter("tea_id0");
   	String cour_time0=req.getParameter("cour_time0");
   	if(!tea_id.equals(tea_id0) || !cour_time.equals(cour_time0) )
  	f=true;
   	return f;
   	}   	                       	
                           	
  public classp doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
                           throws ServletException,IOException,SQLException {                      	
      classp cla = new classp();                    
      String tea_id=req.getParameter("tea_id");
      String cour_id=req.getParameter("cour_id");
      String room_id=req.getParameter("room_id");
      String cour_time=req.getParameter("cour_time");
    if(hasChange(tea_id,cour_time,req,res)){ 
    if(hasMoreclass(tea_id,cour_time,req,res)){
    cla.updateClass(id,tea_id,cour_id,room_id,cour_time);
    }}else{
    cla.updateClass(id,cour_id,room_id);	   	
    	}
		return cla;
  }                        	
                           	
   public int doDelete(String id) throws SQLException {
  	int num=0;
    classp cla=new classp();
    num=cla.deleteClass(id);
    return num;
  } 
  
  
  public void sendBean(HttpServletRequest req, HttpServletResponse res,
                       classp cla, String target)
                       throws ServletException, IOException {
    req.setAttribute("cla", cla);
    RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
    rd.forward(req, res);
  }
  
  
  public void doError(HttpServletRequest req,
                      HttpServletResponse res,
                      String str)
                      throws ServletException, IOException {


    req.setAttribute("problem", str);
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
    rd.forward(req, res);
  }
  
                          	
  public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
                        String id)
                        throws ServletException, IOException {
   classp cla = new classp();                     	
   boolean f=true;                     	
   String message ="";
   if(id==null || id.equals(""))  {
   	f=false;
   	message="错误,班级号不能为空!";
   	doError(req,res,message);	}
   if(cla.hasLogin(id)){
   	f=false;
   	message="对不起,班级("+id+")已经注册了!";
    doError(req,res,message);
   	} 
     return f;
     
  }
  
  public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    doGet(req, res);

  }
  
  
}
最近下载更多
wcheng  LV2 2023年10月18日
lsj123456798  LV3 2022年12月30日
lyzzz520  LV1 2022年12月18日
485415187  LV6 2022年11月22日
微信网友_5970838873509888  LV2 2022年5月23日
微信网友_5764743416303616  LV6 2022年4月22日
roygugu  LV2 2022年4月9日
illkih  LV2 2022年3月17日
17771013609  LV4 2021年12月27日
CCCbbbcai  LV6 2021年12月23日
最近浏览更多
PROFKazami 4月15日
暂无贡献等级
张七七 4月13日
暂无贡献等级
暂无贡献等级
WBelong  LV7 3月8日
王冰冰0001 1月15日
暂无贡献等级
暂无贡献等级
kjsk001 2023年12月31日
暂无贡献等级
冯海涛 2023年12月31日
暂无贡献等级
qwerewqss 2023年12月30日
暂无贡献等级
asddwh  LV12 2023年12月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友