displaydate.cs

来自「C#邮件代码库,用于邮件发送」· CS 代码 · 共 115 行

CS
115
字号
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
	using System.ComponentModel;

    //*********************************************************************
    //
    // DisplayDate Class
    //
    // Abstract class for displaying date
    //
    //*********************************************************************
	[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]	
    public abstract class DisplayDate : WebControl {

        string _dateFormatString = "{0:D}";
        private bool _displayTimeZone = true;


        //*********************************************************************
        //
        // Date Property
        //
        // Override in derived class to display date.
        //
        //*********************************************************************
        abstract public DateTime Date { get; }


        //*********************************************************************
        //
        // DateFormatString Property
        //
        // Format string for displaying date.
        //
        //*********************************************************************
        public string DateFormatString {
            get { return _dateFormatString;}
            set {_dateFormatString = value;}
        }
        


        //*********************************************************************
        //
        // DisplayTimeZone Property
        //
        // Determines whether time zone is displayed.
        //
        //*********************************************************************
        public bool DisplayTimeZone {
            get { return _displayTimeZone; }
            set { _displayTimeZone = value; }
        }


        //*********************************************************************
        //
        // LocalTimeZoneAbbreviation Property
        //
        // Get the abbreviated name of server time zone.
        //
        //*********************************************************************
        private string LocalTimeZoneAbbreviation {
            get {
				string _abb;
				System.Collections.Specialized.NameValueCollection nvc = (System.Collections.Specialized.NameValueCollection)
				System.Configuration.ConfigurationSettings.GetConfig("communityStarterKit/Isp");
				 _abb = (string)nvc["TimeZoneAbbreviation"];
				if(_abb == null)
				{
					string[] splitTZ = TimeZone.CurrentTimeZone.StandardName.Split(' ');
					_abb = String.Empty;
					foreach (string word in splitTZ)
					{
						_abb += word[0];
					}
				}
                return _abb;    
            }
        }




        //*********************************************************************
        //
        // RenderContents Method
        //
        // Display content by retrieving content from context
        //
        //*********************************************************************
        override protected void RenderContents(HtmlTextWriter writer) {
            // Write date
			System.Collections.Specialized.NameValueCollection nvc = (System.Collections.Specialized.NameValueCollection)
			System.Configuration.ConfigurationSettings.GetConfig("communityStarterKit/Isp");
			if(nvc["GmtTimeOffset"] != null)
			{
				double timeOffset =  Convert.ToDouble(nvc["GmtTimeOffset"]);
				writer.Write(String.Format(_dateFormatString, Date.AddHours(timeOffset)));
			}
			else
			{
				writer.Write(String.Format(_dateFormatString, Date.ToLocalTime() ));
			}
			if (_displayTimeZone)
				writer.Write( String.Format(" <span class=\"TimeZone\">({0})</span>", LocalTimeZoneAbbreviation));
        }


    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?