namespace RSIwelcome
{
    /// <summary>
    /// Description for WebPart1.
    /// </summary>
    [DefaultProperty("Text"),
        ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
        XmlRoot(Namespace = "RSIwelcome")]
    public class RSIwelcome : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private const string defaultText = "";

        private string text = defaultText;

        [Browsable(true),
            Category("Miscellaneous"),
            DefaultValue(defaultText),
            WebPartStorage(Storage.Personal),
            FriendlyName("Text"),
            Description("Text Property")]
        public string Text
        {
            get
            {
                return text;
            }

            set
            {
                text = value;
            }
        }

        public string getTime()
        {
            string strTimeStatus = "";
            int gHour = DateTime.Now.Hour;

            if (gHour > 2 && gHour < 12)
            {
                strTimeStatus = "早安!  ";
            }
            else if (gHour > 11 && gHour < 19)
            {

                strTimeStatus = "午安!  ";
            }
            else if (gHour > 18 || gHour < 3)
            {

                strTimeStatus = "晚安!  ";
            }

            return strTimeStatus;

        }

        protected override void RenderWebPart(HtmlTextWriter output)
        {
            string sUserName = Context.User.Identity.Name;
            sUserName = sUserName.Substring(sUserName.IndexOf("\\") + 1);

            string strUI = "<font size=3 color='#0000FF'><b>Hi!&nbsp;" + getUserName(sUserName) + "&nbsp;" + getTime() + "</b></font>";
            output.Write(strUI);
        }
    }
}

posted on 2006-07-05 00:12  volitation  阅读(172)  评论(0)    收藏  举报