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

    protected void cal_DayRender(Object sender, DayRenderEventArgs e) {
        ConnectionStringSettings  setting = ConfigurationManager.ConnectionStrings["MyDB"];
        DbProviderFactory factory = DbProviderFactories.GetFactory(setting.ProviderName);
        using(DbConnection db = factory.CreateConnection()) {
            db.ConnectionString = setting.ConnectionString;
            DbCommand comm = factory.CreateCommand();
            comm.CommandText = 
              "SELECT sid,subject,stime FROM Schedule WHERE sdate=@sdate";
            comm.Connection = db;
            DbParameter param = factory.CreateParameter();
            param.ParameterName = "@sdate";
            param.Value = e.Day.Date.ToString("yyyy/MM/dd");
            comm.Parameters.Add(param);
            db.Open();
            DbDataReader reader = comm.ExecuteReader();
            while(reader.Read()) {
                LiteralControl ltrCr = new LiteralControl("<br />");
                HyperLink link = 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); 
            }
        }
    }
</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>

