⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemdate.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
	using System.Diagnostics;



    //*********************************************************************
    //
    // ItemDate Class
    //
    // Abstract class for displaying a date in a template.
    // This class handles issues with time conversions.
    //
    //*********************************************************************

	public abstract class ItemDate : WebControl {

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



        //*********************************************************************
        //
        // Date Property
        //
        // Stores date in view state.
        //
        //*********************************************************************
        public DateTime Date {
            get { return (DateTime)ViewState["Date"]; }
            set { ViewState["Date"] = value; }
        }



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



        //*********************************************************************
        //
        // DateFormatString Property
        //
        // Enables the date to be formatted.
        //
        //*********************************************************************
        public string DateFormatString {
            get {return _dateFormatString;}
            set {_dateFormatString = value;}
        }



        //*********************************************************************
        //
        // OnDataBinding Method
        //
        // Get the date commented from container.
        //
        //*********************************************************************
        override protected void OnDataBinding(EventArgs e) {
            ContentItem item;

            if (NamingContainer is ContentItem)
                item = (ContentItem)NamingContainer;
            else
                item = (ContentItem)NamingContainer.NamingContainer;


            ContentInfo objContentInfo = (ContentInfo)item.DataItem;
            AssignContentItem(objContentInfo);
        }



        //*********************************************************************
        //
        // AssignContentItem Method
        //
        // Override this method to add an item to the Date property.
        //
        //*********************************************************************
 
         abstract protected void AssignContentItem(ContentInfo contentInfo);



        //*********************************************************************
        //
        // 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
        //
        // Render the date.
        // Note: We convert the date to the local server time.
        //
        //*********************************************************************
        override protected void RenderContents(HtmlTextWriter writer) {
			
			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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -