我需要帮助。我需要根据CurrentUserID启用某些字段。有一个字段是包含员工姓名的UltraCombo。选择员工姓名时,如果CurrentUserID与所选员工的姓名匹配,则应启用其他字段。否则,应锁定其他字段。我试图在代码中使用CanView方法,但我不知道如何在SQL命令中调用。请帮帮我T-T
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();
}发布于 2017-02-27 19:44:34
您正在尝试做的是在客户端上,但是客户端只连接到AppServer,而不连接到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);不清楚您要匹配哪些字段或要禁用哪些字段,但希望这能让您开始使用它。
https://stackoverflow.com/questions/42428930
复制相似问题