<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.tool.SzDateHelp"%>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.drivingSchool.*" %>
<%@ include file="/sessionInfo.jsp"%>

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../share/js/commonTool.js"></script>
<%@ include file="/drivingSchool/tool/ReadIDCard.jsp"%>
</head>
<%
	
	//查询时间段
	//科目顺序
	String sSubjectOrder = SzConvert.strWriteData(request.getParameter("subjectOrder"));	 //科目
	
	//科目信息
	Subject subjectClass = new Subject();
	String subject[] = (String[])subjectClass.getSubjectInfoByOrder(sSubjectOrder);
	int iSelectSubject = 0;
	String sSubjectName = "";
	if (subject != null) {
		iSelectSubject = SzConvert.toInt(subject[0]);
		sSubjectName = subject[1];
	}
		
	String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
	String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));
	//获取选择的部门信息
	String BMID = SzConvert.toZeroStr(request.getParameter("BMID"));
	String BMMC = SzConvert.strWriteData(request.getParameter("BMMC"));
	//学号
	String XH = SzConvert.strWriteData(request.getParameter("XH"));
	//姓名
	String XM = SzConvert.strWriteData(request.getParameter("XM"));
	//流水号
	String LSH = SzConvert.strWriteData(request.getParameter("LSH"));
	int iSelectCoach = SzConvert.toInt(request.getParameter("selectCoach"));	//教练

	//条件sCond
	StringBuffer sCond = new StringBuffer("");
	//如果开始时间和结束时间都为空，就默认为当前月
	if(sSearchBegin.equals("")){
		sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateMonth());
	}
	if (sSearchEnd.equals("")){
		sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.getLastDateMonth());
	}
	//查询的结束时间
	String searchEnd = SzDateHelp.dateToYMD(SzDateHelp.nextDay(SzDateHelp.stringToDate(sSearchEnd)));
	
	if (!sSearchBegin.equals("")) {
        sCond.append(" AND t1.XXMC24>='" + sSearchBegin + "'");
    }
    if (!searchEnd.equals("")) {
        sCond.append(" AND t1.XXMC24<'" + searchEnd + "'");
    }
	
	if (!BMMC.equals("")){
		sCond.append(" AND t1.XXMC6='"+BMMC+"'");
	}
	//学号
	if (!XH.equals("")){
		sCond.append(" AND t1.XXMC3='"+ XH +"'");
	}
	//姓名
	if (!XM.equals("")){
		sCond.append(" AND t1.XXMC2='"+ XM +"'");
	}
	//流水号
	if (!LSH.equals("")){
		sCond.append(" AND t1.XXMC32='"+ LSH +"'");
	}
	//条件
	//sCond.append(" AND t1.XXMC48='已录指纹' and (ifnull(t2.XXMC9,'')='' or (ifnull(t2.XXMC9,'')<>'' and ifnull(t2.XXMC10,'')<>'及格' and ifnull(t2.XXMC10,'')<>''))");
	//只显示教练已分配的学员
	if (iSelectCoach != 0 && iSelectSubject != 0 ) {
		sCond.append(" AND t1.XXMC1 in ( select XXMC14 from BD_DRIVINGSCHOOL_TOSETUPCOACH where XXMC18=");
		sCond.append(iSelectCoach);
		sCond.append(" and XXMC16=");
		sCond.append(iSelectSubject);
		sCond.append(") ");	
	}
	//状态判断：只有状态为：桩考练车的才可以设置为可靠
	//sCond.append(" AND t1.XXMC37='桩考练车'");
	//状态判断：只有状态为：桩考可考，而且考试信息为（考试科目：桩考，可考标志：可考，考试成绩：）
	//sCond.append(" AND t1.XXMC37='桩考可考' ");
	//sCond.append(" AND t2.XXMC21='可考' ");
	Exam exam = new Exam();
	sCond.append(exam.getCond("学时记录", sSubjectName));

	//管理员看所有的，分点文看自己分点的
	sCond.append(isBarManager_SESSION? "":" AND t1.XXMC14=" + iBMID_SESSION);
	
	String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
  int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder"))); 
  if (sSortField.equals("")) { 
    	sSortField = "t1.XXMC34";
    	iSortOrder = SzProperties.I_SortOrder_DESC;
  }
	sCond.append(" ORDER BY "+ sSortField + (iSortOrder==SzProperties.I_SortOrder_DESC? " DESC":" ASC"));
	//获取Vehicle对象
  Student student = new Student();
	//信息ID,学号,流水号,报名时间,姓名,性别,户籍,班别,报名点,身份证号,数码回执,接送地址,招收人员
	String[] fields = new String[]{"t1.XXMC1","t1.XXMC3","t1.XXMC32","t1.XXMC24","t1.XXMC2",
			"t1.XXMC40","t1.XXMC5","t1.XXMC16","t1.XXMC6","t1.XXMC8",
			"t1.XXMC10","t1.XXMC28","t1.XXMC23","t1.XXMC48","t1.XXMC19",
			"ifnull(t2.XXMC5,'')","ifnull(t2.XXMC7,'')","ifnull(t2.XXMC9,'')","ifnull(t2.XXMC10,'')","ifnull(t2.XXMC22,'')"};

	//获取学员信息
	ArrayList<String[]> studentList = student.getKaoShiList(fields,sCond.toString(),"and XXMC3='" + sSubjectName + "'");
	int iSize = studentList.size();
	//学员
	String[] studentInfo = null;
	ToSetUpCourse toSetUpCourse = new ToSetUpCourse();
