306 lines
8.5 KiB
C#
306 lines
8.5 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Utility;
|
|
using System.Collections.Generic;
|
|
using HRM.BO;
|
|
using System.Data;
|
|
using Ease.Core;
|
|
using System.Linq;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class VendorService : ServiceTemplate, IVendorService
|
|
{
|
|
#region Map Functions
|
|
|
|
private void MapObject(Vendor oVendor, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oVendor, (oReader.GetInt32("VendorID").Value));
|
|
oVendor.Name = oReader.GetString("Name");
|
|
oVendor.Code = oReader.GetString("Code");
|
|
oVendor.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oVendor.Status = (EnumStatus)oReader.GetUInt32("Status").GetValueOrDefault();
|
|
oVendor.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oVendor.CreatedDate = oReader.GetDateTime("CreatedDate").GetValueOrDefault(DateTime.MinValue);
|
|
oVendor.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oVendor.ModifiedDate = oReader.GetDateTime("ModifiedDate").GetValueOrDefault(DateTime.MinValue);
|
|
oVendor.Address = oReader.GetString("Address",null);
|
|
oVendor.EmailAddress = oReader.GetString("EmailAddress", null);
|
|
oVendor.Mobile = oReader.GetString("Mobile", null);
|
|
oVendor.Address = oReader.GetString("Address", null);
|
|
oVendor.Telephone = oReader.GetString("Telephone", null);
|
|
oVendor.ContactPerson = oReader.GetString("ContactPerson", null);
|
|
oVendor.VendorType = (EnumVendorType)oReader.GetUInt32("VendorType").GetValueOrDefault();
|
|
oVendor.VendorTypeString = ((EnumVendorType)oReader.GetUInt32("VendorType")).ToString();
|
|
this.SetObjectState(oVendor, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
Vendor oVendor = new Vendor();
|
|
MapObject(oVendor, dr);
|
|
return oVendor as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Implementation of IVendorService
|
|
|
|
public Vendor Get(int id)
|
|
{
|
|
Vendor oVendor = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(VendorDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oVendor = CreateObject<Vendor>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
|
|
return oVendor;
|
|
}
|
|
|
|
public List<Vendor> Get()
|
|
{
|
|
List<Vendor> vendors = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(VendorDA.Get(tc));
|
|
vendors = CreateObjects<Vendor>(oreader);
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
|
|
return vendors;
|
|
}
|
|
|
|
public List<Vendor> Get(EnumVendorType vendorType)
|
|
{
|
|
List<Vendor> vendors = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(VendorDA.Get(tc, vendorType));
|
|
vendors = CreateObjects<Vendor>(oreader);
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
|
|
return vendors;
|
|
}
|
|
|
|
public List<Vendor> Get(EnumStatus status,int payrollTypeID)
|
|
{
|
|
List<Vendor> vendors = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(VendorDA.Get(tc, status, payrollTypeID));
|
|
vendors = CreateObjects<Vendor>(oreader);
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
|
|
return vendors;
|
|
}
|
|
|
|
public List<Vendor> Get(string subStr)
|
|
{
|
|
List<Vendor> vendors = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(VendorDA.Get(tc, subStr));
|
|
vendors = CreateObjects<Vendor>(oreader);
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
|
|
return vendors;
|
|
}
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "vendor", "codeautogenerate", "Vendor", "Code");
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return _code;
|
|
}
|
|
|
|
public int Save(Vendor oVendor)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oVendor.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Vendor", "VendorID");
|
|
base.SetObjectID(oVendor, id);
|
|
int sequenceId = tc.GenerateID("Vendor", "SequenceNO");
|
|
oVendor.Sequence = sequenceId;
|
|
base.SetObjectID(oVendor, (id));
|
|
|
|
VendorDA.Insert(tc, oVendor);
|
|
}
|
|
else
|
|
{
|
|
VendorDA.Update(tc, oVendor);
|
|
}
|
|
|
|
return oVendor.ID;
|
|
}
|
|
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 Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
VendorDA.Delete(tc, id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |