2016-07-18 39 views
0

在SOOrder屏幕上:我有OrderType:C1,C2,CS,SO和C1-> userRole A,C2-> userRole B,CS & SO-> userRole管理員。我想通過userlogin選擇默認Ordertype,如果userlogin = Admin,那麼顯示選擇器是CS & SO。 這是我的代碼編輯器:SOOrderEntry(銷售訂單):在SOOrder屏幕上通過用戶登錄選擇默認值OrderType選擇器

protected void SOOrder_OrderType_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e) 
{ 

    PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles, 
           Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base); 
    if(user != null) 
    { 
    PX.SM.UsersInRoles role = user; 
    if(role.Rolename == "Administrator") 
     e.NewValue = "CS"; 
    else 
     if(role.Rolename == "A") 
     e.NewValue = "C1"; 
     if(role.Rolename == "B") 
     e.NewValue = "C2"; 
    } 
} 

我的結果是:當登錄我們的角色管理員,這表明所有的訂單類型。

回答

0

你可以試試下面

public class CustomOrderTypeSelectorAttribute : PXCustomSelectorAttribute 
    { 
     public CustomOrderTypeSelectorAttribute() 
      : base(typeof(SOOrderType.orderType)) 
     { 
     } 

     public IEnumerable GetRecords() 
     { 
      PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles, 
       Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base); 
      if(user != null) 
      { 

       PXResult<SOOrderType> orderTypes = null; 
       if(roleName == "Administrator") 
       { 
        orderTypes = PXSelect<SOOrderType, 
         Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>, 
          Or<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>>.Select(Base, "CS", "SO"); 
       } 
       else if(roleName == "A") 
       { 
        orderTypes = PXSelect<SOOrderType, 
         Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C1"); 
       } 
       else if(role.Rolename == "B") 
       { 
        orderTypes = PXSelect<SOOrderType, 
         Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C2"); 
       } 

       foreach (var item in orderTypes) 
        yield return item; 
      } 
     } 
    } 

然後使用連接到覆蓋與定製訂單類型屬性選擇上述

+0

緩存我覺得你的構造得到了一個錯誤的名字裏。 – Hybridzz

+0

@Đinh,我大三,所以你能告訴我我是如何把你的編碼? – YSP

+0

@Hybridzz,什麼是構造函數? – YSP