PostionBar.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. namespace Bowin.Web.Controls.Mvc
  7. {
  8. public class PostionBar : BaseControl
  9. {
  10. public List<PostionBarButton> ButtonList { get; set; }
  11. public List<ToolbarButton> ToolButtonList { get; set; }
  12. public string NavIconUrl { get; set; }
  13. private string cssClassName;
  14. public string CssClassName
  15. {
  16. get{return cssClassName;}
  17. set
  18. {
  19. cssClassName=value;
  20. if (string.IsNullOrWhiteSpace(cssClassName))
  21. cssClassName = "current_navbar";
  22. }
  23. }
  24. public string PostionInnerHtml { get; set; }
  25. public PostionBar()
  26. {
  27. ButtonList = new List<PostionBarButton>();
  28. ToolButtonList = new List<ToolbarButton>();
  29. NavIconUrl = "/Content/themes/metro-blue/sysImages/Nav.gif";
  30. }
  31. public Dictionary<string, string> GetAttributesList()
  32. {
  33. Dictionary<string, string> attributesList = new Dictionary<string, string>();
  34. attributesList.Add("id", this.ID);
  35. if (!string.IsNullOrEmpty(this.CssClass))
  36. attributesList.Add("class", this.CssClass);
  37. else
  38. attributesList.Add("class", "style5");
  39. return attributesList;
  40. }
  41. public static PostionBar CreateControl(PostionBarOptions postionBarOptions, IDictionary<string, string> attributes = null)
  42. {
  43. PostionBar postionBar = new PostionBar();
  44. foreach (var button in postionBarOptions.ButtonList)
  45. {
  46. postionBar.ButtonList.Add(button);
  47. }
  48. if (postionBarOptions.ToolButtonList != null)
  49. {
  50. postionBar.ToolButtonList.AddRange(postionBarOptions.ToolButtonList);
  51. }
  52. postionBar.NavIconUrl = postionBarOptions.NavIconUrl;
  53. postionBar.ID = postionBarOptions.ID;
  54. postionBar.PostionInnerHtml = postionBarOptions.PostionInnerHtml;
  55. postionBar.CssClassName = postionBarOptions.CssClass;
  56. return postionBar;
  57. }
  58. public override string Render()
  59. {
  60. StringBuilder sb = new StringBuilder();
  61. if (string.IsNullOrEmpty(this.ID))
  62. {
  63. sb.AppendLine(string.Concat("<div class='",this.CssClassName,"'>"));
  64. }
  65. else
  66. {
  67. //"<div class=\"current_navbar\" id=\"" + this.ID + "\">"
  68. sb.AppendLine(string.Concat("<div class='",this.CssClassName,"'","id='",this.ID,"'>") );
  69. }
  70. sb.AppendLine(" <div class=\"nav_info\">");
  71. sb.AppendLine(" <ul>");
  72. sb.AppendLine((ButtonList != null && ButtonList.Any()) ? " <li><img width=\"16\" height=\"16\" src=\"" + (string.Concat("/", this.NavIconUrl)).Replace("//", "/") + "\"></li>" : "");
  73. sb.AppendLine(string.Join(" <li><span> --> </span></li>", ButtonList.Select(x => x.Render())));
  74. sb.AppendLine(" </ul>");
  75. sb.AppendLine(" </div>");
  76. sb.AppendLine(string.Format("<div class=\"flow_info\" style=\"float: left;\">{0}</div>", this.PostionInnerHtml ?? ""));
  77. sb.AppendLine(" <div class=\"func_info clearfix\">");
  78. sb.AppendLine(string.Join(" ", ToolButtonList.Select(x => x.Render())));
  79. sb.AppendLine(" </div>");
  80. sb.AppendLine("</div>");
  81. return sb.ToString();
  82. }
  83. }
  84. }