ldj/Logical/LAuthority.cs

295 lines
8.3 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00
using System;
using DeiNiu.wms.Data.Model;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2024-05-21 17:28:35 +08:00
using WcfServiceAuthentication;
2023-05-23 16:13:17 +08:00
namespace DeiNiu.wms.Logical
{
[Serializable]
public class LAuthority
{
Authority _obj;
public LAuthority()
{
Initialize();
}
public Authority GetAuthority
{
get
{
return _obj;
}
}
/// <summary>
/// get all data
/// </summary>
public DataSet GetAllData()
{
return _obj.Query();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllActiveData()
{
return _obj.QueryActived();
}
/*
private void leavetypeDsConstruct()
{
return;
}
*/
/// <summary>
/// get a record by id
/// </summary>
public void Initialize(int id)
{
_obj = id != 0 ? new Authority(id) : new Authority();
}
/// <summary>
/// get a record by id 0
/// </summary>
public void Initialize()
{
Initialize(0);
}
public List<Authority> getAuthorities()
{
List<Authority> auths = new List<Authority>();
DataTable dt = getAllActiveData().Tables[0];
foreach (DataRow row in dt.Rows)
{
int id = Convert.ToInt32(row["id"].ToString());
Authority ath = new Authority(id);
auths.Add(ath);
}
return auths;
}
public List<Authority> getAuthorities(int empId, int warehouse)
{
List<Authority> auths = new List<Authority>();
RoleAuthority ll = new RoleAuthority();
DataTable dt = ll.GetAuthByEm(empId, warehouse);
foreach (DataRow row in dt.Rows)
{
int id = Convert.ToInt32(row["id"].ToString());
Authority ath = new Authority(id);
auths.Add(ath);
}
return auths;
}
public Dictionary<String, List<Authority>> getMobileAuthorities(int empId)
{
Dictionary<String, List<Authority>> auths = new Dictionary<String, List<Authority>>();
// DataView dv = new DataView(getAllActiveData().Tables[0]);
DataView dv = _obj.queryCateAuths().DefaultView;
List<Authority> subAuths = getAuthorities(empId,-1);
foreach (Authority a in subAuths)
{
dv.RowFilter = "id =" + a.auth_uplevel;
string key;
foreach (DataRowView dr in dv)
{
key = dr["auth_name"].ToString();
if (auths.ContainsKey(key))
{
auths[key].Add(a);
}
else
{
List<Authority> sa = new List<Authority>();
sa.Add(a);
auths.Add(key, sa);
}
}
}
return auths;
}
// public Dictionary<String, List<Authority>> getCatedAuthorities(int empId,int warehouse=-1)
public Dictionary<String, List<Authority>> getCatedAuthorities(int empId,int warehouse=-1)
{
Dictionary<String, List<Authority>> auths = new Dictionary<String, List<Authority>>();
// DataView dv = new DataView(getAllActiveData().Tables[0]);
DataView dv = _obj.queryCateAuths().DefaultView;
List<Authority> subAuths = getAuthorities(empId, warehouse );
/*
* foreach (Authority a in subAuths)
{
dv.RowFilter = "id =" + a.auth_uplevel;
string key;
foreach (DataRowView dr in dv)
{
key = dr["auth_name"].ToString();
if (auths.ContainsKey(key))
{
auths[key].Add(a);
}
else
{
List<Authority> sa = new List<Authority>();
sa.Add(a);
auths.Add(key, sa);
}
}
}
*/
foreach (DataRowView dr in dv)
{
string formexists = dr["auth_class"].ToString();
string special = dr["auth_special"].ToString();
if (string.IsNullOrEmpty(formexists)
&& string.IsNullOrEmpty(special)
)
{
continue;
}
List<Authority> sa = new List<Authority>();
string key = dr["auth_name"].ToString();
auths.Add(key, sa);
foreach (Authority a in subAuths)
{
if (a.auth_uplevel == Convert.ToInt16(dr["id"].ToString()))
{
// string key = dr["auth_name"].ToString();
if (auths.ContainsKey(key))
{
auths[key].Add(a);
}
else
{
// List<Authority> sa = new List<Authority>();
// sa.Add(a);
// auths.Add(key, sa);
}
}
}
}
return auths;
}
bool validUser(string userId,string passwd)
{
Employee emp = new Employee();
return emp.login(userId,passwd);
}
public int validUserRole(string userId, string passwd, string role)
{
Employee emp = new Employee();
int id = emp.ValidUser(userId, passwd);
if (id > 0)
{
Dictionary<String, List<Authority>> auths = getMobileAuthorities(id);
List<string> auth = new List<string>();
if (auths.ContainsKey(<><CFB8>Ȩ<EFBFBD><C8A8>"))
{
List<Authority> portAuth = auths[<><CFB8>Ȩ<EFBFBD><C8A8>"];
foreach (Authority au in portAuth)
{
if (au.auth_name == role)
{
return id;
}
}
}
}
return 0;
}
public Employee login(string account,string passwd)
{
Employee em = new Employee();
if (em.login(account, passwd))
{
em.em_passwd = "";
em.AuthForms = getAuthObjLst(em.ID, "<22>ƶ<EFBFBD><C6B6>豸");
em.AuthSpecials = getAuthObjLst(em.ID, <><CFB8>Ȩ<EFBFBD><C8A8>");
2023-11-21 19:18:23 +08:00
2023-05-23 16:13:17 +08:00
}
2024-05-21 17:28:35 +08:00
AuthenticationInspector.checkRestrictUsers(em.ID);
2023-05-23 16:13:17 +08:00
return em;
}
public List<Authority> getAuthObjLst(int userId, string type = "")
{
Dictionary<String, List<Authority>> auths = getMobileAuthorities(userId);
List<Authority> auth = new List<Authority>();
if (string.IsNullOrEmpty(type))
{
if (auths.Keys.Contains("<22>ƶ<EFBFBD><C6B6>豸"))
{
List<Authority> portAuth = auths["<22>ƶ<EFBFBD><C6B6>豸"];
foreach (Authority au in portAuth)
{
auth.Add(au);
}
}
if (auths.Keys.Contains(<><CFB8>Ȩ<EFBFBD><C8A8>"))
{
List<Authority> portAuth = auths[<><CFB8>Ȩ<EFBFBD><C8A8>"];
foreach (Authority au in portAuth)
{
auth.Add(au);
}
}
}
else
{
if (auths.Keys.Contains(type))
{
return auths[type];
}
}
return auth;
}
}
}