<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Calendar.ascx.cs" Inherits="Calendar" %>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="Comic Sans MS"
Font-Size="16pt" ForeColor="Maroon" Text="Schedule" ToolTip="日程安排" style="cursor: hand"></asp:Label>
<asp:ImageButton
ID="ImageButton1" runat="server" Height="12px" ImageUrl="~/Image/calendar/btnPre.png"
OnClick="ImageButton1_Click" Width="12px" style="cursor: hand" />
<asp:ImageButton ID="ImageButton2" runat="server"
Height="12px" ImageUrl="~/Image/calendar/btnNext.png" OnClick="ImageButton2_Click"
Width="12px" style="cursor: hand" /><br />
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Comic Sans MS"
Font-Size="17px" ForeColor="Firebrick" Style="text-align: right; cursor: hand;"
Width="207px"></asp:Label><br />
<asp:ImageButton ID="ImageButton3" runat="server" Enabled="False" ImageUrl="~/Image/calendar/title.png" style="cursor: hand" />
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White" BorderWidth="0px" CaptionAlign="Left" FirstDayOfWeek="Sunday" Font-Bold="False" Font-Names="Comic Sans MS" Font-Size="9pt" ForeColor="Black" Height="110px" Width="205px" style="font-size: 12px; cursor: hand; font-family: 'Comic Sans MS'" OnDayRender="Calendar1_DayRender" OnSelectionChanged="Calendar1_SelectionChanged" ShowNextPrevMonth="False" ToolTip="Sunshine Garden" ShowDayHeader="False" ShowTitle="False" OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">
<TodayDayStyle BackColor="#CCCCCC" />
<DayStyle Font-Names="Comic Sans MS" Wrap="True" />
<WeekendDayStyle Font-Names="Comic Sans MS" ForeColor="Red" />
<OtherMonthDayStyle ForeColor="White" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="LightGray" Font-Bold="True" Font-Size="8pt" ForeColor="Black" />
<TitleStyle BackColor="White" BorderColor="Transparent" BorderWidth="2px" Font-Bold="True"
Font-Size="15pt" ForeColor="Firebrick" HorizontalAlign="Right" />
<SelectorStyle ForeColor="Red" />
</asp:Calendar>
Calendar.ascx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
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 SunShineGarden;
public partial class Calendar : System.Web.UI.UserControl
{
private static string [] Month = new String[13]{"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
private static int year, month, day;
private static string[] SpecialDays = new String[32];
private static Database sqlDB = new Database();
private static SqlConnection con = sqlDB.Open();
private static Style SatturdayStyle = new Style();
private static Style SundayStyle = new Style();
private static Style WeekdayStyle = new Style();
private static Style SpecialdayStyle = new Style();
private static bool Judge;
private static DateTime FirstDayOfThisMonth;
private static DateTime FirstDayOfNextMonth;
private static string picUrl;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack) {
day = DateTime.Today.Day;
month = DateTime.Today.Month;
year = DateTime.Today.Year;
SatturdayStyle.ForeColor = System.Drawing.Color.RoyalBlue;
SundayStyle.ForeColor = System.Drawing.Color.Red;
WeekdayStyle.ForeColor = System.Drawing.Color.Black;
SpecialdayStyle.ForeColor = System.Drawing.Color.Orange;
SatturdayStyle.Font.Size = FontUnit.Point(9);
SundayStyle.Font.Size = FontUnit.Point(9);
WeekdayStyle.Font.Size = FontUnit.Point(9);
SpecialdayStyle.Font.Size = FontUnit.Point(9);
}
ShowTitle();
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth)
if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday) e.Cell.ApplyStyle(SatturdayStyle);
else if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday) e.Cell.ApplyStyle(SundayStyle);
else e.Cell.ApplyStyle(WeekdayStyle);
else if ( e.Day.Date >= FirstDayOfNextMonth.Date || (e.Day.Date < FirstDayOfThisMonth.Date && Judge)) e.Cell.Visible = false;
if (e.Day.Date == DateTime.Today.Date && e.Day.IsOtherMonth) e.Cell.BackColor = System.Drawing.Color.White;
if (SpecialDays[e.Day.Date.Day] != "" && e.Day.Date.Month == month)
{
e.Cell.ApplyStyle(SpecialdayStyle);
//e.Cell.Text = "<a href = " + e.SelectUrl + "><span style =\"background-image: url(./Image/calendar/Circle.PNG); background-position:center center; color:Black; text-decoration: none\"> " + e.Day.Date.Day.ToString().Trim() + " </span></a>";
if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday) picUrl = "blue-";
else if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday) picUrl = "orange-";
else picUrl = "black-";
if (e.Day.Date == DateTime.Today.Date) picUrl = picUrl + "1-";
else picUrl = picUrl + "null-";
picUrl = picUrl + e.Day.Date.Day.ToString() + "副本.png";
int day = e.Day.Date.Day;
string temp = SpecialDays[day];
e.Cell.Text = "<img alt=\"\" src=\"./Image/calendar/Calender icons/" + picUrl + "\" style=\"border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none\" onclick=\"ShowMenu(event.x,event.y," + day.ToString() + ")\"/>"
//e.Cell.Text = "<a href = " + e.SelectUrl + "><img alt=\"\" src=\"./Image/calendar/Calender icons/" + picUrl + "\" style=\"border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none\" onclick=\""
+ MakeScript(temp, day.ToString());
e.Cell.ToolTip = e.Day.Date.ToShortDateString() + "\n今天的活动有:\n";
while (temp.IndexOf("#") >= 0)
{
temp = temp.Substring(temp.IndexOf("#") + 1);
e.Cell.ToolTip = e.Cell.ToolTip + temp.Substring(0, temp.IndexOf("#")) + "\n";
temp = temp.Substring(temp.IndexOf("#") + 1);
}
e.Cell.ToolTip = e.Cell.ToolTip.Remove(e.Cell.ToolTip.Length - 1);
e.Day.IsSelectable = false;
}
else { e.Day.IsSelectable = false; }
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
day = Calendar1.SelectedDate.Day;
ShowTitle();
//if (SpecialDays[day] != "") Response.Redirect("TopicView.apsx?" + SpecialDays[day].Substring(0, SpecialDays[day].IndexOf("#")).Trim());
//Response.Write("<div style=\"z-index: 101; left: 12px; width: 200px; position: absolute; top: 109px; height: 120px\">");
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
month--;
if (month == 0) { month = 12; year--; }
ShowTitle();
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
month++;
if (month == 13) { month = 1; year++; }
ShowTitle();
}
private bool IsLeapYear(int year)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true;
else return false;
}
private int GetMonthDay(int month, int year)
{
switch (month)
{
case 2: return IsLeapYear(year) ? 29 : 28;
case 4:
case 6:
case 9:
case 11: return 30;
default: return 31;
}
}
private void ShowTitle()
{
FirstDayOfThisMonth = new DateTime(year, month, 1);
if (month == 12) FirstDayOfNextMonth = new DateTime(year + 1, 1, 1);
else FirstDayOfNextMonth = new DateTime(year, month + 1, 1);
Judge = (FirstDayOfThisMonth.DayOfWeek == DayOfWeek.Sunday);
GetEvent();
Label3.Text = year.ToString() + "'" + Month[month];
Calendar1.VisibleDate = new DateTime(year, month, 1);
if ( month == 1 ) ImageButton1.ToolTip = Month[ 12 ];
else ImageButton1.ToolTip = Month[month - 1];
if (month == 12) ImageButton2.ToolTip = Month[1];
else ImageButton2.ToolTip = Month[ month + 1 ];
Label3.ToolTip = "Today is " + year.ToString() + "-" + month.ToString() + "-" + day.ToString();
}
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
}
protected void GetEvent()
{
if (con.State == ConnectionState.Closed) con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Topic WHERE DateAndTime LIKE '%" + year.ToString() + "-" + month.ToString() + "%'", con);
SqlDataReader dr = cmd.ExecuteReader();
for (int i = 0; i < 32; i++) SpecialDays[i] = "";
while (dr.Read())
{
SpecialDays[GetDay(dr["DateAndTime"].ToString())] += dr["ID"].ToString() + "#"+ dr["TopicName"].ToString() + "#";
}
con.Close();
}
protected int GetDay(string date)
{
date = date.Substring(date.LastIndexOf('-') + 1, 2);
return Int32.Parse(date.Trim());
}
private string MakeScript(string source, string day)
{
string ans = "<div id=\"" + day + "\" style=\"display:none;background-color:LemonChiffon;\"> 今天的活动有:";
string temp="";
while (source.IndexOf("#") >= 0)
{
source = source.Substring(source.IndexOf("#") + 1);
temp = source.Substring(0, source.IndexOf("#"));
source = source.Substring(source.IndexOf("#") + 1);
ans = ans + "<div style=\"cursor:hand\" onmouseover=\"this.style.background='Brown';\" onmouseout=\"this.style.background='LemonChiffon';\" onclick=\"parent.location.href='./ShowArticle?id=" + temp + "'\">"
+ "<span> " + temp + " </span> </div> ";
}
ans = ans + "</div>";
return ans;
}
}
Calendar.js
// JScript 文件
function ShowMenu(x , y, day)
{
var oPopup = window.createPopup();
oPopup.document.bgColor= "LemonChiffon";
var temp = document.getElementById(day);
oPopup.document.body.innerHTML = temp.innerHTML;
temp.style.display="block";
oRect = temp.getBoundingClientRect();
temp.style.display="none";
var width = oRect.right - oRect.left + 20;
if(width < 150) width = 150;
oPopup.show(x + 5, y + 5, width, oRect.bottom - oRect.top + 15, document.body);
}
TopicList
TopicList.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TopicList.ascx.cs" Inherits="TopicList" %>
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
Font-Names="Arial" Font-Size="12px" Width="542px" OnItemCreated="DataList1_ItemCreated">
<HeaderTemplate>
<div style="height: 15px; text-align:right;">
<%# SetHeader() %>
</div>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Image/list/title.png" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="IDLabel" runat="server" Text='<%# ShowID() %>' Width="80px" style="text-align: center"></asp:Label>
<asp:Label ID="TopicNameLabel" runat="server" Text='<%# ShowTitle(Container.DataItem) %>' Width="200px"></asp:Label>
<asp:Image ID="Image2" runat="server" ImageUrl="~/Image/list/new.png" />
<asp:Label ID="PostUserLabel" runat="server" Text='<%# Eval("PostUser") %>' Width="70px" style="text-align: center"></asp:Label>
<asp:Label ID="DateAndTimeLabel" runat="server" Text='<%# ShowDate(Container.DataItem) %>' Width="65px" style="text-align: center"></asp:Label>
<asp:Label ID="ClickLabel" runat="server" Text='<%# Eval("Click") %>' Width="55px" style="text-align: center"></asp:Label>
<br />
</ItemTemplate>
<SeparatorTemplate>
<hr style="border: dashed 1px gray; height: 1px;" />
</SeparatorTemplate>
<FooterTemplate>
<hr style="border: dashed 1px gray; height: 1px;" />
</FooterTemplate>
</asp:DataList><br />
<div style="background-image:url(./Image/list/foot_background.png); background-position:center; background-repeat:no-repeat; height: 60px; width: 538px; text-align:center; font-weight: bold; font-size: 12px; font-family: 'Comic Sans MS';">
<asp:Image ID="Image3" runat="server" ImageUrl="~/Image/list/字母素材/字母/s.GIF" Height="20px" /><asp:Image
ID="Image15" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/u.GIF" /><asp:Image
ID="Image16" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/n.GIF" /><asp:Image
ID="Image17" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/s.GIF" /><asp:Image
ID="Image18" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/h.GIF" /><asp:Image
ID="Image19" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/i.GIF" /><asp:Image
ID="Image20" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/n.GIF" /><asp:Image
ID="Image21" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/e.GIF" />
<asp:Image ID="Image8" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image7" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image5" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image6" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image9" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image10" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image11" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image12" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image13" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" /><asp:Image ID="Image14" runat="server" ImageUrl="~/Image/list/E.GIF" Height="20px" />
<asp:Image ID="Image4" runat="server" ImageUrl="~/Image/list/字母素材/字母/g.GIF" /><asp:Image
ID="Image22" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/A.GIF" /><asp:Image
ID="Image23" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/R.GIF" /><asp:Image
ID="Image24" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/D.GIF" /><asp:Image
ID="Image25" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/e.GIF" /><asp:Image
ID="Image26" runat="server" Height="20px" ImageUrl="~/Image/list/字母素材/字母/n.GIF" /><br />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Image/list/btnfirst.png"
OnClick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Image/list/btnpre.png"
OnClick="ImageButton2_Click" />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Comic Sans MS"
Text="Label"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/Image/list/btnnext.png"
OnClick="ImageButton3_Click" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="~/Image/list/btnlast.png"
OnClick="ImageButton4_Click" />
</div>
TopicList.ascx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
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 SunShineGarden;
public partial class TopicList : System.Web.UI.UserControl
{
private static SqlConnection con;
private static SqlCommand myCommand;
private static string sqlString;
private static int currentForum;
private static int totalCount;
private static int totalPage;
private static int currentPageIndex = 1;
private const int PageSize = 10;
private const int PageNum = 10;
private static int temp;
private static int begin;
private static int end;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (currentForum <= 0) currentForum = 1;
SetSQLString("FROM [Topic] WHERE ([ForumID] = " + currentForum.ToString() + ")");
totalCount = 0;
temp = 0;
BindData();
begin = 1;
end = (PageNum < totalPage ? PageNum : totalPage);
}
RefreshPage();
}
public void SetCurrentForum(int target)
{
currentForum = target;
}
public void SetSQLString(string target)
{
sqlString = target;
}
protected string SetHeader()
{
MakeHeader();
string _text = "Total <strong>{0}</strong>   Page <strong>{1}</strong>/{0}      ";
return String.Format(_text, totalPage, currentPageIndex);
}
protected string ShowID()
{
temp++;
if (temp > PageSize) temp = 1;
int ans = (currentPageIndex - 1) * PageSize + temp;
if (ans < 10) return "0" + ans.ToString();
else return ans.ToString();
}
protected string ShowTitle(object dataItem)
{
DataRowView _row = (DataRowView)dataItem;
string _id = _row["ID"].ToString();
string _output = _row["TopicName"].ToString();
_output = "<a href=\"ViewArticle?id=" + _id + "\" style=\"text-decoration:none; color:black;\">" + _output + "</a>";
return _output;
}
protected string ShowDate(object dataItem)
{
DataRowView _row = (DataRowView)dataItem;
string _output = _row["DateAndTime"].ToString();
_output = _output.Substring(0, _output.IndexOf(" "));
return _output;
}
protected void MakeHeader()
{
Database data = new Database();
con = data.Open();
myCommand = new SqlCommand("SELECT COUNT(*)" + sqlString, con);
SqlDataReader dr = myCommand.ExecuteReader();
dr.Read();
totalCount = Int32.Parse(dr[0].ToString());
dr.Close();
if (totalCount % PageSize == 0) totalPage = totalCount / PageSize;
else totalPage = totalCount / PageSize + 1;
}
private void BindData()
{
Database data = new Database();
con = data.Open();
myCommand = new SqlCommand("SELECT TOP " + PageSize + " * " + sqlString + "ORDER BY [DateAndTime] DESC, [ID]", con);
SqlDataAdapter _adapter = new SqlDataAdapter(myCommand);
DataSet _data = new DataSet();
_adapter.Fill(_data);
DataList1.DataSource = _data;
DataList1.DataBind();
}
private void RefreshPage()
{
JudgePageBtn();
temp = 0;
DataSet _data = new DataSet();
int num = (currentPageIndex * PageSize > totalCount) ? totalCount - (currentPageIndex - 1) * PageSize : PageSize;
SqlCommand myCommand = new SqlCommand("SELECT TOP " + num + " * FROM" +
"(SELECT TOP " + Convert.ToString(currentPageIndex * PageSize) + " * " + sqlString
+ " ORDER BY [DateAndTime] ASC, [ID] DESC) AS t1 ORDER BY [DateAndTime] DESC, [ID] ASC", con);
SqlDataAdapter _adapter = new SqlDataAdapter(myCommand);
_adapter.Fill(_data);
DataList1.DataSource = _data;
DataList1.DataBind();
CreateFooter();
}
public void RefreshPagePublic()
{
RefreshPage();
}
private void JudgePageBtn()
{
if (currentPageIndex == 1)
{
ImageButton1.Enabled = false;
ImageButton2.Enabled = false;
}
else
{
ImageButton1.Enabled = true;
ImageButton2.Enabled = true;
}
if (currentPageIndex == totalPage)
{
ImageButton3.Enabled = false;
ImageButton4.Enabled = false;
}
else
{
ImageButton3.Enabled = true;
ImageButton4.Enabled = true;
}
}
protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
{
}
private void CreateFooter()
{
if (currentPageIndex == end)
if (end < totalPage)
{
begin++; end++;
}
Label1.Controls.Clear();
for (int i = begin; i <= end; i++)
{
addControls(i);
}
if (totalCount == 0) Label1.Text = "1";
if (begin + 1 <= end) Image6.Visible = true; else Image6.Visible = false;
if (begin + 2 <= end) Image7.Visible = true; else Image7.Visible = false;
if (begin + 3 <= end) Image8.Visible = true; else Image8.Visible = false;
if (begin + 4 <= end) Image9.Visible = true; else Image9.Visible = false;
if (begin + 5 <= end) Image10.Visible = true; else Image10.Visible = false;
if (begin + 6 <= end) Image11.Visible = true; else Image11.Visible = false;
if (begin + 7 <= end) Image12.Visible = true; else Image12.Visible = false;
if (begin + 8 <= end) Image13.Visible = true; else Image13.Visible = false;
if (begin + 9 <= end) Image14.Visible = true; else Image14.Visible = false;
}
private void addControls(int i) {
Button btn = new Button();
btn.ID = "btnAdd" + i.ToString();
btn.Text = i.ToString();
btn.Height = Unit.Pixel(20);
btn.BorderWidth = Unit.Pixel(0);
btn.BackColor = System.Drawing.Color.Transparent;
if (i == currentPageIndex) btn.ForeColor = System.Drawing.Color.Red;
btn.Command += new CommandEventHandler(btn_Command);
btn.CommandArgument = i.ToString();
btn.Visible = true;
Label1.Controls.Add(btn);
if (i != end)
{
Label lb = new Label();
lb.ID = "lbAdd" + i.ToString();
lb.Text = "|";
lb.BackColor = System.Drawing.Color.Transparent;
lb.Height = Unit.Pixel(20);
lb.Width = Unit.Pixel(5);
lb.Visible = true;
Label1.Controls.Add(lb);
}
}
void btn_Command(object sender, CommandEventArgs e)
{
currentPageIndex = Int32.Parse(e.CommandArgument.ToString());
RefreshPage();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
currentPageIndex = 1;
RefreshPage();
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
if (currentPageIndex > 1) currentPageIndex -= 1;
RefreshPage();
}
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
if (currentPageIndex < totalPage) currentPageIndex += 1;
RefreshPage();
}
protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
{
currentPageIndex = totalPage;
RefreshPage();
}
protected void GotoPage(int targetPage)
{
if (targetPage <= totalPage && targetPage >= 1) currentPageIndex = targetPage;
else currentPageIndex = 1;
RefreshPage();
}
}