<%@ 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>
</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];
	}	
	int iSelectCoach = SzConvert.toInt(request.getParameter("selectCoach"));	//教练

	//查询时间段
	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 LSH = SzConvert.strWriteData(request.getParameter("LSH"));
	//条件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 XXMC10>='" + sSearchBegin + "'");
  }
  if (!searchEnd.equals("")) {
        sCond.append(" AND XXMC10<'" + searchEnd + "'");
  }
	if (iSelectSubject > 0 ) {
		sCond.append(" AND XXMC16='");
		sCond.append(iSelectSubject);
		sCond.append("'");
	}	
	if (iSelectCoach > 0 ) {
		sCond.append(" AND XXMC18='");
		sCond.append(iSelectCoach);
		sCond.append("'");
	}	
	//学号
	if (!XH.equals("")){
		sCond.append(" AND XXMC3='"+ XH +"'");
	}
	//流水号
	if (!LSH.equals("")){
		sCond.append(" AND XXMC4='"+ LSH +"'");
	}
	sCond.append(" AND XXMC14 in ( select XXMC1 from BD_DRIVINGSCHOOL_XUEYUAN where 1=1 ");
	Exam exam = new Exam();
	sCond.append(exam.getCond("课程安排", sSubjectName));		
	sCond.append(" )");
	
	String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
  int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder"))); 
  if (sSortField.equals("")) { 
    	sSortField = "XXMC6";
    	iSortOrder = SzProperties.I_SortOrder_DESC;
  }
	sCond.append(" ORDER BY "+ sSortField + (iSortOrder==SzProperties.I_SortOrder_DESC? " DESC":" ASC"));
	
	ToSetUpCoach toSetUpCoach = new ToSetUpCoach();

	//ID,学员ID,学员姓名,教练ID,教练名称,场地ID,场地名称,分配时间
	String[] fields = new String[]{"XXMC1","XXMC14","XXMC2","XXMC18","XXMC6","XXMC17","XXMC7","XXMC10"};
	
	ArrayList<String[]>  studentList = toSetUpCoach.getSetUpCoachList(fields, sCond.toString());
	int iSize = studentList.size();
	//学员
	String[] studentInfo = null;
	
	
%>
<!-----上面的工具栏------>
<%@ 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="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,'setUpCoachList2.jsp');")%>
      <%=isBarManager_SESSION? SzPageHelp.button("批量删除", "javascript:deleteSubmit(formUpdate,'control.jsp?OPERATOR=delete');"):""%>
    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formUpdate" method="post">
  <input type="hidden" name="OPERATOR" value="add"> 
  <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="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] %>">
  <input type="hidden" name="subjectOrder" value="<%=sSubjectOrder%>"> 
  <!-- 用于存放临时的选择值 -->
  <input type="hidden" name="tempMC" value=""> 
  <input type="hidden" name="tempID" value=""> 
  <tr class="trClassTitle">
  	<td width="25" align="center"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formUpdate, chkCheckAll, 'chkId');"></td>
  	<td width="150">教练</td>
  	<td width="150">场地</td>
    <td>已分配学员</td>
    <td>分配时间</td>
    <td width="80">删除</td>
  </tr>
<%
	//获取当前时间
	String time_str = SzDateHelp.getTimeStr();
	String sKey = "";
	int i = 0;
	int j = 0;
	//ID,学员ID,学员姓名,教练ID,教练名称,场地ID,场地名称,分配时间
	for(j = 0;j<iSize;j++){
		studentInfo = studentList.get(j);
	%>
	<tr>
		<td><input title="<%=i+1 %>" type="checkbox" name="chkId" value="<%=studentInfo[0] %>"></td>
		<td><%= studentInfo[4]%></td>
		<td><%= studentInfo[6]%></td>
		<td><%= studentInfo[2]%></td>
		<td><%= studentInfo[7]%></td>
		<td align="center">
		<%if (isBarManager_SESSION){  %>
		<a href="javascript:void();" onclick="javascript:if(confirm('确定要删除信息?')){this.href='control.jsp?OPERATOR=delete&subjectOrder=<%=sSubjectOrder%>&chkId=<%=studentInfo[0] %>'}">删除</a>
		<%} else {
			out.println("--");
		} %>
		</td>
	</tr>
<%
	}
