SystemClock.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Bowin.Web.Controls.Mvc
  6. {
  7. public class SystemClock : BaseControl
  8. {
  9. public bool? IsJump { get; set; }
  10. public SystemClock()
  11. {
  12. }
  13. public static SystemClock CreateControl(SystemClockOptions options, Dictionary<string, string> attributes = null)
  14. {
  15. SystemClock systemClock = new SystemClock();
  16. if (attributes != null)
  17. systemClock.Attributes = attributes;
  18. systemClock.CssClass = options.CssClass;
  19. systemClock.ID = options.ID;
  20. systemClock.IsJump = options.IsJump;
  21. return systemClock;
  22. }
  23. public override string Render()
  24. {
  25. StringBuilder sb = new StringBuilder();
  26. sb.Append("<span name='SystemClock' ");
  27. sb.Append(string.Join(" ", GetAttributesList().Select(x => string.Format("{0}=\"{1}\"", x.Key, x.Value))));
  28. sb.Append(" >");
  29. sb.AppendFormat("<span>{0}</span> <span>{1}</span>",
  30. DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss"),
  31. System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)
  32. );
  33. sb.Append("</span>");
  34. if (IsJump.HasValue && IsJump.Value)
  35. sb.Append("<script type = \"text/javascript\" language = \"javascript\"> $(function () { var timer_SystemClock_" + ID + " = setInterval(\"BowinFunction.UpdateClockFun('" + ID + "')\",1000); });</script>");
  36. return sb.ToString();
  37. }
  38. public Dictionary<string, string> GetAttributesList()
  39. {
  40. Dictionary<string, string> attributesList = new Dictionary<string, string>();
  41. if (!string.IsNullOrEmpty(this.CssClass))
  42. attributesList.Add("class", this.CssClass);
  43. attributesList.Add("id", this.ID);
  44. return attributesList;
  45. }
  46. }
  47. }