标签: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; } } }
标签:models read csharp div obj ret 权限 object join
原文地址:https://www.cnblogs.com/xiewenyu/p/13064061.html