zoukankan      html  css  js  c++  java
  • DevExpress XAF 获取当前用户

    代码

    1 Owner = Session.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);

    用户属性

      应用程序的功能可能取决于当前用户。因此,需要获取用户名、用户ID或者整个用户对象。以下是SecuritySystem类公开的属性。

    • SecuritySystem.CurrentUserName      --当前用户名
    • SecuritySystem.CurrentUserId            --当前用户ID
    • SecuritySystem.UserType                   --当前用户类型
    • SecuritySystem.CurrentUser               --当前用户

    SecuritySystem.CurrentUser属性

     1 using DevExpress.ExpressApp;
     2 using DevExpress.ExpressApp.Actions;
     3 using DevExpress.Persistent.Base;
     4 // ... 
     5 public class ShowCurrentUserController : WindowController {
     6     public ShowCurrentUserController() {
     7         PopupWindowShowAction showCurrentUserAction = new PopupWindowShowAction(
     8         this, "ShowCurrentUser", PredefinedCategory.Edit);
     9         showCurrentUserAction.CustomizePopupWindowParams += ShowCurrentUserAction_CustomizePopupWindowParams;
    10     }
    11 
    12     private void ShowCurrentUserAction_CustomizePopupWindowParams(
    13         object sender, CustomizePopupWindowParamsEventArgs e) {
    14         IObjectSpace newObjectSpace = Application.CreateObjectSpace(SecuritySystem.CurrentUser.GetType());
    15         object currentUser = newObjectSpace.GetObject(SecuritySystem.CurrentUser);
    16         e.View = Application.CreateDetailView(newObjectSpace, currentUser);
    17     }
    18 }

     访问标准当前用户

      当需要在筛选条件中使用当前用户时,请使用CurrentUserId函数criteria操作符。

    初始化对象所有者

      将当前对象引用分配给Owner对象。

    1 void IXafEntityObject.OnCreated() {
    2     Owner = objectSpace.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);
    3 }

       XPO对象

    1 public override void AfterConstruction() {
    2     base.AfterConstruction();
    3     if (SecuritySystem.CurrentUser != null) {
    4         Owner = Session.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);
    5     }
    6 }

     根据对象那个所有者配置权限  

      为要筛选的对象类型添加类型权限,并将其AllowRead属性设置为false。

      向该类型权限添加对象权限,将其AllowRead属性设置为true,将Criteria属性设置为“Owner”。Oid = CurrentUserId ()”。

    参考网址

      [1] https://documentation.devexpress.com/eXpressAppFramework/113152/Task-Based-Help/Security/How-to-Get-the-Current-User-in-Code

  • 相关阅读:
    BZOJ1264 [AHOI2006]基因匹配Match 动态规划 树状数组
    BZOJ1845 [Cqoi2005] 三角形面积并 扫描线 计算几何
    BZOJ1258 [CQOI2007]三角形tri 模拟
    BZOJ4972 八月月赛 Problem B 小Q的方格纸 二维前缀和
    BZOJ1218 [HNOI2003]激光炸弹 二维前缀和
    BZOJ1263 [SCOI2006]整数划分 高精度
    BZOJ1209 [HNOI2004]最佳包裹 三维凸包 计算几何
    BZOJ1207 [HNOI2004]打鼹鼠 动态规划
    BZOJ1202 [HNOI2005]狡猾的商人 spfa
    BZOJ1201 [HNOI2005]数三角形 大力出奇迹
  • 原文地址:https://www.cnblogs.com/luyj00436/p/11489360.html
Copyright © 2011-2022 走看看