1

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

    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();
    }
4

1 回答 1

0

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

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

        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);

目前尚不清楚您正在匹配哪些字段或要禁用哪些字段,但希望这可以帮助您入门。

于 2017-02-27T11:44:33.793 回答