CEL_Payroll/Payroll.Service/Budget/Service/MarketSalarySurveyService.cs

318 lines
8.8 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using System.Data;
namespace Payroll.Service
{
public class MarketSalarySurveyService : ServiceTemplate, IMarketSalarySurveyService
{
#region Object Mapping
private void MapObject(MarketSalarySurvey obMarketSurvey, DataReader oReader)
{
SetObjectID(obMarketSurvey, oReader.GetID("MarketSurveyID"));
obMarketSurvey.GradeID = oReader.GetID("GradeID");
obMarketSurvey.CompanyID = oReader.GetID("CompanyID");
obMarketSurvey.Amount = (double)oReader.GetDouble("Amount");
obMarketSurvey.SurveyYear = (DateTime)oReader.GetDateTime("SurveyYear");
//new DateTime((int)oReader.GetInt32("SurveyYear"), 1, 1);
obMarketSurvey.SurveyOn = (EnumSurveyOn)oReader.GetInt32("SurveyOn");
}
protected override T CreateObject<T>(DataReader oReader)
{
MarketSalarySurvey oMarketSurvey = new MarketSalarySurvey();
MapObject(oMarketSurvey, oReader);
return oMarketSurvey as T;
}
#endregion
#region Service Implementayion
public MarketSalarySurvey Get(ID nID)
{
MarketSalarySurvey oMarketSurvey = new MarketSalarySurvey();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MarketSalarySurveyDA.Get(tc, nID));
if (oreader.Read())
{
oMarketSurvey = CreateObject<MarketSalarySurvey>(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
}
return oMarketSurvey;
}
public ObjectsTemplate<MarketSalarySurvey> Get(DateTime surveryYear)
{
ObjectsTemplate<MarketSalarySurvey> oMarketSurvey = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MarketSalarySurveyDA.Get(tc, surveryYear));
oMarketSurvey = this.CreateObjects<MarketSalarySurvey>(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
}
return oMarketSurvey;
}
public ObjectsTemplate<MarketSalarySurvey> Get(DateTime surveryYear, int nSurveyOn, int nGradeID)
{
ObjectsTemplate<MarketSalarySurvey> oMarketSurvey = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MarketSalarySurveyDA.Get(tc, surveryYear, nSurveyOn, nGradeID));
oMarketSurvey = this.CreateObjects<MarketSalarySurvey>(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
}
return oMarketSurvey;
}
public ObjectsTemplate<MarketSalarySurvey> Get(DateTime surveryYear, int nSurveyOn)
{
ObjectsTemplate<MarketSalarySurvey> oMarketSurvey = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MarketSalarySurveyDA.Get(tc, surveryYear, nSurveyOn));
oMarketSurvey = this.CreateObjects<MarketSalarySurvey>(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
}
return oMarketSurvey;
}
public ID Save(MarketSalarySurvey item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("MarketSurvey", "MarketSurveyID");
SetObjectID(item, ID.FromInteger(id));
MarketSalarySurveyDA.Insert(tc, item);
}
else
{
MarketSalarySurveyDA.Update(tc, item);
}
tc.End();
return item.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SaveAll(ObjectsTemplate<MarketSalarySurvey> allItems)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (MarketSalarySurvey item in allItems)
{
if (item.IsNew)
{
int id = tc.GenerateID("MarketSalarySurvey", "MarketSurveyID");
SetObjectID(item, ID.FromInteger(id));
MarketSalarySurveyDA.Insert(tc, item);
}
else
{
MarketSalarySurveyDA.Update(tc, item);
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public void Update(MarketSalarySurvey item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MarketSalarySurveyDA.Update(tc, item);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MarketSalarySurveyDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public bool CheckDesignationExistsOrNot(ID iD,DateTime year)
{
bool flag = true;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataSet oDs = null;
oDs = MarketSalarySurveyDA.CheckDesignationExistsOrNot(tc, iD,year);
if (oDs.Tables[0].Rows.Count > 0)
{
flag = false;
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return flag;
}
#endregion
}
}