<%
class webcalendar
private swidth
private sheight
private sheadcolor
private scellday
private scelltodaycolor
private scellselectcolor
private scellcolor
private slinkcolor
private sheadtextcolor
private sbordercolor
' อย่าเปลี่ยนค่าบรรทัดล่างนี้
private qmonth
private qyear
Private Sub Class_Initialize()
swidth = "100%"
sheight = "210px"
sheadcolor = "#78b600"
scellday = "#93c105"
scelltodaycolor = "#6ac710"
scellselectcolor = "#d8f53a"
scellcolor = "#c8f53a"
slinkcolor = "#e2f7ba"
sheadtextcolor = "#e2f7ba"
sbordercolor = "#517b00"
' อย่าเปลี่ยนค่าบรรทัดล่างนี้
qmonth = request.querystring("qmonth")
if qmonth = "" then qmonth = month(date)
qyear = request.querystring("qyear")
if qyear = "" then qyear = year(date)
End Sub
public property Let width( widthvalue )
swidth = widthvalue
end property
public property Let height( heightvalue )
sheight = heightvalue
end property
public property let headcolor(headcolorvalue)
sheadcolor = headcolorvalue
end property
public property let cellday(celldaycolorvalue)
scellday = celldaycolorvalue
end property
public property let celltodaycolor(celltodaycolorvalue)
scelltodaycolor = celltodaycolorvalue
end property
public property let cellselectcolor(cellselectcolorvalue)
scellselectcolor = cellselectcolorvalue
end property
public property let cellcolor(cellcolorvalue)
scellcolor = cellcolorvalue
end property
public property let linkcolor(linkcolorvalue)
slinkcolor = linkcolorvalue
end property
public property let headtextcolor(headtextcolorvalue)
sheadtextcolor = headtextcolorvalue
end property
public property let bordercolor(bordercolorvalue)
sbordercolor = bordercolorvalue
end property
' สร้างตัวเขียนออกมาเป็น <html> โดยดึงจากฟังก์ชั่น createhtml อีกที
public sub create()
response.write createhtml()
end sub
' ปล่อยค่า html ที่ออกมาเป็นตารางไป
public function createhtml()
html = ""
html = html & "<div style=""width:" & swidth & "; text-align:center;"" align=""center"">" & vbcrlf
html = html & "<table border=""1"" width=""100%"" style="" height:" & sheight & "; border-collapse:collapse; border:1px solid " & sbordercolor & ";"">" & vbcrlf
html = html & " <tr>" & vbcrlf
html = html & " <td colspan=""7"" style=""background-color:" & sheadcolor & ";"">"
html = html & " <table border=""0"" width=""100%"" style=""font-weight:bold;""><tr><td style=""text-align:left;"">"
html = html & " <a style=""text-decoration:none; color:" & slinkcolor & ";"" href=""?"
if qmonth - 1 = 0 then
html = html & "qmonth=12&qyear=" & qyear -1 & """>"
else
html = html & "qmonth=" & qmonth - 1 & "&qyear=" & qyear & """>"
end if
html = html & " «"
html = html & " </td>"
html = html & " <td style=""text-align:center; color:" & sheadtextcolor & ";"">" & monthname(qmonth) & " " & qyear & "</td>"
html = html & " <td style=""text-align:right"">"
html = html & " <a style=""text-decoration:none; color:" & slinkcolor & ";"" href=""?"
if qmonth + 1 = 13 then
html = html & "qmonth=1&qyear=" & qyear + 1 & """>"
else
html = html & "qmonth=" & qmonth + 1 & "&qyear=" & qyear & """>"
end if
html = html & " »"
html = html & " </td></tr></table>"
html = html & " </td>" & vbcrlf
html = html & " </tr>" & vbcrlf
'--------------------หัววันที่ อาทิตย์ถึงจันทร์
html = html & " <tr style=""text-align:center; background-color:" & scellday & ";"">" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">อ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">จ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">อ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">พ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">พ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">ศ</td>" & vbcrlf
html = html & " <td style=""width:" & formatnumber(100/7, 3) & "%;"">ส</td>" & vbcrlf
html = html & " </tr>" & vbcrlf
firstday = weekday(dateserial(qyear, qmonth, 1)) -1
currentday = 1
for calndrrows = 0 to 5
html = html & " <tr>" & vbcrlf
for calndrcols = 0 to 6
if calndrrows = 0 and calndrcols < firstday then' ช่องว่างก่อนวันที่เริ่มต้นของเดือน
html = html & " <td style=""text-align:center; background-color:" & scellcolor & ";""> </td>" & vbcrlf
elseif currentday > lastday(qmonth, qyear) then' ช่องว่างหลังวันสิ้นสุดเดือน
html = html & " <td style=""text-align:center; background-color:" & scellcolor & ";""> </td>" & vbcrlf
else
'---------------------------'
html = html & " <td"
if qmonth = month(date) and currentday = day(date) and qyear = year(date) then' วันที่ปัจจุบัน
html = html & " style=""text-align:center; background-color:" & scelltodaycolor & ";"">"
elseif qdate = currentday then
html = html & " style=""text-align:center; background-color:" & scellselectcolor & ";"">"
else
html = html & " style=""text-align:center; background-color:" & scellcolor & ";"">"
end if
'-------------' จะเพิ่มเติมการคลิกวันที่ก็ทำในช่องนี้
html = html & currentday
'-------------' จะเพิ่มเติมการคลิกวันที่ก็ทำในช่องนี้
html = html & "</td>" & vbcrlf
'---------------------------'
currentday = currentday + 1
end if
next
html = html & " </tr>" & vbcrlf
next
html = html & "</table>" & vbcrlf
html = html & "</div>" & vbcrlf
createhtml = html
end function
function monthname(qmonth)
select case qmonth
case 1
monthname = "January"
case 2
monthname = "Febuary"
case 3
monthname = "March"
case 4
monthname = "April"
case 5
monthname = "May"
case 6
monthname = "June"
case 7
monthname = "July"
case 8
monthname = "August"
case 9
monthname = "September"
case 10
monthname = "October"
case 11
monthname = "November"
case 12
monthname = "December"
case else
monthname = "Error!"
end select
end function
function lastday(qmonth, qyear)
' returns the last day of the month. takes into account leap years
' example: lastday(12,2000) or lastday(12) or lastday
select case qmonth
case 1, 3, 5, 7, 8, 10, 12
lastday = 31
case 4, 6, 9, 11
lastday = 30
case 2
if isdate("29" & "/" & qmonth & "/" & qyear+calendaryearvalue) then lastday = 29 else lastday = 28
case else
lastday = 0
end select
end function
end class
%>
เป็นการทำงานแสดงปฏิทิน
เวลาใช้งานก็.. Code (ASP)
<%
set calendar = new webcalendar
calendar.width = "500px"'<--ตรงนี้คือกำหนดค่าความกว้าง ถ้าไม่กำหนดมันจะใช้ค่าเดิม
' การตั้งค่าให้ลองเปรียบเทียบตัวอย่างบรรทัดบนกับการตั้งค่าอื่นๆอีกมากมายที่เขียนไว้แล้วลองกำหนดดู
calendar.create
set calendar = nothing
%>