閲覧総計:&counter(); (本日:&counter(today); 昨日:&counter(yesterday);) カレンダ コントロールの祝日・会社休日をピンクで表示する方法を確認した。 DBに祝日・会社休日情報を用意し、カレンダ表示に反映させる。 土日は、カレンダ コントロールのプロパティ設定:WeekendDayStyleのBackColorを LightPinkに設定する事で対応する。 10/08/10 【稼働画面】 #ref(祝日会社休日カレンダ表示.jpg); #ref(Access祝日会社休日データ.jpg); ※会社休日夏休み:8/9(月)〜8/13(金) ※9/23秋分の日は会社出勤日 開発環境:VWD2008 + Access2003 + SQL Server2008 サーバ:ASP.NET3.5 + Access2003 【HolidayRender_ads.aspx】 <%@ Page Language="VB" %> <%@ Import Namespace = "System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub cal_dayrender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) ads.SelectParameters.Clear() ads.SelectParameters.Add("CalDate", e.Day.Date.ToString("yyyy/MM/dd")) Dim reader As IDataReader = ads.Select(DataSourceSelectArguments.Empty) ' 日付セル(e.Call)毎に繰り返し Do While reader.Read() '祝日・会社休日をLightPinkに e.Cell.BackColor = Drawing.Color.LightPink Loop End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> カレンダの祝日・会社休日ピンク表示 10/08/10<br /> <br /> <asp:AccessDataSource ID="ads" runat="server" DataFile="~/App_Data/AccessDB.mdb" DataSourceMode="DataReader" SelectCommand="SELECT [ID], [Holiday] FROM [CompanyHolidays] WHERE [Holiday] = @CalDate"> </asp:AccessDataSource> <asp:Calendar id="cal" runat="server" DayHeaderStyle-BackColor="#FFCC66" onDayRender="cal_DayRender" ShowGridLines="true" BorderWidth="3" BorderColor="Black" Font-Name="Verdana" Font-Size="10px" TitleStyle-BackColor="#FFCC66" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="50px" DayStyle-Width="14%" SelectedDayStyle-BackColor="Navy" ShowNextPrev="True" NextPrevFormat="FullMonth" Width="504px"> <SelectedDayStyle BackColor="#CC5533" /> <WeekendDayStyle BackColor="LightPink" /> <DayStyle VerticalAlign="Top" Height="50px" Width="14%"></DayStyle> <DayHeaderStyle BackColor="#FFCC66"></DayHeaderStyle> <TitleStyle BackColor="#FFCC66" Font-Bold="True" Font-Size="12px"></TitleStyle> </asp:Calendar> <br /> </div> </form> </body> </html> 【参考にしたページ】 なし - 1 -- [[1]] &new{2012-03-13 (火) 08:28:23}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:25}; - 1 -- [[-1']] &new{2012-03-13 (火) 08:28:26}; -- 1' -- [[1]] &new{2012-03-13 (火) 08:28:27}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:29}; - 1 -- [[1]] &new{2012-03-18 (日) 03:02:45}; - 1 -- [[1]] &new{2012-03-18 (日) 03:02:48}; - 1 -- [[-1']] &new{2012-03-18 (日) 03:02:49}; -- 1' -- [[1]] &new{2012-03-18 (日) 03:02:50}; - 1 -- [[1]] &new{2012-03-18 (日) 03:02:51}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:17}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:20}; - 1 -- [[-1']] &new{2012-03-18 (日) 14:30:21}; -- 1' -- [[1]] &new{2012-03-18 (日) 14:30:22}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:23}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:30}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:33}; - 1 -- [[-1']] &new{2012-03-18 (日) 14:53:34}; -- 1' -- [[1]] &new{2012-03-18 (日) 14:53:35}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:36}; - 1 -- [[1]] &new{2012-03-19 (月) 09:22:50}; - 1 -- [[1]] &new{2012-03-19 (月) 09:22:53}; - 1 -- [[-1']] &new{2012-03-19 (月) 09:22:54}; -- 1' -- [[1]] &new{2012-03-19 (月) 09:22:55}; - 1 -- [[1]] &new{2012-03-19 (月) 09:22:56}; - 1 -- [[1]] &new{2012-03-19 (月) 09:30:59}; - 1 -- [[1]] &new{2012-03-19 (月) 09:31:02}; - 1 -- [[-1']] &new{2012-03-19 (月) 09:31:03}; -- 1' -- [[1]] &new{2012-03-19 (月) 09:31:04}; - 1 -- [[1]] &new{2012-03-19 (月) 09:31:06}; #comment_nospam - 1 -- [[1]] &new{2012-03-19 (月) 09:31:00}; - 1 -- [[1]] &new{2012-03-19 (月) 09:22:52}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:32}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:19}; - 1 -- [[1]] &new{2012-03-18 (日) 03:02:47}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:24}; #vote(参考になった[0],ふつう[0],参考にならなかった[0]) ~ ~ ~ ●AccessDataSourceコントロールを用いずDBに直接アクセスしたコード 【HolidayRender_direct.aspx】 <%@ Page Language="VB" %> <%@ Import Namespace="System.Data.Common" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> 'MS-AccessDBのConnectionString Dim MyDbConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AccessDB.mdb;Persist Security Info=True" 'MS-AccessDBのProviderName Dim MyDbProviderName As String = "System.Data.OleDb" ' カレンダのそれぞれの日付セルをレンダリングするタイミングで実行 Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Dim setting As ConnectionStringSettings = _ ConfigurationManager.ConnectionStrings(MyDbConnectionString) Dim factory As DbProviderFactory = _ DbProviderFactories.GetFactory(MyDbProviderName) Using db As DbConnection = factory.CreateConnection() db.ConnectionString = MyDbConnectionString ' 出力する日付セルに対応するスケジュール情報を抽出 Dim comm As DbCommand = factory.CreateCommand() comm.CommandText = "SELECT [ID],[Holiday] FROM [CompanyHolidays] WHERE [Holiday]=@CalDate" comm.Connection = db Dim param As DbParameter = factory.CreateParameter() param.ParameterName = "@CalDate" param.Value = e.Day.Date.ToString("yyyy/MM/dd") comm.Parameters.Add(param) db.Open() Dim reader As DbDataReader = comm.ExecuteReader() ' 日付セル(e.Call)毎に繰り返し Do While reader.Read() '祝日・会社休日をLightPinkに e.Cell.BackColor = Drawing.Color.LightPink Loop End Using End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> カレンダの祝日・会社休日をピンク表示(DB直接アクセス法) 10/08/10<br /> <br /> <asp:Calendar id="cal" runat="server" DayHeaderStyle-BackColor="#FFCC66" onDayRender="cal_DayRender" ShowGridLines="true" BorderWidth="3" BorderColor="Black" Font-Name="Verdana" Font-Size="10px" TitleStyle-BackColor="#FFCC66" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="50px" DayStyle-Width="14%" SelectedDayStyle-BackColor="Navy" ShowNextPrev="True" NextPrevFormat="FullMonth" Width="504px"> <SelectedDayStyle BackColor="#CC5533" /> <WeekendDayStyle BackColor="LightPink" /> <DayStyle VerticalAlign="Top" Height="50px" Width="14%"></DayStyle> <DayHeaderStyle BackColor="#FFCC66"></DayHeaderStyle> <TitleStyle BackColor="#FFCC66" Font-Bold="True" Font-Size="12px"></TitleStyle> </asp:Calendar> <br /> </div> </form> </body> </html> 【参考にしたページ】 なし - 1 -- [[1]] &new{2012-03-13 (火) 08:28:47}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:49}; - 1 -- [[-1']] &new{2012-03-13 (火) 08:28:50}; -- 1' -- [[1]] &new{2012-03-13 (火) 08:28:51}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:52}; - 1 -- [[1]] &new{2012-03-18 (日) 03:03:09}; - 1 -- [[1]] &new{2012-03-18 (日) 03:03:11}; - 1 -- [[-1']] &new{2012-03-18 (日) 03:03:12}; -- 1' -- [[1]] &new{2012-03-18 (日) 03:03:13}; - 1 -- [[1]] &new{2012-03-18 (日) 03:03:14}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:41}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:43}; - 1 -- [[-1']] &new{2012-03-18 (日) 14:30:44}; -- 1' -- [[1]] &new{2012-03-18 (日) 14:30:45}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:46}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:55}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:57}; - 1 -- [[-1']] &new{2012-03-18 (日) 14:53:58}; -- 1' -- [[1]] &new{2012-03-18 (日) 14:54:00}; - 1 -- [[1]] &new{2012-03-18 (日) 14:54:01}; - 1 -- [[1]] &new{2012-03-19 (月) 09:23:13}; - 1 -- [[1]] &new{2012-03-19 (月) 09:23:15}; - 1 -- [[-1']] &new{2012-03-19 (月) 09:23:17}; -- 1' -- [[1]] &new{2012-03-19 (月) 09:23:18}; - 1 -- [[1]] &new{2012-03-19 (月) 09:23:19}; - 1 -- [[1]] &new{2012-03-19 (月) 09:31:24}; - 1 -- [[1]] &new{2012-03-19 (月) 09:31:27}; - 1 -- [[-1']] &new{2012-03-19 (月) 09:31:28}; -- 1' -- [[1]] &new{2012-03-19 (月) 09:31:29}; - 1 -- [[1]] &new{2012-03-19 (月) 09:31:31}; #comment_nospam - 1 -- [[1]] &new{2012-03-19 (月) 09:31:25}; - 1 -- [[1]] &new{2012-03-19 (月) 09:23:14}; - 1 -- [[1]] &new{2012-03-18 (日) 14:53:56}; - 1 -- [[1]] &new{2012-03-18 (日) 14:30:42}; - 1 -- [[1]] &new{2012-03-18 (日) 03:03:10}; - 1 -- [[1]] &new{2012-03-13 (火) 08:28:48}; #vote(参考になった[0],ふつう[0],参考にならなかった[0])