Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hey,

i am developing an application for which i have created a database of serial numbers to activate the product. When your enters the correct serial number then it registers the product and provide access to the product but when the user close the application and open the application it again asks for serial number. Is there any way that once user enters the correct serial then it will not ask for serial when the application is closed and opened again!
Posted

Your application likely has a Program.cs file or similar with statement like:

System.Windows.Forms.Application.Run ( new Form1() ) ;

You should be able to change it to something along the lines of:

C#
if ( app is not registered ) System.Windows.Forms.Application.Run ( new registrationform() ) ;
if ( app is registered ) System.Windows.Forms.Application.Run ( new mainform() ) ;


The test for whether or not the app is registered will likely be implemented in the DAL.

Be sure to have the data access code in a separate class; not in the form.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Aug-14 23:01pm    
That is correct, a 5. I would only add that this is not the only way to show identical behavior, just because the role main (starting) form makes little difference: when it is closed, application is closed.
So, it's possible to close application by handling FormClosed of some other form, which would play the role similar to the starting form (which can be, say, hidden). What is simpler, depends on the application.
—SA
PIEBALDconsult 15-Aug-14 10:51am    
Yes, many ways to reach the goal. I think this way yields a better separation of concerns.
Once the key is entered correctly, you can mark the application as registered in a database or any other store like registry.
Next time when the user opens the application, check this storage for registered status and then decide whether the serial box needs to be displayed or not.
 
Share this answer
 
Check out System.Windows.Forms.ApplicationContext[^]

I use this class to first show a login form, and then the main form.

Program.cs
C#
static void Main()
{
  var loginSeq = new LoginSequence();
  Application.Run(loginSeq);
}


LoginSequence.cs
C#
public class LoginSequence : ApplicationContext
{
        private LoginForm _login;

        // Ctor - Show LoginForm first.
        public LoginSequence()
        {
            _login = new LoginForm();
            _login.Closed += LoginFormClosed;
            _login.Show();
        }

        /// <summary>
        /// LoginForm has closed
        /// </summary>
        private void LoginFormClosed(object sender, EventArgs e)
        {
            // Check LoginFrom result
            if (_login.DialogResult == DialogResult.OK)
            {
                // Valid
                _login.Closed -= LoginFormClosed;
                _login = null;

                // Show MainForm
                MainForm = new MainForm();
                MainForm.Show();
            }
            else
            {
                // Invalid user login
                ExitThread();
            }
        }
}


And it is work fine for my use.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900