Closed Thread
Results 1 to 7 of 7

Thread: How would you go about implementing user modes into a desktop application?

  1. #1
    whoiga is offline Newbie
    Join Date
    Jun 2008
    Location
    United States
    Posts
    15
    Rep Power
    0

    How would you go about implementing user modes into a desktop application?

    I'm planning a project for a desktop application that will communicate with a database. I want to incorporate administrative features into the application. Essentially, I'll have two user modes: User, and Admin. A user will have access to necessary form controls & functionality. An admin will have the same access that a user does, but will have access to additional form controls and functionality.

    My problem thus far in the designing phase is that I can't seem to wrap my head around a method of implementation that would keep the code clean and maintainable, while remaining somewhat easy.

    I thought about setting up an enum, and having my user modes within. When a user connects to the database and logs into their account, depending on what flags their account has for their access in the database (perhaps indeed an enum field), the application would set the enum. Then, I would have a function that updates the states of the form controls (and other features) based on the enum, so like... certain context menu items might be disabled, certain textboxes and other controls might become readonly, etc.

    However, I'm not entirely sure that such a methodology will keep things simple and maintainable.


    So here are my two questions:

    How might you go about it?

    If you're not sure, might you know of a good resource (online or text) that I should take a look at? Thus far I've not found very many resources for doing something similar to what I have in mind.
    -Martin

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,494
    Blog Entries
    75
    Rep Power
    143

    Re: How would you go about implementing user modes into a desktop application?

    What you've come up with will probably work. Realize that you have limited yourself to 1) a fixed number of user levels and 2) user level restrictions are hard-coded. User-level access tends to be somewhat non-simple by its nature.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    whoiga is offline Newbie
    Join Date
    Jun 2008
    Location
    United States
    Posts
    15
    Rep Power
    0

    Re: How would you go about implementing user modes into a desktop application?

    Thanks for the feedback. I suppose you're right. I know that I'm sort of limiting myself, but the simple nature of the application I want to create should void the need for additional user modes, though if I did need some, I'd only have to adjust a single method, and if I needed more/less controls, it's just a matter of adding/modifying/removing what happens to them in that method.

    After I posted this thread, I made a quick little application in VS2008 to test my logic and get a feel for what it would be like. It's not the most scalable solution, but as I said the application I want to develop is simple in its nature and it would actually benefit from retaining some simplicity.

    Here's the MainForm.cs code of the little demo I just created:
    [highlight=csharp]using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace EnumUserModeTest
    {
    public partial class MainForm : Form
    {
    public MainForm()
    {
    InitializeComponent();

    SetControls(Mode.User);
    }

    public enum Mode
    {
    User,
    Admin
    }

    private void SetControls(Mode appmode)
    {
    switch (appmode)
    {
    case Mode.Admin:
    this.Text = "Mode: Admin";
    tbUserMessage.ReadOnly = false;
    buttonUserMessage.Enabled = true;
    tbAdminMessage.ReadOnly = false;
    buttonAdminMessage.Enabled = true;
    break;
    case Mode.User:
    this.Text = "Mode: User";
    tbUserMessage.ReadOnly = false;
    buttonUserMessage.Enabled = true;
    tbAdminMessage.ReadOnly = true;
    buttonAdminMessage.Enabled = false;
    break;
    }
    }

    private void buttonUserMessage_Click(object sender, EventArgs e)
    {
    MessageBox.Show(tbUserMessage.Text, "User Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void buttonAdminMessage_Click(object sender, EventArgs e)
    {
    MessageBox.Show(tbAdminMessage.Text, "Admin Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void userToolStripMenuItem_Click(object sender, EventArgs e)
    {
    SetControls(Mode.User);
    }

    private void adminToolStripMenuItem_Click(object sender, EventArgs e)
    {
    SetControls(Mode.Admin);
    }
    }
    }
    [/highlight]
    -Martin

  5. #4
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: How would you go about implementing user modes into a desktop application?

    if i was facing your situation, i would choose a very simple approach, by making one common interface (or forms) and i would make a small form with all the admin controls that opens when the user is admin only...
    but i think yours is better
    yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  6. #5
    Join Date
    May 2008
    Posts
    2,126
    Blog Entries
    1
    Rep Power
    33

    Re: How would you go about implementing user modes into a desktop application?

    I would just put all the controls for every level of user out there. And then just have everything check a user_mode variable before they do anything to check if it has the correct clearance.

  7. #6
    whoiga is offline Newbie
    Join Date
    Jun 2008
    Location
    United States
    Posts
    15
    Rep Power
    0

    Re: How would you go about implementing user modes into a desktop application?

    I suppose I could do that, though I think it wouldn't be as clean, and it might seem disheartening or annoying for a user to constantly find out what he/she can't do, which might make the application more difficult to learn or use.

    I have considered having a separate form with administrative features residing within it, though I'd still be using an enum & a control adjustment method to render it accessible/inaccessible based on the user's level.

    Oh well. I'll find out what works (and what doesn't) soon enough.
    -Martin

  8. #7
    gaylo565's Avatar
    gaylo565 is offline Programming Professional
    Join Date
    May 2007
    Location
    flagstaff, az
    Posts
    268
    Rep Power
    21

    Re: How would you go about implementing user modes into a desktop application?

    I would create a base class then a method for a general user sign in as well as one for the admin. The methods would add the appropriate controls to your form as well as the text for a welcome message or anything else unique to the user. Generally when you create a user system you create a sub-folder for each new user so that permissions for files and other information stored by the user can be set with ease. This would only add a step or two more to your code but I believe it would make maintaining your app much easier in the future

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 06-23-2010, 02:00 AM
  2. Simple Programming for Desktop Application
    By cakka in forum General Programming
    Replies: 11
    Last Post: 09-29-2008, 03:27 AM
  3. Linux google desktop application
    By Onur in forum Linux/Unix General
    Replies: 5
    Last Post: 11-16-2007, 03:49 AM
  4. Building Desktop Application to Monitor Web Acitivty
    By Jonas in forum General Programming
    Replies: 2
    Last Post: 07-16-2006, 10:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts