572 lines
21 KiB
C#
572 lines
21 KiB
C#
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 ProductionBonusSetup Service
|
|
[Serializable]
|
|
public class ProductionBonusSetupService : ServiceTemplate, IProductionBonusSetupService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(ProductionBonusSetup));
|
|
|
|
#endregion
|
|
public ProductionBonusSetupService() { }
|
|
private void MapObject(ProductionBonusSetup oProductionBonusSetup, DataReader oReader)
|
|
{
|
|
//oProductionBonusSetup.ID = oReader.GetID("ProductionBonusSetupID");
|
|
base.SetObjectID(oProductionBonusSetup, oReader.GetID("ProductionBonusSetupID"));
|
|
oProductionBonusSetup.DesignNo = oReader.GetString("DesignNo");
|
|
oProductionBonusSetup.ProgramName = oReader.GetString("ProgramName");
|
|
oProductionBonusSetup.AchivedPercent = oReader.GetDouble("AchivedPercent").GetValueOrDefault();
|
|
oProductionBonusSetup.OTHour = oReader.GetDouble("OTHour").GetValueOrDefault();
|
|
oProductionBonusSetup.MaxPerson = oReader.GetInt32("MaxPerson").Value;
|
|
oProductionBonusSetup.FromDate = oReader.GetDateTime("FromDate").Value;
|
|
oProductionBonusSetup.ToDate = oReader.GetDateTime("ToDate").Value;
|
|
oProductionBonusSetup.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
|
|
oProductionBonusSetup.Status = (EnumBonusStatus)oReader.GetInt32("Status").Value;
|
|
oProductionBonusSetup.CreatedBy = oReader.GetID("CreatedBy");
|
|
oProductionBonusSetup.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
|
|
this.SetObjectState(oProductionBonusSetup, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
ProductionBonusSetup oProductionBonusSetup = new ProductionBonusSetup();
|
|
MapObject(oProductionBonusSetup, oReader);
|
|
return oProductionBonusSetup as T;
|
|
}
|
|
protected ProductionBonusSetup CreateObject(DataReader oReader)
|
|
{
|
|
ProductionBonusSetup oProductionBonusSetup = new ProductionBonusSetup();
|
|
MapObject(oProductionBonusSetup, oReader);
|
|
return oProductionBonusSetup;
|
|
}
|
|
private void MapLineObject(ProdBonusLine oProdBonusLine, DataReader oReader)
|
|
{
|
|
//oProdBonusLine.ID = oReader.GetID("ProdBonusLineID");
|
|
base.SetObjectID(oProdBonusLine, oReader.GetID("ProdBonusLineID"));
|
|
oProdBonusLine.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID");
|
|
// oProdBonusLine.EmployeeID = oReader.GetID("EmployeeID");
|
|
oProdBonusLine.LineName = oReader.GetString("LineName");
|
|
oProdBonusLine.LineAchievedPercent = oReader.GetDouble("LineAchievedPercent").GetValueOrDefault();
|
|
oProdBonusLine.LineOTHour = oReader.GetDouble("LineOTHour").GetValueOrDefault();
|
|
oProdBonusLine.ScheduledHour = oReader.GetDouble("ScheduledHour").GetValueOrDefault();
|
|
this.SetObjectState(oProdBonusLine, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
private ProdBonusLine CreateProdBonusLineObject(DataReader oReader)
|
|
{
|
|
ProdBonusLine item = new ProdBonusLine();
|
|
MapLineObject(item, oReader);
|
|
return item;
|
|
}
|
|
protected ObjectsTemplate<ProdBonusLine> CreateProdBonusLineObjects(DataReader oReader)
|
|
{
|
|
ObjectsTemplate<ProdBonusLine> oItems = new ObjectsTemplate<ProdBonusLine>();
|
|
while (oReader.Read())
|
|
{
|
|
ProdBonusLine item = CreateProdBonusLineObject(oReader);
|
|
oItems.Add(item);
|
|
}
|
|
return oItems;
|
|
}
|
|
private void MapScheduleObject(ProdBonusWorkSchedule oProdBonusWorkSchedule, DataReader oReader)
|
|
{
|
|
//oProdBonusWorkSchedule.ID = oReader.GetID("ProdBonusWorkScheduleID");
|
|
base.SetObjectID(oProdBonusWorkSchedule, oReader.GetID("ProdBonusWorkScheduleID"));
|
|
oProdBonusWorkSchedule.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID");
|
|
//oProdBonusWorkSchedule.StartDateTime = oReader.GetDateTime("StartDateTime").Value;
|
|
//oProdBonusWorkSchedule.EndDateTime = oReader.GetDateTime("EndDateTime").Value;
|
|
|
|
this.SetObjectState(oProdBonusWorkSchedule, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
private ProdBonusWorkSchedule CreateScheduleObject(DataReader oReader)
|
|
{
|
|
ProdBonusWorkSchedule item = new ProdBonusWorkSchedule();
|
|
MapScheduleObject(item, oReader);
|
|
return item;
|
|
}
|
|
protected ObjectsTemplate<ProdBonusWorkSchedule> CreateScheduleObjects(DataReader oReader)
|
|
{
|
|
ObjectsTemplate<ProdBonusWorkSchedule> oItems = new ObjectsTemplate<ProdBonusWorkSchedule>();
|
|
while (oReader.Read())
|
|
{
|
|
ProdBonusWorkSchedule item = CreateScheduleObject(oReader);
|
|
oItems.Add(item);
|
|
}
|
|
return oItems;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public ProductionBonusSetup Get(ID id)
|
|
{
|
|
ProductionBonusSetup oProductionBonusSetup = new ProductionBonusSetup();
|
|
#region Cache Header
|
|
oProductionBonusSetup = _cache["Get", id] as ProductionBonusSetup;
|
|
if (oProductionBonusSetup != null)
|
|
return oProductionBonusSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ProductionBonusSetupDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oProductionBonusSetup = this.CreateObject<ProductionBonusSetup>(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(oProductionBonusSetup, "Get", id);
|
|
#endregion
|
|
return oProductionBonusSetup;
|
|
}
|
|
|
|
public ProductionBonusSetup Get(string DesignNo)
|
|
{
|
|
ProductionBonusSetup oProductionBonusSetup = new ProductionBonusSetup();
|
|
#region Cache Header
|
|
oProductionBonusSetup = _cache["Get", DesignNo] as ProductionBonusSetup;
|
|
if (oProductionBonusSetup != null)
|
|
return oProductionBonusSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ProductionBonusSetupDA.Get(tc, DesignNo));
|
|
if (oreader.Read())
|
|
{
|
|
oProductionBonusSetup = this.CreateObject<ProductionBonusSetup>(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(oProductionBonusSetup, "Get", DesignNo);
|
|
#endregion
|
|
return oProductionBonusSetup;
|
|
}
|
|
|
|
public ObjectsTemplate<ProductionBonusSetup> Get(DateTime dtSalaryMonth)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<ProductionBonusSetup> ProductionBonusSetups = _cache["Get"] as ObjectsTemplate<ProductionBonusSetup>;
|
|
if (ProductionBonusSetups != null)
|
|
return ProductionBonusSetups;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(ProductionBonusSetupDA.Get(tc, dtSalaryMonth));
|
|
ProductionBonusSetups = this.CreateObjects<ProductionBonusSetup>(dr);
|
|
dr.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(ProductionBonusSetups, "Get");
|
|
#endregion
|
|
return ProductionBonusSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<ProductionBonusSetup> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<ProductionBonusSetup> ProductionBonusSetups = _cache["Get"] as ObjectsTemplate<ProductionBonusSetup>;
|
|
if (ProductionBonusSetups != null)
|
|
return ProductionBonusSetups;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(ProductionBonusSetupDA.Get(tc));
|
|
ProductionBonusSetups = this.CreateObjects<ProductionBonusSetup>(dr);
|
|
dr.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(ProductionBonusSetups, "Get");
|
|
#endregion
|
|
return ProductionBonusSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<ProductionBonusSetup> Get(EnumBonusStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<ProductionBonusSetup> ProductionBonusSetups = _cache["Get", status] as ObjectsTemplate<ProductionBonusSetup>;
|
|
if (ProductionBonusSetups != null)
|
|
return ProductionBonusSetups;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ProductionBonusSetupDA.Get(tc, status));
|
|
ProductionBonusSetups = this.CreateObjects<ProductionBonusSetup>(dr);
|
|
dr.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(ProductionBonusSetups, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return ProductionBonusSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<ProdBonusLine> GetProductionBonusLine(ID id)
|
|
{
|
|
|
|
ObjectsTemplate<ProdBonusLine> oProdBonusLine = new ObjectsTemplate<ProdBonusLine>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ProductionBonusSetupDA.GetProductionBonusLine(tc, id));
|
|
|
|
oProdBonusLine = this.CreateProdBonusLineObjects(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 oProdBonusLine;
|
|
}
|
|
|
|
public ObjectsTemplate<ProdBonusParameter> GetProdBonusParameters(ID iD)
|
|
{
|
|
|
|
ObjectsTemplate<ProdBonusParameter> ProdBonusParameters = new ObjectsTemplate<ProdBonusParameter>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ProductionBonusSetupDA.GetProdBonusParameters(tc, iD));
|
|
ProdBonusParameters = this.CreateObjects<ProdBonusParameter>(dr);
|
|
dr.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 ProdBonusParameters;
|
|
}
|
|
|
|
public ObjectsTemplate<ProdBonusWorkSchedule> GetProdBonusWorkSchedules(ID iD)
|
|
{
|
|
ObjectsTemplate<ProdBonusWorkSchedule> ProdBonusWorkSchedules = new ObjectsTemplate<ProdBonusWorkSchedule>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ProductionBonusSetupDA.GetProdBonusWorkSchedules(tc, iD));
|
|
ProdBonusWorkSchedules = this.CreateScheduleObjects(dr);
|
|
dr.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 ProdBonusWorkSchedules;
|
|
}
|
|
|
|
public ID Save(ProductionBonusSetup oProductionBonusSetup)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Get Uncalled Properties
|
|
|
|
foreach (var item in oProductionBonusSetup.ProductionBonusLines)
|
|
{
|
|
var temp = item.ProdBonusWorkSchedules;
|
|
var temp1 = item.ProdBonusSupervisors;
|
|
var temp2 = item.ProdBonusParameters;
|
|
}
|
|
|
|
#endregion
|
|
|
|
if (oProductionBonusSetup.IsNew)
|
|
{
|
|
#region New
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
int id = tc.GenerateID("ProductionBonusSetup", "ProductionBonusSetupID");
|
|
base.SetObjectID(oProductionBonusSetup, ID.FromInteger(id));
|
|
ProductionBonusSetupDA.Insert(tc, oProductionBonusSetup);
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region Update
|
|
|
|
#region Get Prev ProdLines
|
|
|
|
List<ProdBonusLine> oldLines = GetProductionBonusLine(oProductionBonusSetup.ID);
|
|
|
|
foreach (var item in oldLines)
|
|
{
|
|
item.ProdBonusWorkSchedules =(new ProdBonusLineService()).GetProdBonusWorkSchedules(item.ID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
ProductionBonusSetupDA.Update(tc, oProductionBonusSetup);
|
|
|
|
#region Delete Normal Childs
|
|
|
|
//ProductionBonusSetupDA.DeleteAttn(tc, oProductionBonusSetup.ID.Integer);
|
|
ProductionBonusSetupDA.DeleteSupervisor(tc, oProductionBonusSetup.ID.Integer);
|
|
ProductionBonusSetupDA.DeleteParameter(tc, oProductionBonusSetup.ID.Integer);
|
|
|
|
#endregion
|
|
|
|
#region Delete Prod Lines with Schedule
|
|
|
|
foreach (var line in oldLines)
|
|
{
|
|
if (!oProductionBonusSetup.ProductionBonusLines.Any(x => x.ID == line.ID))
|
|
{
|
|
foreach (var shedule in line.ProdBonusWorkSchedules)
|
|
{
|
|
ProductionBonusSetupDA.DeleteSchedule(tc, shedule.ID.Integer);
|
|
}
|
|
ProductionBonusSetupDA.DeleteLine(tc, line.ID.Integer);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#region Insert Or Update Prod Lines
|
|
|
|
|
|
foreach (ProdBonusLine oProdBonusLine in oProductionBonusSetup.ProductionBonusLines)
|
|
{
|
|
//ProdBonusLineDA.DeleteChiled(tc, oProdBonusLine.ID.Integer);
|
|
if (oProdBonusLine.IsNew)
|
|
{
|
|
#region New
|
|
|
|
oProdBonusLine.ProdBonusSetupID = oProductionBonusSetup.ID;
|
|
base.SetObjectID(oProdBonusLine, ID.FromInteger(tc.GenerateID("ProdBonusLine", "ProdBonusLineID")));
|
|
ProdBonusLineDA.Insert(tc, oProdBonusLine);
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region Update
|
|
|
|
ProdBonusLineDA.Update(tc, oProdBonusLine);
|
|
|
|
#region Delete WorkSchedule
|
|
|
|
List<ProdBonusWorkSchedule> oldWorkSchedule = (new ProdBonusLineService()).GetProdBonusWorkSchedules(tc, oProdBonusLine.ID);
|
|
|
|
foreach (var wSchedule in oldWorkSchedule)
|
|
{
|
|
if (!oProdBonusLine.ProdBonusWorkSchedules.Any(x => x.ID == wSchedule.ID))
|
|
{
|
|
ProductionBonusSetupDA.DeleteSchedule(tc, wSchedule.ID.Integer);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region Insert Normal Childs
|
|
|
|
foreach (ProdBonusSupervisor supervisor in oProdBonusLine.ProdBonusSupervisors)
|
|
{
|
|
base.SetObjectID(supervisor, ID.FromInteger(tc.GenerateID("ProdBonusSupervisor", "ProdBonusSupervisorID")));
|
|
supervisor.ProdBonusSetupID = oProductionBonusSetup.ID;
|
|
supervisor.ProdBonusLineID = oProdBonusLine.ID;
|
|
ProdBonusSupervisorDA.Insert(tc, supervisor);
|
|
}
|
|
foreach (ProdBonusParameter param in oProdBonusLine.ProdBonusParameters)
|
|
{
|
|
base.SetObjectID(param, ID.FromInteger(tc.GenerateID("ProdBonusParameter", "ProdBonusParameterID")));
|
|
param.ProdBonusSetupID = oProductionBonusSetup.ID;
|
|
param.ProdBonusLineID = oProdBonusLine.ID;
|
|
ProdBonusParameterDA.Insert(tc, param);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Workschedule Insert Or Update
|
|
|
|
foreach (ProdBonusWorkSchedule oProdBonusWorkSchedule in oProdBonusLine.ProdBonusWorkSchedules)
|
|
{
|
|
if (oProdBonusWorkSchedule.IsNew)
|
|
{
|
|
base.SetObjectID(oProdBonusWorkSchedule, ID.FromInteger(tc.GenerateID("ProdBonusWorkSchedule", "ProdBonusWorkScheduleID")));
|
|
oProdBonusWorkSchedule.ProdBonusSetupID = oProductionBonusSetup.ID;
|
|
oProdBonusWorkSchedule.ProdBonusLineID = oProdBonusLine.ID;
|
|
ProdBonusWorkScheduleDA.Insert(tc, oProdBonusWorkSchedule);
|
|
}
|
|
else
|
|
{
|
|
ProdBonusWorkScheduleDA.Update(tc, oProdBonusWorkSchedule);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
tc.End();
|
|
return oProductionBonusSetup.ID;
|
|
}
|
|
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);
|
|
ProductionBonusSetupDA.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
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region IProductionBonusSetupService Members
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|