Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 14-Aug-14 8:04am
junaid2319
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
 
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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 15-Aug-14 10:51am
   
Yes, many ways to reach the goal. I think this way yields a better separation of concerns.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check out System.Windows.Forms.ApplicationContext[^]
 
I use this class to first show a login form, and then the main form.
 
Program.cs
static void Main()
{
  var loginSeq = new LoginSequence();
  Application.Run(loginSeq);
}
 
LoginSequence.cs
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 730
1 CPallini 320
2 Sergey Alexandrovich Kryukov 305
3 BillWoodruff 295
4 Peter Leow 255


Advertise | Privacy | Mobile
Web01 | 2.8.141029.1 | Last Updated 15 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100