码迷,mamicode.com
首页 > Windows程序 > 详细

WINFORM权限系统开发系列教程(五)

时间:2020-06-08 10:42:16      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:models   read   csharp   div   obj   ret   权限   object   join   

数据访问DAL和实体类

UserInfo.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xwy.WindowsFormsApp.Models
{
    public class UserInfoModel
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string UserPwd { get; set; }

    }
}

  

RoleInfo.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xwy.WindowsFormsApp.Models
{
    public class RoleInfoModel
    {
        public int RoleId { get; set; }
        public string RoleName { get; set; }



    }
}

  

UserDAL.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xwy.WindowsFormsApp.Common;
using Xwy.WindowsFormsApp.DAL.Helpers;
using Xwy.WindowsFormsApp.Models;

namespace Xwy.WindowsFormsApp.DAL
{
    public class UserDAL
    {
        public int Login(UserInfoModel user)
        {
            string sql = "select UserId from UserInfos where UserName=@UserName and UserPwd=@UserPwd";
            SqlParameter[] paras =
            {
                new SqlParameter("@UserName",user.UserName),
                new SqlParameter("@UserPwd",user.UserPwd)
            };
            object oId = DBHelper.ExecuteScalar(sql,1,paras);
            if (oId != null && oId.ToString() != "")
            {
                return oId.GetInt();
            }
            else
            {
                return 0;
            }
        }
        
        public List<RoleInfoModel> GetUserRoles(int userId)
        {
            string sql = "select r.RoleId,RoleName from UserRoleInfos ur inner join RoleInfos r on r.RoleId=ur.RoleId where UserId=@UserId";
            SqlParameter paraId = new SqlParameter("@UserId", userId);
            SqlDataReader dr = DBHelper.ExecuteReader(sql, 1, paraId);
            List<RoleInfoModel> list = new List<RoleInfoModel>();
            while(dr.Read())
            {
                RoleInfoModel roleInfo = new RoleInfoModel();
                roleInfo.RoleId = dr["RoleId"].ToString().GetInt();
                roleInfo.RoleName = dr["RoleName"].ToString();
                list.Add(roleInfo);
            }
            dr.Close();//关闭阅读器
            return list;
        }
    
    }
}

  

 

WINFORM权限系统开发系列教程(五)

标签:models   read   csharp   div   obj   ret   权限   object   join   

原文地址:https://www.cnblogs.com/xiewenyu/p/13064061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!