views:

138

answers:

0

Hello, firstly I would like to thank you in advance for any assistance provided. I am new to software development and have designed several Client/Server applications over the last 12 months or so, I am currently working on a project that involves a user logging in to gain access to the application and I am looking at the most efficient and "simple" method of storing the users permissions once logged in to the application which can be used throughout restricting access to certain tabs on the main form. I have created a static class called "User" detailed below:

 static class User
{
    public static int _userID;
    public static string _moduleName;
    public static string _userName;

    public static object[] UserData(object[] _dataRow)
    {
         _userID = (int)_dataRow[0];
        _userName = (string)_dataRow[1];
        _moduleName = (string)_dataRow[2];

        return _moduleName;
    }



}

When the user logs in and they have been authenticated, I wish to store the _moduleName objects in memory so I can control which tabs on the main form tab control they can access, for example; if the user has been assigned the following roles in the database: "Sales Ledger", "Purchase Ledger" they can only see the relevant tabs on the form, by way of using a Switch - Case block once the login form is hidden and the main form is instantiated. I can store the userID and userName variables in the main form once it loads by means of say for example:

Here we process the login data from the user:

DataAccess _dal = new DataAccess();
        switch (_dal.ValidateLogin(txtUserName.Text, txtPassword.Text))
        {
            case DataAccess.ValidationCode.ConnectionFailed:
                MessageBox.Show("Database Server Connection Failed!");
                break;

            case DataAccess.ValidationCode .LoginFailed:
                MessageBox.Show("Login Failed!");
                _dal.RecordLogin(out errMsg, txtUserName.Text, workstationID, false);
                break;

            case DataAccess.ValidationCode .LoginSucceeded:
                frmMain frmMain = new frmMain();
                _dal.GetUserPrivList(out errMsg,2); //< here I access my DB and get  the user permissions based on the current login.

                frmMain.Show();
                this.Hide();
                break;

            default:
                break;
        }

    private void frmMain_Load(object sender, EventArgs e)
    {
        int UserID = User._userID;
    }

That works fine, however the _modules object contains mutiple permissions/roles depending on what has been set in the database, how can I store the multiple values and access them via a Switch-Case block?

Thank you again in advance.