122 lines
4.7 KiB
C#
122 lines
4.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
internal class UserLogInInfoDA
|
|
{
|
|
#region Constructor
|
|
|
|
private UserLogInInfoDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, UserLogInInfo item)
|
|
{
|
|
string sql = SQLParser.MakeSQL(
|
|
@"INSERT INTO UserLoginInfo(SLID, UserID, LoginTime, PCNumber, LogoutTime, LogoutType, IPAddress, DeviceId)
|
|
VALUES(%n, %n, %D, %s, %D, %n, %s, %s)",
|
|
item.ID, item.UserID, item.LoginTime, item.PCNumber, item.LogoutTime, item.LogoutType,
|
|
item.IPAddress, item.DeviceId);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
internal static void Update(TransactionContext tc, UserLogInInfo item)
|
|
{
|
|
string sql = SQLParser.MakeSQL(@"Update UserLoginInfo set LogoutTime=%D,LogoutType=%n where SlID=%n",
|
|
item.LogoutTime, (int)item.LogoutType, item.ID);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
#endregion
|
|
|
|
internal static IDataReader UpdateLogoutTime(TransactionContext tc, int nLoginID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
"update UserLogInInfo set LogoutTime=%D,LogoutType=%n Where UserID=%n AND LogoutTime is null",
|
|
DateTime.Now, (int)EnumLogoutType.User, nLoginID);
|
|
}
|
|
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader Get(TransactionContext tc)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM UserLogInInfo Order By SequenceNO");
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, string sLoginID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
"SELECT * FROM UserLogInInfo a,Users b where a.userid=b.userid and Lower(b.Loginid)=%s and a.LogoutTime is null and a.LogoutType != %n",
|
|
sLoginID.ToLower(), (int)EnumLogoutType.WebUser);
|
|
}
|
|
|
|
internal static IDataReader GetLastLogin(TransactionContext tc, string sLoginID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
@"SELECT a.* FROM UserLogInInfo a,Users b where a.userid=b.userid and Lower(b.Loginid)=%s and a.LogoutTime is NOT NULL ORDER BY LOGINTIME DESC
|
|
|
|
", sLoginID.ToLower());
|
|
}
|
|
|
|
internal static IDataReader GetLastWebLogin(TransactionContext tc, string sLoginID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
@"SELECT a.* FROM UserLogInInfo a, Users b, Employee c where a.userid=b.userid and c.EMPLOYEENO = b.LOGINID and Lower(c.EMAILADDRESS)=%s and a.LogoutType = %n ORDER BY LOGINTIME DESC
|
|
|
|
", sLoginID.ToLower(), (int)EnumLogoutType.WebUser);
|
|
}
|
|
|
|
internal static IDataReader GetLoggedUsers(TransactionContext tc)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM UserLogInInfo a where a.LogoutTime is null");
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int ID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM UserLogInInfo Where UserLogInInfoID=%n", ID);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, DateTime dtFrom, DateTime dtTo)
|
|
{
|
|
DateTime dtf = new DateTime(dtFrom.Year, dtFrom.Month, dtFrom.Day, 1, 0, 0);
|
|
DateTime dtt = new DateTime(dtTo.Year, dtTo.Month, dtTo.Day, 23, 59, 59);
|
|
return tc.ExecuteReader("select * from UserLoginInfo where logintime between %d AND %d order by logintime",
|
|
dtf, dtt);
|
|
}
|
|
|
|
// System Audit Trail: every login in the date range (both days inclusive),
|
|
// with the user's LoginID / Name, newest first.
|
|
internal static IDataReader GetAuditTrail(TransactionContext tc, DateTime dtFrom, DateTime dtTo)
|
|
{
|
|
string sql = SQLParser.MakeSQL(
|
|
@"SELECT a.*, u.LoginID, u.UserName
|
|
FROM UserLoginInfo a
|
|
LEFT JOIN Users u ON u.UserID = a.UserID
|
|
WHERE a.LoginTime >= %d AND a.LoginTime < %d
|
|
ORDER BY a.LoginTime DESC",
|
|
dtFrom.Date, dtTo.Date.AddDays(1));
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
|
|
internal static long NoofLogin(TransactionContext tc, int UserID)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT Count(*) FROM UserLoginInfo WHERE UserID=%n ", UserID);
|
|
object odata = tc.ExecuteScalar(sql);
|
|
if (odata == DBNull.Value) return 0;
|
|
else
|
|
{
|
|
return Convert.ToInt64(odata);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |