CEL_Payroll/Payroll.Service/Basic/Service/SystemInformationService.cs

274 lines
9.6 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region SystemInformation Service
[Serializable]
public class SystemInformationService : ServiceTemplate, ISystemInformationService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SystemInformation));
#endregion
public SystemInformationService() { }
private void MapObject(SystemInformation oSystemInformation, DataReader oReader)
{
base.SetObjectID(oSystemInformation, ID.FromInteger(1));
oSystemInformation.name = oReader.GetString("NAME");
oSystemInformation.Code = oReader.GetString("Code");
oSystemInformation.corporateAddress = oReader.GetString("CORPORATEADDRESS");
oSystemInformation.factoryAddress = oReader.GetString("FACTORYADDRESS");
oSystemInformation.TelephoneNo = oReader.GetString("TELEPHONE");
oSystemInformation.email = oReader.GetString("EMAIL");
oSystemInformation.webAddress = oReader.GetString("WEBADDRESS");
oSystemInformation.systemStartDate = oReader.GetDateTime("SYSTEMSTARTDATE").Value;
oSystemInformation.TaxYearEndDate = oReader.GetDateTime("TAXYEARENDDATE").Value;
oSystemInformation.NextPayProcessDate = oReader.GetDateTime("NEXTPAYPROCESSDATE").Value;
oSystemInformation.maxYearOfService = oReader.GetInt32("MAXYEAROFSERVICE").Value;
oSystemInformation.pFContriStaff = oReader.GetDouble("PFCONTRISTAFF").Value;
oSystemInformation.pFContriCompany = oReader.GetDouble("PFCONTRICOMPANY").Value;
oSystemInformation.pFInterest = oReader.GetDouble("PFINTEREST").Value;
oSystemInformation.TaxParamID = oReader.GetID("PARAMID");
oSystemInformation.oTFilePath = oReader.GetString("OTFILEPATH");
oSystemInformation.PFYearEndDate = oReader.GetDateTime("PFYEARENDDATE").Value;
this.SetObjectState(oSystemInformation,Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SystemInformation oSystemInformation = new SystemInformation();
MapObject(oSystemInformation, oReader);
return oSystemInformation as T;
}
protected SystemInformation CreateObject(DataReader oReader)
{
SystemInformation oSystemInformation = new SystemInformation();
MapObject(oSystemInformation, oReader);
return oSystemInformation;
}
public string GetDatabaseName()
{
string s = "";
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
s = tc.Connection.Database.ToString();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return s;
}
#region Service implementation
public SystemInformation Get()
{
SystemInformation oSystemInformation = new SystemInformation();
#region Cache Header
oSystemInformation = _cache["Get"] as SystemInformation;
if (oSystemInformation != null)
return oSystemInformation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(SystemInformationDA.Get(tc));
if (oreader.Read())
{
oSystemInformation = this.CreateObject<SystemInformation>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oSystemInformation, "Get");
#endregion
return oSystemInformation;
}
public void UpdCurrYerTaxParamter(ID taxParameterID, ID PayrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SystemInformationDA.UpdateTaxParamId(tc, taxParameterID, PayrollTypeID);
//TaxMergeMasterService srv = new TaxMergeMasterService();
//List<TaxMergeMaster> oTaxMergeMasters = srv.GetPrevByTaxParamID(tc, PayrollTypeID.Integer);
//foreach (TaxMergeMaster item in oTaxMergeMasters)
//{
// item.TaxParameterID = taxParameterID;
// foreach (TaxMergeMaster.TaxMergeDetail detail in item.TaxMergeDetails)
// {
// detail.TaxParameterID = taxParameterID;
// }
//}
//srv.Save(oTaxMergeMasters, tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DateTime GetServerDate()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
string s = Convert.ToString(tc.Connection);
DateTime ServerDate = SystemInformationDA.GetServerDate(tc, s);
tc.End();
return ServerDate;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Save This System Information", e);
#endregion
}
}
public static DateTime GetServerDate(TransactionContext tc)
{
try
{
string s = Convert.ToString(tc.Connection);
DateTime ServerDate = SystemInformationDA.GetServerDate(tc, s);
return ServerDate;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Save This System Information", e);
#endregion
}
}
public ID Update(SystemInformation oSystemInformation)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SystemInformationDA.Update(tc, oSystemInformation);
tc.End();
return oSystemInformation.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DataTable GetPasswordSetup()
{
DataTable dt = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dt = SystemInformationDA.GetPasswordSetup(tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dt;
}
public void Save(HardPasswordSetup oItem)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SystemInformationDA.Save(tc, oItem);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public string GetConnectionString()
{
TransactionContext tc = null;
string connection = string.Empty;
try
{
tc = TransactionContext.Begin(true);
connection = tc.Connection.ConnectionString;
if (connection != null)
return connection;
}
catch(Exception ex)
{
throw ex;
}
return connection;
}
#endregion
}
#endregion
}