C # WinForm Implementation remembers login status for user login

Source: Internet
Author: User

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

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.