HuNan_NOSqlSugar/DM_Weight/CommonDal/LoginDal.cs

38 lines
1.7 KiB
C#
Raw Normal View History

2024-07-06 10:01:30 +08:00
using DM_Weight.Models;
using Newtonsoft.Json;
using SCHelper.Database;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.CommonDal
{
public class LoginDal
{
public UserList GetLoginInfo(string userName,string passWord)
{
UserList user = new UserList(); ;
string sql = @"select ul.id as id,ul.User_name as userName,r.id as rId,r.role_name,r.permissions,r.machine_id from user_list ul
INNER JOIN role r on ul.machine_role_id=r.id where ul.Id=@ID and ul.machine_id=@machine_id and r.machine_id=@machine_id";
DataSet ds= DBHelper.GetInstance().ExecuteQuery(sql);
if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count>0)
{
user.Id =Convert.ToInt32(ds.Tables[0].Rows[0]["id"] ??0);
user.UserName = ds.Tables[0].Rows[0]["userName"].ToString() ?? "";
user.Nickname = ds.Tables[0].Rows[0]["userName"].ToString()??"";
user.MachineId = ds.Tables[0].Rows[0]["machine_id"].ToString()??"";
RoleDm role = new RoleDm();
role.Id = Convert.ToInt32(ds.Tables[0].Rows[0]["rId"] ?? 0);
role.RoleName = ds.Tables[0].Rows[0]["role_name"].ToString() ?? ""; ;
role.Permissions = JsonConvert.DeserializeObject<List<PremissionDm>>(ds.Tables[0].Rows[0]["permissions"] is DBNull ? "" : ds.Tables[0].Rows[0]["permissions"].ToString()); // JsonConvert.SerializeObject(reader.GetString("permissions")).ToList();
user.Role = role;
}
return user;
}
}
}