using Ease.Core.DataAccess; using Ease.Core.Model; using System; using System.Collections.Generic; namespace HRM.BO { #region SearchEmployee // Please do to modify or add this class without talk to shamim public class SearchEmployee:AuditTrailBase { #region Constructor public SearchEmployee() { _employeeID = 0; _name = string.Empty; _employeeNo = string.Empty; _locationID = 0; _categoryID = 0; _departmentID = 0; _gradeID = 0; _selected = false; Employee = null; //DepartmentObj = null; } #endregion #region Properties #region EmployeeID : ID private int _employeeID; public int EmployeeID { get { return _employeeID; } set { _employeeID = value; } } #endregion #region name : string private string _name; public string Name { get { return _name; } set { _name = value; } } #endregion #region employeeNo : string private string _employeeNo; public string EmployeeNo { get { return _employeeNo; } set { _employeeNo = value; } } #endregion // Please do not modify or add this class without talk to shamim #region EmployeeEmail : string private string _employeeEmail; public string EmployeeEmail { get { return _employeeEmail; } set { _employeeEmail = value; } } #endregion #region LocationID : ID private int _locationID; public int LocationID { get { return _locationID; } set { _locationID = value; } } public string locationName { get; set; } #endregion #region CategoryID : ID private int _categoryID; public int CategoryID { get { return _categoryID; } set { _categoryID = value; } } #endregion // Please do not modify or add this class without talk to shamim public string CategoryName { get; set; } #region DepartmentID : ID private int _departmentID; public int DepartmentID { get { return _departmentID; } set { _departmentID = value; } } public string departmentName { get; set; } //public Department DepartmentObj { get; set; } //private Department _department; //public Department DepartmentObj //{ // get // { // if (_department == null && _departmentID != null && !_departmentID.IsUnassigned && _departmentID.Integer > 0) // { // _department = Department.Get(_departmentID); // } // return _department; // } //} #endregion #region cardID : ID private int _cardID; public int CardID { get { return _cardID; } set { _cardID = value; } } #endregion #region GradeID : ID private int _gradeID; public int GradeID { get { return _gradeID; } set { _gradeID = value; } } public string gradeName { get; set; } public int designationID { get; set; } public string designationName { get; set; } //public Grade GradeObj { get; set; } //private Grade _grade; //public Grade GradeObj //{ // get // { // if (_grade == null && _gradeID != null && !_gradeID.IsUnassigned && _gradeID.Integer > 0) // { // _grade = Grade.Get(_gradeID); // } // return _grade; // } //} #endregion #region selected : bool private bool _selected; public bool Selected { get { return _selected; } set { _selected = value; } } #endregion // Please do not modify or add this class without talk to shamim public Employee Employee { get; set; } public HREmployee HREmployee { get; set; } public static string getEmpID(List emps) { string str = ""; emps.ForEach(x => { if(x!=null) str = str + x.EmployeeID + ","; }); if (str.Length > 0) str = str.Substring(0, str.Length - 1); return str; } //#region employee : Employee //private Employee _employee; //public Employee Employee //{ // get // { // if (_employeeID.Integer > 0 && _employee == null) // { // _employee = new Employee(); // _employee = Employee.Get(_employeeID); // } // return this._employee; // } // set // { // _employee = value; // } //} //#endregion //#region HREmployee : HREmployee //private HREmployee _hrEmployee; //public HREmployee HREmployee //{ // get // { // if (_employeeID.Integer > 0 && _hrEmployee == null) // { // _hrEmployee = new HREmployee(); // _hrEmployee = _hrEmployee.Get(_employeeID); // } // return this._hrEmployee; // } // set // { // _hrEmployee = value; // } //} //#endregion #region Service Factory ISearchEmployeeService : ISearchEmployeeService //internal static ISearchEmployeeService Service //{ // get { return Services.Factory.CreateService(typeof(ISearchEmployeeService)); } //} #endregion #endregion //#region Functions //public static List Search(string sql) //{ // List searchEmployees = null; // try // { // searchEmployees = Service.Search(sql); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(searchEmployees, "Get"); // #endregion // return searchEmployees; //} //public static SearchEmployee GetSearchEmployeeFromEmployee(Employee oEmp) //{ // SearchEmployee oSearch = new SearchEmployee(); // oSearch._employeeID = oEmp.ID; // oSearch._name = oEmp.Name; // oSearch._employeeNo = oEmp.EmployeeNo; // oSearch._locationID = oEmp.LocationID; // oSearch._categoryID = oEmp.CategoryID; // oSearch._departmentID = oEmp.DepartmentID; // oSearch._gradeID = oEmp.GradeID; // oSearch._cardID = oEmp.CardID; // oSearch._selected = true; // oSearch._employee = oEmp; // return oSearch; //} //private int ID //{ // get // { // throw new ServiceException("Search employee object id is virtual, it can't be use"); // } //} //#endregion public static bool IsEmployeeExist(List semployees, int employeId) { foreach (SearchEmployee item in semployees) { if (item.EmployeeID == employeId) { if (item.Selected == true) return true; else return false; } } return false; } public string RefreshList() { throw new NotImplementedException(); } } #endregion #region ISearchEmployee Service public interface ISearchEmployeeService { List Find(SearchManager oManager); List FindCordinator(int? id, int? payrollTypeID); List FindEmpCodeName(int payrolltypeid, string code, string name); SearchEmployee get(int empid); List GetEmployeeNotYetUser(int payrollTypeID); List GetTeam(int employeeid); List GetTeam(int employeeid, EnumStatus enumStatus); List GetTeamForAttnReguApprove(int employeeid, EnumStatus enumStatus); public List GetSelectedSearchEmployee(List empids); } #endregion public class SearchManager { private EnumSearchFrom _searchFrom; private EnumChronology _chronology; public bool withName { get; set; } public int TaxParamID { get; set; } public DateTime LastPayProcessMonth { get; set; } private string _rootTable; public bool checkDataPermission { get; set; } public int? userid { get; set; } public int? payrolltypeID { get; set; } public bool searchForSalary { get; set; } public bool searchUndoSalary { get; set; } public SearchManager() { this.withName = false; this.checkDataPermission = false; } public string RootTable { get { return _rootTable; } set { _rootTable = value; } } public EnumSearchFrom SearchFrom { get { return _searchFrom; } set { _searchFrom = value; } } public bool IsNegletWithheld { get; set; } public EnumChronology Chronology { get { return _chronology; } set { _chronology = value; } } public SearchManager(EnumSearchFrom searchFrom) { _searchFrom = searchFrom; _chronology = EnumChronology.NotNeeded; this.checkDataPermission = false; this.userid = null; this.payrolltypeID = null; } #region ISearchFrom Members private SearchParameter _searchParameter; public SearchParameter Parameter { get { if (_searchParameter == null) { _searchParameter = new SearchParameter(); // _searchParameter.AddDefaultParameter(); } return _searchParameter; } set { _searchParameter = value; } } #endregion public class SearchParameter { private List _searchParameters; private EnumSearchParameter _parameter; private EnumSearchObjDataType _dataType; private object _parameterValue; private string _paramSQL; private EnumSQLOperator _sqlOperator; public List SearchParameters { get { return this._searchParameters; } set { this._searchParameters = value; } } private void Add(EnumSearchParameter paramter, EnumSearchObjDataType datatype, object value) { SearchParameter oparameter = new SearchParameter(); oparameter.Paramter = paramter; oparameter.DataType = datatype; oparameter.ParameterValue = value; oparameter.SqlOperator = EnumSQLOperator.EqualTo; _searchParameters.Add(oparameter); } public void Add(EnumSearchParameter paramter, EnumSQLOperator sqloperator, EnumSearchObjDataType datatype, object value) { SearchParameter oparameter = new SearchParameter(); oparameter.Paramter = paramter; oparameter.DataType = datatype; oparameter.ParameterValue = value; oparameter.SqlOperator = sqloperator; _searchParameters.Add(oparameter); } public void Add(EnumSearchParameter paramter, EnumSQLOperator sqloperator) { SearchParameter oparameter = new SearchParameter(); oparameter.Paramter = paramter; oparameter.DataType = EnumSearchObjDataType.String; oparameter.ParameterValue = ""; oparameter.SqlOperator = sqloperator; _searchParameters.Add(oparameter); } public void AddDefaultParameter(int payrolltypeid, EnumEmployeeStatus Employeestatus) { SearchParameter oparameter = new SearchParameter(); oparameter.Paramter = EnumSearchParameter.PayrollTypeID; oparameter.DataType = EnumSearchObjDataType.Number; oparameter.ParameterValue = payrolltypeid; oparameter.SqlOperator = EnumSQLOperator.EqualTo; _searchParameters.Add(oparameter); SearchParameter sts = new SearchParameter(); sts.Paramter = EnumSearchParameter.Status; sts.DataType = EnumSearchObjDataType.Number; sts.ParameterValue = Convert.ToInt32( Employeestatus); sts.SqlOperator = EnumSQLOperator.EqualTo; _searchParameters.Add(sts); } public void Add(SearchParameter oparameter) { if (oparameter != null) { _searchParameters.Add(oparameter); } } public void Add(EnumSearchParameter paramter, bool value) { this.Add(paramter, EnumSearchObjDataType.boolean, value); } public void Remove(EnumSearchParameter paramter) { SearchParameter param = null; foreach (SearchParameter item in this._searchParameters) { if (item.Paramter == EnumSearchParameter.PayrollTypeID) { param = item; break; } } if (param != null) _searchParameters.Remove(param); } public void Add(EnumSearchParameter paramter, int value) { this.Add(paramter, EnumSearchObjDataType.Number, value); } public void Add(EnumSearchParameter paramter, string value) { this.Add(paramter, EnumSearchObjDataType.String, value); } public void Add(EnumSearchParameter paramter, DateTime value) { this.Add(paramter, EnumSearchObjDataType.Date, value); } public SearchParameter() { _searchParameters = new List(); } public EnumSearchParameter Paramter { get { return _parameter; } set { _parameter = value; } } public EnumSearchObjDataType DataType { get { return _dataType; } set { _dataType = value; } } public object ParameterValue { get { return _parameterValue; } set { _parameterValue = value; } } public EnumSQLOperator SqlOperator { get { return _sqlOperator; } set { _sqlOperator = value; } } public string GetParameterSQL(string rootTable, bool buildFromWhere) { SearchObject sObject = new SearchObject(); #region Create Search Object int nCount = 1; foreach (SearchParameter param in this._searchParameters) { string fieldName = GetFieldName(param.Paramter); if (fieldName == "") continue; if (param.ParameterValue == null) continue; fieldName = rootTable + "." + fieldName; string value = ""; if (param.DataType == EnumSearchObjDataType.Date || param.DataType == EnumSearchObjDataType.DateWithTime) { //value = ((DateTime)param.ParameterValue).ToString("dd MMM yyyy"); value = (Convert.ToDateTime(param.ParameterValue)).ToString("dd MMM yyyy"); } else value = param.ParameterValue.ToString(); //if (fieldName == "EMPLOYEE.EmployeeNo") //{ // param.SqlOperator = EnumSQLOperator.In; //} //if (fieldName == "EMPLOYEE.JoiningDate") //{ // if (nCount == 1) // { // param.SqlOperator = EnumSQLOperator.GraterThan; // nCount++; // } // else // { // param.SqlOperator = EnumSQLOperator.SmallerThan; // } //} sObject.Add(param.SqlOperator, fieldName, value, string.Empty, param.DataType); } return sObject.BuildQuery(buildFromWhere); #endregion } public string GetFieldName(EnumSearchParameter parameter) { string fieldName = ""; switch (parameter) { case EnumSearchParameter.CategoryID: fieldName = "CategoryID"; break; case EnumSearchParameter.DesignationID: fieldName = "DesignationID"; break; case EnumSearchParameter.GradeID: fieldName = "GradeID"; break; case EnumSearchParameter.GradeSegmentID: fieldName = "GradeID"; break; case EnumSearchParameter.LocationID: fieldName = "LOCATIONID"; break; case EnumSearchParameter.ReligionID: fieldName = "ReligionID"; break; case EnumSearchParameter.DepartmentID: fieldName = "DepartmentID"; break; case EnumSearchParameter.BranchID: fieldName = "BranchID"; break; case EnumSearchParameter.Name: fieldName = "Name"; break; case EnumSearchParameter.Status: fieldName = "Status"; break; case EnumSearchParameter.Posted: break; case EnumSearchParameter.Confirm: fieldName = "IsConfirmed"; break; case EnumSearchParameter.OTEligible: fieldName = "ISELIGIBLEOT"; break; case EnumSearchParameter.BonusId: break; case EnumSearchParameter.Gender: fieldName = "Gender"; break; case EnumSearchParameter.PFMember: fieldName = "PFMEMBERTYPE"; break; case EnumSearchParameter.FinalizedSalary: break; case EnumSearchParameter.SalaryBarchID: break; case EnumSearchParameter.OPIID: break; case EnumSearchParameter.Expatriate: fieldName = "FOREIGNEXPAT"; break; case EnumSearchParameter.TermID: break; case EnumSearchParameter.AssingedAccCard: fieldName = "CardID"; break; case EnumSearchParameter.PayrollTypeID: fieldName = "PayrollTypeID"; break; case EnumSearchParameter.EmployeeNo: case EnumSearchParameter.FromEmployeeNO: case EnumSearchParameter.ToEmployeeNO: case EnumSearchParameter.EmployeeNoIn: fieldName = "EmployeeNo"; break; case EnumSearchParameter.NationalID: fieldName = "NationalID"; break; case EnumSearchParameter.JoiningDate: fieldName = "JoiningDate"; break; case EnumSearchParameter.LM: fieldName = "LineManagerID"; break; case EnumSearchParameter.JoiningDateFrom: fieldName = "JoiningDate"; break; case EnumSearchParameter.JoiningDateTo: fieldName = "JoiningDate"; break; default: break; } return fieldName; } public string GetFromAndToDateSyntax() { string syntax = ""; SearchParameter fromDate = _searchParameters.Find(delegate(SearchParameter item) { return (item.Paramter == EnumSearchParameter.FromDate); }); if (fromDate == null) return "";//throw new ServiceException("From Date/Month not found in the Search Parameter"); DateTime fromdate = Convert.ToDateTime( fromDate.ParameterValue); SearchParameter secondDate = _searchParameters.Find(delegate(SearchParameter item) { return (item.Paramter == EnumSearchParameter.ToDate); }); if (secondDate == null) syntax = "=" + "'" + fromdate.ToString("dd MMM yyyy") + "'"; else { DateTime todate = Convert.ToDateTime(secondDate.ParameterValue); syntax = " BETWEEN '" + fromdate.ToString("dd MMM yyyy") + "' AND '" + todate.ToString("dd MMM yyyy") +"'"; } return syntax; } public SearchParameter GetByParamer(EnumSearchParameter parameter) { SearchParameter sParameter = _searchParameters.Find(delegate(SearchParameter item) { return (item.Paramter == parameter); }); return sParameter; } } } }