%>
	<tr class="trClassTitle2">
		<td colspan="10" align="center">合计:<%=j %> &nbsp;&nbsp;(只列出<%=sSubjectName %>未通过的学员)</td>
	</tr>
  </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 deleteSubmit(formName,sUrl){
		var chkCount = NumberOfCheck(formName.chkId);
		if (chkCount <= 0){
			alert("请选择要删除的信息!");
			return false;
		}
		if (!confirm('确定要删除选中的信息吗？')){
			return false;
		}
		formName.action = sUrl;
		formName.submit();
	}

	function ShenHeSubmit(formName,sUrl){
		
		var count = document.getElementById("count").value;
		var checkeds = 0;
		for (var i = 0;i<count;i++){
			//学员ID
			var students = document.getElementsByName("student"+i);
			var cd = document.getElementById("CD" + i).value;
			var jl = document.getElementById("JL" + i).value;
			
			var studentID = "",sName = "";
			for (var j = 0;j<students.length;j++){
				studentID = students[j].value;
				sName = document.getElementById("sName" + studentID).value;
				if (students[j].checked){
					checkeds++;
					if (cd == ""){
						alert("请为 "+ sName +" 指定训练场！");
						return false;
					} else if (jl == ""){
						alert("请为 "+ sName +" 指定教练！");
						return false;
					}
				}
			}
		}
		if (checkeds == 0){
			alert("请选择学员!");
			return false;
		}
		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 singleSubmit(obj,i){
		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;
		
		var cdid = document.getElementById("CDID" + i).value;
		var cd = document.getElementById("CD" + i).value;
		var jlid = document.getElementById("JLID" + i).value;
		var jl = document.getElementById("JL" + i).value;
		
		if (cd == ""){
			alert("请选择训练场！");
			return false;
		} else if (jl == ""){
			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 + 
					"&CDID0=" + cdid + "&CD0=" + cd + "&JLID0=" + jlid + "&JL0=" + jl;
		//学员ID
		var students = document.getElementsByName("student"+i);
		var studentID = "";
		var checkeds = 0;
		for (var j = 0;j<students.length;j++){
			if (students[j].checked){
				checkeds++;
				studentID = students[j].value;
				postStr += "&student0=" + studentID;
				postStr += "&sName"+ studentID +"=" + document.getElementById("sName" + studentID).value;
				postStr += "&sBJ"+ studentID +"=" + document.getElementById("sBJ" + studentID).value;
				postStr += "&sBJID"+ studentID +"=" + document.getElementById("sBJID" + studentID).value;
				postStr += "&sXH"+ studentID +"=" + document.getElementById("sXH" + studentID).value;
				postStr += "&sLSH"+ studentID +"=" + document.getElementById("sLSH" + studentID).value;
			}
		}
		if (checkeds == 0){
			alert("请选择学员!");
			return false;
		}
		//进行编码
		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"){
					//("OPERATOR"+i)不能为空
					//document.getElementById("OPERATOR"+i).value = "";
					//已经设置的设为disabled
					for (var j = 0;j<students.length;j++){
						if (students[j].checked){
							students[j].checked = "";
							students[j].disabled = "true";
						}
					}
				} else {
					obj.disabled = "";
				}
				ajax.abort();
				ajax = null;
			}
		}
		
	}
	
	//特殊选择函数
	function OpenSelectWin(vTableName,objID,objMC) {
	  var type= "";
	  var url = "../../share/formEngine2/select_win.jsp";
	  url = url + "?tableName=" + vTableName + "&index=-1";
	  window.showModalDialog(url,window,"status=no;dialogWidth=580px;dialogHeight=350px");
	  //临时hidden值赋值目标文本框
	  if (formUpdate.tempID.value.indexOf(",")>0){
	  	alert("对不起，不能选择多个！");
	  	return false;
	  }
	  objID.value = formUpdate.tempID.value;
	  objMC.value = formUpdate.tempMC.value;
	}
	
	


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