12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Web.Controls.Mvc
- {
- public class SystemClock : BaseControl
- {
- public bool? IsJump { get; set; }
- public SystemClock()
- {
- }
- public static SystemClock CreateControl(SystemClockOptions options, Dictionary<string, string> attributes = null)
- {
- SystemClock systemClock = new SystemClock();
- if (attributes != null)
- systemClock.Attributes = attributes;
- systemClock.CssClass = options.CssClass;
- systemClock.ID = options.ID;
- systemClock.IsJump = options.IsJump;
- return systemClock;
- }
- public override string Render()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("<span name='SystemClock' ");
- sb.Append(string.Join(" ", GetAttributesList().Select(x => string.Format("{0}=\"{1}\"", x.Key, x.Value))));
- sb.Append(" >");
- sb.AppendFormat("<span>{0}</span> <span>{1}</span>",
- DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss"),
- System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)
- );
- sb.Append("</span>");
- if (IsJump.HasValue && IsJump.Value)
- sb.Append("<script type = \"text/javascript\" language = \"javascript\"> $(function () { var timer_SystemClock_" + ID + " = setInterval(\"BowinFunction.UpdateClockFun('" + ID + "')\",1000); });</script>");
- return sb.ToString();
- }
- public Dictionary<string, string> GetAttributesList()
- {
- Dictionary<string, string> attributesList = new Dictionary<string, string>();
- if (!string.IsNullOrEmpty(this.CssClass))
- attributesList.Add("class", this.CssClass);
- attributesList.Add("id", this.ID);
- return attributesList;
- }
- }
- }
|