<%@ Page Language="VB" MasterPageFile="~/day02/MyMaster.master" Title="簡易スケジュール帳" %>
<%@ Import Namespace="System.Data.Common" %>
<script runat="server">

    Protected Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
        Dim setting As ConnectionStringSettings = _
    ConfigurationManager.ConnectionStrings("MyDB")
        Dim factory As DbProviderFactory = _
        DbProviderFactories.GetFactory(setting.ProviderName)
        Using db As DbConnection = factory.CreateConnection()
            db.ConnectionString = setting.ConnectionString
            Dim comm As DbCommand = factory.CreateCommand()
            comm.CommandText = _
              "SELECT sid,subject,stime FROM Schedule WHERE sdate=@sdate"
            comm.Connection = db
            Dim param As DbParameter = factory.CreateParameter()
            param.ParameterName = "@sdate"
            param.Value = e.Day.Date.ToString("yyyy/MM/dd")
            comm.Parameters.Add(param)
            db.Open()
            Dim reader As DbDataReader = comm.ExecuteReader()
            Do While reader.Read()
                Dim ltrCr As New LiteralControl("<br />")
                Dim link As New HyperLink()
                link.NavigateUrl = "Details.aspx?sid=" & reader.GetInt32(0)
                link.Text = reader.GetString(2) & "&nbsp;" & reader.GetString(1)
                e.Cell.Controls.Add(ltrCr)
                e.Cell.Controls.Add(link)
            Loop
        End Using
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cph" Runat="Server">
    <asp:Calendar ID="cal" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66"
        BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
        ForeColor="#663399" Height="375px" ShowGridLines="True" Width="500px" OnDayRender="cal_DayRender">
        <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
        <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
        <SelectorStyle BackColor="#FFCC66" />
        <OtherMonthDayStyle ForeColor="#CC9966" />
        <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
        <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
        <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
    </asp:Calendar>
</asp:Content>

