2017-02-24 65 views
0

我需要幫助。我需要啓用某些字段取決於CurrentUserID。有一個字段是UltraCombo包含的員工姓名。選擇員工姓名時,如果CurrentUserID與所選員工姓名匹配,則應啓用其他字段。否則,應該鎖定其他字段。我試圖在代碼中使用CanView方法,但我不知道如何在SQL命令中調用。普萊舍幫助我的T形啓用某些字段的權限取決於CurrentUserID Epicor ERP10

private bool CanView(string field) 
{ 
    bool result = true; 
    EpiDataView edv = oTrans.EpiDataViews["CallContextClientData"] as EpiDataView; 
    string CurrentUser = edv.dataView[edv.Row]["CurrentUserId"].ToString(); 
    string ConnectionString = "Data Source=RWNAERP;Initial Catalog=ERP10TESTRWNA;Persist Security Info=True;User ID=sa;Password=Epicor10"; 
    string CompanyId = ((Ice.Core.Session)(oTrans.Session)).CompanyID; 
    string UserID = ((Ice.Core.Session)(oTrans.Session)).UserID; 
    using (SqlConnection connection1 = new SqlConnection(ConnectionString)) 
    { 
     DataTable dt = new DataTable(); 
     connection1.Open(); 
     SqlCommand cmd = new SqlCommand("SELECT DcdUserID FROM dbo.UserFile WHERE [email protected] AND [email protected]", connection1); 
     cmd.CommandType = CommandType.Text; 
     cmd.Parameters.Add("DcdUserID", SqlDbType.NVarChar).Value = UserID; 
     SqlDataAdapter sqlDa = new SqlDataAdapter(cmd); 
     sqlDa.Fill(dt); 
     if (dt.Rows.Count > 0) 
     { 
      result = false; 
     } 
     if (CurrentUser != "") 
     { 
      result = true; 
     } 
     connection1.Close(); 
     connection1.Dispose(); 
    } 

回答

0

你所要做的是在客戶端,但客戶端只能連接到應用服務器,從來沒有到SQL數據庫。只有AppServer應該連接到數據庫。

假設你正在添加此代碼作爲自定義腳本,它得到會話變量的當前用戶信息即

 var session = (Ice.Core.Session)oTrans.Session; 
     var userId = session.UserID; 
     var userName = session.UserName; 
     var userEmail = session.UserEmail; 

在Epicor.exe客戶端禁用領域更容易與RowRule最好做,即

 var callContextClientData = oTrans.Factory("CallContextClientData"); 
     var disableFieldsForUser = new RowRule("CurrentUserId", RuleCondition.Equals, ((Ice.Core.Session)trans.Session).UserID); 
     disableFieldsForUser.AddAction(RuleAction.AddControlSettings(stockDtlEpiDataView, "CallContextClientData.ShortChar01", SettingStyle.Disabled)); 
     callContextClientData.AddRowRule(disableFieldsForUser); 

您不清楚哪些字段您匹配或您想禁用,但希望這應該讓你開始。