<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
<HTML>
	<HEAD>
		<TITLE>入学登记表</TITLE>
	</HEAD>
	<BODY>
<%!
 	    // 定义变量
		ResultSet rs = null;

 	    String username     ; // 用户名
 	    String personalcode ; // 身份证号
 	    String pwd          ; // 密码
 	    String gender       ; // 性别
 	    String birthdate    ; // 出生日期
 	    String phone        ; // 联系电话
 	    String email        ; // Email
 	    String jiguan       ; // 籍贯
 	    String hukou        ; // 户口
 	    String postaddress  ; // 通信地址
 	    String postalcode   ; // 邮政编码
 	    String university   ; // 毕业院校
 	    String major        ; // 专业
 	    String g_time       ; // 毕业时间
 	    String degree       ; // 最高学历
 	    String english      ; // 英语水平
 	    String work_year    ; // 工作年限
 	    String shixi        ; // 是否需要实习
 	    String tjgz         ; // 是否需要推荐工作
 	    String goal         ; // 培训目标
 	    String source       ; // 信息来源
		String sql = "";
%>
<%
 	    // 下面获取用户提交过来的数据
		request.setCharacterEncoding("GBK");
 	    username     = request.getParameter("Name");                 // 用户名
 	    personalcode = request.getParameter("PersonalCode");         // 身份证号
 	    pwd          = request.getParameter("pwd");                  // 密码
 	    gender       = request.getParameter("Sex");                  // 性别
 	    birthdate    = request.getParameter("BirthDate");            // 出生日期
 	    phone        = request.getParameter("HomeTel");              // 联系电话
 	    email        = request.getParameter("Email");                // Email
 	    jiguan       = request.getParameter("Jiguan");               // 籍贯        
 	    hukou        = request.getParameter("Hukou");                // 户口
 	    postaddress  = request.getParameter("Post");                 // 通信地址
 	    postalcode   = request.getParameter("PostalCode");           // 邮政编码
 	    university   = request.getParameter("Uni");                  // 毕业院校
 	    major        = request.getParameter("Spec");                 // 专业
 	    g_time       = request.getParameter("GradTime");             // 毕业时间
 	    degree       = request.getParameter("Edu");                  // 最高学历
 	    english      = request.getParameter("EngLevel");             // 英语水平
 	    work_year    = request.getParameter("workyear");             // 工作年限
 	    shixi        = request.getParameter("ToPra");                // 是否需要实习
 	    tjgz         = request.getParameter("RecWork");              // 是否需要推荐工作
 	    goal         = request.getParameter("EduTgt");               // 培训目标
 	    source       = request.getParameter("InfoSrc");              // 信息来源

		sql = "select studentid,name from test_studentinfo where ";
		sql+= "certid = '" + personalcode + "'";
		rs  = conn.executeQuery( sql );
		if(rs.next()) {
			out.println("<center>");
		    out.println("身份证号码为: "     + personalcode + "的用户已经注册！<br><br>");
			out.println("注册的用户ID为: "   + rs.getInt("studentid") + "<br><br>");
            out.println("注册的用户姓名为: "  + rs.getString("name") + "<br><br>");
			out.println("如果您忘记了登录密码，请向管理员咨询。<br><br>");
 	        out.println("<a href=javascript:history.back()>单击这里返回注册页面</a>");
			out.println("</center>");

			return;
		}

        sql  = "insert into test_studentinfo (";
 	    sql += "studentid,name,certid,password,gender,birth,phone,email,hometown,hukou";
 	    sql += ",txdz,yzbm,school,major,g_time,degree,english,work_year";
        sql += ",shixi,tjgz,goal,source,regtime) values ";
 	    sql += "(test_seq_student.nextval,";
 	    
 	    if(username != null && !username.equals("")) {
 	        sql += "'" + username + "',";	
 	    }else {
 	        out.println("<h1>用户名输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

 	    if(personalcode != null && !personalcode.equals("") && personalcode.length()>=15) {
 	        sql += "'" + personalcode + "',";	
 	    }else {
 	        out.println("<h1>用户身份证输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
 	    if(pwd != null && !pwd.equals("")) {
 	        sql += "'" + pwd + "',";	
 	    }else {
 	        out.println("<h1>密码输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(gender != null && !gender.equals("")) {
 	        sql += "'" + gender + "',";	
 	    }else {
 	        out.println("<h1>性别输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

	    if(birthdate != null && !birthdate.equals("")) {
 	        sql += "to_date('" + birthdate + "','YYYY/MM/DD'),";	
 	    }else {
 	        out.println("<h1>出生日期输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
 	    if(phone != null && !phone.equals("")) {
 	        sql += "'" + phone + "',";	
 	    }else {
 	        out.println("<h1>联系电话输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
  	    if(email != null && !email.equals("")) {
 	        sql += "'" + email + "',";	
 	    }else {
 	        out.println("<h1>email输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
	    
  	    if(jiguan != null && !jiguan.equals("")) {
 	        sql += "'" + jiguan + "',";	
 	    }else {
 	        out.println("<h1>籍贯输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(hukou != null && !hukou.equals("")) {
 	        sql += "'" + hukou + "',";	
 	    }else {
 	        out.println("<h1>户口输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(postaddress != null && !postaddress.equals("")) {
 	        sql += "'" + postaddress + "',";	
 	    }else {
 	        out.println("<h1>通信地址输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(postalcode != null && !postalcode.equals("")) {
 	        sql += "'" + postalcode + "',";	
 	    }else {
 	        out.println("<h1>邮政编码输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(university != null && !university.equals("")) {
 	        sql += "'" + university + "',";	
 	    }else {
 	        out.println("<h1>毕业学校输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(major != null && !major.equals("")) {
 	        sql += "'" + major + "',";	
 	    }else {
 	        out.println("<h1>专业输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(g_time != null && !g_time.equals("")) {
 	        sql += "to_date('" + g_time + "','YYYY/MM'),";	
 	    }else {
 	        out.println("<h1>毕业时间输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
  	    if(degree != null && !degree.equals("")) {
 	        sql += "'" + degree + "',";	
 	    }else {
 	        out.println("<h1>学历输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
  	    if(english != null && !english.equals("")) {
 	        sql += "'" + english + "',";	
 	    }else {
 	        out.println("<h1>英语水平输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
 	    
  	    if(work_year != null && !work_year.equals("")) {
 	        sql += "'" + work_year + "',";	
 	    }else {
 	        out.println("<h1>工作年限输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(shixi != null && !shixi.equals("")) {
 	        sql += "'" + shixi + "',";	
 	    }else {
 	        out.println("<h1>是否需要推荐实习输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(tjgz != null && !tjgz.equals("")) {
 	        sql += "'" + tjgz + "',";	
 	    }else {
 	        out.println("<h1>是否需要推荐工作输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(goal != null && !goal.equals("")) {
 	        sql += "'" + goal + "',";	
 	    }else {
 	        out.println("<h1>培训目标输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }

  	    if(source != null && !source.equals("")) {
 	        sql += "'" + source + "',";	
 	    }else {
 	        out.println("<h1>信息来源输入非法！请返回重新输入！</h1>");	
 	        out.println("<a href=javascript:history.back()>返回</a>");
 	        return;
 	    }
		sql += "sysdate)";
	
 	    // 执行插入操作
		int result = 0;
 	    try {
 	        result = conn.executeUpdate( sql );
 	    }catch(Exception ee) {
		    response.sendRedirect("/test/public/dberror.jsp?errmsg=" + ee.toString());    	
 	    }
 	    
		if(result !=1 ) {
		    response.sendRedirect("/test/public/dberror.jsp?errmsg=" + sql);   
		    return; 	
		}

		sql = "select studentid,password from test_studentinfo where ";
		sql+= "certid = '" + personalcode + "'";
		rs  = conn.executeQuery( sql );

		String userid   = "";;
		String password = "";
		if(rs.next()) {
			userid   = rs.getInt("studentid") + "";
			password = rs.getString("password");
		}

		out.println("<center>");
		out.println("您的信息已经正确保存！请记住您的用户ID和密码<br><br>");
		out.println("用户ID："  + userid   + "<br><br>");
		out.println("用户密码：" + password + "<br><br>");
        out.println("<a href=/test>单击这里返回登录页面</a>");
		out.println("</center>");

%>
	</BODY>
</HTML>
