临时存放
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Web.UI;
using
System.ComponentModel;
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace
ClassLibrary1
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public class BlogDateControl:System.Web.UI.WebControls.WebControl,System.Web.UI.INamingContainer,System.Web.UI.IPostBackEventHandler
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private static readonly object ClickKey=new object();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[Description("单击日期触发的时间!")]
public event EventHandler Click
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
add
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Events.AddHandler(ClickKey, value);
}
remove
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Events.RemoveHandler(ClickKey, value);
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
private static readonly string[] header = new string[]
{ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private DateTime showDate;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Gets or sets the show date.
/// </summary>
/// <value>The show date.</value>
[Description("格式必须为yyyy-MM一样")]
public string ShowDate
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (showDate == null)
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
return showDate.ToString("yyyy-MM");
}
set
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (value == null)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
showDate = Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
showDate = Convert.ToDateTime(value+"-01");
}
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected override void AddAttributesToRender(HtmlTextWriter writer)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//为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);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <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
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return HtmlTextWriterTag.Table;
}
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 将控件的内容呈现到指定的编写器中。此方法主要由控件开发人员使用。
/// </summary>
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"></see>,表示要在客户端呈现 HTML 内容的输出流。</param>
protected override void RenderContents(HtmlTextWriter writer)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(BlogDateControl.header[i]);
writer.RenderEndTag();
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.WriteLine(" ");
writer.RenderEndTag();
}
for (int i = 1; i <= days; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
writer.Write("<td οnclick=\"");
writer.Write(Page.GetPostBackEventReference(this, this.ShowDate+"-"+i.ToString().PadLeft(2,'0')));
writer.Write("\">"+i.ToString()+"</td>");
//writer.RenderEndTag();
if ((i + spaceday) % 7 == 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
}
if ((spaceday + days) % 7 != 0)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int allcount = spaceday + days > 35 ? 42 : 35;
for (int i = 0; i < allcount - spaceday - days; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag();
}
writer.RenderEndTag();
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected virtual void OnClick(StringEventArgs e)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
EventHandler clickEventDelegate =
(EventHandler)Events[ClickKey];
if (clickEventDelegate != null)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
clickEventDelegate(this, e);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
IPostBackEventHandler 成员#region IPostBackEventHandler 成员
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public void RaisePostBackEvent(string eventArgument)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//throw new Exception("The method or operation is not implemented.");
OnClick(new StringEventArgs(eventArgument));
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#endregion
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public class StringEventArgs : EventArgs
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private string argString;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string ArgString
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return argString; }
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public StringEventArgs(string arg)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.argString = arg;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override string ToString()
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return this.argString;
}
}
}
转载于:https://www.cnblogs.com/deadshot123/archive/2007/05/21/753682.html