using Ease.Core.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace HRM.BO { //public interface ISetupManager //{ // void FillMe(ID id); // List SetupDetails { get; set; } // EmployeeSetupParameter ApplicableParameters(Employee Employee); // List ApplicableParameters(List employees); //} public class EmployeeSetupParameter // where T: TermParameter { public EmployeeSetupParameter(EnumParameterSetup setup) { Employee = null; //_parameterIDs = new List(); //_setup = setup; } //public Employeeshort Employee { get; set; } public List ParameterIDs { get; set; } public Employee Employee { get; set; } private EnumParameterSetup _setup; //public List GetParameters() where T : ObjectTemplate, ISetupManager //{ // List temp = new List(); // 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; //} } public class SetupManager { private string _ConfigSection = string.Empty; private ConfigReader m_oReader = null; private string m_sStatus = string.Empty; private List _SelectedSetupdetails = null; private List _SavedSetupdetails = null; private List _UsedSetupdetails = null; private List _RemainingSetupDetails = null; private EnumParameterSetup _setupparameter; public SetupManager() { _SavedSetupdetails = new List(); _UsedSetupdetails = new List(); _SelectedSetupdetails = new List(); _RemainingSetupDetails = new List(); m_oReader = null; _ConfigSection = string.Empty; _setupparameter = EnumParameterSetup.None; } public SetupManager(EnumParameterSetup setup, string configSection) { _SavedSetupdetails = new List(); _UsedSetupdetails = new List(); _SelectedSetupdetails = new List(); _RemainingSetupDetails = new List(); _ConfigSection = configSection; //m_oReader = new ConfigReader(_ConfigSection); //this needs to be called in bl _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, List 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 static List ApplicableParameters(Employee oEmp, EnumParameterSetup setup) //{ // List parametersID = new List(); // List setupTypes = SetupDetail.GetTypes(setup); // if (setupTypes == null) return parametersID; // List 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, List 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(string setupIDs, int objectID, // EnumParameterSetup setup, EnmSetupManagerTranType type) //{ // SetupDetail odetail = new SetupDetail(); // List setupDetails = SetupDetail.Service.GetUsedParameters(setup, setupIDs, 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 , List details) { List parametersID = new List(); if (setupTypes == null) return parametersID; foreach (EnmSetupManagerTranType type in setupTypes) { int nTranID = SetupDetail.GetTranID(oEmp, type); if (nTranID == 0) 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); } } return parametersID; } public List GetSetupDetails { get { return _RemainingSetupDetails; } } public List SelectedSetupDetails { get { _SelectedSetupdetails.Clear(); foreach (SetupDetail detail in m_oReader.Details) { if (detail.IsSelected) { _SelectedSetupdetails.Add(detail); } } return _SelectedSetupdetails; } } public List 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; } } } }