以另一种形式使用方法中的值 [英] Use value from a method in another form
问题描述
我有以下情况:我制作的程序具有三种类型的用户帐户:超级用户,管理员和顾问。
I have the following scenario: a program I made has three type of user accounts: superuser, administrator and consultant.
登录表单可以很好地工作并且可以通过一种方法我可以得到用户的类型并打开相应的用户主要表单。
The login forms works well and through a method I can get the type of the user and open the respective main form of said user.
问题是这样的:用户共享某些表单。但是,我不知道如何让应用程序知道它必须根据用户返回的三种主要形式中的哪一种。
The problem is this: there are some forms that the users share. But, I don't know how to have the application know which of the three main forms it must return depending of the user.
问题是:有一种解决方法保留登录表单中的值(用户类型),并在其他表单上使用它?
Question is: there is a way for keep the value (user type) from the login form and use it on the other forms?
这是我如何获取数据库中type的值:
Here is how I get the value of type in the database:
public string sacartipo()
{string tipo = "";
username = usuario.Text;
obj.Usuario = usuario.Text;
password = contra.Text;
obj.Contrasena = contra.Text;
tipo = obj.Logeo(username, password);
return tipo; //This is the variable that stores the type of user.
}
推荐答案
您可以将用户类型(在用户登录后)存储在会话变量中,例如 Session [ role] = value
并在任何需要的地方使用。
You can store the user type(after the user logs in) in a session variable like Session["role"]=value
and use it anywhere you want.
这篇关于以另一种形式使用方法中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!