EditorHelper.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using DevExpress.XtraEditors;
  2. using Ips.Library.Basic;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace Ips.Library.DxpLib
  10. {
  11. public class EditorHelper
  12. {
  13. public static void SaveEditorToAppConfig(Control container)
  14. {
  15. if (container == null) return;
  16. foreach (Control ctrl in container.Controls)
  17. {
  18. if (ctrl is BaseEdit)
  19. {
  20. var self = (BaseEdit)ctrl;
  21. var objVal = self.EditValue;
  22. ToolConfig.SetAppSetting(self.Name, objVal == null ? "" : objVal.ToString());
  23. }
  24. else
  25. {
  26. SaveEditorToAppConfig(ctrl);
  27. }
  28. }
  29. }
  30. public static void LoadEditorFromAppConfig(Control container)
  31. {
  32. if (container == null) return;
  33. foreach (Control ctrl in container.Controls)
  34. {
  35. if (ctrl is BaseEdit)
  36. {
  37. var self = (BaseEdit)ctrl;
  38. string configVal = ToolConfig.GetAppSetting(self.Name);
  39. if (self is CheckEdit)
  40. {
  41. bool bVal;
  42. bool.TryParse(configVal, out bVal);
  43. self.EditValue = bVal;
  44. }
  45. else
  46. {
  47. if (self.EditValue != null && self.EditValue is Enum)
  48. {
  49. self.EditValue = configVal.To(self.EditValue);
  50. }
  51. else
  52. {
  53. self.EditValue = configVal;
  54. }
  55. }
  56. }
  57. else
  58. {
  59. LoadEditorFromAppConfig(ctrl);
  60. }
  61. }
  62. }
  63. }
  64. }