In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Winform development framework how to achieve system login, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
In the course of the operation of the business system, sometimes users need to switch users to log in again. This is sometimes because one person manages multiple user accounts and wants to manage different data through different account logins. Another situation is the shift operation of the hotel, and another person takes over the previous person for system maintenance and management. This kind of re-login is actually one of the friendly operations. Just imagine, if you log in with a different account, you need to launch the system and re-find the running program, and if the system starts slowly, you still need to wait, so it is sometimes necessary to log in again. Therefore, the realization of this function also reflects the detail-oriented performance of the system we developed.
In addition, automatic login (actually accepting login through command line parameters) is also very common. Sometimes, we let the client remember the user's account password, and we log in by transferring the command line in the background. Let the system program receive the relevant parameter values and log in.
1. Implementation of system re-login
The general idea is that after logging in to the system, there is a re-login function entry in the system menu. Click to ask the customer to re-enter the password to log in, as shown below.
The code implementation is to put the user-related operations into a function during initialization to ensure that the login user information can be refreshed by re-executing the function operation. As shown below.
In the InitUserRelated function, we put user-related initialization operations in it, including displaying login user information, user actionable buttons or menus, home page information and other related items, as shown below.
/ initialize user-related system information / private void InitUserRelated () {ChildWinManagement.LoadMdiForm (this, typeof (FirstPage)); / / Welcome page # region initialize the system name try {string Manufacturer = config.AppConfigGet ("Manufacturer"); string ApplicationName = config.AppConfigGet ("ApplicationName") String AppWholeName = 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 String userName = 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 (); / / block InitSkinGallery () based on permissions; UserLookAndFeel.Default.SetSkinStyle ("Office 2010 Blue");}
InitAuthorizedUI is a function to determine what permissions the user has. According to the function points obtained by the permission system, the interface elements are refreshed here, those with permissions are displayed, and those without are hidden, as shown below.
/ private void InitAuthorizedUI () {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 being encapsulated in this way, it is convenient for us to log in again. In the menu operation of re-login, the implementation code is as follows.
Private void btnRelogin_ItemClick (object sender, DevExpress.XtraBars.ItemClickEventArgs e) {if (MessageDxUtil.ShowYesNoAndWarning ("are you sure you need to log in again?") ! = DialogResult.Yes) return; Portal.gc.MainDialog.Hide (); Login dlg = new Login (); dlg.StartPosition = FormStartPosition.CenterScreen; if (DialogResult.OK = = dlg.ShowDialog ()) {if (dlg.bLogin) {CloseAllDocuments (); InitUserRelated ();}} dlg.Dispose () Portal.gc.MainDialog.Show ();}
The implementation of the above operation process, basically completed the re-login operation.
2. the realization of automatic login of the system.
System automatic login is sometimes necessary, in the user's own absolute trust of the computer, automatic login for users, very convenient and friendly, don't you see, QQ, Wangwang and so on. In fact, the idea of implementation is to pass login parameters to the exe execution file, and if necessary, the login parameters can also be encrypted to run calls to third parties. Previously, we have done an operation that automatically starts the desktop program Visio application software on the Web. In fact, the principle is the same, which is achieved by passing parameters to the execution file.
[STAThread] static void Main (string [] args) {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (false); if (args.Length > 0) {LoginByArgs (args);} else {LoginNormal (args) }} / use parameterized login / private static void LoginByArgs (string [] args) {CommandArgs commandArgs = CommandLine.Parse (args) If (commandArgs.ArgPairs.Count > 0) {# region get the user parameter string userName = string.Empty; string identity = string.Empty Foreach (KeyValuePair pair in commandArgs.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)) {bool bLogin = Portal.gc.LoginByIdentity (userName.Trim (), identity) If (bLogin) {ShowMainDialog ();} else {LoginNormal (args) }
Sometimes, even if we feel that users do not need to log in through the command line, then we can use simulated automatic login to solve the problem that we always need to enter the user account password when starting the program during the development process.
We just need to enter the built-in username and password in the properties of the project so that we don't have to log in to test it.
These are the ideas and methods for system re-login and system automatic login (command line login) in the Winform development framework.
After reading the above, have you mastered how to achieve system login in the Winform development framework? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.