CEL_Payroll/Payroll.BO/SetupManager/SetupManager.cs
2024-09-17 14:30:13 +06:00

340 lines
12 KiB
C#

using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using Ease.CoreV35.Model;
using System.Linq;
using System.Reflection;
namespace Payroll.BO
{
public interface ISetupManager
{
void FillMe(ID id);
ObjectsTemplate<SetupDetail> SetupDetails { get; set; }
EmployeeSetupParameter ApplicableParameters(Employee Employee);
List<EmployeeSetupParameter> ApplicableParameters(ObjectsTemplate<Employee> employees);
}
[Serializable]
public class EmployeeSetupParameter //<T> where T: TermParameter
{
public EmployeeSetupParameter(EnumParameterSetup setup)
{
_employee = null;
_parameterIDs = new List<int>();
_setup = setup;
}
private Employee _employee;
public Employee Employee
{
get
{
return _employee;
}
set
{
_employee = value;
}
}
private List<int> _parameterIDs;
public List<int> ParameterIDs
{
get
{
return _parameterIDs;
}
set
{
_parameterIDs = value;
}
}
private EnumParameterSetup _setup;
public ObjectsTemplate<T> GetParameters<T>() where T : ObjectTemplate, ISetupManager
{
ObjectsTemplate<T> temp = new ObjectsTemplate<T>();
foreach (int i in _parameterIDs)
{
ConstructorInfo cInfo = typeof(T).GetConstructor(new Type[] { });
T obj = (T)cInfo.Invoke(null);
obj.FillMe(ID.FromInteger(i));
temp.Add(obj);
}
return temp;
}
}
[Serializable]
public class SetupManager
{
private string _ConfigSection = string.Empty;
private ConfigReader m_oReader = null;
private string m_sStatus = string.Empty;
private ObjectsTemplate<SetupDetail> _SelectedSetupdetails = null;
private ObjectsTemplate<SetupDetail> _SavedSetupdetails = null;
private ObjectsTemplate<SetupDetail> _UsedSetupdetails = null;
private ObjectsTemplate<SetupDetail> _RemainingSetupDetails = null;
private EnumParameterSetup _setupparameter;
public SetupManager()
{
_SavedSetupdetails = new ObjectsTemplate<SetupDetail>();
_UsedSetupdetails = new ObjectsTemplate<SetupDetail>();
_SelectedSetupdetails = new ObjectsTemplate<SetupDetail>();
_RemainingSetupDetails = new ObjectsTemplate<SetupDetail>();
m_oReader = null;
_ConfigSection = string.Empty;
_setupparameter = EnumParameterSetup.None;
}
public SetupManager(EnumParameterSetup setup, string configSection)
{
_SavedSetupdetails = new ObjectsTemplate<SetupDetail>();
_UsedSetupdetails = new ObjectsTemplate<SetupDetail>();
_SelectedSetupdetails = new ObjectsTemplate<SetupDetail>();
_RemainingSetupDetails = new ObjectsTemplate<SetupDetail>();
_ConfigSection = configSection;
m_oReader = new ConfigReader(_ConfigSection);
_setupparameter = setup;
}
public void SetParameter(EnumParameterSetup setup, string configSection, ID setupID, ID objectID)
{
_ConfigSection = configSection;
_setupparameter = setup;
_UsedSetupdetails = SetupDetail.GetUsedParameters(_setupparameter, objectID.Integer);
if (setupID.IsUnassigned == false)
{
_SavedSetupdetails = SetupDetail.GetUsedParameters(_setupparameter, setupID.Integer, objectID.Integer);
foreach (SetupDetail item in _SavedSetupdetails)
{
int index = SetupDetail.GetIndex(m_oReader.Details, item.TranID.Integer, item.TranType);
if (index > -1)
{
m_oReader.Details[index].IsSelected = true;
_RemainingSetupDetails.Add(m_oReader.Details[index]);
}
else throw new ServiceException("root item not found to saved item");
}
}
bool found = false;
foreach (SetupDetail detail in m_oReader.Details)
{
found = false;
foreach (SetupDetail udetail in _UsedSetupdetails)
{
if (udetail.TranType == detail.TranType && udetail.TranID.Integer == detail.TranID.Integer)
{
found = true;
break;
}
}
if (!found) _RemainingSetupDetails.Add(detail);
}
}
public static List<int> ApplicableParametersForReport(Employee oEmp, List<EnmSetupManagerTranType> setupTypes, ObjectsTemplate<SetupDetail> details)
{
List<int> parametersID = new List<int>();
//List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(setup);
if (setupTypes == null) return parametersID;
//ObjectsTemplate<SetupDetail> details = SetupDetail.GetParameters(setup);
foreach (EnmSetupManagerTranType type in setupTypes)
{
ID nTranID = SetupDetail.GetTranID(oEmp, type);
if (nTranID == null) continue;
if (nTranID.IsUnassigned == true) continue;
var setupIds = (from detail in details
where detail.TranType == type
&& detail.TranID == nTranID
select detail.SetupID).Distinct();
if (setupIds != null)
{
foreach (var id in setupIds)
parametersID.Add(id.Integer);
}
}
return parametersID;
}
public static List<int> ApplicableParameters(Employee oEmp, EnumParameterSetup setup)
{
List<int> parametersID = new List<int>();
List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(setup);
if (setupTypes == null) return parametersID;
ObjectsTemplate<SetupDetail> details = SetupDetail.GetParameters(setup);
foreach (EnmSetupManagerTranType type in setupTypes)
{
ID nTranID = SetupDetail.GetTranID(oEmp, type);
if (nTranID == null) continue;
if (nTranID.IsUnassigned == true) continue;
var setupIds = (from detail in details
where detail.TranType == type
&& detail.TranID == nTranID
select detail.SetupID).Distinct();
foreach (var id in setupIds)
parametersID.Add(id.Integer);
}
return parametersID;
}
public static List<int> ApplicableParameters2(Employee oEmp, EnumParameterSetup setup, List<EnmSetupManagerTranType> setupTypes, ObjectsTemplate<SetupDetail> details)
{
List<int> parametersID = new List<int>();
if (setupTypes == null) return parametersID;
foreach (EnmSetupManagerTranType type in setupTypes)
{
ID nTranID = SetupDetail.GetTranID(oEmp, type);
if (nTranID == null) continue;
if (nTranID.IsUnassigned == true) continue;
var setupIds = (from detail in details
where detail.TranType == type
&& detail.TranID == nTranID
select detail.SetupID).Distinct();
foreach (var id in setupIds)
parametersID.Add(id.Integer);
}
return parametersID;
}
public List<int> GetObjectID(int setupID, int objectID,
EnumParameterSetup setup, EnmSetupManagerTranType type)
{
SetupDetail odetail = new SetupDetail();
ObjectsTemplate<SetupDetail> setupDetails = SetupDetail.Service.GetUsedParameters(setup, setupID, objectID);
List<int> temp = new List<int>();
foreach (SetupDetail item in setupDetails)
{
temp.Add(item.TranID.Integer);
}
return temp;
}
public static List<int> ApplicableParameters(Employee oEmp,
EnumParameterSetup setup, List<EnmSetupManagerTranType> setupTypes
, ObjectsTemplate<SetupDetail> details)
{
List<int> parametersID = new List<int>();
if (setupTypes == null) return parametersID;
foreach (EnmSetupManagerTranType type in setupTypes)
{
ID nTranID = SetupDetail.GetTranID(oEmp, type);
if (nTranID.IsUnassigned == true) continue;
var setupIds = (from detail in details
where detail.TranType == type
&& detail.TranID == nTranID
select detail.SetupID).Distinct();
foreach (var id in setupIds)
parametersID.Add(id.Integer);
}
return parametersID;
}
public ObjectsTemplate<SetupDetail> GetSetupDetails
{
get
{
return _RemainingSetupDetails;
}
}
public ObjectsTemplate<SetupDetail> SelectedSetupDetails
{
get
{
_SelectedSetupdetails.Clear();
foreach (SetupDetail detail in m_oReader.Details)
{
if (detail.IsSelected)
{
_SelectedSetupdetails.Add(detail);
}
}
return _SelectedSetupdetails;
}
}
public ObjectsTemplate<SetupDetail> SavedSetupDetails
{
get
{
return _SavedSetupdetails;
}
}
public EnumParameterSetup SetupFor
{
get
{
return _setupparameter;
}
}
public bool IsSelected
{
get
{
bool found;
m_sStatus = "OK";
foreach (EnmSetupManagerTranType type in m_oReader.EnumTypes)
{
found = false;
foreach (SetupDetail detail in m_oReader.Details)
{
if (detail.TranType == type && detail.IsSelected == true)
{
found = true;
break;
}
}
if (!found)
{
m_sStatus = "No " + type.ToString() + " is selected.";
return found;
}
}
return true;
}
}
public string StatusMessage
{
get
{
return m_sStatus;
}
}
public int TotalTypes
{
get
{
return m_oReader.TotalTypes;
}
}
public List<string> GetTypes
{
get
{
return m_oReader.Types;
}
}
}
}