พี่ๆ ในที่นี้มีใครมี โค๊ดสร้างปฏิทินกิจกรรม ที่แบบว่า ในวันนี้มีกิจกรรมอะไร โดยสามารถคลิกเข้าไปดูรายละเอียดในวันที่ได้ครับ พอดีว่าทำเว็บลงทะเบียนกิจกรรม โปรเจ็คจบ เลยว่าจะทำปฏิทินกิจกรรม ไว้แสดงว่า เดือนนี้ วันที่เท่าไรมีกิจกรรมอะไร และในกิจกรรมนั้นมีรายล
ให้โค้ดไปงงเล่น
RollOverImageButton.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyCustomControls
{
/// <summary>
/// A control that display an image and response to mouse click on the image.
/// </summary>
[ToolboxData("<{0}:RollOverImageButton runat=\"server\" />")]
public class RollOverImageButton : ImageButton
{
/// <summary>
/// Gets or sets the location of an image it display in the RollOverImage control.
/// </summary>
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("Gets or sets the location of an image to display in the System.Web.UI.WebControls.Image control.")]
[Editor(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Localizable(true)]
[UrlProperty()]
public virtual string RollOverImageUrl
{
get
{
string s = (string)ViewState["RollOverImageUrl"];
return (s == null) ? string.Empty : s;
}
set { ViewState["RollOverImageUrl"] = value; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute("onmouseover", "this.src='" + base.ResolveClientUrl(RollOverImageUrl) + "'");
writer.AddAttribute("onmouseout", "this.src='" + base.ResolveClientUrl(ImageUrl) + "'");
}
}
}
Calendar.css
/* event calendar
----------------------------------------------------------*/
#calendar
{
width: 100%;
overflow: auto;
}
#calendar_left
{
float: left;
border: 1px solid #ee9900;
width: 539px;
}
.calendar_right
{
float: right;
width: 179px;
background-color: #ffffcc;
/*background-image: url(/images/notebackground.png);*/
background-repeat: repeat-y;
padding: 0px 15px 10px 10px;
border: 1px solid #ffff33;
overflow: auto;
}
.calendar_event
{
position: absolute;
background-color: #ee9900;
z-Index: 1001;
}
.shadow
{
position: absolute;
top: 0px;
left: 0px;
opacity: 0.6;
filter: alpha(opacity=60);
background-color: #000000;
z-Index: 1000;
width: 100%;
}
table.CalendarBody
{
border: 1px solid #eeeeee;
}
td.CalendarMonth
{
background-color: #ee9900;
color: White;
border-bottom: 1px solid White;
height: 38px;
font-weight: bold;
font-size: 15px;
}
td.CalendarHead
{
background-color: #ee9900;
color: White;
border: 1px solid White;
font-weight: bold;
width: 74px;
height: 37px;
text-align: center;
}
.CalendarDate
{
width: 20px;
height: 20px;
position: relative;
top: 0px;
left: 0px;
text-align: center;
padding-top: 2px;
}
.CalendarToday
{
width: 30px;
height: 30px;
position: relative;
top: 0px;
left: -5px;
text-align: center;
padding-top: 2px;
background-image: url(/images/todaymark.png);
background-repeat: no-repeat;
background-position: center top;
/*border: 1px solid black;*/
}
td.CalendarCell
{
background-color: #dddddd;
border: 1px solid #eeeeee;
height: 74px;
vertical-align: top;
font-weight: bold;
}
td.CalendarCellNormal
{
color: Black;
background-color: White;
border: 1px solid #eeeeee;
height: 74px;
vertical-align: top;
font-weight: bold;
}
td.CalendarCellNormal:hover
{
color: Black;
background-color: #ffff77;
border: 1px solid #eeeeee;
cursor: pointer;
height: 74px;
vertical-align: top;
font-weight: bold;
}
td.CalendarCellHolliday
{
color: Red;
background-color: #fff6e7;
border: 1px solid #eeeeee;
height: 74px;
vertical-align: top;
font-weight: bold;
}
td.CalendarCellHolliday:hover
{
color: Red;
background-color: #ffff77;
border: 1px solid #eeeeee;
cursor: pointer;
height: 74px;
vertical-align: top;
font-weight: bold;
}
.daypanel
{
width: 90%;
height: 90%;
}
.activitylist
{
line-height: 20px;
padding: 5px 10px 10px 10px;
margin: 0px 0px 0px 10px;
}
.td_activity
{
height: 25px;
vertical-align: bottom;
background-image: url(/images/notebackground.png);
}
/* Activity Detail */
/*============================*/
.calendar_detail
{
width: 700px;
background-color: #ffffff;
overflow: auto;
padding: 5px;
}
.event_head
{
/* height: 9%; */
background-color: white;
border-top: 1px solid #ee9900;
border-left: 1px solid #ee9900;
border-right: 1px solid #ee9900;
padding: 1px;
}
.table_name
{
width: 100%;
padding-top: 1px;
padding-left: 1px;
padding-right: 1px;
border-collapse: collapse;
}
.table_detail
{
width: 100%;
border: 1px solid #ee9900;
border-collapse: collapse;
}
.row_head
{
border: 1px solid #ee9900;
background-color: white;
padding-top: 1px;
padding-left: 1px;
padding-right: 1px;
width: 10%;
}
.row_alt
{
background-color: #fff6e7;
}
.cell_name
{
padding: 10px;
background-color: #fecb70;
font-weight: bold;
font-size: 15px;
color: #666666;
vertical-align: middle;
text-align: center;
}
.panel_activity
{
width: 626px;
height: 442px;
/* background-color: lightgray; */
position: absolute;
top: 78px;
left: 79px;
overflow: auto;
}
.panel_detail
{
position: absolute;
width: 130px;
padding: 10px;
overflow: hidden;
border: none;
opacity: 0.6;
border-radius: 5px;
-moz-border-radius: 5px; /* Firefox 3.6 and earlier */
}
EventCalendar.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EventCalendar.ascx.cs" Inherits="UserControls_EventCalendar" %>
<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="false" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="~/images/loadingBar.gif" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<div id="calendar">
<div id="calendar_left">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Table ID="Table1" CssClass="CalendarBody" runat="server">
<asp:TableRow>
<asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
<customControl:RollOverImageButton ID="RollOverImageButton1" ImageUrl="~/images/arrow-left.png" RollOverImageUrl="~/images/arrow-left-over.png" ToolTip="Back" runat="server" />
</asp:TableCell>
<asp:TableCell CssClass="CalendarMonth" ColumnSpan="5" HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Label ID="LabelMonthName" runat="server" Text="Label"></asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
<customControl:RollOverImageButton ID="RollOverImageButton2" ImageUrl="~/images/arrow-right.png" RollOverImageUrl="~/images/arrow-right-over.png" ToolTip="Next" runat="server" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="PanelRight" CssClass="calendar_right" runat="server">
<asp:Table ID="TableActivity" style="width: 100%;" runat="server">
<asp:TableRow>
<asp:TableCell CssClass="td_activity">
<asp:Label ID="Label1" runat="server" Text="Label" style="font-weight: bold;"></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" OnLoad="UpdatePanel3_Load">
<ContentTemplate>
<asp:Button ID="ButtonHidden3" runat="server" Text="Button" style="display: none;" />
<ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender3"
TargetControlID="ButtonHidden3" PopupControlID="PanelActivity" CancelControlID="ImageButton1"
BackgroundCssClass="modalBackground" DropShadow="True"
RepositionMode="RepositionOnWindowScroll">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelActivity" CssClass="modalPopup" runat="server">
<asp:Panel ID="PanelClose" CssClass="close" runat="server">
<asp:ImageButton ID="ImageButton1" CssClass="close" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" />
</asp:Panel>
<asp:Panel ID="PanelEvent" CssClass="calendar_detail" runat="server">
<asp:Panel ID="PanelEventHead" CssClass="event_head" runat="server">
<asp:Table ID="Table2" CssClass="table_name" runat="server">
<asp:TableRow runat="server">
<asp:TableCell ID="CellTitle" CssClass="cell_name" runat="server">
<asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
<asp:Panel ID="PanelEventDetail" CssClass="event_detail" runat="server">
<asp:Table ID="TableDetail" CssClass="table_detail" BorderStyle="Solid" BorderWidth="1" runat="server">
</asp:Table>
</asp:Panel>
</asp:Panel>
</asp:Panel>
<ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="PanelActivity" Opacity=".8" Rounded="true" TrackPosition="true" />
<ajaxToolkit:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="PanelEvent" Radius="4" Corners="All" />
</ContentTemplate>
</asp:UpdatePanel>
EventCalendar.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
public partial class UserControls_EventCalendar : System.Web.UI.UserControl
{
private int rightHeight;
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["date"] == null)
{
ViewState["date"] = DateTime.Now;
Calendar((DateTime)ViewState["date"]);
EventDetail((DateTime)ViewState["date"]);
}
RollOverImageButton1.Click += new ImageClickEventHandler(RollOverImageButton1_Click);
RollOverImageButton2.Click += new ImageClickEventHandler(RollOverImageButton2_Click);
}
protected void RollOverImageButton1_Click(object sender, ImageClickEventArgs e)
{
DateTime currentDate = (DateTime)ViewState["date"];
ViewState["date"] = currentDate.AddMonths(-1);
Calendar((DateTime)ViewState["date"]);
EventDetail((DateTime)ViewState["date"]);
}
protected void RollOverImageButton2_Click(object sender, ImageClickEventArgs e)
{
DateTime currentDate = (DateTime)ViewState["date"];
ViewState["date"] = currentDate.AddMonths(1);
Calendar((DateTime)ViewState["date"]);
EventDetail((DateTime)ViewState["date"]);
}
protected void EventDetail(DateTime date)
{
PanelRight.Height = Unit.Parse(string.Format("{0}px", (rightHeight * 74).ToString()));
Label1.Text = string.Format("เดือน{0} {1}", date.ToString("MMMM", new System.Globalization.CultureInfo("th-TH")), date.ToString("yyyy", new System.Globalization.CultureInfo("th-TH")));
foreach (DataRow Dr in GetMonthActivity(date).Rows)
{
TableRow row2 = new TableRow();
TableActivity.Rows.Add(row2);
TableCell cell2 = new TableCell();
cell2.CssClass = "td_activity";
row2.Cells.Add(cell2);
string color;
switch ((int)Dr["TypeID"])
{
default:
color = "red";
break;
case 2:
color = "orange";
break;
case 3:
color = "green";
break;
case 4:
color = "#0066cc";
break;
case 5:
color = "#f06eaa";
break;
}
Table table1 = new Table();
cell2.Controls.Add(table1);
TableRow row11 = new TableRow();
table1.Rows.Add(row11);
TableCell cell11 = new TableCell();
row11.Cells.Add(cell11);
Panel panelType = new Panel();
panelType.Width = Unit.Parse("10px");
panelType.Height = Unit.Parse("10px");
panelType.Style.Add(HtmlTextWriterStyle.BackgroundColor, color);
cell11.Controls.Add(panelType);
TableCell cell12 = new TableCell();
if (Dr["ActivityName"].ToString().Length > 20)
{
cell12.Text = string.Format("{0}...", Dr["ActivityName"].ToString().Substring(0, 20));
cell12.ToolTip = Dr["ActivityName"].ToString();
}
else
{
cell12.Text = Dr["ActivityName"].ToString();
}
row11.Cells.Add(cell12);
TableRow row1 = new TableRow();
TableActivity.Rows.Add(row1);
TableCell cell1 = new TableCell();
cell1.CssClass = "td_activity";
cell1.Style.Add(HtmlTextWriterStyle.TextAlign, "right");
if (Convert.ToDateTime(Dr["StartDate"]).Date.CompareTo(Convert.ToDateTime(Dr["EndDate"]).Date) == 0)
{
if (Convert.ToDateTime(Dr["StartDate"]).ToString("HH:mm") == "08:30" && Convert.ToDateTime(Dr["EndDate"]).ToString("HH:mm") == "16:30")
{
cell1.Text = Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH"));
}
else
cell1.Text = string.Format("{0} [{1}-{2}]", Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["StartDate"]).ToString("HH:mm", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["EndDate"]).ToString("HH:mm", new System.Globalization.CultureInfo("th-TH")));
}
else
{
cell1.Text = string.Format("{0} - {1}", Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["EndDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")));
}
row1.Cells.Add(cell1);
}
}
protected void Calendar(DateTime date)
{
LabelMonthName.Text = date.ToString("เดือนMMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH"));
int daysInMonth = DateTime.DaysInMonth(date.Year, date.Month);
int fristDayOfWeek = (int)DateTime.ParseExact(string.Format("1/{0}/{1}", date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
int lastDayOfWeek = (int)DateTime.ParseExact(string.Format("{0}/{1}/{2}", daysInMonth.ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
int loopDays = daysInMonth + fristDayOfWeek + (7 - lastDayOfWeek);
rightHeight = (loopDays / 7) + 1;
foreach (TableRow Tbr in Table1.Rows)
{
if (Table1.Rows.GetRowIndex(Tbr) != 0)
Table1.Rows.Remove(Tbr);
}
TableRow Trh = new TableRow();
Table1.Rows.Add(Trh);
foreach (string str in new string[] {"อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัสบดี", "ศุกร์", "เสาร์"})
{
TableCell Tch = new TableCell();
Trh.Cells.Add(Tch);
Tch.CssClass = "CalendarHead";
Tch.Text = str;
}
for (int i = 0; i < loopDays / 7; i++)
{
TableRow Tr = new TableRow();
Table1.Rows.Add(Tr);
for (int j = 0; j < 7; j++)
{
int printDay = j + (7 * i) - (fristDayOfWeek - 1);
TableCell Tc = new TableCell();
Tr.Cells.Add(Tc);
if (printDay < 1 || printDay > daysInMonth)
{
Tc.CssClass = "CalendarCell";
}
else
{
DateTime aDate = DateTime.ParseExact(string.Format("{0}/{1}/{2}", (j + (7 * i) - (fristDayOfWeek - 1)).ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture);
StringBuilder Sb = new StringBuilder();
Sb.AppendLine("<table style=\"width: 100%; height:100%; border-collapse: collapse;\">");
Sb.Append("<tr style=\"height: 20%;\">");
Sb.AppendLine("<td>");
Sb.AppendLine("<div>");
Sb.AppendFormat("<div class={0} style=\"float: left;\">{1}</div>", (DateTime.Now.ToShortDateString() == aDate.ToShortDateString()) ? "CalendarToday" : "CalendarDate", (j + (7 * i) - (fristDayOfWeek - 1)).ToString());
if (HaveHolidays(aDate))
{
Sb.AppendFormat("<div class=\"activitypanel1{0}\" style=\"width: 10px; height: 10px; float: right; margin-top: 5px; background-color: red;\"></div>", aDate.ToString("ddMMyy"));
AddBalloon(1, aDate);
}
Sb.AppendLine("</div>");
Sb.AppendLine("</td>");
Sb.AppendLine("</tr>");
Sb.AppendLine("<tr style=\"height: 40%;\">");
Sb.AppendLine("<td><div style=\"width: 10px; height: 10px;\"></div></td>");
Sb.AppendLine("</tr>");
Sb.AppendLine("<tr style=\"height: 20%;\">");
Sb.AppendLine("<td>");
Sb.AppendLine("<div>");
if (HaveMoENActivity(aDate))
{
Sb.AppendFormat("<div class=\"activitypanel2{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: orange\"></div>", aDate.ToString("ddMMyy"));
AddBalloon(2, aDate);
}
if (HaveActivity(aDate))
{
Sb.AppendFormat("<div class=\"activitypanel3{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: green\"></div>", aDate.ToString("ddMMyy"));
AddBalloon(3, aDate);
}
if (HaveMeeting(aDate))
{
Sb.AppendFormat("<div class=\"activitypanel4{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #0066cc\"></div>", aDate.ToString("ddMMyy"));
AddBalloon(4, aDate);
}
if (HaveTraining(aDate))
{
Sb.AppendFormat("<div class=\"activitypanel5{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #f06eaa\"></div>", aDate.ToString("ddMMyy"));
AddBalloon(5, aDate);
}
Sb.AppendLine("</div>");
Sb.AppendLine("</td>");
Sb.AppendLine("</tr>");
Sb.AppendLine("</table>");
Panel CalendarDate = new Panel();
CalendarDate.CssClass = "daypanel";
CalendarDate.Controls.Add(new LiteralControl(Sb.ToString()));
Tc.CssClass = (j == 0 || j == 6) ? "CalendarCellHolliday" : "CalendarCellNormal";
Tc.Controls.Add(CalendarDate);
if (HaveHolidays(aDate) || HaveMoENActivity(aDate) || HaveActivity(aDate) || HaveMeeting(aDate) || HaveTraining(aDate))
Tc.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(UpdatePanel3, aDate.ToShortDateString()));
}
}
}
}
protected void UpdatePanel3_Load(object sender, EventArgs e)
{
string sEventArguments = this.Request.Params["__EVENTARGUMENT"];
if (!string.IsNullOrEmpty(sEventArguments))
{
if (IsNumeric(sEventArguments.Substring(0, 1)))
{
DateTime aDate;
if (DateTime.TryParse(sEventArguments, out aDate))
{
if (aDate.CompareTo(DateTime.Now.Date) == 0)
{
if (HaveHolidays(aDate))
{
string holidaysList = string.Empty;
foreach (DataRow Dr in GetHolidays(aDate).Rows)
{
holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
}
LabelTitle.Text = string.Format("<span style=\"color: blue;\">วันนี้</span> {0} - <span style=\"color: red;\">[{1}]</span>", aDate.ToString("\tวันddddที่ d MMMM พ.ศ. yyyy\t", new System.Globalization.CultureInfo("th-TH")), holidaysList.Substring(0, holidaysList.Length - 2));
}
else
{
LabelTitle.Text = string.Format("<span style=\"color: blue;\">วันนี้</span> {0}", aDate.ToString("\tวันddddที่ d MMMM พ.ศ. yyyy\t", new System.Globalization.CultureInfo("th-TH")));
}
}
else
{
if (HaveHolidays(aDate))
{
string holidaysList = string.Empty;
foreach (DataRow Dr in GetHolidays(aDate).Rows)
{
holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
}
LabelTitle.Text = string.Format("{0} - <span style=\"color: red;\">[{1}]</span>", aDate.ToString("วันddddที่ d MMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH")), holidaysList.Substring(0, holidaysList.Length - 2));
}
else
{
LabelTitle.Text = aDate.ToString("วันddddที่ d MMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH"));
}
}
}
foreach (string timeName in new string[] { "8.00", "9.00", "10.00", "11.00", "12.00", "13.00", "14.00", "15.00", "16.00" })
{
TableRow Tr1 = new TableRow();
TableDetail.Rows.Add(Tr1);
TableCell TcName = new TableCell();
TcName.RowSpan = 2;
TcName.CssClass = "row_head";
Tr1.Cells.Add(TcName);
Table TableName = new Table();
TableName.Width = Unit.Parse("100%");
TableName.Height = Unit.Parse(string.Format("{0}px", (600 / 12 - 1).ToString()));
TableName.Style.Add(HtmlTextWriterStyle.BorderCollapse, "collapse");
TcName.Controls.Add(TableName);
TableRow TrName = new TableRow();
TableName.Rows.Add(TrName);
TableCell Name = new TableCell();
Name.CssClass = "cell_name";
Name.Text = timeName;
TrName.Cells.Add(Name);
TableCell Tc1 = new TableCell();
Tc1.Width = Unit.Parse("90%");
Tc1.CssClass = "row_alt";
Tc1.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
Tr1.Cells.Add(Tc1);
TableRow Tr2 = new TableRow();
TableDetail.Rows.Add(Tr2);
TableCell Tc2 = new TableCell();
Tc2.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
Tr2.Cells.Add(Tc2);
}
Panel PanelActivity = new Panel();
PanelActivity.CssClass = "panel_activity";
PanelEventDetail.Controls.Add(PanelActivity);
int i = 0;
string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };
foreach (DataRow Dr in GetAllActivity(aDate).Rows)
{
int top = GetTop((DateTime)Dr["StartDate"], aDate);
int height = GetHeight((DateTime)Dr["EndDate"], aDate, top);
Panel aPanel = new Panel();
aPanel.CssClass = "panel_detail";
aPanel.Height = Unit.Parse(string.Format("{0}px", height.ToString()));
aPanel.Style.Add(HtmlTextWriterStyle.Top, string.Format("{0}px", top.ToString()));
aPanel.Style.Add(HtmlTextWriterStyle.Left, string.Format("{0}px", (i * 150 + (i + 1) * 2 + i + i).ToString()));
aPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, color[(int)Dr["TypeID"] - 1]);
aPanel.Controls.Add(new LiteralControl(string.Format("<span style=\"color: white; font-weight: bold;\" title=\"{0} [{1}]\">{0}</span><br /><span style=\"color: white;\">[{1}]</span>", Dr["ActivityName"].ToString(), GetTime(top, height).ToString())));
PanelActivity.Controls.Add(aPanel);
i++;
}
ModalPopupExtender3.Show();
}
}
}
protected bool HaveHolidays(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
return (from a in intranet2012.Activity
where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a).Count() > 0 ? true : false;
}
protected bool HaveMoENActivity(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
return (from a in intranet2012.Activity
where a.TypeID == 2 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a).Count() > 0 ? true : false;
}
protected bool HaveActivity(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
return (from a in intranet2012.Activity
where a.TypeID == 3 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a).Count() > 0 ? true : false;
}
protected bool HaveMeeting(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
return (from a in intranet2012.Activity
where a.TypeID == 4 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a).Count() > 0 ? true : false;
}
protected bool HaveTraining(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
return (from a in intranet2012.Activity
where a.TypeID == 5 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a).Count() > 0 ? true : false;
}
protected DataTable GetHolidays(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
var holidays = from a in intranet2012.Activity
where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
select a;
return Intranet2012Datebase.LINQToDataTable(holidays);
}
protected DataTable GetAllActivity(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
var activity = from a in intranet2012.Activity
where a.TypeID != 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
orderby a.StartDate ascending
select a;
return Intranet2012Datebase.LINQToDataTable(activity);
}
protected DataTable GetMonthActivity(DateTime aDate)
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
var activity = (from a in intranet2012.Activity
where (a.StartDate.Year == aDate.Year && a.StartDate.Month == aDate.Month) || (a.EndDate.Year == aDate.Year && a.EndDate.Month == aDate.Month)
orderby a.StartDate ascending
select a).ToList();
return Intranet2012Datebase.LINQToDataTable(activity);
}
protected void AddBalloon(int ActivityType, DateTime date)
{
ClientScriptManager clientScript = Page.ClientScript;
string scriptName = string.Format("activitypanel{0}{1}", ActivityType.ToString(), date.ToString("ddMMyy"));
if (!clientScript.IsStartupScriptRegistered(this.GetType(), scriptName))
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
var activity = from a in intranet2012.Activity
where a.TypeID == ActivityType && (a.StartDate.Date.CompareTo(date) <= 0 && a.EndDate.Date.CompareTo(date) >= 0)
orderby a.StartDate, a.EndDate ascending
select a;
string activityType = (from t in intranet2012.ActivityType
where t.ID == ActivityType
select t.TypeName).First();
string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("$(function() {");
stringBuilder.AppendFormat("$(\".activitypanel{0}{1}\").each(function()", ActivityType.ToString(), date.ToString("ddMMyy"));
stringBuilder.Append("{ $(this).balloon({ contents: \"");
stringBuilder.AppendFormat("<span style='margin: 10px 0px 0px 10px; font-weight: bold; color: {0}'>{1}</span><br />", color[ActivityType - 1], activityType);
stringBuilder.Append("<ul class='activitylist'>");
foreach (TableActivity a in activity)
{
string duration;
if (a.StartDate.Date.CompareTo(a.EndDate.Date) == 0 && a.StartDate.TimeOfDay == new TimeSpan(8, 30, 0) && a.EndDate.TimeOfDay == new TimeSpan(16, 30, 0))
{
duration = "[เต็มวัน]";
}
else if (a.StartDate.Date.CompareTo(a.EndDate.Date) != 0)
{
duration = string.Format("[{0} - {1}]", a.StartDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), a.EndDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")));
}
else
{
duration = string.Format("[{0}น. - {1}น.]", a.StartDate.ToString("HH:mm"), a.EndDate.ToString("HH:mm"));
}
stringBuilder.AppendFormat("<li>{0} {1}</li>", a.ActivityName, duration);
}
stringBuilder.Append("</ul>\", position: \"bottom\" }); });");
stringBuilder.AppendLine("});");
ScriptManager.RegisterStartupScript(Page, this.GetType(), scriptName, stringBuilder.ToString(), true);
}
}
protected int GetHeight(DateTime EndDate, DateTime CurrentDate, int top)
{
int height = 416;
if (CurrentDate.CompareTo(EndDate.Date) > 0)
{
height = 416;
}
else if (CurrentDate.CompareTo(EndDate.Date) == 0)
{
switch (EndDate.ToString("HH:mm"))
{
case "09:00":
height = 26;
break;
case "09:30":
height = 52;
break;
case "10:00":
height = 78;
break;
case "10:30":
height = 104;
break;
case "11:00":
height = 130;
break;
case "11:30":
height = 156;
break;
case "12:00":
height = 182;
break;
case "12:30":
height = 208;
break;
case "13:00":
height = 234;
break;
case "13:30":
height = 260;
break;
case "14:00":
height = 286;
break;
case "14:30":
height = 312;
break;
case "15:00":
height = 338;
break;
case "15:30":
height = 364;
break;
case "16:00":
height = 390;
break;
case "16:30":
height = 416;
break;
}
}
return (height - top - 20 < 0) ? 416 - top - 20 : height - top - 20;
}
protected int GetTop(DateTime StartDate, DateTime CurrentDate)
{
int top = 0;
if (CurrentDate.CompareTo(StartDate.Date) < 0)
{
top = 0;
}
else if (CurrentDate.CompareTo(StartDate.Date) == 0)
{
switch (StartDate.ToString("HH:mm"))
{
case "08:30":
top = 0;
break;
case "09:00":
top = 26;
break;
case "09:30":
top = 52;
break;
case "10:00":
top = 78;
break;
case "10:30":
top = 104;
break;
case "11:00":
top = 130;
break;
case "11:30":
top = 156;
break;
case "12:00":
top = 182;
break;
case "12:30":
top = 208;
break;
case "13:00":
top = 234;
break;
case "13:30":
top = 260;
break;
case "14:00":
top = 286;
break;
case "14:30":
top = 312;
break;
case "15:00":
top = 338;
break;
case "15:30":
top = 364;
break;
case "16:00":
top = 390;
break;
}
}
return top;
}
protected string GetTime(int Top, int Height)
{
string start = string.Empty;
string end = string.Empty;
switch (Top)
{
case 0:
start = "08:30";
break;
case 26:
start = "09:00";
break;
case 52:
start = "09:30";
break;
case 78:
start = "10:00";
break;
case 104:
start = "10:30";
break;
case 130:
start = "11:00";
break;
case 156:
start = "11:30";
break;
case 182:
start = "12:00";
break;
case 208:
start = "12:20";
break;
case 234:
start = "13:00";
break;
case 260:
start = "13:30";
break;
case 286:
start = "14:00";
break;
case 312:
start = "14:30";
break;
case 338:
start = "15:00";
break;
case 364:
start = "15:30";
break;
case 390:
start = "16:00";
break;
}
switch (Height + Top + 20)
{
case 26:
end = "09:00";
break;
case 52:
end = "09:30";
break;
case 78:
end = "10:00";
break;
case 104:
end = "10:30";
break;
case 130:
end = "11:00";
break;
case 156:
end = "11:30";
break;
case 182:
end = "12:00";
break;
case 208:
end = "12:20";
break;
case 234:
end = "13:00";
break;
case 260:
end = "13:30";
break;
case 286:
end = "14:00";
break;
case 312:
end = "14:30";
break;
case 338:
end = "15:00";
break;
case 364:
end = "15:30";
break;
case 390:
end = "16:00";
break;
case 416:
end = "16:30";
break;
}
return string.Format("{0}น. - {1}น.", start, end);
}
public bool IsNumeric(string stringToTest)
{
int result;
if (int.TryParse(stringToTest, out result))
{
return true;
}
else
{
return false;
}
}
}
Date :
2012-12-26 12:50:49
By :
ห้ามตอบเกินวันละ 2 กระทู้
เเง่ม ๆ ลองทำตามทั้งหมดเเล้ว error ครับ เดี๋ยวผมลองเเก้ไปอีกทีครับ
Date :
2012-12-26 13:10:57
By :
Kaen17
คือผมไม่เข้าใจของ ฟอร์ม อยากรู้ว่าใช้อะไรเข้ามาเกี่ยวข้อมั้งครับ คือผม copy ไปวางละ error เเบบนี้ครับ
EventCalendar.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EventCalendar.ascx.cs" Inherits="UserControls_EventCalendar" %>
<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="false" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="~/images/loadingBar.gif" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<div id="calendar">
<div id="calendar_left">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Table ID="Table1" CssClass="CalendarBody" runat="server">
<asp:TableRow>
<asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
<customControl:RollOverImageButton ID="RollOverImageButton1" ImageUrl="~/images/arrow-left.png" RollOverImageUrl="~/images/arrow-left-over.png" ToolTip="Back" runat="server" />
</asp:TableCell>
<asp:TableCell CssClass="CalendarMonth" ColumnSpan="5" HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Label ID="LabelMonthName" runat="server" Text="Label"></asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
<customControl:RollOverImageButton ID="RollOverImageButton2" ImageUrl="~/images/arrow-right.png" RollOverImageUrl="~/images/arrow-right-over.png" ToolTip="Next" runat="server" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="PanelRight" CssClass="calendar_right" runat="server">
<asp:Table ID="TableActivity" style="width: 100%;" runat="server">
<asp:TableRow>
<asp:TableCell CssClass="td_activity">
<asp:Label ID="Label1" runat="server" Text="Label" style="font-weight: bold;"></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" OnLoad="UpdatePanel3_Load">
<ContentTemplate>
<asp:Button ID="ButtonHidden3" runat="server" Text="Button" style="display: none;" />
<ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender3"
TargetControlID="ButtonHidden3" PopupControlID="PanelActivity" CancelControlID="ImageButton1"
BackgroundCssClass="modalBackground" DropShadow="True"
RepositionMode="RepositionOnWindowScroll">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelActivity" CssClass="modalPopup" runat="server">
<asp:Panel ID="PanelClose" CssClass="close" runat="server">
<asp:ImageButton ID="ImageButton1" CssClass="close" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" />
</asp:Panel>
<asp:Panel ID="PanelEvent" CssClass="calendar_detail" runat="server">
<asp:Panel ID="PanelEventHead" CssClass="event_head" runat="server">
<asp:Table ID="Table2" CssClass="table_name" runat="server">
<asp:TableRow runat="server">
<asp:TableCell ID="CellTitle" CssClass="cell_name" runat="server">
<asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
<asp:Panel ID="PanelEventDetail" CssClass="event_detail" runat="server">
<asp:Table ID="TableDetail" CssClass="table_detail" BorderStyle="Solid" BorderWidth="1" runat="server">
</asp:Table>
</asp:Panel>
</asp:Panel>
</asp:Panel>
<ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="PanelActivity" Opacity=".8" Rounded="true" TrackPosition="true" />
<ajaxToolkit:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="PanelEvent" Radius="4" Corners="All" />
</ContentTemplate>
</asp:UpdatePanel>
ประวัติการแก้ไข 2012-12-26 20:49:41
Date :
2012-12-26 20:48:38
By :
Kaen17
ascx เป็น user control
ไม่ใช่ฟอร์ม
เปลี่ยนไปเป็น aspx ก็ได้ แต่เปลี่ยนเอง
Date :
2012-12-27 08:53:41
By :
ห้ามตอบเกินวันละ 2 กระทู้
แล้วก็พวก ajaxtoolkits นี่หามาติดตั้งก่อนนะ
ก่อนจะใช้
Date :
2012-12-27 08:59:29
By :
ห้ามตอบเกินวันละ 2 กระทู้
Load balance : Server 02