博客上的日历控件的初步实现

临时存放

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
using  System.Web.UI;
None.gif
using  System.ComponentModel;
None.gif
None.gif
namespace  ClassLibrary1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class  BlogDateControl:System.Web.UI.WebControls.WebControl,System.Web.UI.INamingContainer,System.Web.UI.IPostBackEventHandler   
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private static readonly object ClickKey=new object();
InBlock.gif
InBlock.gif        [Description(
"单击日期触发的时间!")]
InBlock.gif        
public event EventHandler Click
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            add
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Events.AddHandler(ClickKey, value);
ExpandedSubBlockEnd.gif            }

InBlock.gif            remove
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Events.RemoveHandler(ClickKey, value);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private static readonly string[] header = new string[] dot.gif"星期日""星期一""星期二""星期三""星期四""星期五""星期六" };
InBlock.gif
InBlock.gif        
private DateTime showDate;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Gets or sets the show date.
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <value>The show date.</value>

InBlock.gif        [Description("格式必须为yyyy-MM一样")] 
InBlock.gif        
public string ShowDate
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (showDate == null)
InBlock.gif                    showDate 
= Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");
InBlock.gif                
return showDate.ToString("yyyy-MM"); 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    showDate 
= Convert.ToDateTime(System.DateTime.Now.Year + "-" + System.DateTime.Now.Month + "-01");    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    showDate 
= Convert.ToDateTime(value+"-01");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void AddAttributesToRender(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//为table标签定义属性和样式
InBlock.gif           
// writer.AddAttribute(HtmlTextWriterAttribute.Width, "287px");
InBlock.gif            
//writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "1px");
InBlock.gif
            writer.AddAttribute(HtmlTextWriterAttribute.Border, "1px");
InBlock.gif            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, 
"0");
InBlock.gif            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, 
"0");
InBlock.gif            
base.AddAttributesToRender(writer);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取与此 Web 服务器控件相对应的 <see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 值。此属性主要由控件开发人员使用。
InBlock.gif        
/// </summary>
InBlock.gif        
/// <value></value>
ExpandedSubBlockEnd.gif        
/// <returns><see cref="T:System.Web.UI.HtmlTextWriterTag"></see> 枚举值之一。</returns>

InBlock.gif        protected override HtmlTextWriterTag TagKey
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return HtmlTextWriterTag.Table;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 将控件的内容呈现到指定的编写器中。此方法主要由控件开发人员使用。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"></see>,表示要在客户端呈现 HTML 内容的输出流。</param>

InBlock.gif        protected override void RenderContents(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif           
InBlock.gif            
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Thead);
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
InBlock.gif            writer.AddAttribute(HtmlTextWriterAttribute.Align, 
"center");
InBlock.gif            writer.AddAttribute(HtmlTextWriterAttribute.Colspan, 
"7");
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif            
InBlock.gif            writer.Write(
this.showDate.Year+""+this.showDate.Month+"");
InBlock.gif            writer.RenderEndTag();
InBlock.gif            writer.RenderEndTag();
InBlock.gif            writer.RenderEndTag();
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
InBlock.gif            
for (int i = 0; i < BlogDateControl.header.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif                writer.Write(BlogDateControl.header[i]);
InBlock.gif                writer.RenderEndTag();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            writer.RenderEndTag();
InBlock.gif            DateTime end
=this.showDate.AddMonths(1);
InBlock.gif            
int days=((TimeSpan)end.Subtract(this.showDate)).Days;
InBlock.gif            
int spaceday = Convert.ToInt32(this.showDate.DayOfWeek);
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
InBlock.gif            
for (int i = 0; i < spaceday; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif                writer.WriteLine(
"&nbsp;");
InBlock.gif                writer.RenderEndTag();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
for (int i = 1; i <= days; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.Write(
"<td οnclick=\"");
InBlock.gif
                writer.Write(Page.GetPostBackEventReference(thisthis.ShowDate+"-"+i.ToString().PadLeft(2,'0')));
InBlock.gif                writer.Write(
"\">"+i.ToString()+"</td>");
InBlock.gif
                
InBlock.gif                
//writer.RenderEndTag();
InBlock.gif
                if ((i + spaceday) % 7 == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    writer.RenderEndTag();
InBlock.gif                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
if ((spaceday + days) % 7 != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
int allcount = spaceday + days > 35 ? 42 : 35;
InBlock.gif                
for (int i = 0; i < allcount - spaceday - days; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif                    writer.Write(
"&nbsp;");
InBlock.gif                    
InBlock.gif                    writer.RenderEndTag();
ExpandedSubBlockEnd.gif                }

InBlock.gif                writer.RenderEndTag();
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected virtual void OnClick(StringEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            EventHandler clickEventDelegate 
=
InBlock.gif               (EventHandler)Events[ClickKey];
InBlock.gif            
if (clickEventDelegate != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                clickEventDelegate(
this, e);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IPostBackEventHandler 成员#region IPostBackEventHandler 成员
InBlock.gif
InBlock.gif        
public void  RaisePostBackEvent(string eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif             
//throw new Exception("The method or operation is not implemented.");
InBlock.gif
            OnClick(new StringEventArgs(eventArgument));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif    
public class StringEventArgs : EventArgs
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private string argString;
InBlock.gif
InBlock.gif        
public string ArgString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn argString; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public StringEventArgs(string arg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.argString = arg;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public override string ToString()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return this.argString;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/deadshot123/archive/2007/05/21/753682.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值