166 lines
6.7 KiB
C#
166 lines
6.7 KiB
C#
|
using HRM.BO;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using System;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
internal class UserRoleDA
|
|||
|
{
|
|||
|
#region Constructor
|
|||
|
|
|||
|
private UserRoleDA()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Insert function
|
|||
|
|
|||
|
internal static void Insert(TransactionContext tc, UserRole item)
|
|||
|
{
|
|||
|
//item.Status = EnumStatus.Inactive;
|
|||
|
item.EventDate = DateTime.Now;
|
|||
|
item.CreatedDate = DateTime.Now;
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"INSERT INTO UserRole(UserRoleID,RoleID,UserID,EventDate,CreatedBy,status,ComputerName,ApprovedComputerName)" +
|
|||
|
" VALUES(%n, %n, %n,%D,%n,%n,%s,%s)", item.ID, item.RoleID, item.UserID, item.EventDate, item.CreatedBy,
|
|||
|
(int)item.UserRoleStatus, item.ComputerName, item.ApprovedComputerName);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Update function
|
|||
|
|
|||
|
internal static void Update(TransactionContext tc, UserRole item)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery(
|
|||
|
"UPDATE UserRole SET roleID=%n, userID=%n, AuthorizedDate=%D,AuthorizedBy=%n,status=%n,ComputerName=%s,ApprovedComputerName=%s" +
|
|||
|
" WHERE UserRoleID=%n", item.RoleID, item.UserID, DateTime.Now, item.UserID, item.UserRoleStatus,
|
|||
|
item.ComputerName, item.ComputerName, item.ID);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get Function
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM UserRole");
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, int RoleID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM UserRole WHERE RoleID=%n", RoleID);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader Get(TransactionContext tc, EnumRoleType roleType, int? UserID, int? roleID)
|
|||
|
{
|
|||
|
string sqlClause = " ";
|
|||
|
sqlClause = SQLParser.MakeSQL(" AND r.roleType = %n", roleType);
|
|||
|
|
|||
|
|
|||
|
if (UserID != null)
|
|||
|
{
|
|||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL(" ur.UserID= %n", UserID);
|
|||
|
}
|
|||
|
|
|||
|
if (roleID != null)
|
|||
|
{
|
|||
|
sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL(" ur.roleid= %n", roleID);
|
|||
|
}
|
|||
|
|
|||
|
return tc.ExecuteReader(
|
|||
|
@"SELECT ur.*, u.LOGINID LoginID, u.USERNAME UserName,R.Name RoleName FROM UserRole ur,[Users] u, Role R
|
|||
|
WHERE ur.RoleID=r.RoleID and u.UserID =ur.UserID %q order by u.LoginID,R.Name", sqlClause);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader GetByUserID(TransactionContext tc, int UserID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM UserRole WHERE UserID=%n and Status=1", UserID);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader getAllByUserEMpNo(TransactionContext tc, string empIn)
|
|||
|
{
|
|||
|
return tc.ExecuteReader(
|
|||
|
@"SELECT ur.*, u.LoginID, r.Name RoleName, u.employeeID FROM UserRole ur, Users u, Employee e, Role r where
|
|||
|
ur.UserID = u.UserId and u.LoginID= e.EmployeeNo and r.RoleID = ur.RoleID
|
|||
|
and e.employeeid IN (%q)", empIn);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static IDataReader GetRoleRelateEmp(TransactionContext tc, string empIn)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT ul.* FROM UserRole ul, Users u WHERE u.UserID= ul.UserID and u.LoginID=%s",
|
|||
|
empIn);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static DataSet GetRoleAudit(TransactionContext tc, int type, DateTime fromDate, DateTime ToDate)
|
|||
|
{
|
|||
|
DataSet oIDs = new DataSet();
|
|||
|
try
|
|||
|
{
|
|||
|
// string sSQL = SQLParser.MakeSQL(@"SELECT zr.*,(SELECT Username FROM users WHERE userid=zr.createdby) ActionBy,(SELECT Username FROM users WHERE userid=zr.UserID) UserName,r.Name RoleName
|
|||
|
// FROM z_UserRole zr,[Role] r
|
|||
|
// WHERE zr.RoleID = r.RoleID
|
|||
|
// AND zr.AuditDate>=%d
|
|||
|
// And zr.AuditDate<=%d AND zr.AuditType IN('Inserted','Update (after)') AND zr.RoleID=%n
|
|||
|
// AND zr.[Status]<>12
|
|||
|
// ORDER BY zr.AuditDate DESC", fromDate, ToDate,nRoleID);
|
|||
|
string sSQL = SQLParser.MakeSQL(
|
|||
|
@"SELECT zr.*,(SELECT Loginid FROM users WHERE userid=zr.createdby) ActionBy,(SELECT Username FROM users WHERE userid=zr.UserID) UserName,r.Name RoleName
|
|||
|
FROM z_UserRole zr,Role r
|
|||
|
WHERE zr.RoleID = r.RoleID
|
|||
|
AND zr.AuditDate>=%d
|
|||
|
And zr.AuditDate<=%d AND zr.AuditType IN('Inserted','Update (after)')
|
|||
|
AND zr.Status<>12
|
|||
|
ORDER BY zr.AuditDate DESC", fromDate, ToDate);
|
|||
|
|
|||
|
oIDs = tc.ExecuteDataSet(sSQL);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new Exception(ex.Message);
|
|||
|
}
|
|||
|
|
|||
|
return oIDs;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Delete function
|
|||
|
|
|||
|
internal static void Delete(TransactionContext tc, int id)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM UserRole WHERE RoleID=%n", id);
|
|||
|
}
|
|||
|
|
|||
|
internal static void DeleteByUserID(TransactionContext tc, int nUserID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM UserRole WHERE UserID=%n", nUserID);
|
|||
|
}
|
|||
|
|
|||
|
internal static void Update(TransactionContext tc, int id, EnumStatus status)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("UPDATE UserRole SET Status = %n,AuthorizedBy=%n,AuthorizedDate=%D WHERE UserID = %n",
|
|||
|
status, id, DateTime.Now, id);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
internal static DataSet GetUserMenuByRole(TransactionContext tc, string roleId)
|
|||
|
{
|
|||
|
string sql = SQLParser.MakeSQL(
|
|||
|
@"SELECT RP.ROLEID,RP.MENUKEY,CAN.VALUE Name,C.VALUE URL FROM ROLEPERMISSION RP,CONFIGURATIONATTRIBUTE CA,CONFIGURATION C,CONFIGURATIONATTRIBUTE CAN
|
|||
|
WHERE C.NODE='formname' AND RP.MENUKEY=CA.VALUE AND CA.ATTRIBUTENAME='key' AND CA.PARENTID=C.PARENTID AND CAN.PARENTID=C.PARENTID AND CAN.ATTRIBUTENAME='name'
|
|||
|
AND RP.ROLEID IN (%q) AND RP.ISAPPROVED=1 GROUP BY RP.ROLEID,RP.MENUKEY,CAN.VALUE,CA.PARENTID,C.VALUE ORDER BY RP.MENUKEY",
|
|||
|
roleId);
|
|||
|
return tc.ExecuteDataSet(sql);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|