.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

http://www.devexpress.com/Support/Center/p/Q341530.aspx

http://www.devexpress.com/Support/Center/p/S38032.aspx

系統管理工具:管理用戶UI設置,匯入、匯出、復位。

http://www.devexpress.com/example=E968 結合下面代碼一起使用效果更佳。

 

public class ImportExportUserDifferencesController : WindowController
    {
        private SimpleAction exportDifferencesAction;
        private SimpleAction importDifferencesAction;
        public const string ActiveKeyConfiguratorOnly = "ConfiguratorOnly";
        public ImportExportUserDifferencesController()
        {
            exportDifferencesAction = new SimpleAction(this"ExportUserDifferences", PredefinedCategory.Tools);
            exportDifferencesAction.ImageName = "Action_LocalizationExport";
            exportDifferencesAction.Execute += exportDifferencesAction_Execute;
            importDifferencesAction = new SimpleAction(this"ImportUserDifferences", PredefinedCategory.Tools);
            importDifferencesAction.ImageName = "Action_LocalizationImport";
            importDifferencesAction.Execute += importDifferencesAction_Execute;
            this.TargetWindowType = WindowType.Main;
        }
        //public void UpdateActivity()
        
//{
        
//    bool canEditModel = SecuritySystem.IsGranted(new ModelOperationPermissionRequest());
        
//    importDifferencesAction.Active["Security"] = canEditModel;
        
//    exportDifferencesAction.Active["Security"] = canEditModel;
        
//}

        protected virtual void UpdateActivity()
        {
            using (IObjectSpace objectSpace = Application.CreateObjectSpace())
            {
                bool isActive = SecuritySystem.CurrentUserName == DatabaseUserSettingsModule.ConfiguratorUserName
                    || (SecuritySystem.CurrentUser != null && objectSpace.IsObjectFitForCriteria(
                        SecuritySystem.CurrentUser,
                        new FunctionOperator(IsCurrentUserInRoleOperator.OperatorName, new OperandValue(DatabaseUserSettingsModule.ConfiguratorRoleName))
                    ).GetValueOrDefault(false)
                );
                importDifferencesAction.Active[ActiveKeyConfiguratorOnly] = isActive;
                exportDifferencesAction.Active[ActiveKeyConfiguratorOnly] = false;//已經有匯出功能,此處關閉。
            }
        }

        private void exportDifferencesAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.AddExtension = true;
            saveFileDialog.Filter = "Model differences files (*.xafml)|*.xafml";
            saveFileDialog.FileName = ModelDifferenceStore.UserDiffDefaultName + ".xafml";
            if (saveFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
            {
                string file = Path.GetFileNameWithoutExtension(saveFileDialog.FileName);
                string path = Path.GetDirectoryName(saveFileDialog.FileName);
                FileModelStore fileModelStore = new FileModelStore(path, file);
                Frame.SaveModel();
                fileModelStore.SaveDifference(((ModelApplicationBase)Application.Model).LastLayer);
            }
        }
        private void importDifferencesAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.AddExtension = true;
            openFileDialog.Filter = "Model differences files (*.xafml)|*.xafml";
            openFileDialog.FileName = ModelDifferenceStore.UserDiffDefaultName + ".xafml";
            if (openFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
            {
                string file = Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                string path = Path.GetDirectoryName(openFileDialog.FileName);
                FileModelStore fileModelStore = new FileModelStore(path, file);
                ApplicationModelsManager.RereadLastLayer(fileModelStore, Application.Model);
                Frame.View.LoadModel();
                //UpdateActivity();
            }
        }
        //protected override void OnWindowChanging(Window window)
        
//{
        
//    base.OnWindowChanging(window);
        
//    UpdateActivity();
        
//}

        protected override void OnActivated()
        {
            base.OnActivated();
            UpdateActivity();
        } 
    }

 

posted on 2011-10-21 11:39  Tonyyang  阅读(517)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/