private void ButtonProperty_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { UIPublic.ShowWaitingForm(); var propertyValue = EditValue; var objectType = propertyValue.GetType(); BaseObjectEditControl editControl = null; // 如果不是PaoObject类型,则显示默认编辑控件 if (!objectType.IsAddonType()) { editControl = EditorPublic.CreateEditControl(objectType) as BaseObjectEditControl; } if (editControl == null) { var editController = EditorPublic.GetOrCreateEditControllerFromStorage <ObjectLayoutEditController>(objectType); editControl = editController.CreateEditControl(objectType) as BaseObjectEditControl; } editControl.EditValue = IOPublic.ObjectClone(propertyValue); UIPublic.CloseWaitingForm(); if (WinFormPublic.ShowDialog(editControl) == DialogReturn.OK) { EditValue = editControl.EditValue; } SetControlStatus(); }
/// <summary> /// 获取预定义的编辑控制器 /// </summary> /// <param name="objectType">对象类型</param> /// <param name="propertyName">属性名称</param> /// <returns>编辑控制器</returns> public BaseEditController GetPredefinedEditController(Type objectType, string propertyName) { if (PredefinedEditorTypes.IsNotNullOrEmpty() && PredefinedEditorTypes.ContainsKey(propertyName) && PredefinedEditorTypes[propertyName] != null) { return(EditorPublic.GetOrCreateEditControllerFromStorage(objectType, PredefinedEditorTypes[propertyName])); } return(null); }
private void ButtonRecoverFormat_ItemClick(object sender, ItemClickEventArgs e) { if (DefaultLayoutData.IsNotNullOrEmpty()) { if (UIPublic.ShowYesNoDialog("您是否需要默认格式?") == DialogReturn.Yes) { EditorPublic.RemoveEditControllerFromStorage(EditValue.GetType(), Controller.GetType()); this.PropertyGridControl.SetLayoutData(DefaultLayoutData); } } }
/// <summary> /// 获取默认的编辑控制器 /// </summary> /// <param name="objectType">对象类型</param> /// <param name="editorType">编辑器类型</param> /// <returns>默认编辑控制器</returns> public static BaseEditController GetOrCreateEditControllerFromStorage(Type objectType, Type editorType) { var editController = EditorPublic.GetEditControllerFromStorage(objectType, editorType); if (editController == null) { editController = editorType.CreateInstance() as BaseEditController; EditorPublic.SetEditControllerToStorage(objectType, editController); } return(editController); }
protected override void OnClose() { var editValue = EditValue; var controller = Controller as ObjectPropertyEditController; if (controller != null) { controller.LayoutData = this.PropertyGridControl.GetLayoutData(); // 如果设置了ObjectType,则保存默认配置 if (controller.StaticType && editValue != null) { EditorPublic.SetEditControllerToStorage(editValue.GetType(), controller); } } base.OnClose(); }
protected override void OnClose() { var controller = Controller as ObjectLayoutEditController; if (controller != null) { controller.LayoutData = this.DataLayoutControl.GetLayoutData(); // 如果设置了ObjectType,则保存默认配置 if (controller.StaticType && ObjectType != null) { EditorPublic.SetEditControllerToStorage(ObjectType, controller); } } base.OnClose(); }
public static BaseEditController GetEditController(PropertyDescriptor propertyDescriptor) { BaseEditController editController = null; var editorType = EditorPublic.GetEditorTypeByReflection(propertyDescriptor); if (editorType == null) { editController = GetEditController(propertyDescriptor.PropertyType); } else { editController = editorType.CreateInstance() as BaseEditController; EditorPublic.SetEditControllerToStorage(propertyDescriptor.PropertyType, editController); } return(editController); }
private void PropertyGridControl_CustomRecordCellEdit(object sender, DevExpress.XtraVerticalGrid.Events.GetCustomRowCellEditEventArgs e) { RepositoryItem repositoryItem = null; var propDesc = PropertyGridControl.GetPropertyDescriptor(e.Row); if (propDesc == null) { return; } var controller = Controller as ObjectPropertyEditController; if (controller != null) { var editController = controller.GetPredefinedEditController(propDesc.PropertyType, propDesc.Name); if (editController != null) { repositoryItem = editController.CreateRepositoryItem(propDesc.PropertyType); } } if (repositoryItem == null) { if (propDesc.PropertyType.IsAddon()) { // 如果是插件,统一使用CommonObjectEditControl,这样可以新增空对象 var editController = new CommonObjectEditController(); editController.StartEditProperty(EditValue, propDesc.Name); repositoryItem = editController.CreateRepositoryItem(propDesc.PropertyType); } else { repositoryItem = EditorPublic.CreateRepositoryItem(propDesc); } } if (repositoryItem != null) { e.RepositoryItem = repositoryItem; } }
/// 通用获取或创建编辑器步骤:(BaseObjectEditController中) /// 1. 从BaseObjectEditController中的PredefinedEditors属性中获取编辑控制器; /// 2. 通过类或属性的EditorTypeAttribute获取编辑控制器类型; /// 3. 根据类型获取默认的编辑控制器; /// 4. 从客户端存储中获取编辑控制器的配置; /// 5. 创建编辑器; /// /// 指定数据类型获取编辑器的步骤: /// 1. 通过类或属性的EditorTypeAttribute获取编辑控制器类型; /// 2. 根据类型获取默认的编辑控制器; /// 3. 从客户端存储中获取编辑控制器的配置; /// 4. 创建编辑器; /// /// 指定编辑器类型创建编辑器的步骤: /// 1. 从客户端存储中获取编辑控制器的配置; /// 3. 创建编辑器; public static BaseEditController GetEditController(Type objectType) { BaseEditController editController = null; var editorType = EditorPublic.GetEditorTypeByReflection(objectType); if (editorType == null) { editorType = GetDefaultEditorType(objectType); } if (editorType == null) { return(null); } editController = EditorPublic.GetEditControllerFromStorage(objectType, editorType); if (editController == null) { editController = editorType.CreateInstance() as BaseEditController; EditorPublic.SetEditControllerToStorage(objectType, editController); } return(editController); }
private void PropertyGridControl_PopupMenuShowing(object sender, DevExpress.XtraVerticalGrid.Events.PopupMenuShowingEventArgs e) { if (e.Row != null) { var controller = Controller as ObjectPropertyEditController; if (controller == null) { return; } var propDesc = PropertyGridControl.GetPropertyDescriptor(e.Row); if (propDesc != null) { // 修改字段标题 var menuChangeCaption = new DXEditMenuItem("标题(&C)" , new TextEditController().CreateRepositoryItem(typeof(string))); menuChangeCaption.Width = 100; menuChangeCaption.EditValue = e.Row.Properties.Caption; menuChangeCaption.BeginGroup = true; menuChangeCaption.EditValueChanged += (s, a) => { if (menuChangeCaption.EditValue.IsNull()) { e.Row.Properties.Caption = propDesc.Name; } else { e.Row.Properties.Caption = (string)menuChangeCaption.EditValue; } }; e.Menu.Items.Add(menuChangeCaption); // 增加删除行菜单 var menuHideRow = new DXMenuItem("隐藏行(&D)" , (s, a) => { e.Row.Visible = false; }); e.Menu.Items.Add(menuHideRow); // 增加更改编辑器菜单 var menuChangeEditor = new DXMenuItem("更改编辑器(&E)..." , (s, a) => { Type editControllerType; if (EditorPublic.SelectEditControllerType(propDesc.PropertyType, out editControllerType) == DialogReturn.OK) { if (editControllerType != null) { var editController = editControllerType.CreateInstance() as BaseEditController; if (controller != null) { controller.SetPredfinedEditController(propDesc.Name, editController.GetType()); } } } } , Properties.Resources.renamedatasource_16x16); menuChangeEditor.BeginGroup = true; e.Menu.Items.Add(menuChangeEditor); // 增加恢复编辑器菜单 var menuRecoverEditor = new DXMenuItem("恢复编辑器(&R)" , (s, a) => { if (UIPublic.ShowYesNoDialog("您确定要恢复默认的编辑器吗?") == DialogReturn.Yes) { controller.RemovePredefinedEditController(propDesc.Name); } } , Properties.Resources.clearformatting_16x16); e.Menu.Items.Add(menuRecoverEditor); } // 恢复所有编辑器 var menuClearEditors = new DXMenuItem("恢复所有编辑器(&C)" , (s, a) => { if (UIPublic.ShowYesNoDialog("您确定要恢复所有默认的编辑器吗?") == DialogReturn.Yes) { controller.ClearPredefinedEditControllers(); } } , Properties.Resources.clear_16x16); menuClearEditors.BeginGroup = true; e.Menu.Items.Add(menuClearEditors); } }
private void DataLayoutControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) { if (e.HitInfo.Item != null) { var controller = Controller as ObjectLayoutEditController; if (controller == null) { return; } var layoutItem = e.HitInfo.Item as LayoutControlItem; if (layoutItem == null) { return; } var editControl = layoutItem.Control; var propDesc = editControl.Tag as PropertyDescriptor; if (propDesc != null) { // 修改字段标题 var menuChangeCaption = new DXEditMenuItem("标题(&C)" , new TextEditController().CreateRepositoryItem(typeof(string))); menuChangeCaption.Width = 100; menuChangeCaption.EditValue = layoutItem.Text; menuChangeCaption.BeginGroup = true; menuChangeCaption.EditValueChanged += (s, a) => { if (menuChangeCaption.EditValue.IsNull()) { layoutItem.Text = propDesc.Name; } else { layoutItem.Text = (string)menuChangeCaption.EditValue; } }; e.Menu.Items.Add(menuChangeCaption); // 增加更改编辑器菜单 var menuChangeEditor = new DXMenuItem("更改编辑器(&E)..." , (s, a) => { Type editControllerType; if (EditorPublic.SelectEditControllerType(propDesc.PropertyType, out editControllerType) == DialogReturn.OK) { if (editControllerType != null) { var editController = editControllerType.CreateInstance() as BaseEditController; // 清除前保存配置 controller.LayoutData = this.DataLayoutControl.GetLayoutData(); controller.SetPredfinedEditController(propDesc.Name, editController.GetType()); EditValue = EditValue; } } } , Properties.Resources.renamedatasource_16x16); menuChangeEditor.BeginGroup = true; e.Menu.Items.Add(menuChangeEditor); // 增加恢复编辑器菜单 var menuRecoverEditor = new DXMenuItem("恢复编辑器(&R)" , (s, a) => { if (UIPublic.ShowYesNoDialog("您确定要恢复默认的编辑器吗?") == DialogReturn.Yes) { // 清除前保存配置 controller.LayoutData = this.DataLayoutControl.GetLayoutData(); controller.RemovePredefinedEditController(propDesc.Name); EditValue = EditValue; } } , Properties.Resources.clearformatting_16x16); e.Menu.Items.Add(menuRecoverEditor); } // 恢复所有编辑器 var menuClearEditors = new DXMenuItem("恢复所有编辑器(&C)" , (s, a) => { if (UIPublic.ShowYesNoDialog("您确定要恢复所有默认的编辑器吗?") == DialogReturn.Yes) { // 清除前保存配置 controller.LayoutData = this.DataLayoutControl.GetLayoutData(); controller.ClearPredefinedEditControllers(); EditValue = EditValue; } } , Properties.Resources.clear_16x16); menuClearEditors.BeginGroup = true; e.Menu.Items.Add(menuClearEditors); } }
/// <summary> /// 根据对象填充属性字段 /// </summary> /// <param name="groupItem">组项目</param> /// <param name="objType">对象类型</param> private void RetrieveFields(LayoutControlGroup groupItem, Type objType) { UIPublic.ShowWaitingForm(); this.DataLayoutControl.CloseControl(); EditControls.Clear(); this.DataLayoutControl.Clear(true, true); var controller = Controller as ObjectLayoutEditController; if (objType == null) { return; } this.DataLayoutControl.SuspendLayout(); TabbedControlGroup tabbledGroup = null; foreach (PropertyDescriptor propDesc in TypeDescriptor.GetProperties(objType)) { if (!propDesc.IsBrowsable) { continue; } BaseEditController editController = null; Control editControl = null; if (controller != null) { editController = controller.GetPredefinedEditController(propDesc.PropertyType, propDesc.Name); } if (editController == null) { if (propDesc.PropertyType.IsAddon()) { var commonEditController = new CommonObjectEditController(); commonEditController.StartEditProperty(EditValue, propDesc.Name); editController = commonEditController; } else { editController = EditorPublic.GetEditController(propDesc); } } editControl = editController.CreateEditControl(propDesc.PropertyType); if (editControl.GetType().GetProperty("EditValue") == null) { throw new Exception("编辑控件必须实现EditValue属性"); } LayoutControlItem layoutControlItem = null; if (editControl is BaseObjectEditControl) { if (tabbledGroup == null) { tabbledGroup = groupItem.AddTabbedGroup(); } var layoutGroupItem = tabbledGroup.AddTabPage(); layoutGroupItem.Name = "Group_" + propDesc.Name; layoutGroupItem.Text = propDesc.DisplayName; layoutGroupItem.CustomizationFormText = "组_" + propDesc.DisplayName; layoutGroupItem.Padding = new DevExpress.XtraLayout.Utils.Padding(0); layoutControlItem = layoutGroupItem.AddItem(); layoutControlItem.TextLocation = DevExpress.Utils.Locations.Top; } else { layoutControlItem = groupItem.AddItem(); layoutControlItem.TextLocation = DevExpress.Utils.Locations.Left; } EditControls.Add(propDesc, editControl); editControl.Tag = propDesc; editControl.Name = propDesc.Name; layoutControlItem.Control = editControl; layoutControlItem.Name = propDesc.Name; layoutControlItem.Text = propDesc.DisplayName; layoutControlItem.CustomizationFormText = propDesc.DisplayName; if (editControl is BaseObjectEditControl) { layoutControlItem.TextVisible = false; } else { layoutControlItem.TextVisible = true; } } this.DataLayoutControl.ResumeLayout(); this.DataLayoutControl.SetDefaultLayout(); // 读取布局数据 if (controller != null && controller.LayoutData.IsNotNullOrEmpty()) { this.DataLayoutControl.SetLayoutData(controller.LayoutData); } UIPublic.CloseWaitingForm(); }