Tuesday, September 9, 2008

ASP:Timetable management: How to create each date of a timetable as a button?


<%
days=end_date - start_date+1
wdstart_date=weekday(start_date)
empty_boxes=wdstart_date -1
wdend_date=weekday(end_date)
suffix_empty_boxes=7-weend_date
total_boxes=empty_boxes + days
first_date=start_date - empty_boxes
response.write(total_boxes)
%>
<table border="1" align="center">
<tr>
<td align="center" bgcolor="#d0d0d0">
Sun
</td>
<td align="center" bgcolor="#d0d0d0">
Mon
</td>
<td align="center" bgcolor="#d0d0d0">
Tue
</td>
<td align="center" bgcolor="#d0d0d0">
Wed
</td>
<td align="center" bgcolor="#d0d0d0">
Thu
</td>
<td align="center" bgcolor="#d0d0d0">
Fri
</td>
<td align="center" bgcolor="#d0d0d0">
Sat
</td>


</tr>
<tr>
<%
for i=1 to total_boxes
wday=weekday(first_date)
if wday=7 and day(first_date)>=8 and day(first_date)<=14 then
second_saturday="yes"
else
second_saturday="no"
end if

if wday=1 then
disabled="disabled"
else
disabled=""
end if

%>
<td width="70" height="30">
<%
Set ObjRsChk=Myconn.Execute("select distinct(tt_id) from master_timetable where co_sch_id='" & co_sch_id & "' and tt_date=to_date('"&first_date&"','mm/dd/yyyy')")
If ObjRsChk.Eof then
record_exists_color="#ff0000"
Else
record_exists_color="#d0d0d0"
End If

if i <= empty_boxes or i >=suffix_empty_boxes then
Response.write("&nbsp;")
first_date=first_date +1
Elseif second_saturday="yes" then
%>

<button onclick="location.href='tt_management4.asp?co_sch_id=<%=co_sch_id%>&tt_date=<%=first_date%>'" style="color:#404040;font-size:9px;font-family:arial;height:30px;width:70px; background-color:#a0a0a0">
<%
Response.write(ddmmyy(first_date))

Response.write("<br>2nd Sat")
first_date=first_date +1
%>
</button>

<%
Else
if cstr(Request("tt_date"))=cstr(first_date) then
current_date_selected="disabled"
else
current_date_selected="no"
End If
%>
<button <%=current_date_selected%> onclick="location.href='tt_management4.asp?co_sch_id=<%=co_sch_id%>&tt_date=<%=first_date%>'" style="font-family:arial;height:30px;width:70px;background-color:<%=record_exists_color%>">
<%
Response.write(ddmmyy(first_date))
first_date=first_date +1
%>
</button>

<%
End if
%>

</td>
<%
if i mod 7=0 then
%>
</tr>
<tr>
<%
end if
%>
<%
next
%>
</tr></table>


<!--#date buttons ends here-->
<%
If ObjRsCo.Eof Then
Response.Redirect(BACK_FILE_NAME & "?result=Error.Course schedule id not present")
Else
%>
<table border="0" class="formgrid" align="center">
<tr>

<td >
<%=ObjRsCo("co_name")%> *
<%=ObjRsCo("duration")%> *
<%=ObjRsCo("duration_type")%> *
<%=ObjRsCo("ctype_code")%>
</td>
</tr>
</table>

<%
End If
%>

No comments: