'--==[頁面]======================================================================--
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test_Calendar.aspx.vb" Inherits="Test_Calendar" %>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<asp:TextBox ID="txt_CalViewYear" runat="server" Width="70px" MaxLength="4"></asp:TextBox><BR>
<asp:Label ID="lab_CalList" runat="server" Text=""></asp:Label><BR>
<asp:Label ID="labPageError" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Calendar ID="cal_Month_01" runat="server" BackColor="White" BorderColor="#3366CC" ShowNextPrevMonth="false"
BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px" >
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="White" BackColor="White" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
<td>
<asp:Calendar ID="cal_Month_02" runat="server" BackColor="White" BorderColor="#3366CC" ShowNextPrevMonth="false"
BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px" >
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="White" BackColor="White" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
<td>
<asp:Calendar ID="cal_Month_03" runat="server" BackColor="White" BorderColor="#3366CC" ShowNextPrevMonth="false"
BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px" >
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="White" BackColor="White" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
'--==[程式]======================================================================--
Partial Class Test_Calendar
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lab_CalList.Text = ""
If Not IsPostBack Then
txt_CalViewYear.Text = Format(Now, "yyyy")
s_CalViewShow()
End If
End Sub
#Region "行事曆設定一覽表"
'--===================================================
'01月份_DayRender
Protected Sub cal_Month_01_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles cal_Month_01.DayRender
Call s_CalDayShow(cal_Month_01, "1", e)
End Sub
'01月份_PreRender
Protected Sub cal_Month_01_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_01.PreRender
Call s_CalViewAdd(cal_Month_01, "1")
End Sub
'01月份_SelectionChanged
Protected Sub cal_Month_01_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_01.SelectionChanged
Call s_CalSessListAdd(cal_Month_01, "1")
End Sub
'--===================================================
'02月份_DayRender
Protected Sub cal_Month_02_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles cal_Month_02.DayRender
Call s_CalDayShow(cal_Month_02, "2", e)
End Sub
'02月份_PreRender
Protected Sub cal_Month_02_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_02.PreRender
Call s_CalViewAdd(cal_Month_02, "2")
End Sub
'02月份_SelectionChanged
Protected Sub cal_Month_02_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_02.SelectionChanged
Call s_CalSessListAdd(cal_Month_02, "2")
End Sub
'--===================================================
'03月份_DayRender
Protected Sub cal_Month_03_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles cal_Month_03.DayRender
Call s_CalDayShow(cal_Month_03, "3", e)
End Sub
'03月份_PreRender
Protected Sub cal_Month_03_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_03.PreRender
Call s_CalViewAdd(cal_Month_03, "3")
End Sub
'03月份_SelectionChanged
Protected Sub cal_Month_03_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cal_Month_03.SelectionChanged
Call s_CalSessListAdd(cal_Month_03, "3")
End Sub
#End Region
#Region "行事曆設定一覽表_函式集"
'函式_行事曆設定一覽表_顯示設定
Protected Sub s_CalViewShow()
Try
'設定顯示年份
Dim sL_CalYear As String = txt_CalViewYear.Text
txt_CalViewYear.Text = sL_CalYear
cal_Month_01.VisibleDate = sL_CalYear & "/1/1"
cal_Month_02.VisibleDate = sL_CalYear & "/2/1"
cal_Month_03.VisibleDate = sL_CalYear & "/3/1"
If Replace(Session("SelectDates"), "0001/01/01,", "") <> "" Then
lab_CalList.Text += "您已點選了:" & Replace(Session("SelectDates"), "0001/01/01,", "")
End If
Catch ex As Exception
labPageError.Text = ex.Message
End Try
End Sub
'函式_行事曆設定一覽表_日期顯示處理 For DayRender事件
Protected Sub s_CalDayShow(ByVal cal As Calendar, ByVal sP_calMonth As String, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
Try
If Format(e.Day.Date, "MM") = Right("00" & sP_calMonth, 2) Then
If InStr(Session("CalDel"), Format(e.Day.Date, "yyyyMMdd") & ",") > 0 Then
e.Cell.BackColor = Drawing.Color.YellowGreen
ElseIf InStr(Session("CalAdd"), Format(e.Day.Date, "yyyyMMdd") & ",") > 0 Then
e.Cell.BackColor = Drawing.Color.Yellow
End If
Else
If Format(Now, "yyyyMMdd") = Format(e.Day.Date, "yyyyMMdd") Then
e.Cell.BackColor = Drawing.Color.White
End If
End If
Catch ex As Exception
labPageError.Text = ex.Message
End Try
End Sub
'函式_行事曆設定一覽表_Session處理 For SelectionChanged事件
Protected Sub s_CalSessListAdd(ByVal cal As Calendar, ByVal sP_calMonth As String)
Try
Dim sL_SelectDate As String = String.Empty
Dim is_Cancel As Integer = 0
'因只剩一個日期時,重覆按時,元件會無法觸發SelectionChanged事件,所以先加入"0001/01/01"假日期。
If InStr(Session("SelectDates"), "0001/01/01") = 0 Then
Session("SelectDates") += "0001/01/01,"
End If
For i = 0 To cal.SelectedDates.Count - 1
sL_SelectDate = cal.SelectedDates(i).ToShortDateString()
If Month(sL_SelectDate) = sP_calMonth Then
If InStr(Session("SelectDates"), sL_SelectDate & ",") > 0 Then
is_Cancel = 1
Session("SelectDates") = Replace(Session("SelectDates"), sL_SelectDate & ",", "")
Else
Session("SelectDates") += sL_SelectDate & ","
End If
End If
Next
'當重覆按相同的日期,則取消,因為無法即時顯示,所以重新載入。
If is_Cancel = 1 Then
Response.Redirect("Test_Calendar.aspx?type=Calendar")
End If
If Replace(Session("SelectDates"), "0001/01/01,", "") <> "" Then
lab_CalList.Text += "您已點選了:" & Replace(Session("SelectDates"), "0001/01/01,", "")
End If
Catch ex As Exception
labPageError.Text = ex.Message
End Try
End Sub
'函式_行事曆設定一覽表_顯示處理 For PreRender事件
Protected Sub s_CalViewAdd(ByVal cal As Calendar, ByVal sP_calMonth As String)
Try
Dim sL_Datelist() As String = Split(Session("SelectDates"), ",")
For i = 0 To sL_Datelist.Length - 1
If IsDate(sL_Datelist(i)) AndAlso (Month(sL_Datelist(i)) = sP_calMonth Or sL_Datelist(i) = "0001/01/01") Then
cal.SelectedDates.Add(sL_Datelist(i))
End If
Next
Catch ex As Exception
labPageError.Text = ex.Message
End Try
End Sub
#End Region
End Class
留言列表