Question

EDIT: Question Reconstructed.

OK, I have revisited my get and set methods, but I am still very unclear on how it all works.

What I want to achieve is the Model is populated by the Controller, from the values that it takes form the form. This is then sent to the Db_Facade, which compares the uName and uPwd, and if they are equal returns the ACCESS, which will be set for the entire scope of the program.

I don't know if the get and set declarations are done correctly, or if they can be bunched together (If this is possible it would be great because I will be using this for much larger collections of data), and I'm pretty sure I'm implementing them wrong as well.

If you can help, my knowledge of Accessors is incredibly limited.

Here is my Compare Login method in my Controller:

    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();
    }

Here is my Model:

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;
        }
    }
}

Here is the dummy database comparison:

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;
        }
      */
    }
}

I don't know if it's needed, but here is my View

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);
    }
}
Was it helpful?

Solution

2 Questions / Hints

1.) Where do you call your getLoginACCESS() ?

2.) Why do you think Db_Facade is able to access getACCESSfrom your class User_Controller?

a solution would be to modyfie your getLoginACCESS() to getLoginACCESS(User_Model getACCESS) and than call it in your Compare_Login(User_Login_View Login_View) befor your if like Db_Facade.etLoginACCESS(getACCESS);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top