Basically, I want to make a windows form application to be able to view and/or manipulate a postgres database.

My first question is if using c#/winforms is an okay way to do this? If not, any suggestions? One of my co-workers suggested using drubal to make an interface to do all this but I have never used that before so I really have no idea. Any thoughts on this would be greatly appreciated.

My second question, is about actually making the application with winforms... well not how to make it, but more on the best way to make it.

What I want to do is have it so that when the application is first started, you are presented with a login screen (2 textboxes, 2 labels, and a button). Upon entering your information the application confirms your credentials and also checks which privileges you should be allowed.

If the user turns out to be an administrator, I want to have them presented with buttons to do anything. If the user is just a normal person, then they will only be able to view data.

The problem I've run into is that I am not really sure on the best way to switch from the login screen, to the new screen... at least in a way that makes sense.

I figure there are a few options but none of them seem really intuitive and are all kinda brute forced.

The first would be that upon clicking the "login" button, that everything currently on the screen is gets it "Visible" variable set to false, and then depending on what type of user the person is, the corresponding buttons/textboxes/labels get Visible set to true. The problems with this are obviously the fact that to actually design this, you would have tons of overlapping controls everywhere and it would just be a giant mess.

The second option I thought of would be to put corresponding controls in their own panels, so rather then hiding/unhiding controls indivdually I could just hide/unhide the appropriate panels. The problem I see with this, is that although it will be less code from only 1 or 2 hide/unhide statements, I will still have tons of panels overlapping everywhere in the designer.

The third option I was looking into, were user controls. At first I thought this was a solution from a description I had read but upon further reading it doesn't really seem like it would work the way I thought.

Another option would be to just open a whole new frame. This is definitely possible, and not that hard to do, and it also doesn't create a massive mess in the designer, but my only problem is that it would be nice if everything could be done in one single frame. I don't really want to have 4-5+ windows just sitting there.

TLDR: I am curious about the best way to easily change the contents of a frame, depending on what type of user logs in and/or what buttons they press.

Hah, I was extremely bored at work so I decided to whip together a little project for you to learn from.

Keep in mind this is really minimal and breaks a few rules as far as cross threading violations are concerned. If you are concerned about that look into delegates (theres probably 10,000 threads on here about them) and invoking accross threads.

I'm not going to describe much of it to you, as it's so simple that it is probably self explanatory. (Note: I wrote it in Visual Studio 2010 so the solution file won't open if you have anything earlier)

Let me know if you have any questions about it.

Oh yeah the login info is as follows (its hardcoded):

Advanced 4321
Admin 1234

anything else logs you in as a Basic user

So depending on what inputs you get,you just create a new Form that contains the appropriate information/buttons.

I also see that you have to pass data from form to form.

What I still don't understand is what I would do if I wanted this to all happen without creating any new windows at all. I guess the most simple comparison is clicking on a link in any web browser. Its the same window but the webpage (in the context of what I'm trying to do, it would be a certain set of buttons) changes.

I appreciate the help though

Well that all depends on how you, the developer want to do things.

It can be as simple as hiding/unhiding controls, or just simply creating the controls from scratch programmatically (exactly the same thing that occurs in the Form.Designer.cs file). This is a bit more involved of an approach - you have to know exactly where you want the controls to go, and all of their properties must be set in this way instead of using the properties window in the form designer including the control's events. Note that you can even add other forms to a panel (essentially modularizing your layout) by using an approach like this:

Form1 formInAPanel = new Form1();
            formInAPanel.TopLevel = false;

If you are trying to build something as dynamic as a web browser you may be over-complicating the way you want to achieve your goal. If there is going to be hundreds or thousands of different logins, each with different layouts of the form then maybe this is the way to go - although a web application may be more suited for this than a windows one (no use re-inventing wheels now).

If it is just a few buttons that need to be changed then I would simply change the label on them (if need be) and in their on_click event use a switch to determine the action it is to perform based on the permission level. Even simpler - have a button for everything and just disable the ones you can't use due to permissions.

There is definately more than one way to skin a cat here. A form has a member called Controls that can be added to or subtracted from at will with user-designed controls (such as the ones I made and included in the example project) or generic windows controls (ie buttons, textboxes, etc). If you wanted to have the login info in the same 'form' as the main form, you could always remove/hide the testboxes and buttons, resize the form via its size property, then populate it with controls. It is often more organized to put these controls into a panel - think of a panel as a control that contains a collection of controls within the forms collection of controls. (I had to read that a few times to make sure I typed it out right).

I am not sure what your issue is with passing data from form to form - it is trivial. In a php login script it would do the exact same thing - except instead of 'forms' it is passing data between web pages which is the exact same concept.

Sorry for writing a novel. I hope I covered more of your concerns here - it was a good way to kill 20 minutes of work time.