PageSCValue.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MECF.Framework.Common.DataCenter;
  8. namespace MECF.Framework.UI.Core.View.Common
  9. {
  10. public class PageSCValue
  11. {
  12. protected Dictionary<string, PropertyInfo> _fieldMap = new Dictionary<string, PropertyInfo>();
  13. public PageSCValue()
  14. {
  15. }
  16. public List<string> GetKeys()
  17. {
  18. return _fieldMap.Keys.ToList();
  19. }
  20. public void UpdateKeys(PropertyInfo[] property)
  21. {
  22. _fieldMap.Clear();
  23. foreach (PropertyInfo fiGroup in property)
  24. {
  25. _fieldMap[fiGroup.Name.Replace("_", ".")] = fiGroup;
  26. }
  27. }
  28. public void NewUpdateKeys(PropertyInfo[] property)
  29. {
  30. _fieldMap.Clear();
  31. foreach (PropertyInfo fiGroup in property)
  32. {
  33. var tempStr = fiGroup.Name.Replace("_", ".");
  34. int index = tempStr.LastIndexOf(".");
  35. tempStr=tempStr.Remove(index, 1);
  36. tempStr=tempStr.Insert(index, "_");
  37. _fieldMap[tempStr] = fiGroup;
  38. }
  39. }
  40. public void Update(Dictionary<string, object> result)
  41. {
  42. if (result == null)
  43. return;
  44. foreach (KeyValuePair<string, object> item in result)
  45. {
  46. if (_fieldMap.ContainsKey(item.Key))
  47. {
  48. _fieldMap[item.Key].SetValue(this, item.Value, null);
  49. }
  50. }
  51. }
  52. public void Update(string key, string value)
  53. {
  54. if (!_fieldMap.ContainsKey(key))
  55. return;
  56. if (_fieldMap[key].PropertyType == typeof(double))
  57. {
  58. _fieldMap[key].SetValue(this, Convert.ToDouble(value), null);
  59. }
  60. else if (_fieldMap[key].PropertyType == typeof(int))
  61. {
  62. _fieldMap[key].SetValue(this, Convert.ToInt32(value), null);
  63. }
  64. else if (_fieldMap[key].PropertyType == typeof(string))
  65. {
  66. _fieldMap[key].SetValue(this, value, null);
  67. }
  68. else if (_fieldMap[key].PropertyType == typeof(bool))
  69. {
  70. _fieldMap[key].SetValue(this, Convert.ToBoolean(value), null);
  71. }
  72. }
  73. public Dictionary<string, object> GetValue()
  74. {
  75. Dictionary<string, object> result = new Dictionary<string, object>();
  76. foreach (var item in _fieldMap)
  77. {
  78. result[item.Key] = item.Value.GetValue(this, null);
  79. }
  80. return result;
  81. }
  82. }
  83. }