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 SetupDetails { get; set; } EmployeeSetupParameter ApplicableParameters(Employee Employee); List ApplicableParameters(ObjectsTemplate employees); } [Serializable] public class EmployeeSetupParameter // where T: TermParameter { public EmployeeSetupParameter(EnumParameterSetup setup) { _employee = null; _parameterIDs = new List(); _setup = setup; } private Employee _employee; public Employee Employee { get { return _employee; } set { _employee = value; } } private List _parameterIDs; public List ParameterIDs { get { return _parameterIDs; } set { _parameterIDs = value; } } private EnumParameterSetup _setup; public ObjectsTemplate GetParameters() where T : ObjectTemplate, ISetupManager { ObjectsTemplate temp = new ObjectsTemplate(); 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 _SelectedSetupdetails = null; private ObjectsTemplate _SavedSetupdetails = null; private ObjectsTemplate _UsedSetupdetails = null; private ObjectsTemplate _RemainingSetupDetails = null; private EnumParameterSetup _setupparameter; public SetupManager() { _SavedSetupdetails = new ObjectsTemplate(); _UsedSetupdetails = new ObjectsTemplate(); _SelectedSetupdetails = new ObjectsTemplate(); _RemainingSetupDetails = new ObjectsTemplate(); m_oReader = null; _ConfigSection = string.Empty; _setupparameter = EnumParameterSetup.None; } public SetupManager(EnumParameterSetup setup, string configSection) { _SavedSetupdetails = new ObjectsTemplate(); _UsedSetupdetails = new ObjectsTemplate(); _SelectedSetupdetails = new ObjectsTemplate(); _RemainingSetupDetails = new ObjectsTemplate(); _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 ApplicableParametersForReport(Employee oEmp, List setupTypes, ObjectsTemplate details) { List parametersID = new List(); //List setupTypes = SetupDetail.GetTypes(setup); if (setupTypes == null) return parametersID; //ObjectsTemplate 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 ApplicableParameters(Employee oEmp, EnumParameterSetup setup) { List parametersID = new List(); List setupTypes = SetupDetail.GetTypes(setup); if (setupTypes == null) return parametersID; ObjectsTemplate 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 ApplicableParameters2(Employee oEmp, EnumParameterSetup setup, List setupTypes, ObjectsTemplate details) { List parametersID = new List(); 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 GetObjectID(int setupID, int objectID, EnumParameterSetup setup, EnmSetupManagerTranType type) { SetupDetail odetail = new SetupDetail(); ObjectsTemplate setupDetails = SetupDetail.Service.GetUsedParameters(setup, setupID, objectID); List temp = new List(); foreach (SetupDetail item in setupDetails) { temp.Add(item.TranID.Integer); } return temp; } public static List ApplicableParameters(Employee oEmp, EnumParameterSetup setup, List setupTypes , ObjectsTemplate details) { List parametersID = new List(); 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 GetSetupDetails { get { return _RemainingSetupDetails; } } public ObjectsTemplate SelectedSetupDetails { get { _SelectedSetupdetails.Clear(); foreach (SetupDetail detail in m_oReader.Details) { if (detail.IsSelected) { _SelectedSetupdetails.Add(detail); } } return _SelectedSetupdetails; } } public ObjectsTemplate 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 GetTypes { get { return m_oReader.Types; } } } }