|
|
|
Web (ASP.NET) ดึงข้อมูลจาก Database มาโชว์ในปฏิทิน Calendar ครับ จะทำได้อย่างไร???? |
|
|
|
|
|
|
|
ดึงข้อมูลจาก db มาโชว์ในปฏิทินครับ จะทำได้อย่างไร????
Code (C#)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CalendarM.aspx.cs" Inherits="WebApp.CalendarM" %>
<%@ Register assembly="EventCalendar" namespace="ExtendedControls" tagprefix="ECalendar" %>
<!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>
<style type="text/css">
.style1
{
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="font-weight: 700; font-size: large">
Calendar<br />
<br />
<br />
</div>
<div class="style1">
<asp:GridView ID="gvSelectedDateEvents" runat="server" Width="60%">
</asp:GridView>
</div>
<div class="style1">
<ECalendar:EventCalendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Silver"
BorderWidth="1px" Font-Names="Verdana"
Font-Size="9pt" ForeColor="Blue" Height="500px"
Width="60%" FirstDayOfWeek="Monday" NextMonthText="" PrevMonthText=""
ShowGridLines="True" NextPrevFormat="ShortMonth"
ShowDescriptionAsToolTip="True" BorderStyle="Solid" EventDateColumnName=""
EventDescriptionColumnName="" EventHeaderColumnName=""
OnSelectionChanged="Calendar1_SelectionChanged">
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" />
<SelectorStyle BorderColor="#404040" BorderStyle="Solid" />
<DayStyle HorizontalAlign="Left" VerticalAlign="Top" Wrap="True" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Size="8pt" ForeColor="#333333" Font-Bold="True" VerticalAlign="Bottom" />
<DayHeaderStyle BorderWidth="1px" Font-Bold="True" Font-Size="8pt" />
<TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True"
Font-Size="12pt" ForeColor="#333399" HorizontalAlign="Center" VerticalAlign="Middle" />
</ECalendar:EventCalendar>
</div>
</form>
</body>
</html>
Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
namespace WebApp
{
public partial class CalendarM : System.Web.UI.Page
{
private DataTable GetEvents()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", Type.GetType("System.Int32"));
dt.Columns.Add("EventStartDate", Type.GetType("System.DateTime"));
dt.Columns.Add("EventEndDate", Type.GetType("System.DateTime"));
dt.Columns.Add("EventHeader", Type.GetType("System.String"));
dt.Columns.Add("EventDescription", Type.GetType("System.String"));
dt.Columns.Add("EventForeColor", Type.GetType("System.String"));
dt.Columns.Add("EventBackColor", Type.GetType("System.String"));
int idCount = 1;
DataRow dr;
// Yesterday's Events
dr = dt.NewRow();
dr["Id"] = idCount++;
dr["EventStartDate"] = DateTime.Now.AddDays(-1);
dr["EventEndDate"] = DateTime.Now.AddDays(-1);
dr["EventHeader"] = "My Yesterday's Single Day Event";
dr["EventDescription"] = "My Yesterday's Single Day Event Details";
dr["EventForeColor"] = "White";
dr["EventBackColor"] = "Navy";
dt.Rows.Add(dr);
// Three Day's Event Starting Tomorrow
dr = dt.NewRow();
dr["Id"] = idCount++;
dr["EventStartDate"] = DateTime.Now.AddDays(1);
dr["EventEndDate"] = DateTime.Now.AddDays(+1);
dr["EventHeader"] = "My Three Days Event";
dr["EventDescription"] = "My Three Days Event Details, which starts tomorrow";
dr["EventForeColor"] = "White";
dr["EventBackColor"] = "Green";
dt.Rows.Add(dr);
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
Calendar1.EventStartDateColumnName = "EventStartDate";
Calendar1.EventEndDateColumnName = "EventEndDate";
Calendar1.EventDescriptionColumnName = "EventDescription";
Calendar1.EventHeaderColumnName = "EventHeader";
Calendar1.EventBackColorName = "EventBackColor";
Calendar1.EventForeColorName = "EventForeColor";
Calendar1.EventSource = GetEvents();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
SelectedDatesCollection theDates = Calendar1.SelectedDates;
DataTable dtSelectedDateEvents = Calendar1.EventSource.Clone();
DataRow dr;
foreach (DataRow drEvent in Calendar1.EventSource.Rows)
foreach (DateTime selectedDate in theDates)
if (selectedDate.Date >= (Convert.ToDateTime(drEvent[Calendar1.EventStartDateColumnName])).Date
&& selectedDate.Date <= (Convert.ToDateTime(drEvent[Calendar1.EventEndDateColumnName])).Date)
{
// This Condition is just to ensure that Every Event Details are added just only once
// irrespective of the number of days for which the event occurs.
if (dtSelectedDateEvents.Select("Id= " + Convert.ToInt32(drEvent["Id"])).Length > 0)
continue;
dr = dtSelectedDateEvents.NewRow();
dr["Id"] = drEvent["Id"];
dr[Calendar1.EventStartDateColumnName] = drEvent[Calendar1.EventStartDateColumnName];
dr[Calendar1.EventEndDateColumnName] = drEvent[Calendar1.EventEndDateColumnName];
dr[Calendar1.EventHeaderColumnName] = drEvent[Calendar1.EventHeaderColumnName];
dr[Calendar1.EventDescriptionColumnName] = drEvent[Calendar1.EventDescriptionColumnName];
dr[Calendar1.EventForeColorName] = drEvent[Calendar1.EventForeColorName];
dr[Calendar1.EventBackColorName] = drEvent[Calendar1.EventBackColorName];
dtSelectedDateEvents.Rows.Add(dr);
}
gvSelectedDateEvents.DataSource = dtSelectedDateEvents;
gvSelectedDateEvents.DataBind();
}
}
}
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
ประวัติการแก้ไข 2013-01-01 20:26:25
|
|
|
|
|
Date :
2013-01-01 09:03:54 |
By :
Kaen17 |
View :
2223 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยหน่อยครับ
|
|
|
|
|
Date :
2013-01-01 23:29:01 |
By :
Kaen17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีใครพอได้มั้งครับ ??
|
|
|
|
|
Date :
2013-01-02 07:50:14 |
By :
Kaen17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำที่ DayRender ครับ มันจะ Loop ในแต่ล่ะวัน จากนั้นก็ให้เราไปตรวจสอบใน Database ครับ ตัวอย่างที่เคยเขียนไว้
Code (C#)
private void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
MyDates Item = default(MyDates);
////Temporary storage for looping through the collection
string TextColor = null;
DateTime DayHold = "01/01/1900";
////Temporary date to check for multiple items per day
bool MultipleItemDay = false;
bool DayTextHasChanged = false;
StringBuilder temp = default(StringBuilder);
if ((MyCollection == null) == true) {
Get_DBItems();
}
foreach ( Item in MyCollection) {
if (DayHold != Item._Date) {
if (DayTextHasChanged == true) {
break; // TODO: might not be correct. Was : Exit For
}
DayHold = Item._Date;
}
e.Cell.ToolTip = clsDateTimeFormat.ConvertDateThaiShort(e.Day.Date);
if (e.Day.Date == Item._Date.ToString) {
e.Cell.Font.Bold = true;
if (e.Day.Date == System.DateTime.Today) {
e.Cell.BackColor = Color.FromName("Plum");
}
e.Cell.ForeColor = Color.OrangeRed;
//If MultipleItemDay = False Then
// temp = New StringBuilder
//Else
// ' temp.Append("<br>")
//End If
//temp.Append("<br><a href=" & Request.ServerVariables("SCRIPT_NAME") & "?p=editday&Action=edit&IDRef=" & Item._ID & ">")
//temp.Append("<img src=""Module/Calendars/Images/writeok.gif"" border=""0""> ")
//temp.Append("</a>")
//DayTextHasChanged = True
}
}
//If DayTextHasChanged = True Then
// e.Cell.Controls.Add(New LiteralControl(temp.ToString()))
//End If
}
|
|
|
|
|
Date :
2013-01-02 08:51:39 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จะเอาไปเเทรกตรงไหนครับ ?
|
|
|
|
|
Date :
2013-01-03 09:05:52 |
By :
Kaen17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันเป็น Event ครับ
|
|
|
|
|
Date :
2013-01-03 09:08:03 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|