123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Web.Controls.Mvc
- {
- public class Button:BaseControl
- {
- public Button()
- {
- Enable = true;
- IsPlain = false;
- }
- public ButtonIcon? Icon { get; set; }
- public string Text { get; set; }
- public bool? Enable { get; set; }
- public bool? IsPlain { get; set; }
- public string OnClick { get; set; }
- public override string Render()
- {
- StringBuilder htmlBuilder = new StringBuilder();
- htmlBuilder.Append("<a href=\"javascript:void(0);\" ");
- htmlBuilder.Append(string.Join(" ", GetPropertyList().Select(x => string.Format("{0}=\"{1}\"", x.Key, x.Value))));
- htmlBuilder.AppendLine(" >");
- if (!string.IsNullOrEmpty(this.Text))
- {
- htmlBuilder.AppendLine(this.Text);
- }
- else
- {
- htmlBuilder.AppendLine(" ");
- }
- htmlBuilder.AppendLine("</a> ");
- return htmlBuilder.ToString();
- }
- protected IDictionary<string, string> GetPropertyList()
- {
- var dictPropertyList = new Dictionary<string, string>();
- if (!string.IsNullOrEmpty(this.ID))
- {
- dictPropertyList.Add("id", this.ID);
- }
- dictPropertyList.Add("class", string.Format("easyui-linkbutton {0}", string.IsNullOrEmpty(this.CssClass) ? "" : this.CssClass));
- dictPropertyList.Add("href", "javascript:void(0);");
- if (!string.IsNullOrEmpty(this.OnClick))
- {
- dictPropertyList.Add("onclick", this.OnClick );
- }
- #region data-options
- var dictOptions = new Dictionary<string, string>();
- if (Icon.HasValue)
- {
- dictOptions.Add("iconCls", "'" + ButtonIconHelper.GetButtonIconClass(Icon.Value) + "'");
- }
- if (IsPlain.HasValue)
- {
- dictOptions.Add("plain", IsPlain.ToString().ToLower());
- }
- if (Enable.HasValue)
- {
- dictOptions.Add("disabled", (!Enable).ToString().ToLower());
- }
- dictPropertyList.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value))));
- #endregion data-options
- if (Enable.HasValue && !Enable.Value)
- {
- dictPropertyList.Add("disabled", "disabled");
- }
- return dictPropertyList;
- }
- public static Button CreateControl(ButtonOptions buttonOptions, IDictionary<string, string> attributes = null)
- {
- Button button = new Button();
- if (attributes != null)
- {
- button.Attributes = attributes;
- }
- button.CssClass = buttonOptions.CssClass;
- button.Icon = buttonOptions.Icon;
- button.ID = buttonOptions.ID;
- button.Text = buttonOptions.Text;
- button.IsPlain = buttonOptions.IsPlain;
- button.Enable = buttonOptions.Enable;
- button.OnClick = buttonOptions.OnClick;
- return button;
- }
- }
- }
|