首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >启用某些字段的权限取决于CurrentUserID Epicor ERP10

启用某些字段的权限取决于CurrentUserID Epicor ERP10
EN

Stack Overflow用户
提问于 2017-02-24 08:52:15
回答 1查看 360关注 0票数 1

我需要帮助。我需要根据CurrentUserID启用某些字段。有一个字段是包含员工姓名的UltraCombo。选择员工姓名时,如果CurrentUserID与所选员工的姓名匹配,则应启用其他字段。否则,应锁定其他字段。我试图在代码中使用CanView方法,但我不知道如何在SQL命令中调用。请帮帮我T-T

代码语言:javascript
复制
    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 Name=@Name AND EmpID=@EmpID", 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();
    }
EN

回答 1

Stack Overflow用户

发布于 2017-02-27 19:44:34

您正在尝试做的是在客户端上,但是客户端只连接到AppServer,而不连接到SQL数据库。只有AppServer应该连接到数据库。

假设您将此代码作为自定义脚本添加,则从会话变量获取当前用户信息要容易得多。

代码语言:javascript
复制
        var session = (Ice.Core.Session)oTrans.Session;
        var userId = session.UserID;
        var userName = session.UserName;
        var userEmail = session.UserEmail;

在Epicor.exe客户端的禁用字段中,最好使用RowRule,即

代码语言:javascript
复制
        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);

不清楚您要匹配哪些字段或要禁用哪些字段,但希望这能让您开始使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42428930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档