using System; using System.Collections.Generic; using System.Text; using Cksoft.Data; using DllUfpEntity; using System.Linq; namespace DllUfpDal { public class RoleDal { private IDatabase CurrDb; public RoleDal(IDatabase db) { this.CurrDb = db; } public IEnumerable Get(int start, int length, string order, string sort, string filter, string errorinfo) { var roles = CurrDb.FindListForCondition($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo); return roles; } public int GetCount(string filter) { string sql = $"select count(1) from Role a where 1=1 {filter}"; return Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "0"); } public Role Get(string id) { return CurrDb.FindEntityFor(id); } /// /// 添加角色并返回角色Id /// /// /// /// public int Add(Role role, string userCode) { role.RecCode = role.ModCode = userCode; role.RecTime = role.ModTime = DateTime.Now; string sql = $"insert into Role (FCode,FName,Remark,RecCode,RecTime,ModCode,ModTime,SystemId) " + $"values ('{role.FCode}','{role.FName}','{role.Remark}','{role.RecCode}','{role.RecTime.ToString("yyyy-MM-dd")}','{role.ModCode}','{role.ModTime.ToString("yyyy-MM-dd")}','{role.SystemId}');"; sql += "select @@identity;"; var id = Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "-1"); return id; } public int Update(Role role, string userCode) { return CurrDb.UpdateFor(role, userCode); } public IEnumerable getStaffRole(int id) { string sql = $"select * from StaffRole where RoleId='{id}'"; return CurrDb.FindList(sql); } public IEnumerable getRoleFunc(int id) { string sql = $"select * from RoleFunc where RoleId='{id}'"; return CurrDb.FindList(sql); } public int Delete(int id, ref string msg) { string sql = $"delete from StaffRole where RoleId='{id}'"; var res = CurrDb.ExecuteBySql(sql); if (res < 0) { msg = "删除用户角色时失败"; return -1; } sql = $"delete from RoleFunc where RoleId='{id}'"; res = CurrDb.ExecuteBySql(sql); if (res < 0) { msg = "删除角色功能时失败"; return -1; } res = CurrDb.DeleteFor(id); if (res < 0) { msg = "删除角色主表时失败"; return -1; } return 1; } } }