844 lines
25 KiB
C#
844 lines
25 KiB
C#
|
using HRM.BO;
|
|||
|
using HRM.DA;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class LocationService : ServiceTemplate, ILocationService
|
|||
|
{
|
|||
|
public LocationService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void MapObject(Location oLocation, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oLocation, oReader.GetInt32("LocationID").Value);
|
|||
|
oLocation.Code = oReader.GetString("code");
|
|||
|
oLocation.Name = oReader.GetString("description");
|
|||
|
oLocation.NameInBangla = oReader.GetString("descriptioninbangla", true, null);
|
|||
|
//oLocation.NameInBangla = oReader.GetString("descriptioninbangla") == null ? null : oReader.GetString("descriptioninbangla");
|
|||
|
oLocation.ParentID = oReader.GetInt32("parentID");
|
|||
|
// oLocation.ParentsID = oReader.GetString("parentsID");
|
|||
|
oLocation.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oLocation.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oLocation.Tier = oReader.GetInt32("TIRE").Value;
|
|||
|
oLocation.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|||
|
//oLocation.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? null : ID.FromInteger(oReader.GetInt32("PayrollTypeID").Value);
|
|||
|
oLocation.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oLocation.ModifiedBy = oReader.GetInt32("ModifiedBy");
|
|||
|
oLocation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
oLocation.Longitude = oReader.GetDouble("Longitude", 0);
|
|||
|
oLocation.Latitude = oReader.GetDouble("Latitude", 0);
|
|||
|
oLocation.AttendancePoint = oReader.GetBoolean("AttendancePoint", false);
|
|||
|
oLocation.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value;
|
|||
|
oLocation.LatLongSetBy = oReader.GetInt32("LatLongSetBy");
|
|||
|
oLocation.LatLongSetDate = oReader.GetDateTime("LatLongSetDate");
|
|||
|
oLocation.LatLongApproveStatus = oReader.GetBoolean("LatLongApproveStatus", false);
|
|||
|
|
|||
|
this.SetObjectState(oLocation, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Location oLocation = new Location();
|
|||
|
MapObject(oLocation, oReader);
|
|||
|
return oLocation as T;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public Location Get(TransactionContext tc, int id)
|
|||
|
{
|
|||
|
Location oLocation = null;
|
|||
|
try
|
|||
|
{
|
|||
|
DataReader oreader = new DataReader(LocationDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(oreader);
|
|||
|
}
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oLocation;
|
|||
|
}
|
|||
|
|
|||
|
public Location Get(int id)
|
|||
|
{
|
|||
|
Location oLocation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(LocationDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(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 oLocation;
|
|||
|
}
|
|||
|
|
|||
|
public Location GetEmployeeLocation(int EmpID)
|
|||
|
{
|
|||
|
Location oLocation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(LocationDA.GetEmployeeLocation(tc, EmpID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(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 oLocation;
|
|||
|
}
|
|||
|
|
|||
|
public bool CheckEmployeeLocationIsExist(int EmpID)
|
|||
|
{
|
|||
|
bool isLocationExist = false;
|
|||
|
Location oLocation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader oreader = new DataReader(LocationDA.GetEmployeeLocation(tc, EmpID));
|
|||
|
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(oreader);
|
|||
|
|
|||
|
if(oLocation.AttendancePoint == true && oLocation.LatLongApproveStatus == false)
|
|||
|
{
|
|||
|
isLocationExist = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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 isLocationExist;
|
|||
|
}
|
|||
|
|
|||
|
public string GetNextCode(int tier)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
_code = GlobalFunctionService.GetMaxCode(tc, "location", "codeautogenerate", "location", "Code", tier);
|
|||
|
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 List<Location> GetLocations()
|
|||
|
{
|
|||
|
List<Location> locations = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.Get(tc));
|
|||
|
locations = this.CreateObjects<Location>(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(locations, "Get");
|
|||
|
|
|||
|
//#endregion
|
|||
|
|
|||
|
return locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetAllLocation(int payrollTypeID, EnumStatus status, string code, string name)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetAllLocation(tc, payrollTypeID, status, code, name));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetAllLocation(string code, string name)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetAllLocation(tc, code, name));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
public string GetNextCode(int _tier, string _parentCode)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
//#### _code = GlobalFunctionService.GetMaxCodeofTree(tc, "location", "codeautogenerate", "location", "Code","LocationID","ParentID", _parentCode, _tier);
|
|||
|
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 string GetNextCode(int _tier, int parentid)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
string parentCode = string.Empty;
|
|||
|
try
|
|||
|
{
|
|||
|
if (parentid != -1)
|
|||
|
{
|
|||
|
Location parent = this.Get((int)parentid);
|
|||
|
if (parent != null)
|
|||
|
parentCode = parent.Code;
|
|||
|
}
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
_code = GlobalFunctionService.GetMaxCodeofTree(tc, "location", "codeautogenerate", "location", "Code",
|
|||
|
"LocationID", "ParentID", parentCode, _tier);
|
|||
|
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 Location Get(string code)
|
|||
|
{
|
|||
|
Location oLocation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(LocationDA.Get(tc, code));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(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 oLocation;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> Get(EnumStatus sts)
|
|||
|
{
|
|||
|
List<Location> allLocations = new List<Location>();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(LocationDA.Get(tc, sts));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
allLocations = this.CreateObjects<Location>(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 allLocations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetForJV(DateTime dSalaryMonth, int payrollTypeID)
|
|||
|
{
|
|||
|
List<Location> allLocations = new List<Location>();
|
|||
|
TransactionContext tc = null;
|
|||
|
//try
|
|||
|
//{
|
|||
|
// tc = TransactionContext.Begin();
|
|||
|
// DataReader oreader = new DataReader(LocationDA.GetForJV(tc, dSalaryMonth,payrollTypeID));
|
|||
|
// if (oreader.Read())
|
|||
|
// {
|
|||
|
// allLocations = this.CreateObjects<Location>(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 allLocations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> Get()
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.Get(tc));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetChield(int parentID)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetChilds(tc, parentID));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetParents(EnumStatus status, int payrollTypeID)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetParent(tc, status, payrollTypeID));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> Get(EnumStatus status, int payrollTypeID)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.Get(tc, status, payrollTypeID));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public List<Location> GetByTier(int tier)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetByTier(tc, tier));
|
|||
|
locations = this.CreateObjects<Location>(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 locations;
|
|||
|
}
|
|||
|
|
|||
|
public int Save(Location oLocation)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oLocation.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("Location", "LocationID");
|
|||
|
int sequenceId = tc.GenerateID("Location", "SequenceNO");
|
|||
|
oLocation.Sequence = sequenceId;
|
|||
|
base.SetObjectID(oLocation, id);
|
|||
|
LocationDA.Insert(tc, oLocation);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LocationDA.Update(tc, oLocation);
|
|||
|
}
|
|||
|
|
|||
|
tc.End();
|
|||
|
return oLocation.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(int id )
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
LocationDA.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
|
|||
|
|
|||
|
public static void SaveForUpload(TransactionContext tc, List<Location> locations, List<Location> saveItems )
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string parentcode = "";
|
|||
|
foreach (Location oLocation in locations)
|
|||
|
{
|
|||
|
if (saveItems.FindIndex(x => x.ID == oLocation.ID) < 0)
|
|||
|
{
|
|||
|
int seqNo = tc.GenerateID("Location", "SequenceNo");
|
|||
|
oLocation.Sequence = seqNo;
|
|||
|
parentcode = string.Empty;
|
|||
|
|
|||
|
//bool isAutoGenerated = ConfigurationManager.GetBoolValue("location", "codeautogenerate",
|
|||
|
// EnumConfigurationType.Logic);
|
|||
|
if (oLocation.ParentID != null && oLocation.ParentID != 0)
|
|||
|
parentcode = locations.Find(o => o.ID == oLocation.ParentID).Code;
|
|||
|
if (oLocation.Code == string.Empty)
|
|||
|
{
|
|||
|
oLocation.Code = GlobalFunctionService.GetMaxCodeofTree(tc, "location", "codeautogenerate", "Location", "Code", "LocationID", "ParentID", parentcode, oLocation.Tier);
|
|||
|
}
|
|||
|
oLocation.CreatedBy = oLocation.CreatedBy;
|
|||
|
oLocation.CreatedDate = DateTime.Now;
|
|||
|
LocationDA.Insert(tc, oLocation);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//oLocation.ModifiedBy = oLocation.ModifiedBy;
|
|||
|
//oLocation.ModifiedDate = DateTime.Now;
|
|||
|
//LocationDA.Update(tc, oLocation);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public Location GetByEmployeeID(int employeeID)
|
|||
|
{
|
|||
|
Location oLocation = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(LocationDA.GetByEmployeeID(tc, employeeID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oLocation = this.CreateObject<Location>(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 oLocation;
|
|||
|
}
|
|||
|
public DataSet GetLocationFromCoord(double Lat, double Long)
|
|||
|
{
|
|||
|
DataSet dSet = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
dSet = LocationDA.GetLocationFromCoord(tc, Lat, Long);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
return dSet;
|
|||
|
}
|
|||
|
public DataTable GetLocationAllTier(int locationID)
|
|||
|
{
|
|||
|
DataTable locationDT = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
locationDT = LocationDA.GetLocationAllTier(tc, locationID);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
return locationDT;
|
|||
|
}
|
|||
|
public bool SaveLocation(int locationID, double latitude, double longitude, int userid, bool latLongApproveStatus)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
LocationDA.SaveLocation(tc, locationID, latitude, longitude, userid, latLongApproveStatus);
|
|||
|
tc.End();
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
public List<Location> GetLowerTierLocations(int LocationID)
|
|||
|
{
|
|||
|
List<Location> locations = new List<Location>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(LocationDA.GetLowerTierLocations(tc, LocationID));
|
|||
|
locations = this.CreateObjects<Location>(dr);
|
|||
|
dr.Close();
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
return locations;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|