CEL_Payroll/Payroll.Service/Users/DA/UserRoleDA.cs
2024-09-17 14:30:13 +06:00

122 lines
4.9 KiB
C#

using System;
using Payroll.BO;
using System.Data;
using System.Linq;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
#region UserRoleDA
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.Integer, item.RoleID, item.UserID.Integer, item.EventDate, Payroll.BO.User.CurrentUser.ID.Integer, item.Status, 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,CreatedBy=%n" +
" WHERE UserRoleID=%n", item.RoleID, item.UserID.Integer, DateTime.Now, Payroll.BO.User.CurrentUser.ID.Integer, item.Status, item.ComputerName, item.ApprovedComputerName, DataReader.GetNullValue(item.CreatedBy, IDType.Integer), item.ID.Integer);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM UserRole");
}
internal static IDataReader Get(TransactionContext tc, ID nID)
{
return tc.ExecuteReader("SELECT * FROM UserRole WHERE RoleID=%n", nID.Integer);
}
internal static IDataReader GetByUserID(TransactionContext tc, ID nUserID)
{
return tc.ExecuteReader("SELECT * FROM UserRole WHERE UserID=%n", nUserID.Integer);
}
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) as UserName,r.Name as 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) as UserName,r.Name as 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, ID nID)
{
tc.ExecuteNonQuery("DELETE FROM [UserRole] WHERE RoleID=%n", nID.Integer);
}
internal static void DeleteByUserID(TransactionContext tc, ID nID)
{
tc.ExecuteNonQuery("DELETE FROM [UserRole] WHERE UserID=%n", nID.Integer);
}
internal static void DeleteByUserID(TransactionContext tc, int nUserID)
{
tc.ExecuteNonQuery("DELETE FROM [UserRole] WHERE UserID=%n", nUserID);
}
internal static void Update(TransactionContext tc, ID nID, EnumStatus status)
{
tc.ExecuteNonQuery("UPDATE [UserRole] SET Status = %n,AuthorizedBy=%n,AuthorizedDate=%D WHERE UserID = %n", status, Payroll.BO.User.CurrentUser.ID.Integer, DateTime.Now, nID.Integer);
}
#endregion
}
#endregion
}