421 lines
13 KiB
C#
421 lines
13 KiB
C#
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using HRM.BO;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
[Serializable]
|
|
public class GlobalFunctionService : ServiceTemplate, IGlobalFunctionService
|
|
{
|
|
public GlobalFunctionService()
|
|
{
|
|
}
|
|
|
|
public DateTime GetServerDate()
|
|
{
|
|
object serverDate = null;
|
|
if (serverDate != null)
|
|
return Convert.ToDateTime(serverDate);
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
serverDate = GlobalFunctionDA.ServerDate(tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return Convert.ToDateTime(serverDate);
|
|
}
|
|
|
|
public DateTime GetServerDate(TransactionContext tc)
|
|
{
|
|
object serverDate = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
serverDate = GlobalFunctionDA.ServerDate(tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return Convert.ToDateTime(serverDate);
|
|
}
|
|
public DefaultConfigurationValue RefreshServerValue()
|
|
{
|
|
|
|
int roundofDigit = new SystemConfigarationService().GetconfigIntValue(EnumConfigurationType.Logic, "root", "roundofdegit");
|
|
string DaysInmonth = Convert.ToString(new SystemConfigarationService().GetconfigValue(EnumConfigurationType.Logic, "root", "monthfraction"));
|
|
if (DaysInmonth == string.Empty)
|
|
{
|
|
DaysInmonth = "THIRTYDAYS";
|
|
}
|
|
return new DefaultConfigurationValue(roundofDigit, DaysInmonth, false);
|
|
|
|
}
|
|
public int GetdaysInMonth()
|
|
{
|
|
return 30;
|
|
}
|
|
public DateTime GetCurrentDate()
|
|
{
|
|
object currentDate = null;
|
|
if (currentDate != null)
|
|
return Convert.ToDateTime(currentDate);
|
|
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
currentDate = GlobalFunctionDA.CurrentDate(tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return Convert.ToDateTime(currentDate);
|
|
}
|
|
|
|
public DateTime GetYearEndDate()
|
|
{
|
|
object yearEndDate = null;
|
|
if (yearEndDate != null)
|
|
return Convert.ToDateTime(yearEndDate);
|
|
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
yearEndDate = GlobalFunctionDA.GetYearEnd(tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return Convert.ToDateTime(yearEndDate);
|
|
}
|
|
|
|
public DataTable AvailableUserObject()
|
|
{
|
|
DataTable dataTable = new DataTable("UserObjects");
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
IDataReader iDataReader = GlobalFunctionDA.AvailableUserObject(tc);
|
|
dataTable.Load(iDataReader);
|
|
iDataReader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
throw new ServiceException(e.Message, e);
|
|
}
|
|
|
|
return dataTable;
|
|
}
|
|
|
|
//public DateTime GetOperationDate()
|
|
//{
|
|
// try
|
|
// {
|
|
// DateTime dateTime = DateTime.MaxValue;
|
|
// return dateTime;
|
|
// }
|
|
// catch (ServiceException e)
|
|
// {
|
|
// throw new Exception("Not implement in service\n" + e.Message, e);
|
|
// }
|
|
//}
|
|
|
|
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;
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dataReader)
|
|
{
|
|
GlobalFunctions globalFunctions = null; //new GlobalFunctions();
|
|
|
|
//MapObject(globalFunctions, dataReader);
|
|
|
|
return globalFunctions as T;
|
|
}
|
|
|
|
|
|
|
|
public static string GetMaxCode(TransactionContext tc, 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 = 3;
|
|
|
|
|
|
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)
|
|
{
|
|
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 = 3;
|
|
|
|
if (parentTag != string.Empty && childTag != string.Empty)
|
|
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 = 3;// 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)
|
|
//{
|
|
// return GetMaxCodeofTree(tc, parentTag, childTag, TableName, ColumnName, string.Empty, string.Empty, parentCode, Tier);
|
|
//}
|
|
|
|
|
|
public static string GetMaxCodeofTree(TransactionContext tc, string parentTag, string childTag,
|
|
string TableName, string ColumnName, string IDColumnName, string parentIDColumnName, string parentCode,
|
|
int Tier)
|
|
{
|
|
string sCode = "";
|
|
int intValue = 0;
|
|
try
|
|
{
|
|
//#####
|
|
int Codelength =
|
|
3; //ConfigurationManager.GetAttributeIntValue(parentTag, childTag, "codelength", EnumConfigurationType.Logic);
|
|
if (Codelength < 1 || 10 < Codelength)
|
|
Codelength = 3;
|
|
//####
|
|
if(TableName.ToLower()=="department")
|
|
{
|
|
Codelength = 4;
|
|
}
|
|
if (TableName.ToLower() == "assetcategory")
|
|
{
|
|
Codelength = 1;
|
|
}
|
|
bool
|
|
isAutoGenerated =
|
|
true; //ConfigurationManager.GetBoolValue(parentTag, childTag, EnumConfigurationType.Logic);
|
|
if (isAutoGenerated == true)
|
|
{
|
|
//if (string.IsNullOrWhiteSpace(parentIDColumnName))
|
|
//{
|
|
// sCode = GlobalFunctionDA.GetMaxCode(tc, TableName, ColumnName, Tier);
|
|
//}
|
|
//else
|
|
//{
|
|
sCode = GlobalFunctionDA.GetMaxCode(tc, TableName, ColumnName, IDColumnName, parentIDColumnName,
|
|
parentCode, 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);
|
|
|
|
int idx = sCode.LastIndexOf('.');
|
|
if (idx != -1)
|
|
{
|
|
intValue = Convert.ToInt32(sCode[(idx + 1)..]);
|
|
}
|
|
if (idx == -1 && Tier == 1)
|
|
{
|
|
intValue = Convert.ToInt32(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
|
|
}
|
|
}
|
|
}
|
|
} |