你的位置:首页 > ASP.net教程

[ASP.net教程]mvc+三层 网站项目:用户登录

第一:数据库-用户表为(Manger)

第二,三层-Model,实体层 Manger(用户表)

namespace YL.Model
{
    public class Manger
    {
        //系统用户编号
        public int Id
        {
            get;
            set;
        }
        public int RoleId
        {
            get;
            set;
        }
        //用户名
        public string UserName
        {
            get;
            set;
        }
        //用户密码
        public string UserPassWord
        {
            get;
            set;
        }
        //角色Id
        public int RoleIdng
        {
            get;
            set;
        }
        //
        public int IsEnable
        {
            get;
            set;
        }
        public DateTime CreateTime
        {            get;
            set;
        }
        public string Remark
        {
            get;
            set;
        }
        public int IsDel
        {
            get;
            set;
        }
        public int CreateUserId
        {            get;
            set;
        }
        public int UpdateUserId
        {
            get;
            set;
        }
        public int DelUserId
        {
            get;
            set;
        }
        public int UserInfo
        {
            get;
            set;
        }
    }}

第三:Dal,数据访问层,MangerDAL

public Model.Manger GetLogin(string UserName)

{

 StringBuilder SQL = new StringBuilder();//实例化SQL对象
            SQL.Append("select Id, UpdateUserId, DelUserId, UserName, UserPassWord, RoleId, IsEnable, CreateTime, Remark, IsDel, CreateUserId");
            SQL.Append(" from Manager "); //@:此处要空格,否则会出现sql语句错误
            SQL.Append(" Where [email protected]");//因为是登录,所以SQL用查询语句,sql.Append=和胶水一样,把几个语句合作一起,[email protected]
            SqlParameter[] parameters = {
                    new SqlParameter("@UserName", SqlDbType.NVarChar,50)
            };
            parameters[0].Value = UserName;
            var data = new MySqlAdoProvide().ExecuteReader(dr => dr.GetEntity<Model.Manger>(), MySqlHelper.connectionStringManager, SQL.ToString(), parameters).FirstOrDefault();
            //data,实体转换为实体对象,SQL转换为string类型,此处用来扩展方法,可另行换别的
            return data;//返回data数据

 

}

第四:BLL业务逻辑层 MangerBLL

public Model.Manger GetLogin(string UserName)

{

retun  dal.GetLogin(Username);

}