WINFORM权限系统开发系列教程

Posted xiewenyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WINFORM权限系统开发系列教程相关的知识,希望对你有一定的参考价值。

数据访问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权限系统开发系列教程的主要内容,如果未能解决你的问题,请参考以下文章

WINFORM权限系统开发系列教程

WINFORM权限系统开发系列教程主窗口

WINFORM权限系统开发系列教程

WINFORM权限系统开发系列教程

WINFORM权限系统开发系列教程角色管理模块

winform 自定义控件,继承自ListView 和treeview 怎么做,一般用于做权限操作