|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
C#中有两处地方用到new关键字,第一处也是最常见的一处是用在调用构造函数的时候,这种情况也是大家见的最多的一种。另一处是用在派生类中,作用有隐藏成员,切断继承关系等,相信第二处的用法大家明显要比第一处生疏。asp.net|博客|程序|日历 最终效果:
前台页面
<%@Pagelanguage="c#"Codebehind="WebForm1.aspx.cs"AutoEventWireup="false"Inherits="Blog_calendar.WebForm1"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<metaname="GENERATOR"Content="MicrosoftVisualStudio.NET7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
<asp:calendarid="Calendar1"CellPadding="2"Width="160px"TitleStyle-BackColor="#000000"BorderColor="#aaaaaa"
DayHeaderStyle-BackColor="#5e715e"OtherMonthDayStyle-ForeColor="#cccccc"DayNameFormat="Full"
runat="server"TitleStyle-ForeColor="#ffffff"NextPrevStyle-ForeColor="#ffffff"CellSpacing="1"
WeekendDayStyle-BackColor="#eeeeee"DayHeaderStyle-ForeColor="#ffffff"SelectionMode="None"
TodayDayStyle-BorderColor="#5e715e"TodayDayStyle-BorderWidth="1"TodayDayStyle-Font-Bold="true"
TodayDayStyle-ForeColor="#5e715e">
<TodayDayStyleFont-Bold="True"BorderWidth="1px"ForeColor="#5E715E"BorderColor="#5E715E"></TodayDayStyle>
<NextPrevStyleForeColor="White"></NextPrevStyle>
<DayHeaderStyleForeColor="White"BackColor="#404040"></DayHeaderStyle>
<TitleStyleForeColor="White"BackColor="Black"></TitleStyle>
<WeekendDayStyleBackColor="Silver"></WeekendDayStyle>
<OtherMonthDayStyleForeColor="#CCCCCC"></OtherMonthDayStyle>
</asp:calendar>
</form>
</body>
</HTML>
背景程序:
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.Threading;
usingSystem.Globalization;
usingSystem.Data.SqlClient;
namespaceBlog_calendar
{
///<summary>
///WebForm1的择要申明。
///</summary>
publicclassWebForm1:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.CalendarCalendar1;
privateint[]arrCurrentDays,arrPreDays,arrNextDays;//三个变量分离是以后月,前一月,和下一个月
privateintintCurrentMonth,intPreMonth,intNextMonth;//三个整型数组寄存绝对月份写有blog的日期
privatevoidPage_Load(objectsender,System.EventArgse)
{
//在此处安排用户代码以初始化页面
}
privatevoidCalendar1_PreRender(objectsender,System.EventArgse)
{
ThreadthreadCurrent=Thread.CurrentThread;
CultureInfociNew=(CultureInfo)threadCurrent.CurrentCulture.Clone();
ciNew.DateTimeFormat.DayNames=newstring[]{"日","一","二","三","四","五","六"};
ciNew.DateTimeFormat.FirstDayOfWeek=DayOfWeek.Sunday;
threadCurrent.CurrentCulture=ciNew;
}
privatevoidCalendar1_DayRender(objectsender,System.Web.UI.WebControls.DayRenderEventArgse)
{
//该控件在创立每地利产生。
CalendarDayd=((DayRenderEventArgs)e).Day;
TableCellc=((DayRenderEventArgs)e).Cell;
//初始化以后月有Blog的日期数组
if(intPreMonth==0)
{
intPreMonth=d.Date.Month;//注重:日历控件初始化时我们失掉的第一个月并非以后月,而是前一个月的月份
//Response.Write(d.Date.Month.ToString());
intCurrentMonth=intPreMonth+1;
if(intCurrentMonth>12)
intCurrentMonth=1;
intNextMonth=intCurrentMonth+1;
if(intNextMonth>12)
intNextMonth=1;
arrPreDays=getArrayDay(d.Date.Year,intPreMonth);//失掉前一个月有blog的日期数组
arrCurrentDays=getArrayDay(d.Date.Year,intCurrentMonth);//失掉当月有blog的日期数组
arrNextDays=getArrayDay(d.Date.Year,intNextMonth);//失掉下个月有blog的日期数组
}
intj=0;
if(d.Date.Month.Equals(intPreMonth))
{
while(!arrPreDays[j].Equals(0))
{
if(d.Date.Day.Equals(arrPreDays[j]))
{
c.Controls.Clear();
c.Controls.Add(newLiteralControl("<ahref=WebForm1.aspx?year="+d.Date.Year+"-"+
d.Date.Month+"-"+d.Date.Day+">"+d.Date.Day+"</a>"));
}
j++;
}
}
elseif(d.Date.Month.Equals(intCurrentMonth))
{
while(!arrCurrentDays[j].Equals(0))
{
if(d.Date.Day.Equals(arrCurrentDays[j]))
{
c.Controls.Clear();
c.Controls.Add(newLiteralControl("<ahref=WebForm1.aspx?time="+d.Date.Year+"-"+
d.Date.Month+"-"+d.Date.Day+"title="+d.Date.Year+/+d.Date.Month+/+d.Date.Day+">"+d.Date.Day+"</a>"));
}
j++;
}
}
elseif(d.Date.Month.Equals(intNextMonth))
{
while(!arrNextDays[j].Equals(0))
{
if(d.Date.Day.Equals(arrNextDays[j]))
{
c.Controls.Clear();
c.Controls.Add(newLiteralControl("<ahref=WebForm1.aspx?year="+d.Date.Year+"-"+
d.Date.Month+"-"+d.Date.Day+">"+d.Date.Day+"</a>"));
}
j++;
}
}
}
privateint[]getArrayDay(intintYear,intintMonth)
{
inti=0;
int[]intArray=newint[31];
//从数据库里拔取切合请求的纪录,将日期存进数组
stringmySelectQuery="selectOrderDatefromtestwhereyear(OrderDate)="+intYear+
"andmonth(OrderDate)="+intMonth;
SqlConnectionmyConnection=newSqlConnection("server=localhost;UID=sa;pwd=fan;database=test");
SqlCommandmyCommand=newSqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReadermyReader;
myReader=myCommand.ExecuteReader();
while(myReader.Read())
{
if(i==0)
{
intArray=myReader.GetDateTime(0).Day;
i++;
}
elseif(myReader.GetDateTime(0).Day!=intArray[i-1])
{
intArray=myReader.GetDateTime(0).Day;
i++;
}
}
myReader.Close();
myConnection.Close();
returnintArray;
}
#regionWeb窗体计划器天生的代码
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该挪用是ASP.NETWeb窗体计划器所必须的。
//
InitializeComponent();
base.OnInit(e);
}
///<summary>
///计划器撑持所需的办法-不要利用代码编纂器修正
///此办法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Calendar1.DayRender+=newSystem.Web.UI.WebControls.DayRenderEventHandler(this.Calendar1_DayRender);
this.Calendar1.PreRender+=newSystem.EventHandler(this.Calendar1_PreRender);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}
你觉得数据库怎么样? |
|