I\'m working on a project and i need some implementention ideas. So far i used windows forms. The application will be used by different users on the same pc. I\'m not a good rel
You can add this to your Main starting point. Basically, you need to be able to loop through the process again once the user gets passed the login form:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
DialogResult running = DialogResult.OK;
while (running == DialogResult.OK) {
form_login login = new form_login();
Application.Run(login);
running = login.DialogResult;
if (login.DialogResult == DialogResult.OK)
Application.Run(new Form1());
// or your other forms...
}
}
This is assuming your login form has an OK and a Cancel button that sets those dialog results.
If the login works, then it launches the main form, Form1. When the user closes Form1, it starts the Login form again. If the user cancels the login, the application is exited.
Assuming that all changes are stored in the database, and the form is initialized with what's in the database, then you shouldn't have to do anything special.
This is like saying,
The only thing to keep in mind is that your form needs to be initialized with what's in the database before any user sees it.
Also, it's unusual these days to have a multi-user system that is only accessed sequentially, with no more than 1 user at a time. If you're not sure if that will always be the case, it may make more sense to implement this as a web application.
However, if you're building something like a point-of-sale system, though, where you need hardware like bar code scanners or credit card readers, you should be fine with a winforms app - and, in fact, it makes more sense than a web app in that case - keeping all of the data in a central, shared database like MS SQL Server will take care of most of your synchronization issues.
Update
If you're really asking about how to keep the app running when a user logs out: Application.Run()
should really only be called once, when the app starts. You'll launch your main form:
using(var mainForm = new MainForm())
Application.Run(mainForm);
The class MainForm
might represent, for instance, your main data entry screen.
MainForm
would then be responsible for determining if a user is logged and, if necessary, showing a modal login form. There are a few other posts that address this:
Using Multiple Forms in c#