123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Web.Controls.Mvc
- {
- public class Combotree : BaseControl
- {
- public Combotree()
- : base()
- {
- Enable = true;
- }
- public bool? Enable { get; set; }
- public bool Required { get; set; }
- public string DataSourceUrl { get; set; }
- public string Style { get; set; }
- public object SelectedValue { get; set; }
- public string DataCondition { get; set; }
- public override string Render()
- {
- StringBuilder htmlBuilder = new StringBuilder();
- htmlBuilder.Append("<input ");
- htmlBuilder.Append(string.Join(" ", GetPropertyList().Select(x => string.Format("{0}=\"{1}\"", x.Key, x.Value))));
- htmlBuilder.AppendLine(" />");
- return htmlBuilder.ToString();
- }
- public static BaseControl CreateControl(CombotreeOptions combotreeOptions, IDictionary<string, object> attributes = null)
- {
- Combotree combotree = new Combotree();
- combotree.ID = combotreeOptions.ID;
- combotree.CssClass = combotreeOptions.CssClass;
- combotree.DataSourceUrl = combotreeOptions.DataSourceUrl;
- combotree.Style = combotreeOptions.Style;
- //combotree.Required = combotreeOptions.Required;
- combotree.SelectedValue = combotreeOptions.SelectedValue;
- combotree.Name = combotreeOptions.Name;
- combotree.DataCondition = combotreeOptions.DataCondition;
- if (attributes != null)
- {
- Dictionary<string, string> _attr = new Dictionary<string, string>();
- attributes.ToList().ForEach(it =>
- {
- _attr.Add(it.Key, (it.Value ?? "").ToString());
- });
- combotree.Attributes = _attr;
- }
- return combotree;
- }
- protected Dictionary<string, string> GetPropertyList()
- {
- var dictPropertyList = new Dictionary<string, string>();
- if (!string.IsNullOrEmpty(this.ID))
- {
- dictPropertyList.Add("id", this.ID);
- }
- if (!string.IsNullOrEmpty(this.Name))
- {
- dictPropertyList.Add("name", this.Name);
- }
- if (!string.IsNullOrEmpty(this.DataCondition))
- {
- dictPropertyList.Add("data-condition", this.Name);
- }
- //if (this.SelectedValue != null)
- //{
- // dictPropertyList.Add("value", this.SelectedValue.ToString());
- //}
- if (!string.IsNullOrEmpty(Style))
- dictPropertyList.Add("style", this.Style);
- dictPropertyList.Add("class", string.Format("easyui-combotree {0}", this.CssClass == null ? "" : this.CssClass));
- #region data-options
- var dictOptions = new Dictionary<string, string>();
- if (!string.IsNullOrWhiteSpace(this.DataSourceUrl))
- {
- dictOptions.Add("url", "'" + this.DataSourceUrl + "'");
- }
- if (this.SelectedValue != null)
- {
- dictOptions.Add("value", "'" + this.SelectedValue.ToString() + "'");
- }
- //dictOptions.Add("required", "'" + this.Required.ToString() + "'");
-
-
-
- if (Attributes.ContainsKey("data-val-required"))
- {
- //dictOptions.Add("required", "'false'");
- //dictOptions.Add("missingMessage", "'" + Attributes["data-val-required"] + "'");
- }
- dictPropertyList.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value))));
- #endregion
- //Where(w => w.Key != "data-val")
- Attributes.ToList().ForEach(it =>
- {
- dictPropertyList.Add(it.Key, it.Value);
- });
- return dictPropertyList;
- }
- }
- }
|