System login implementation of WinForm development framework

Source: Internet
Author: User

In the operation of the business system, sometimes, users need to switch users to re-login, this situation is due to a person to manage multiple user accounts, in the hope of different account login to manage different materials, the other is the hotel's shift operation, another person to replace the person in front of the system maintenance management. This re-login is actually a kind of friendly operation, imagine, a change account login, you need to launch the system, re-look for the running program to be able to, and if the system starts a bit slower, still need to wait, so the implementation of re-login, and sometimes necessary. The realization of this function is also a manifestation of the attention to detail of the systems we develop.

In addition, automatic login (in fact, accept the command line parameters to log in) is also very common, sometimes, let the client remember the user's account password, we in the background by the transfer command line way to log in, so that the system program receives the relevant parameter values can be logged in.

1, the system re-login implementation

The general idea is that after logging into the system, there is a login function entry in the System menu, click to ask the customer to re-enter the password to log in, as shown below.

Code implementation is to initialize the time, the user-related operations into a function, to ensure that the re-execution of this function will be able to re-refresh the login user information. as shown below.

In the inituserrelated function, we put the user-related initialization operations in the inside, including display login user information, user-operated buttons or menu, home information and other related items, the code is as follows.

/// <summary>  ///initializing user-related system Information/// </summary>  Private voidinituserrelated () {Childwinmanagement.loadmdiform ( This,typeof(FirstPage));//Welcome Page     #regionInitialize the system nameTry     {          stringManufacturer = Config. Appconfigget ("manufacturer"); stringApplicationName = config. Appconfigget ("ApplicationName"); stringAppwholename =string. Format ("{0}-{1}", manufacturer, applicationname); Portal.gc.gAppUnit=manufacturer; Portal.gc.gAppMsgboxTitle=Appwholename; Portal.gc.gAppWholeName=Appwholename;  This. Text = Appwholename +"      ";  This. Notifyicon1.balloontiptext =Appwholename;  This. Notifyicon1.balloontiptitle =Appwholename;  This. Notifyicon1.text =Appwholename; stringUserName =Portal.gc.LoginInfo.RealName; if(string. IsNullOrEmpty (UserName)) {UserName=Portal.gc.LoginInfo.Name; } userstatus=string. Format ("Current User: {0} ({1})", UserName, Portal.gc.RoleInfo.RoleName); Commandstatus=string. Format ("Welcome to {0}", Portal.gc.gAppWholeName); }      Catch { }       #endregion  Initauthorizedui ();//Masking by PermissionsInitskingallery (); UserLookAndFeel.Default.SetSkinStyle ("Office Blue"); } 

One of the Initauthorizedui is to determine what permissions the user has functions, according to the permission system to get the function point, here to re-refresh the interface elements, have permission to display, no hidden can be, as shown below.

/// <summary>  ///based on the permissions masking function/// </summary>  Private voidInitauthorizedui () { This. tool_report.enabled = Portal.gc.HasFunction (" Report");  This. tool_dict.enabled = Portal.gc.HasFunction ("Dictionary");  This. tool_itemdetail.enabled = Portal.gc.HasFunction ("Itemdetail");  This. tool_purchase.enabled = Portal.gc.HasFunction ("Purchase");  This. tool_stocksearch.enabled = Portal.gc.HasFunction ("Stocksearch");  This. tool_takeout.enabled = Portal.gc.HasFunction ("Takeout");  This. tool_warehouse.enabled = Portal.gc.HasFunction ("WareHouse"); //this.menu_run_systemLog.Enabled = Portal.gc.HasFunction ("Loginlog");      This. tool_settings.enabled = Portal.gc.HasFunction ("Parameters");  This. tool_monthlystatistic.enabled = Portal.gc.HasFunction ("monthlystatistic");  This. tool_annualstatistic.enabled = Portal.gc.HasFunction ("annualstatistic");  This. tool_clearall.enabled = Portal.gc.HasFunction ("Clearalldata");  This. tool_importitemdetail.enabled = Portal.gc.HasFunction ("Importitemdetail"); } 

After this encapsulation, we need to re-login to facilitate, we re-login menu operation inside, the implementation code is as follows.

Private voidBtnrelogin_itemclick (Objectsender, DevExpress.XtraBars.ItemClickEventArgs e) {      if(Messagedxutil.showyesnoandwarning ("are you sure you want to sign in again? ") !=Dialogresult.yes)return;       Portal.gc.MainDialog.Hide (); Login Dlg=NewLogin (); Dlg. StartPosition=Formstartposition.centerscreen; if(DialogResult.OK = =dlg. ShowDialog ()) {if(Dlg.blogin) {closealldocuments ();          Inituserrelated (); }} dlg.      Dispose ();  Portal.gc.MainDialog.Show (); } 

Implement the above procedure, basically completed the re-login operation.

2, System automatic login implementation

System Automatic Login Sometimes it is necessary, in the user's own absolute trust of the computer, automatic login to the user, very convenient and friendly, you do not see, QQ so, and so on. In fact, the realization of the idea is to execute the EXE file login parameters can be, if necessary, the parameter value of the login may also be encrypted, to the third party to run the call, has done before a Web automatically start the desktop program Visio application software operation, in fact, the same principle, Implemented by passing parameters to the execution file.

STAThread]   Static void Main (string[] args)  {      application.enablevisualstyles ();      Application.setcompatibletextrenderingdefault (false);        if 0 )      {          Loginbyargs (args);      }       Else      {          loginnormal (args);      }  
/// <summary>          ///using parameterized Logins/// </summary>          /// <param name= "args" ></param>          Private Static voidLoginbyargs (string[] args) {Commandargs Commandargs=commandline.parse (args); if(CommandArgs.ArgPairs.Count >0)              {                  #regionGet user parametersstringUserName =string.                  Empty; stringIdentity =string.                  Empty; foreach(keyvaluepair<string,string> Pairinchcommandargs.argpairs) {if("U". Equals (pair. Key, StringComparison.OrdinalIgnoreCase)) {UserName=pair.                      Value; }                      if("P". Equals (pair. Key, StringComparison.OrdinalIgnoreCase)) {identity=pair.                      Value; }                  }                   #endregion                   if(!string. IsNullOrEmpty (userName) &&!string. IsNullOrEmpty (Identity)) {BOOLBlogin =Portal.gc.LoginByIdentity (Username.trim (), identity); if(blogin) {showmaindialog (); }                      Else{loginnormal (args); }                  }              }          } 

Sometimes, even if the user does not need to login through the command line, then we ourselves in order to avoid the development process, the start of the program, always need to enter the user account password problem, you can also use the simulation of automatic login to solve.

We just need to enter the built-in username and password in the project's properties, so we can test it without having to log in.

System login implementation of WinForm development framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.