Пример #1
0
        public override void Login()
        {
            DBfactory Sqlconn = SQLdatabase.getInstanceSQL();  //Gọi SQL từ Factory Pattern

            var conn = Sqlconn.CreateConnection();

            conn.Open();
            string sqlSelect = "SELECT count(*)  FROM Users WHERE NameLogin = @NameLogin and PassW=@PassW";
            var    cmd       = (SqlCommand)Sqlconn.CreateCommand(sqlSelect, conn);

            cmd.Parameters.AddWithValue("NameLogin", account.getUserName());
            cmd.Parameters.AddWithValue("PassW", account.getPassword());
            var       dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();

            dt.Load(dr);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.success = true;
                Home f = new Home();
                f.Show();
            }
            else
            {
                this.success = false;
                MessageBox.Show("Erorr: Username or Password incorect!");
            }
        }