<%@ 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>
<script language="javascript">
  function selectStudent(vShijianduan, vDate,vBMID_Str) {
  	formBar.txtShijianduan.value = vShijianduan;
  	formBar.txtDate.value = vDate;
  	
  	var vCoach = formBar.selectCoach.value;
  	if (vCoach == "" || vCoach == "0") {
  		alert("请选择教练");
  		return;
  	} 
  	var vSubject = formBar.selectSubject.value;
  	if (vSubject == "" || vSubject == "0") {
  		alert("请选择科目");
  		return;
  	}  	
  	
  	
  	url = "student_select.jsp?selectCoach=" + vCoach + "&selectSubject=" + vSubject + "&txtShijianduan=" + vShijianduan + "&txtDate=" + vDate+"&txtBMIDStr="+vBMID_Str;
  	window.showModalDialog(url,window,"status=no;dialogWidth=680px;dialogHeight=450px");
  	//window.open(url,"","width=680,height=450");
  }
  
 	function checkMonth(oFormName, sV, sUrl) {
 		oFormName.selectWeek.value = sV;
 		oFormName.action = sUrl;
 		oFormName.target = "_self";
 		oFormName.submit();
 	}  
 	
 	function deleteSubmit(formName,sUrl){
		var chkCount = NumberOfCheck(formName.chkId);
		if (chkCount <= 0){
			alert("请选择要删除的信息!");
			return false;
		}
		if (!confirm('确定要删除选中的信息吗？')){
			return false;
		}
		formName.action = sUrl;
		formName.submit();
	}
</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];
	}	
		
	String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
	String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));
	//教练
	int iSelectCoach = SzConvert.toInt(request.getParameter("selectCoach"));
	String selectWeek = SzConvert.toZeroStr(request.getParameter("selectWeek"));
	//获取选择的部门信息
	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("");
	//如果开始时间和结束时间都为空，就默认为当前月
	Date currentDate = null;
	if (sSearchBegin.equals("")) {
		currentDate = SzDateHelp.getDate();
	} else {
		currentDate = SzDateHelp.stringToDate(sSearchBegin);
	}
	if (selectWeek.equals("0")) {
		currentDate = SzDateHelp.getDate();
	} else if (selectWeek.equals("-1")) {
		//上一周
		currentDate = SzDateHelp.dayBefore(currentDate, 7);
	} else if (selectWeek.equals("1")) {
		//下一周
		currentDate = SzDateHelp.dayAfter(currentDate, 7);
	}
	Date dSearchBegin = SzDateHelp.getFirstDateWeek(currentDate);
	Date dSearchEnd = SzDateHelp.getLastDateWeek(currentDate);
	sSearchBegin = SzDateHelp.dateToYMD(dSearchBegin);
	sSearchEnd = SzDateHelp.dateToYMD(dSearchEnd);
	String strDate = SzDateHelp.dateToYMD(currentDate);
	
   // sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateWeek(selDate));
   // sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateNextWeek(selDate));
	//查询的结束时间
	String searchEnd = SzDateHelp.dateToYMD(SzDateHelp.nextDay(SzDateHelp.stringToDate(sSearchEnd)));
	
	Exam exam = new Exam();
	//取得对应条件的排课map
	Map mapSchedule = exam.getMapSchedule(Integer.toString(iSelectCoach), Integer.toString(iSelectSubject), XH, LSH, sSearchBegin, sSearchEnd);
	
	String weekName[] = {"周日","周一","周二","周三","周四","周五","周六"};
	Date date = null;
	ArrayList list = null;
	ArrayList fenDianList = null;
	String[] fdValue = null;
	int i =0;
	String fdidStr = "0";
