<%response.expires=-1%>
<!--#include file="../inc/Secure.htm"-->
<!--#include file="../inc/conn.htm"-->

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="../CSS/main.css">
</HEAD>
<%
selectdate=trim(request("SelectDate"))
if selectdate="" then selectdate=date()
%>
<BODY BGCOLOR="#FFFFFF">
<div align=center>
<table border=0 width="70%">
<tr>
<td><a href="WriteLog.htm">值班人员填写值班记录/日志</a></td>
<td><a href="ReadLog.htm">查看值班记录/日志</a></td>
<td><a href="Watch_Cancel.htm">取消值班登记</a></td>
</tr>
</table></div>
<div align=center>
<table border=1 cellpadding=3 cellspacing=1 width="95%" bgcolor=#EEEEEE bordercolordark="#FFFFFF" bordercolorlight="#999999">
<tr>
	<td width="15%" nowrap><font color=red><b>值班人一揽</b></font></td>
	<td align=center><font color=red><%=year(selectdate)&"年"&month(selectdate)&"月"&day(selectdate)&"日"%></font></td>
	<td align=right width="25%">
	<a href="watch_index.htm?selectdate=<%=cdate(selectdate)-1%>" title="昨日"><img src="../images/arrow_left.gif" border=0></a>
	<a href="watch_index.htm" title="今日"><img src="../images/today.gif" border=0></a>
	<a href="watch_index.htm?selectdate=<%=cdate(selectdate)+1%>" title="明日"><img src="../images/arrow_right.gif" border=0></a>
	</td>
</tr>
</table>

<table border=1 cellpadding=3 cellspacing=0 width="95%" bgcolor=#EEEEEE bordercolordark="#FFFFFF" bordercolorlight="#999999">
<tr>
<td width="20%">部门/值班人及时间</td>
<td colspan=2>&nbsp;</td>
</tr>
<%
set rs=server.createobject("Adodb.recordset")
sql="select * from tbldepartment where ID>0 Order by name"
rs.open sql,oConn
while not rs.eof
Department=trim(rs("ID"))%>
<tr>
<td>
	<%=trim(rs("name"))%>&nbsp;
</td>
<td>
	<%=GetWatch(Department,selectdate)%>&nbsp;
</td>
<td><a href="watch_Order.htm?Department=<%=Department%>&SelectDate=<%=selectdate%>">安排值班>></a></td>
</tr>
<%rs.movenext
wend
rs.close
set rs=nothing
%>
</table></div>

</BODY>
</HTML>
<!--#include file="../inc/conn_close.htm"-->
<%

private function GetWatch(byval Department,byval times)
set rstmp=server.createobject("Adodb.recordset")
sql="select * from tblwatch where Starttime<='"& times&" 23:30:00" &"' and EndTime>='"& times &"' and Department="& Department

rstmp.open sql,oConn
if not rstmp.eof then
GetWatch=""
while not rstmp.eof
	if GetWatch="" then
	GetWatch=GetWatch& trim(rstmp("WatchName"))&"<a href=Watch_detail.htm?selectdate="&selectdate&"&ID="&trim(rstmp("ID"))&">（<font color=red>"&trim(rstmp("StartTime"))&"——"&trim(rstmp("endTime"))&"</font>）</a>"
	else
	GetWatch=GetWatch&"<BR>"& trim(rstmp("WatchName"))&"<a href=Watch_detail.htm?selectdate="&selectdate&"&ID="&trim(rstmp("ID"))&">（<font color=red>"&trim(rstmp("StartTime"))&"——"&trim(rstmp("endTime"))&"</font>）</a>"
	end if
rstmp.movenext
wend
else
	GetWatch="未安排"
end if
rstmp.close
end function


private function toyestoday (byval strtoday)
	today=cdate(strtoday)
	today_year=year(today)
	today_month=month(today)
	today_day=day(today)
	yestoday_year=year(today)
	yestoday_month=month(today)
	yestoday_day=day(today)
if today_day-1>0 then
	yestoday_day=yestoday_day-1
elseif today_month="1" then
	yestoday_day=getmaxday(today_year,today_month)
	yestoday_month="12"
else
	yestoday_day=getmaxday(today_year,today_month)
	yestoday_month=yestoday_month-1
end if
toyestoday=yestoday_year&"-"&yestoday_month&"-"&yestoday_day
end function

private function totomorrow (byval strtoday)
	today=cdate(strtoday)
	today_year=year(today)
	today_month=month(today)
	today_day=day(today)
	tomorrow_year=year(today)
	tomorrow_month=month(today)
	tomorrow_day=day(today)
	if ((today_year mod 4=0) and (today_year mod 100<>0)) or (today_year mod 400=0) then
		runnian=true
	else
		runnian=false
	end if
	
	select case today_month
	case "1","3","5","7","8","10"
		if today_day="31" then
		tomorrow_day="1"
		tomorrow_month=today_month+1
		else
		tomorrow_day=today_day+1
		end if
	case "4","6","9","11"
		if today_day="30" then
		tomorrow_day="1"
		tomorrow_month=today_month+1
		else
		tomorrow_day=today_day+1
		end if
	case "2"
		if runnian and today_day="29" then
			tomorrow_day="1"
			tomorrow_month=today_month+1
		elseif (not runnian) and today_day="28" then
			tomorrow_day="1"
			tomorrow_month=today_month+1
		else
			tomorrow_day=today_day+1	
		end if
	case "12"
		if today_day="31" then
		tomorrow_day="1"
		tomorrow_month=today_month+1
		tomorrow_year=today_year+1
		else
		tomorrow_day=today_day+1
		end if

end select

totomorrow =tomorrow_year&"-"&tomorrow_month&"-"&tomorrow_day
end function

private function getmaxday(byval stryear, byval strmonth)
	if ((stryear mod 4=0) and (stryear mod 100<>0)) or (stryear mod 400=0) then
		runnian=true
	else
		runnian=false
	end if
	strmonth=strmonth-1
	if strmonth="0" then strmonth="12"

	select case strmonth
	case "1","3","5","7","8","10","12"
	getmaxday="31"
	case "4","6","9","11"
	getmaxday="30"
	case "2"
		if runnian then
			getmaxday="29"
		else
			getmaxday="28"
		end if
	case else
	getmaxday="31"
	end select
end function
%>