DictionaryDropdownListColumn.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using EMIS.ViewModel;
  6. using Bowin.Common.JSON;
  7. using Bowin.Web.Controls.Mvc;
  8. using EMIS.Utility;
  9. namespace EMIS.Web.Controls
  10. {
  11. public class DictionaryDropdownListColumn : EditableColumn
  12. {
  13. public DictionaryItem DictionaryType { get; set; }
  14. public string FieldName { get; set; }
  15. protected override IDictionary<string, string> GetOptionsList()
  16. {
  17. var dictOptions = base.GetOptionsList();
  18. dictOptions.Add("columnType", "'dictionary'");
  19. //dictOptions.Add("dictionaryData",
  20. // string.Concat("[",
  21. // string.Join(",", DictionaryHelper.GetDictionaryValue(DictionaryType).Select(x => string.Format("{{ Text:'{0}',Value:'{1}' }}", x.Name, x.Value))),
  22. // "]"));
  23. dictOptions.Add("dictionaryCode", "'" + DictionaryType.ToString() + "'");
  24. if (!string.IsNullOrEmpty(FieldName))
  25. dictOptions.Add("fieldname", "\'" + FieldName + "\'");
  26. else
  27. throw new Exception("必须指定FieldName属性。");
  28. if (this.IsRequired.HasValue && this.IsRequired.Value)
  29. {
  30. if (this.Validator == null)
  31. {
  32. this.Validator = new DropdownListRequiredValidator();
  33. }
  34. dictOptions.Add("validateClass", "'" + this.Validator.ValidatorClass + "'");
  35. dictOptions.Add("validateOption", this.Validator.GetOptions().ToJson().Replace("\"", "'"));
  36. }
  37. return dictOptions;
  38. }
  39. }
  40. }