namespace dms{public class Logininfo {public string AccountID { set; get; } public string Accountpassword { set; get; } Public DateTime accountlogintime { set; get; } private static Logininfo _currentuser = null; public static Logininfo CurrentUser { get { if (_currentuser = = null) { _currentuser = New Logininfo (); } return _currentuser;}}}
Seems to be called single-piece mode (Singleton) ... Anyway finish this course design and take a good look at the design pattern of things (escape
namespace dms{public partial class login interface: Form {public Login interface () {InitializeComponent (); private void Buttonadmin_click (object sender, EventArgs e) {if (TextBoxUserName.Text.Trim () != "" || TextBoxPassWord.Text.Trim ()! = "") {//Connect database for comparison ...//prepare try//to start {Conn. Open (); SqlDataReader reader = cmd. ExecuteReader (); Reader. Read (); if (reader. HasRows)//Existing account {/* Below four lines is the key */LoginInfo.CurrentUser.Accoun TID = TextBoxUserName.Text.Trim (); LoginInfo.CurrentUser.AccountPassWord = TextBoxPassWord.Text.Trim (); LoginInfo.CurrentUser.AccountLoginTime = DateTime.Now; Here you remember to pass the Logininfo instance into the next interface, or the next interface will not get the current login information Administrator parent Interface Adminmain = new Administrator Parent interface (LoGininfo.currentuser); This. Hide (); Adminmain.show (); } else {MessageBox.Show ("username or password is wrong! "," prompt "); Textboxusername.text = ""; Textboxpassword.text = ""; Textboxusername.focus (); } reader. Close (); } catch (SqlException ex) {MessageBox.Show ("DMS has an error:" + ex.) Message); } finally {Conn. Close (); }} else MessageBox.Show ("User name or password is blank, please reenter!") "," prompt "); } }
C # WinForm Implementation remembers login status for user login