CEL_Payroll/Payroll.Service/Global/Service/GlobalFunctionService.cs
2024-09-17 14:30:13 +06:00

215 lines
6.8 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;
namespace Payroll.Service
{
public class GlobalFunctionService : ServiceTemplate, IGlobalFunctionService
{
public GlobalFunctionService()
{
}
protected override T CreateObject<T>(DataReader dr)
{
return new object() as T;
}
public DateTime GetOperationDate()
{
DateTime opDate;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
opDate = GlobalFunctionDA.GetOperationDate(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 opDate;
}
public DataSet GetSalarySummary(DateTime fromDate, DateTime toDate)
{
DataSet opDate;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
opDate = GlobalFunctionDA.GetSalarySummary(tc, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return opDate;
}
public static string GetMaxCode(TransactionContext tc, string parentTag, string childTag, string TableName, string ColumnName)
{
string sCode="";
int intValue=0;
try
{
sCode = GlobalFunctionDA.GetMaxCode(tc, TableName, ColumnName);
if (sCode != "")
{
if (!int.TryParse(sCode, out intValue))
throw new ServiceException("Invalid code format; system can't do auto increment" + sCode);
intValue = intValue + 1;
}
else
intValue = 1;
int Codelength = ConfigurationManager.GetAttributeIntValue(parentTag, childTag, "codelength", EnumConfigurationType.Logic);
if (Codelength < 1 || 10 < Codelength)
Codelength = 3;
return intValue.ToString().PadLeft(Codelength, '0');
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public static string GetMaxCode(TransactionContext tc, string parentTag, string childTag, string TableName, string ColumnName, int tier)
{
string sCode = "";
int intValue = 0;
try
{
sCode = GlobalFunctionDA.GetMaxCode(tc, TableName, ColumnName, tier);
if (sCode != "")
{
if (!int.TryParse(sCode, out intValue))
throw new ServiceException("Invalid code format; system can't do auto increment" + sCode);
intValue = intValue + 1;
}
else
intValue = 1;
int Codelength = ConfigurationManager.GetAttributeIntValue(parentTag, childTag, "codelength", EnumConfigurationType.Logic);
if (Codelength < 1 || 10 < Codelength)
Codelength = 3;
return intValue.ToString().PadLeft(Codelength, '0');
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public static string GetMaxCodeofTree(TransactionContext tc, string parentTag, string childTag,
string TableName, string ColumnName, string parentCode, int Tier)
{
string sCode = "";
int intValue = 0;
try
{
int Codelength = ConfigurationManager.GetAttributeIntValue(parentTag, childTag, "codelength", EnumConfigurationType.Logic);
if (Codelength < 1 || 10 < Codelength)
Codelength = 3;
bool isAutoGenerated = ConfigurationManager.GetBoolValue(parentTag, childTag, EnumConfigurationType.Logic);
if (isAutoGenerated == true)
sCode = GlobalFunctionDA.GetMaxCode(tc, TableName, ColumnName, Tier);
if (sCode != "")
{
if (sCode.Length > parentCode.Length)
{
sCode = sCode.Substring(parentCode.Length + 1, (sCode.Length - parentCode.Length) - 1);
}
else throw new ServiceException("Invalid Code format:" + sCode);
if (!int.TryParse(sCode, out intValue))
throw new ServiceException("Invalid code format; system can't do auto increment" + sCode);
intValue = intValue + 1;
}
else intValue = 1;
return ((parentCode=="")? "" : parentCode+ ".") + intValue.ToString().PadLeft(Codelength, '0');
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void BackupDatabase(string sPath)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
GlobalFunctionDA.BackupDatabase(tc, sPath);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
}
}