我正在使用MVP模式编程。 在Task类中,我调用了函数。
private List<ValuePair > DisplayUserRole(string sName)
{
MySqlConnection connection = DbAccess.OpenConnection(ConnectionStringName.LabTrack);
_mapper1 = new UserAuthorizationMapper(connection);
int ixCustomer=1;
int ixProgram=1;
int ixWorkPackage=1;
int ixActivity=1;
string ixUsercode="626e28e8-e67a-4d11-8d2c-129d0ab79e96";
bool isUserAuthorized = _mapper1.IsUserAuthorised(sName, ixCustomer, ixProgram, ixWorkPackage, ixActivity, ixUsercode);
List<ValuePair> listUserRoleValuePair = new List<ValuePair>();
var ixUserList= _mapper1.FindUserRoleLike(sName,ixCustomer,ixProgram,ixWorkPackage,ixActivity);
User user = null;
foreach (var ixUser in ixUserList)
{
user = new UserMapper(connection).FindById(ixUser);
if (user != null)
{
var name = user.SFirstName + " " + user.SLastName;
listUserRoleValuePair.Add(new ValuePair(ixUser, name));
}
}
return listUserRoleValuePair;
}
在Mapper类中我在select查询中得到ArgumentoutofRangeException,说“索引和长度必须引用字符串中的位置”。
public bool IsUserAuthorised(string userRole, int ixCustomer, int ixProgram, int ixWorkPackage, int ixActivity, string ixUser)
{
bool result = false;
SelectAll(Cmd(@"SELECT CASE WHEN Count(*)>=1 THEN 'True' "+
" ELSE 'False' END AS IsUserAuthorised " +
" FROM (SELECT ua.ixUserAuthorization FROM tblechecklistuserroleassignmentxref ra "+
" INNER JOIN tblechecklistuserrole ur ON ur.ixUserRole=ra.ixUserRole AND ur.sname='?0' "+
" INNER JOIN tblechecklistuserauthorization ua ON au.ixUserAuthorization=ra.ixUserAuthorization "+
" AND ua.ixcustomer='?1'AND ua.ixprogram='?2'AND ua.ixworkpackage='?3'AND ua.ixactivity='?4' "+
" AND ua.ixUser='?5') a ",
userRole,
ixCustomer,
ixProgram,
ixWorkPackage,
ixActivity,
ixUser ),
delegate(MySqlDataReader reader)
{
result=Convert.ToBoolean(GetDbValue<string>(reader,"isUserAuthorised"));
});
return result;
}
如何修改我的查询以获取要执行的代码。
答案 0 :(得分:1)
不是
的简单情况result=Convert.ToBoolean(GetDbValue<string>(reader,"isUserAuthorised"));
需要
result=Convert.ToBoolean(GetDbValue<string>(reader,"IsUserAuthorised")); (capitalised)
我猜你的错误是搜索结果而不是查询...
答案 1 :(得分:1)
问号后没有单引号。
public bool IsUserAuthorised(string userRole, int ixCustomer, int ixProgram, int ixWorkPackage, int ixActivity, string ixUser)
{
bool result = false;
SelectAll(Cmd(@"SELECT CASE WHEN Count(*)>=1 THEN 'True' ELSE 'False' END AS IsUserAuthorised " +
" FROM (SELECT ua.ixUserAuthorization FROM tblechecklistuserroleassignmentxref ra "+
" INNER JOIN tblechecklistuserrole ur ON ur.ixUserRole=ra.ixUserRole AND ur.sname=?0 "+
" INNER JOIN tblechecklistuserauthorization ua ON au.ixUserAuthorization=ra.ixUserAuthorization "+
" AND ua.ixcustomer=?1 AND ua.ixprogram=?2 AND ua.ixworkpackage=?3AND ua.ixactivity=?4 "+
" AND ua.ixUser=?5) a ", userRole,
ixCustomer,
ixProgram,
ixWorkPackage,
ixActivity, ixUser ), delegate(MySqlDataReader reader)
{
结果= Convert.ToBoolean(GetDbValue(阅读器 “isUserAuthorised”));
});
返回结果;
}