临时存放
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
namespace ClassLibrary1
{
public class BlogDateControl:System.Web.UI.WebControls.WebControl,System.Web.UI.INamingContainer,System.Web.UI.IPostBackEventHandler
{
private static readonly object ClickKey=new object();
[Description("单击日期触发的时间!")]
public event EventHandler Click
{
add
{
Events.AddHandler(ClickKey, value);
}
remove
{
Events.RemoveHandler(ClickKey, value);
}
}
private static readonly string[] header = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
private DateTime showDate;
/// <summary>
/// Gets or sets the show date.
/// </summary>
/// <value>The show date.</value>
[Description("格式必须为yyyy-MM一样")]
public string ShowDate
{
get
{
if (showDate == null)
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
return showDate.ToString("yyyy-MM");
}
set
{
if (value == null)
{
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
}
else
{
showDate = Convert.ToDateTime(value+"-01");
}
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
//为table标签定义属性和样式
// writer.AddAttribute(HtmlTextWriterAttribute.Width, "287px");
//writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "1px");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1px");
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
base.AddAttributesToRender(writer);
}
/// <summary>
/// 获取与此 Web 服务器控件相对应的 <see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 值。此属性主要由控件开发人员使用。
/// </summary>
/// <value></value>
/// <returns><see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 枚举值之一。</returns>
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Table;
}
}
/// <summary>
/// 将控件的内容呈现到指定的编写器中。此方法主要由控件开发人员使用。
/// </summary>
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"></see>,表示要在客户端呈现 HTML 内容的输出流。</param>
protected override void RenderContents(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Thead);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "7");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(this.showDate.Year+"年"+this.showDate.Month+"月");
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int i = 0; i < BlogDateControl.header.Length; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(BlogDateControl.header[i]);
writer.RenderEndTag();
}
writer.RenderEndTag();
DateTime end=this.showDate.AddMonths(1);
int days=((TimeSpan)end.Subtract(this.showDate)).Days;
int spaceday = Convert.ToInt32(this.showDate.DayOfWeek);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int i = 0; i < spaceday; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.WriteLine(" ");
writer.RenderEndTag();
}
for (int i = 1; i <= days; i++)
{
writer.Write("<td onclick=\"");
writer.Write(Page.GetPostBackEventReference(this, this.ShowDate+"-"+i.ToString().PadLeft(2,'0')));
writer.Write("\">"+i.ToString()+"</td>");
//writer.RenderEndTag();
if ((i + spaceday) % 7 == 0)
{
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
}
if ((spaceday + days) % 7 != 0)
{
int allcount = spaceday + days > 35 ? 42 : 35;
for (int i = 0; i < allcount - spaceday - days; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag();
}
writer.RenderEndTag();
}
}
protected virtual void OnClick(StringEventArgs e)
{
EventHandler clickEventDelegate =
(EventHandler)Events[ClickKey];
if (clickEventDelegate != null)
{
clickEventDelegate(this, e);
}
}
IPostBackEventHandler 成员
}
public class StringEventArgs : EventArgs
{
private string argString;
public string ArgString
{
get { return argString; }
}
public StringEventArgs(string arg)
{
this.argString = arg;
}
public override string ToString()
{
return this.argString;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
namespace ClassLibrary1
{
public class BlogDateControl:System.Web.UI.WebControls.WebControl,System.Web.UI.INamingContainer,System.Web.UI.IPostBackEventHandler
{
private static readonly object ClickKey=new object();
[Description("单击日期触发的时间!")]
public event EventHandler Click
{
add
{
Events.AddHandler(ClickKey, value);
}
remove
{
Events.RemoveHandler(ClickKey, value);
}
}
private static readonly string[] header = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
private DateTime showDate;
/// <summary>
/// Gets or sets the show date.
/// </summary>
/// <value>The show date.</value>
[Description("格式必须为yyyy-MM一样")]
public string ShowDate
{
get
{
if (showDate == null)
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
return showDate.ToString("yyyy-MM");
}
set
{
if (value == null)
{
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
}
else
{
showDate = Convert.ToDateTime(value+"-01");
}
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
//为table标签定义属性和样式
// writer.AddAttribute(HtmlTextWriterAttribute.Width, "287px");
//writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "1px");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1px");
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
base.AddAttributesToRender(writer);
}
/// <summary>
/// 获取与此 Web 服务器控件相对应的 <see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 值。此属性主要由控件开发人员使用。
/// </summary>
/// <value></value>
/// <returns><see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 枚举值之一。</returns>
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Table;
}
}
/// <summary>
/// 将控件的内容呈现到指定的编写器中。此方法主要由控件开发人员使用。
/// </summary>
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"></see>,表示要在客户端呈现 HTML 内容的输出流。</param>
protected override void RenderContents(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Thead);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "7");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(this.showDate.Year+"年"+this.showDate.Month+"月");
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int i = 0; i < BlogDateControl.header.Length; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(BlogDateControl.header[i]);
writer.RenderEndTag();
}
writer.RenderEndTag();
DateTime end=this.showDate.AddMonths(1);
int days=((TimeSpan)end.Subtract(this.showDate)).Days;
int spaceday = Convert.ToInt32(this.showDate.DayOfWeek);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int i = 0; i < spaceday; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.WriteLine(" ");
writer.RenderEndTag();
}
for (int i = 1; i <= days; i++)
{
writer.Write("<td onclick=\"");
writer.Write(Page.GetPostBackEventReference(this, this.ShowDate+"-"+i.ToString().PadLeft(2,'0')));
writer.Write("\">"+i.ToString()+"</td>");
//writer.RenderEndTag();
if ((i + spaceday) % 7 == 0)
{
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
}
if ((spaceday + days) % 7 != 0)
{
int allcount = spaceday + days > 35 ? 42 : 35;
for (int i = 0; i < allcount - spaceday - days; i++)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag();
}
writer.RenderEndTag();
}
}
protected virtual void OnClick(StringEventArgs e)
{
EventHandler clickEventDelegate =
(EventHandler)Events[ClickKey];
if (clickEventDelegate != null)
{
clickEventDelegate(this, e);
}
}
IPostBackEventHandler 成员
}
public class StringEventArgs : EventArgs
{
private string argString;
public string ArgString
{
get { return argString; }
}
public StringEventArgs(string arg)
{
this.argString = arg;
}
public override string ToString()
{
return this.argString;
}
}
}