EchoTex_Payroll/HRM.DA/DA/SearchReport/AuthorizedPersonDA.cs

136 lines
4.8 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
namespace HRM.DA
{
#region AuthorizedPersonDA
internal class AuthorizedPersonDA
{
#region Constructor
private AuthorizedPersonDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, AuthorizedPerson item)
{
string sSQl = SQLParser.MakeSQL(
"INSERT INTO AuthorisedPerson(PersonID, Name, Position, DESIGNATION, CreatedBy, CreatedDate,Email,EmployeeId,Phone,Extension)" +
" VALUES(%n, %s, %n, %s, %n, %d,%s,%n,%s,%s)",
item.ID, item.Name, item.Sequence, item.Designation,
DataReader.GetNullValue(item.CreatedBy), DataReader.GetNullValue(item.CreatedDate),item.Email,item.EmployeeId,item.Phone,item.Extension);
tc.ExecuteNonQuery(sSQl);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, AuthorizedPerson item)
{
tc.ExecuteNonQuery(@"UPDATE AuthorisedPerson SET Name=%s, Position=%n, DESIGNATION=%s,Email=%s,EmployeeId=%n,Phone=%s,Extension=%s,
ModifiedBy =%n, ModifiedDate = %d WHERE PersonID=%n",
item.Name, item.Sequence, item.Designation, item.Email, item.EmployeeId, item.Phone, item.Extension,
item.ModifiedBy, DataReader.GetNullValue(item.ModifiedDate), item.ID);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM AuthorisedPerson Order by Position");
}
internal static IDataReader Get(TransactionContext tc, int nID)
{
return tc.ExecuteReader("SELECT * FROM AuthorisedPerson WHERE PersonID=%n", nID);
}
public static object GetMaxPosition(TransactionContext tc)
{
return tc.ExecuteScalar("SELECT MAX(Position) FROM AuthorisedPerson");
}
internal static IDataReader GetByReportID(TransactionContext tc, int reportID)
{
return tc.ExecuteReader(@"SELECT ap.*
FROM AuthorisedPerson ap ,REPORTAUTHORISATION ra
WHERE ap.PERSONID = ra.PERSONID
AND ra.REPORTID = %n", reportID);
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int nID)
{
tc.ExecuteNonQuery("DELETE FROM AuthorisedPerson WHERE PersonID=%n", nID);
}
#endregion
#region Other Functions
public static bool IsExist(TransactionContext tc, string Name)
{
string str =
Ease.Core.DataAccess.SQLParser.MakeSQL("SELECT COUNT(*) FROM AuthorisedPerson Where Name = %s", Name);
object obj = tc.ExecuteScalar(str);
return Convert.ToInt32(obj) > 0;
}
//Get Image
public static DataSet GetImage(TransactionContext tc, int nPersonID)
{
return tc.ExecuteDataSet(@"SELECT SignatureData FROM AuthorisedPerson WHERE PersonID=%n", nPersonID);
//SqlDataAdapter sDataAdapter = new SqlDataAdapter();
//DataSet dSet = new DataSet();
//SqlCommand command = new SqlCommand("SELECT SignatureData FROM AuthorisedPerson WHERE PersonID=@PersonID", connection);
//command.Parameters.Add("@PersonID", SqlDbType.Int).Value = nPersonID;
//sDataAdapter.SelectCommand = command;
//connection.Open();
//sDataAdapter.Fill(dSet);
//return dSet;
}
//Insert Image
public static void UpdateData(string connectionString, AuthorizedPerson item)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand("UPDATE AuthorisedPerson SET " + "SignatureData=@Signature,FileName=@FileName WHERE PersonID=@PersonID ", connection);
command.Parameters.Add("@PersonID", SqlDbType.Int).Value = item.ID;
command.Parameters.Add("@FileName", SqlDbType.VarChar);
command.Parameters["@FileName"].Value = item.FileName;
command.Parameters.Add("@Signature", SqlDbType.VarBinary);
command.Parameters["@Signature"].Value = item.Signature;
connection.Open();
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
}
}
#endregion
}
#endregion
}