CEL_Payroll/Payroll.Service/Users/DA/UserDA.cs

119 lines
5.7 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
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 UserDA
internal class UserDA
{
#region Constructor
private UserDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, User item)
{
item.CreatedDate = DateTime.Now;
tc.ExecuteNonQuery("INSERT INTO Users(UserID, loginID, userName, ownerID, password, empPasswordHint, SISU, CREATIONDATE,UserType,isforcechangepass,status,AuthorizedBy,LastChangeDate,LockedWorkStation,PasswordHint,GroupNo,Reason,TempStatus,ComputerName,ApprovedComputerName)" +
" VALUES(%n, %s, %s, %n, %s, %s, %n, %D, %n, %n,%n,%n,%d,%s,%s,%n,%s,%n,%s,%s)", item.ID.Integer, item.LoginID, item.Name, DataReader.GetNullValue(item.ParentID != null ? item.ParentID.Integer : 0),
item.Password, item.PasswordHints, item.SISU, item.CreatedDate, Convert.ToInt32(item.UserType), Convert.ToInt16(item.IsForceChangePass), item.Status, DataReader.GetNullValue(item.AuthorizedBy, IDType.Integer), DateTime.Today, item.LockedWorkStation, item.PasswordHints, item.GroupNumber, item.Reason, (int)item.TempStatus, item.ComputerName, item.ApprovedComputerName);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, User item)
{
item.CreatedDate = DateTime.Now;
item.AuthorizedDate = DateTime.Now;
tc.ExecuteNonQuery("UPDATE Users SET loginID=%s, userName=%s, ownerID=%n, password=%s, empPasswordHint=%s, SISU=%n , isforcechangepass = %n,status=%n,CREATIONDATE=%D,AuthorizedBy=%n,AuthorizedDate=%D,LastChangeDate=%d,LockedWorkStation=%s,PasswordHint=%s,GroupNo=%n,Reason=%s,TempStatus=%n,ComputerName=%s,ApprovedComputerName=%s" +
" WHERE UserID=%n", item.LoginID, item.Name, item.ParentID.Integer, item.Password, item.PasswordHints, item.SISU, Convert.ToInt16(item.IsForceChangePass), item.Status, item.CreatedDate, DataReader.GetNullValue(item.AuthorizedBy, IDType.Integer), item.AuthorizedDate, DateTime.Today, item.LockedWorkStation, item.PasswordHints, item.GroupNumber, item.Reason, (int)item.TempStatus, item.ComputerName, item.ApprovedComputerName, item.ID.Integer);
}
internal static void Update(TransactionContext tc, User item, EnumStatus status)
{
item.AuthorizedDate = DateTime.Now;
tc.ExecuteNonQuery("UPDATE Users SET ownerID=%n, Status = %n,AuthorizedBy=%n,AuthorizedDate=%D,Reason=%s,TempStatus=%n,CREATIONDATE=%D,ComputerName=%s,ApprovedComputerName=%s WHERE UserID = %n", DataReader.GetNullValue(item.ParentID != null ? item.ParentID.Integer : 0), status, DataReader.GetNullValue(item.AuthorizedBy, IDType.Integer), item.AuthorizedDate, item.Reason, (int)item.TempStatus, DataReader.GetNullValue(item.CreatedDate), item.ComputerName, item.ApprovedComputerName, item.ID.Integer);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc, EnumSystemType type)
{
return tc.ExecuteReader("SELECT * FROM Users where UserType = %n", type);
}
internal static IDataReader Get(TransactionContext tc, ID nID)
{
return tc.ExecuteReader("SELECT * FROM Users WHERE UserID=%n", nID.Integer);
}
internal static IDataReader Get(TransactionContext tc, string sName)
{
return tc.ExecuteReader("SELECT * FROM Users WHERE USERNAME=%s", sName);
}
internal static IDataReader GetByLogInID(TransactionContext tc, string sLogInID, EnumSystemType eSysType)
{
return tc.ExecuteReader("SELECT * FROM Users WHERE LOGINID=%s AND UserType = %n", sLogInID, eSysType);
}
internal static DataSet GetUsers(TransactionContext tc, EnumSystemType type, DateTime fromDate, DateTime ToDate)
{
DataSet oIDs = new DataSet();
try
{
string sSQL = SQLParser.MakeSQL(@"Select zu.AuditDate,(SELECT LoginID FROM Users u2 WHERE userid=zu.ownerid) as ActionBy,zu.UserName,zu.ComputerName,zu.Status
from Z_Users zu where zu.AuditDate>=%d
And zu.AuditDate<=%d
AND zu.USERTYPE=%n
AND zu.[Status]<>12
AND zu.AuditType IN('Inserted','Update (after)')
ORDER BY zu.AuditDate DESC", fromDate, ToDate, (int)type);
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("Update [Users] SET ownerID=%n WHERE UserID=%n", Payroll.BO.User.CurrentUser.ID.Integer, nID.Integer);
tc.ExecuteNonQuery("DELETE FROM [Users] WHERE UserID=%n", nID.Integer);
}
#endregion
internal static IDataReader GetByID(TransactionContext tc, int userID)
{
return tc.ExecuteReader("SELECT * FROM Users WHERE UserID = %n ", userID);
}
}
#endregion
}