当然不行了,userRightCharacter.UserValRight(); 改变的只是userRightCharacter对象内声明的那个UserDataRight对象,并没有影响到userDataRight对象.
你可以修改public void UserValRight()为public void UserValRight(out UserDataRight userDataRights),然后将userDataRight对象传入
userRightCharacter.UserValRight(out userDataRight);
你可以修改public void UserValRight()为public void UserValRight(out UserDataRight userDataRights),然后将userDataRight对象传入
userRightCharacter.UserValRight(out userDataRight);
{ struct UserDataRight
{
public bool UserDelRight; //删除权限
public bool UserSelRight ; //查询权限
public bool UserAddRight; //新增权限
public bool UserEditRight; //编辑权限
public bool UserSaveRight; //保存权限
}
public class UserCharacter
{
protected string strUserID;
public UserCharacter()
{ }
public UserCharacter(string UserID)
{
this.strUserID=UserID; } public void UserValRight(out UserDataRight userDataRight){
try
{
//此处连接数据库部分省略 SqlDataReader userGroupRecord=cmdUserRight.ExecuteReader();
//初始化权限
userDataRight.UserAddRight=false;
userDataRight.UserDelRight=false;
userDataRight.UserEditRight=false;
userDataRight.UserSaveRight=false;
userDataRight.UserSelRight=false;
while(userGroupRecord.Read()){
//判断是否有查询权限
if(userGroupRecord.GetValue(3).ToString()=="1"){
userDataRight.UserSelRight=true;
}
}
userGroupRecord.Close(); } catch(SqlException sqlE){
MessageBox.Show("数据库连接错误!"+sqlE.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}catch(Exception e){MessageBox.Show("异常错误!"+e.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}////////////////////调用部分的代码是UserCharacter userRightCharacter=new UserCharacter("001");
UserDataRight userDataRights;
userDataRights=new UserDataRight();
userRightCharacter.UserValRight(out userDataRights);
if(userDataRights.UserAddRight==true)
{
MessageBox.Show("有新增权限");
}else{
MessageBox.Show("sdddd");
}
////////////////////
错误是E:\CRM\CRM_LANDSERVER\classPackage\UserCharacter.cs(50): The out parameter 'userDataRight' must be assigned to before control leaves the current method////////////////////非常感谢yqdeng(享受生活每一天)兄弟!!!