123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using DevExpress.XtraEditors;
- using Ips.Library.Basic;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Ips.Library.DxpLib
- {
- public class EditorHelper
- {
- public static void SaveEditorToAppConfig(Control container)
- {
- if (container == null) return;
- foreach (Control ctrl in container.Controls)
- {
- if (ctrl is BaseEdit)
- {
- var self = (BaseEdit)ctrl;
- var objVal = self.EditValue;
- ToolConfig.SetAppSetting(self.Name, objVal == null ? "" : objVal.ToString());
- }
- else
- {
- SaveEditorToAppConfig(ctrl);
- }
- }
- }
- public static void LoadEditorFromAppConfig(Control container)
- {
- if (container == null) return;
- foreach (Control ctrl in container.Controls)
- {
- if (ctrl is BaseEdit)
- {
- var self = (BaseEdit)ctrl;
- string configVal = ToolConfig.GetAppSetting(self.Name);
- if (self is CheckEdit)
- {
- bool bVal;
- bool.TryParse(configVal, out bVal);
- self.EditValue = bVal;
- }
- else
- {
- if (self.EditValue != null && self.EditValue is Enum)
- {
- self.EditValue = configVal.To(self.EditValue);
- }
- else
- {
- self.EditValue = configVal;
- }
- }
- }
- else
- {
- LoadEditorFromAppConfig(ctrl);
- }
- }
- }
- }
- }
|