%>	
<%@ include file="/share/title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <tr>
    <td>
      科目：<B><%=sSubjectName%></B>    
      教练选择:<%=SzPageHelp.idSelectSubmit("BD_DRIVINGSCHOOL_COACH", "XXMC1", "XXMC2","selectCoach", iSelectCoach, "", "") %>
      学号<input type="text" name="XH" class="txtClassSearch" value="<%=XH %>">
      流水号<input type="text" name="LSH" class="txtClassSearch" value="<%=LSH %>">
  	<input type="hidden" name="selectSubject" value="<%=iSelectSubject%>">      
  	<input type="hidden" name="subjectOrder" value="<%=sSubjectOrder%>">    	
  	<input type="hidden" name="txtShijianduan" value="">
  	<input type="hidden" name="txtDate" value="">     
  	<input type="hidden" name="selectWeek" value="<%=selectWeek%>">

     <br>
	 	<input type="button" value="上周" class="btnClassShort" OnClick="javascript:checkMonth(formBar, '-1', 'index.jsp');">
	 	<input type="button" value="本周" class="btnClassShort" OnClick="javascript:checkMonth(formBar, '0', 'index.jsp');">
    <input type="button" value="下周" class="btnClassShort" OnClick="javascript:checkMonth(formBar, '1', 'index.jsp');">
      开始<input type="text" name="txtSearchBegin" class="txtClassSearch" value="<%=sSearchBegin%>" readonly>
      结束<input type="text" name="txtSearchEnd" class="txtClassSearch" value="<%=sSearchEnd%>" readonly>
      <%=SzPageHelp.button("btnClass", "查询", "javascript:FormSubmit(formBar,'index.jsp');", "btnSearch")%>
      <%//=isBarManager_SESSION? SzPageHelp.button("批量删除", "javascript:deleteSubmit(formUpdate,'delete.jsp?OPERATOR=delete');"):""%>
      <%//=SzPageHelp.button("批量删除", "javascript:deleteSubmit(formUpdate,'delete.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="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="txtShijianduan" value="">
  <input type="hidden" name="txtDate" value="">
  <input type="hidden" name="selectCoach" value="<%=iSelectCoach%>">
  <input type="hidden" name="selectSubject" value="<%=iSelectSubject%>">
  <input type="hidden" name="subjectOrder" value="<%=sSubjectOrder%>">
  <input type="hidden" name="selectWeek" value="<%=selectWeek%>">
  <!-- 用于存放临时的选择值 -->
  <input type="hidden" name="tempMC" value=""> 
  <input type="hidden" name="tempID" value=""> 
  
  <tr class="trClassTitle">
  	<td width="100">日期</td>
  	<td>学员</td>
  </tr>
  <%
  		strDate = "";
		for (date = dSearchBegin; date.before(SzDateHelp.dayAfter(dSearchEnd, 1)); date = SzDateHelp.dayAfter(date, 1)) {
			strDate = SzDateHelp.dateToYMD(date);
			out.println("<tr>");
			out.println("<td align=\"center\">");
			out.println(weekName[date.getDay()]);
			out.println("(" + SzDateHelp.dateToYMD(date).substring(8) + "号)");
			out.println("</td>");
			
			//取得已排课
			list = (ArrayList)mapSchedule.get(new String(strDate));
			Iterator iter2 = null;
			if (list != null) {
				iter2 = list.iterator();
			}
			
			String str[] = null;
			i = 0;
			out.println("<td onMouseOver=\"javascript:this.className='trMouseOver'\"  onMouseOut=\"javascript:this.className='trMouseOut'\">");
			//KCXXMC8 练车日期 , KCXXMC9 练车时间段, KCXXMC4 学员,KCXXMC5 学员ID ,KCXXMC14 练场 ,KCXXMC19 学员确认状态,KCXXMC10 教练 ,KCXXMC12 科目
			while (iter2 != null && iter2.hasNext()) {
				str = (String[])iter2.next();
				if (i >0) {
					//out.println("<br>");
				}
				out.println("<span style=\"width: auto;\"><input type=\"checkbox\" name=\"chkId\" value=\""+ str[0] +"\">");
				out.print((str[2] + "," + str[3] + "," + str[4]).trim() + "</span>");
				i++;
			}
			out.println(i==0? "&nbsp;":"");		
			out.println("</td>");
			out.println("</tr>");
		}
	%>
  
  </form>
</table>



