달력을 그리고 그 안에 데이타를 채우는 CLASS
<%
'***************************************************************************
'* PROJECT : UCCalendar
'* PATH : /
'* FILE : UCCalendar.asp
'* AUTHOR : KHAN
'* DATE : 2006-09-15
'* DESCRIPTION : 달력그리기
'* REMARKS :
'* MODITY :
'***************************************************************************
%>
<%
'//////////////////////////////////////////////////////////////////////////////
'//
'// Class
'//
'//////////////////////////////////////////////////////////////////////////////
Class UCCalendar
'=========================================================
Private m_arCal '달력배열
Private m_arData '해당 날짜의 데이타 배열
Private m_arHolidays '국경일 배열
Private m_cur_date '원하는 날짜
Private m_cal_header 'calendar header 요일태그 포함.
Private m_cal_bottom 'calendar bottom
Private m_week_header 'week html header
Private m_week_bottom 'week html bottom
Private m_normal_html '보통일 html
Private m_saturday_html '토요일 html
Private m_sunday_html '일요일 html
Private m_curday_html '오늘 html
Private m_blank_html '빈칸 html
Private m_holiday_html '공휴일 html
Private m_start_num '월1일의 배열 위치
Private m_week_cnt '해당 월의 주 수
Private m_days_cnt '해당 월의 일 수
Private m_IsViewHoliday '공휴일 표시여부 True/False
'=========================================================
Public Property Get cur_date
cur_date = m_cur_date
End Property
Public Property Let cur_date(ByVal pVal)
If IsDate(pVal) then
m_cur_date = pVal
Else
m_cur_date = Date
End If
SetArray()
End Property
Public Property Let cal_header(ByVal pVal)
m_cal_header = pVal
End Property
Public Property Let cal_bottom(ByVal pVal)
m_cal_bottom = pVal
End Property
Public Property Let week_header(ByVal pVal)
m_week_header = pVal
End Property
Public Property Let week_bottom(ByVal pVal)
m_week_bottom = pVal
End Property
Public Property Let normal_html(ByVal pVal)
m_normal_html = pVal
End Property
Public Property Let saturday_html(ByVal pVal)
m_saturday_html = pVal
End Property
Public Property Let sunday_html(ByVal pVal)
m_sunday_html = pVal
End Property
Public Property Let curday_html(ByVal pVal)
m_curday_html = pVal
End Property
Public Property Let blank_html(ByVal pVal)
m_blank_html = pVal
End Property
Public Property Let holiday_html(ByVal pVal)
m_holiday_html = pVal
End Property
Public Property Let IsViewHoliday(ByVal pVal)
m_IsViewHoliday = pVal
End Property
'=========================================================
Private Sub Class_Initialize
'Html 기본값
m_cal_header = "<table border=""1""><tr align=""center""><td>일</td><td>월</td><td>화</td><td>수</td><td>목</td><td>금</td><td>토</td></tr>"
m_cal_bottom = "</table>"
m_week_header = "<tr>"
m_week_bottom = "</tr>"
'//일이 들어갈 곳에 "{{DAY}}"를 삽입
'//내용이 들어갈 곳에 "{{CONTENT}}"를 삽입
m_normal_html = "<td>{{DAY}} {{CONTENT}}</td>"
m_saturday_html = "<td><font color='blue'>{{DAY}}</font> {{CONTENT}}</td>"
m_sunday_html = "<td><font color='red'>{{DAY}}</font> {{CONTENT}}</td>"
m_curday_html = "<td><font color='green'><b>{{DAY}}</b></font> {{CONTENT}}</td>"
m_blank_html = "<td> </td>"
m_holiday_html = "<td><font color='red'>{{DAY}}</font> {{CONTENT}}</td>"
'//공휴일 초기화
ReDim m_arHolidays(2, 7)
m_arHolidays(0, 0)="1-1" : m_arHolidays(1, 0)="신정"
m_arHolidays(0, 1)="3-1" : m_arHolidays(1, 1)="3.1절"
m_arHolidays(0, 2)="4-5" : m_arHolidays(1, 2)="식목일"
m_arHolidays(0, 3)="5-5" : m_arHolidays(1, 3)="어린이날"
m_arHolidays(0, 4)="6-6" : m_arHolidays(1, 4)="현충일"
m_arHolidays(0, 5)="8-15" : m_arHolidays(1, 5)="광복절"
m_arHolidays(0, 6)="10-1" : m_arHolidays(1, 6)="개천절"
m_arHolidays(0, 7)="12-25" : m_arHolidays(1, 7)="성탄절"
m_IsViewHoliday = False
'날짜 오늘을 기본으로 처리
m_cur_date = Date
'오늘 날짜를 기준으로 배열 Redim
SetArray()
End Sub
Private Sub Class_Terminate
m_arCal = Empty
m_arData = Empty
End Sub
'=========================================================
'yr년 mnth월이 일수 계산
dim temp,leap,noDays
Private Function GetLastDay(yr, mnth)
temp = yr mod 4
if temp=0 then
leap = 1
else
leap = 0
end if
noDays=0
select case mnth
case 1, 3, 5, 7, 8, 10, 12
noDays = 31
case else
if mnth=2 then
noDays = 28 + leap
else
noDays = 30
end if
end select
GetLastDay = noDays
End Function
'----------------------------------------------------------
'm_cur_date의 달의 주수를 계산 html, data 배열 재선언
dim week_cnt
Private Function SetArray()
m_start_num = Weekday(Year(m_cur_date)&"-"&month(m_cur_date)&"-1")-1
m_days_cnt = GetLastDay(Year(m_cur_date), Month(m_cur_date))
week_cnt = 5
Select Case m_start_num+1
Case 1, 2, 3, 4, 5 : m_week_cnt = 5 '월, 화, 수, 목
Case 6
If m_days_cnt>30 Then
m_week_cnt = 6
Else
m_week_cnt = 5
End If
Case 7
If m_days_cnt>29 Then
m_week_cnt = 6
Else
m_week_cnt = 5
End If
End select
ReDim m_arCal(6, m_week_cnt-1)
ReDim m_arData(6, m_week_cnt-1)
End Function
'----------------------------------------------------------
'html 과 data배열 값을 이용 html배열에 값을 채움.
Public Function InitArray()
dim i,iday,k,j
'첫째줄 첫칸부터 1일 전까지 빈칸
For i = 0 To m_start_num - 1
m_arCal(i, 0) = SetHtml("", " ")
Next
'첫째줄 1일부터 토요일까지
iday = 1
For i = m_start_num To 6
m_arCal(i, 0) = SetHtml(Year(m_cur_date)&"-"&month(m_cur_date)&"-"&iday , m_arData(i, 0))
iday = iday + 1
Next
'둘째줄 월요일부터 그달 마지막 날까지
For k = 1 To m_week_cnt-1
j=0
While j<7 And iday<=m_days_cnt
m_arCal(j, k) = SetHtml(Year(m_cur_date)&"-"&month(m_cur_date)&"-"&iday, m_arData(j, k))
j = j + 1
iday = iday + 1
Wend
If iday>m_days_cnt Then Exit For End If
Next
'그 달 마지막날 다음날부터 그 줄 끝까지 빈칸
For k = k To m_week_cnt-1
j = j
While j<7
m_arCal(j, k) = SetHtml("", " ")
j = j + 1
Wend
Next
End Function
'----------------------------------------------------------
'pDate특성에 맞는 html에 pVal값을 넣어서 돌려줌.
Private Function SetHtml(pDate, pVal)
Dim retval,hcnt,cur_html
retval = ""
Dim str_day
If IsDate(pDate) Then
str_day = Day(pDate)
Else
str_day = ""
End If
Dim IsHoliday, strHoliNm
IsHoliday = False
strHoliNm = ""
If IsDate(pDate) then
For hcnt = 0 To UBound(m_arHolidays, 2)
If DateDiff("d", pDate, Year(pDate)&"-"&m_arHolidays(0, hcnt))=0 Then
IsHoliday = True
strHoliNm = m_arHolidays(1, hcnt)
End If
Next
End If
If IsDate(pDate) then
If DateDiff("d", pDate, Date)=0 Then
cur_html=m_curday_html
ElseIf IsHoliday And m_IsViewHoliday Then
cur_html=m_holiday_html
pVal = strHoliNm & " " & pVal
Else
Select Case Weekday(pDate)
Case 1 : cur_html=m_sunday_html
Case 2, 3, 4, 5, 6 : cur_html=m_normal_html
Case 7 : cur_html=m_saturday_html
End Select
End If
retval = Replace(cur_html, "{{DAY}}", str_day)
Else
retval = Replace(m_blank_html, "{{DAY}}", "")
End If
retval = Replace(retval, "{{CONTENT}}", pVal)
SetHtml = retval
End Function
'----------------------------------------------------------
'data배열에 pData위치에 pVal값을 입력
Public Function SetDataDay(pDate, pVal)
'response.write pDate & "--<br />"
Dim retval, strHtml,day_order,cur_row,cur_col
retval = True
day_order = m_start_num + Day(pDate)
cur_row = (day_order-1)\ 7
cur_col = Weekday(pDate)-1
m_arData(cur_col, cur_row) = m_arData(cur_col, cur_row) & "<br />" & pVal
SetDataDay = retval
End Function
'----------------------------------------------------------
'html배열의 값을 보여줌.
dim i,j
Public Function DrawCalendar()
InitArray()
response.write m_cal_header & vbCrLf
For i = 0 To UBound(m_arCal, 2)
response.write m_week_header & vbCrLf
For j = 0 To 6
response.write m_arCal(j, i) & vbCrLf
Next
response.write m_week_bottom & vbCrLf
Next
response.write m_cal_bottom & vbCrLf
End Function
End Class
'//////////////////////////////////////////////////////////////////////////////
%>
<%
'//////////////////////////////////////////////////////////////////////////////
'//
'// Sample
'//
'//////////////////////////////////////////////////////////////////////////////
'----------------------------------------------------------
Sub DrawDefault
Set cal = new UCCalendar
response.write cal.cur_date & "<br />"
cal.SetDataDay cal.cur_date, "내용"
cal.SetDataDay DateAdd("d", 5, cal.cur_date), "<br />내용"
cal.DrawCalendar
End Sub
'----------------------------------------------------------
Sub DrawType1
Set cal = new UCCalendar
with cal
.cur_date = "1945-8-15"
.cal_header = "<table border=""0"" cellpadding=""3"" cellspacing=""1"" bgcolor=""#999999""><tr align=""center"" bgcolor=""#FFFCCE""><td>일</td><td>월</td><td>화</td><td>수</td><td>목</td><td>금</td><td>토</td></tr>"
.cal_bottom = "</table>"
.week_header = "<tr>"
.week_bottom = "</tr>"
'//일이 들어갈 곳에 "{{DAY}}"를 삽입
'//내용이 들어갈 곳에 "{{CONTENT}}"를 삽입
.normal_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFFFFF""><font color=""#333333"" size=""2"">{{DAY}} {{CONTENT}}</font></td>"
.saturday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#E7F1FE""><font color=""blue"" size=""2"">{{DAY}}</font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.sunday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FEE9E7""><font color=""red"" size=""2"">{{DAY}}</font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.curday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#D5E6AE""><font color=""#336600"" size=""3""><b>{{DAY}}</b></font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.blank_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#EEEEEE""><font color=""#333333"" size=""2"">{{DAY}} {{CONTENT}}</font></td>"
.SetDataDay DateAdd("d", 0, .cur_date), "<br />내용"
.SetDataDay DateAdd("d", -1, .cur_date), "<br />내용"
.SetDataDay DateAdd("d", 5, .cur_date), "<br />내용"
response.write .cur_date & "<br />"
.DrawCalendar
End with
End Sub
'----------------------------------------------------------
Sub DrawType2
Set cal = new UCCalendar
with cal
.cur_date = "1945-4-14"
str_cal_header = "<table align="center" border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#E4E4E4">"
str_cal_header = str_cal_header & "<tr align=""center"" bgcolor=""#FFFCCE"">"
str_cal_header = str_cal_header & "<td width="14%" height="30" bgcolor="#F1F1F1" align="center"><b><font size="2" color="red">일</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2">월</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2">화</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2">수</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2">목</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2">금</font></b></td>"
str_cal_header = str_cal_header & "<td width="14%" bgcolor="#F1F1F1" align="center"><b><font size="2" color="blue">토</font></b></td></tr>"
.cal_header = str_cal_header
.cal_bottom = "</table>"
.week_header = "<tr>"
.week_bottom = "</tr>"
'//일이 들어갈 곳에 "{{DAY}}"를 삽입
'//내용이 들어갈 곳에 "{{CONTENT}}"를 삽입
.normal_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFFFFF""><font color=""#000000"" size=""2"">{{DAY}} {{CONTENT}}</font></td>"
.saturday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#F3F6FF""><font color=""blue"" size=""2"">{{DAY}}</font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.sunday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFF6F8""><font color=""red"" size=""2"">{{DAY}}</font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.curday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFFFFF"" style='border-width:1px; border-color:rgb(255,153,51); border-style:solid;'><font color=""#336600"" size=""3""><b>{{DAY}}</b></font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.blank_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFFFFF""></td>"
.holiday_html = "<td width=""80"" height=""80"" valign=""top"" bgcolor=""#FFF6F8""><font color=""red"" size=""2"">{{DAY}}</font> <font color=""#333333"" size=""2"">{{CONTENT}}</font></td>"
.SetDataDay DateAdd("d", 0, .cur_date), "<br />내용"
.SetDataDay "1945-08-5", "<br />내용"
.SetDataDay DateAdd("d", 5, .cur_date), "내용"
.SetDataDay DateAdd("d", 5, .cur_date), "내용2"
.IsViewHoliday = True
response.write .cur_date & "<br />"
.DrawCalendar
End with
End Sub
'----------------------------------------------------------
'Call DrawDefault
'Call DrawType1
'Call DrawType2
'//////////////////////////////////////////////////////////////////////////////
%>