編輯:問題重構。在MVC中使用{get set}訪問器獲取多個值
好的,我已經重新訪問了我的get和set方法,但我仍然不清楚它是如何工作的。
我想要實現的是模型由控制器填充,從它形成的值的形式。然後將它發送到Db_Facade,它將uName和uPwd進行比較,如果它們相等,則返回ACCESS,該值將在程序的整個範圍內設置。
我不知道get和set聲明是否正確完成,或者它們是否可以聚集在一起(如果這可能會很好,因爲我將使用它來獲得更大的數據集合),以及我很確定我也錯誤地執行了它們。
如果可以幫忙,我對Accessors的瞭解是非常有限的。
這裏是我的控制器我比較登錄方法:
public static void Compare_Login(User_Login_View Login_View)
{
User_Model getACCESS = new User_Model(); // Creates a new oject of User_Model
getACCESS.Name = Login_View.txtUsername.Text; //Populates the Model from the Login View
getACCESS.Pwd = Login_View.txtPassword.Text;
if (getACCESS.ACCESSLEVEL > 0)
{
Login_View.Close();
}
else
{
Login_View.lblError.Visible = true;
}
Login_View.Menu.SetMenuView();
}
這裏是我的模型:
public class User_Model
{
public string Name
{
get
{
return Db_Facade.uName;
}
set
{
Db_Facade.uName = value;
}
}
public string Pwd
{
get
{
return Db_Facade.uPwd;
}
set
{
Db_Facade.uPwd = value;
}
}
public int ACCESSLEVEL
{
get
{
return Db_Facade.ACCESS;
}
set
{
Db_Facade.ACCESS = value;
}
}
}
這裏是虛擬數據庫比較:
class Db_Facade
{
public static string uName;
public static string uPwd;
public static string cPwd;
public static int ACCESS;
public static void getLoginACCESS()
{
uName = "paul";
uPwd = "pwd";
ACCESS = 1;
/* I get a "getACCESS does not exist" error here
if (uName == getACCESS.Name && uPwd == getACCESS.Pwd)
{
getACCESS.ACCESSLEVEL = ACCESS;
}
else
{
getACCESS.ACCESSLEVEL = 0;
}
*/
}
}
我不t知道是否需要,但這裏是我的看法
public partial class User_Login_View : Form
{
public Menu_View Menu { get; set; }
public User_Login_View()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
User_Controller.Compare_Login(this);
}
}
什麼是你的問題? – alexmac
我不明白你的代碼試圖做什麼。 – Amy
向我們展示您的視圖模型。從我在這裏可以收集到的信息來看...你完全錯了。 –