%>
<!-----上面的工具栏------>
<%@ include file="/docEngine/title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  <input type="hidden" name="subjectOrder" value="<%=sSubjectOrder%>">    
  <tr>
    <td>
      科目：<B><%=sSubjectName%></B>
     <% 
     if (sSubjectName.equals("文考")) {
     } else {
    	 out.println("教练选择:");
    	 out.println(SzPageHelp.idSelectSubmit("BD_DRIVINGSCHOOL_COACH", "XXMC1", "XXMC2","selectCoach", iSelectCoach, "", ""));
     }
     %>    

    
      报名点<input type="text" name="BMMC" class="txtClassSearch" value="<%=BMMC%>">
      学号<input type="text" name="XH" class="txtClassSearch" value="<%=XH %>">
      流水号<input type="text" name="LSH" class="txtClassSearch" value="<%=LSH %>">
      姓名<input type="text" name="XM" class="txtClassSearch" value="<%=XM %>" OnDblClick="javascript:ReadIDCard();">
      开始<input type="text" name="txtSearchBegin" class="txtClassSearch" value="<%=sSearchBegin%>">
      <%=SzPageHelp.calendar2Select("../../","formBar.txtSearchBegin")%>
      结束<input type="text" name="txtSearchEnd" class="txtClassSearch" value="<%=sSearchEnd%>">
      <%=SzPageHelp.calendar2Select("../../","formBar.txtSearchEnd")%>
      <%=SzPageHelp.button("查询", "javascript:FormSubmit(formBar,'xueshi.jsp');")%>
      <%=SzPageHelp.button("批量保存", "javascript:ShenHeSubmit(formList,'control.jsp');")%>
      <%=SzPageHelp.button("导到excel", "document.location.href='../../upload/driverschool/" + iDLID_SESSION + ".xls';")%>
    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <input type="hidden" name="OPERATOR" value="xueshi"> 
  <input type="hidden" name="subjectOrder" value="<%=sSubjectOrder%>">   
  <input type="hidden" name="SzDLXM" value="<%=sDLXM_SESSION %>">
  <input type="hidden" name="SzDLID" value="<%=iDLID_SESSION %>">
  <input type="hidden" name="SzBMMC" value="<%=sBMMC_SESSION %>">
  <input type="hidden" name="SzBMID" value="<%=iBMID_SESSION %>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  <input type="hidden" name="BMMC" value="<%=BMMC%>">
  <input type="hidden" name="XH" value="<%=XH %>">
  <input type="hidden" name="LSH" value="<%=LSH %>">
  <input type="hidden" name="XM" value="<%=XM %>">
  <input type="hidden" name="txtSearchBegin" value="<%=sSearchBegin%>">
  <input type="hidden" name="txtSearchEnd" value="<%=sSearchEnd%>">
  <input type="hidden" name="KSKM" value="<%=subject[1] %>">
  <input type="hidden" name="KSKMID" value="<%=subject[0] %>">
  <tr class="trClassTitle">
  	<!-- 信息ID,学号,报名时间,姓名,性别,户籍,班别,报名点,身份证号,数码回执,接送地址,招收人员 -->
  	<td>序号</td>
  	<td><%=SzPageHelp.sortTitle("学号", "t1.XXMC3", sSortField, iSortOrder, strLevel_SESSION)%></td>
  	<td><%=SzPageHelp.sortTitle("流水号", "t1.XXMC32", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("报名时间", "t1.XXMC24", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("姓名", "t1.XXMC2", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("性别", "t1.XXMC40", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("户籍", "t1.XXMC5", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("班别", "t1.XXMC16", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("报名点", "t1.XXMC6", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td><%=SzPageHelp.sortTitle("身份证号", "t1.XXMC8", sSortField, iSortOrder, strLevel_SESSION)%></td>
    <td width="100">练车课时</td>
    <td width="115"><input type="checkbox" name="checkAll" onclick="javascript:checked_All(this,'XSJL');">学时记录</td>
  </tr>
<%
	ArrayList listExcel = new ArrayList();
	ArrayList listColumn = null;

	listColumn = new ArrayList();
	listColumn.add("学号");
	listColumn.add("流水号");
	listColumn.add("报名时间");							
	listColumn.add("姓名");
	listColumn.add("性别");
	listColumn.add("户籍");
	listColumn.add("班别");
	listColumn.add("报名点");
	listColumn.add("身份证号");


	listExcel.add(listColumn);

	//获取当前时间
	String time_str = SzDateHelp.getTimeStr();
	String sKey = "0";
	boolean isPass = false;
	int i = 0;
	for (;i<iSize;i++){
		studentInfo = studentList.get(i);
		isPass = studentInfo[19].equals("");

		listColumn = new ArrayList();
		listColumn.add(studentInfo[1]);
		listColumn.add(studentInfo[2]);
		listColumn.add(SzConvert.truncate(studentInfo[3],10));							
		listColumn.add(studentInfo[4]);
		listColumn.add(studentInfo[5]);
		listColumn.add(studentInfo[6]);
		listColumn.add(studentInfo[7]);
		listColumn.add(studentInfo[8]);
		listColumn.add(studentInfo[9]);

		listExcel.add(listColumn);

		
	%>
	<input type="hidden" name="OPERATOR<%=i %>" value="xueshi"> 
	<input type="hidden" name="KEY<%=i %>" value="<%=sKey %>"> 
	<input type="hidden" name="XYID<%=i %>" value="<%=studentInfo[0] %>">
	<input type="hidden" name="XYXM<%=i %>" value="<%=studentInfo[4] %>"> 
	<input type="hidden" name="XH<%=i %>" value="<%=studentInfo[1] %>"> 
	<input type="hidden" name="LSH<%=i %>" value="<%=studentInfo[2] %>"> 
	<input type="hidden" name="BJMC<%=i %>" value="<%=studentInfo[7] %>"> 
	<input type="hidden" name="BJID<%=i %>" value="<%=studentInfo[14] %>"> 
	<tr id="tr<%=i %>">
		<td><%=i+1 %></td>
		<td><a href="javascript:void(0);" onclick="javascript:OpenWin_Detail('../../share/formEngine2/update.jsp?OPERATOR=detail&FormID=1384&type=0&ShowMode=open&KEY=<%=studentInfo[0] %>');"><%=studentInfo[1] %></a>&nbsp;</td>
		<td><%=studentInfo[2] %>&nbsp;</td>
		<td><%=SzConvert.truncate(studentInfo[3],10) %>&nbsp;</td>
		<td><%=studentInfo[4] %>&nbsp;</td>
		<td><%=studentInfo[5] %>&nbsp;</td>
		<td><%=studentInfo[6] %>&nbsp;</td>
		<td><%=studentInfo[7] %>&nbsp;</td>
		<td><%=studentInfo[8] %>&nbsp;</td>
		<td><%=studentInfo[9] %>&nbsp;</td>
		<td><%=toSetUpCourse.getStudentCourseCount(studentInfo[0], Integer.toString(iSelectSubject)) %></td>
		<td><INPUT type="checkbox" name="XSJL<%=i %>" value="合格" text="合格" >合格</td>
	</tr>
	<%
	}
	net.sz600.tool.SzFile.writeExcel("学时记录","upload//driverschool//", iDLID_SESSION + ".xls",listExcel);
%>
	<input type="hidden" name="count" value="<%=i %>">
  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" type="text/javascript">
	function ShenHeSubmit(formName,sUrl){
		if (!confirm("确定是否要批量保存?")){
			return false;
		}
		formName.action = sUrl;
		formName.submit();
	}
	
    function OpenWin_Detail(sUrl) {
  		window.open(sUrl,"","left=100,top=50,width=800,height=600,status=yes,scrollbars=yes,resizable=yes");	
  	}
	
	function checked_All(obj,prefixName){
		var count = document.getElementById("count").value;
		for (var i = 0;i<count;i++){
			var ocjCheckbox = document.getElementById(prefixName + i);
			ocjCheckbox.checked = obj.checked;
		}
	}
	
	function singleSubmit(obj,i){
		var xyid = document.getElementById("XYID"+i).value;
		var yysj = document.getElementById("YYSJ"+i).value;
		var kssj = document.getElementById("KSSJ"+i).value;
		var ksbz = document.getElementById("KSBZ"+i).value;
		
		var objLX = document.getElementsByName("KSLX"+i);
		var kslx = objLX[0].checked? objLX[0].value:objLX[1].value;
		
		var key = document.getElementById("KEY"+i).value;
		var xyxm = document.getElementById("XYXM"+i).value;
		var lsh = document.getElementById("LSH"+i).value;
		var xh = document.getElementById("XH"+i).value;
		var bjmc = document.getElementById("BJMC"+i).value;
		var bjid = document.getElementById("BJID"+i).value;
		
		var dlid = document.getElementById("SzDLID").value;
		var dlxm = document.getElementById("SzDLXM").value;
		var bmmc = document.getElementById("SzBMMC").value;
		var bmid = document.getElementById("SzBMID").value;
		var kskm = document.getElementById("KSKM").value;
		var kskmid = document.getElementById("KSKMID").value;
		//考试时间不能为空
		if (kssj == ''){
			alert("请选择考试时间！");
			return false;
		}
 
		var sUrl = "singleControl.jsp?post=ajaxPost&OPERATOR0=add&count=1";
		var postStr = "SzDLID="+ dlid +"&SzDLXM="+ dlxm + "&SzBMID="+ bmid +"&SzBMMC="+ bmmc +"&KSKM=" + kskm + "&KSKMID=" + kskmid +
				"&KEY0="+ key + "&XH0=" + xh + "&XYXM0=" + xyxm + "&LSH0=" + lsh + "&BJMC0=" + bjmc + "&BJID0=" + bjid + 
				"&XYID0="+ xyid +"&YYSJ0="+ yysj +"&KSSJ0="+ kssj +"&KSLX0="+ kslx +"&KSBZ0="+ ksbz;
		//编码post数据
		postStr = encodeURI(encodeURI(postStr));
		//实例化Ajax
		var ajax = null;
		if (window.XMLHttpRequest){
			ajax = new XMLHttpRequest();
		} else if (window.ActiveXObject){
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			return;
		}
		obj.disabled = "disabled";
		//通过Post方式打开链接
		ajax.open("POST",sUrl,true);
		//定义传输文件头部信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		//发送Post数据
		ajax.send(postStr);
		//回调函数
		ajax.onreadystatechange = function(){
			if (ajax.readyState == 4 && ajax.status == 200) {
				var message = ajax.responseText;
				message = message.substring(message.indexOf("[")+1,message.indexOf("]"));
				if (message == "true"){
					document.getElementById("OPERATOR"+i).value = "";
					document.getElementById("KSBZ"+i).disabled = "disabled";
				} else {
					alert(message);
					obj.disabled = "";
				}
				ajax.abort();
				ajax = null;
			}
		}
	}
	


</script>
<%
    ////如果要使用日历控件，必须输出这个calendarFrame
    out.println(SzPageHelp.calendar2Frame("../../"));
%>