Ejemplo n.º 1
0
    public static ReturnObject GetLeaveData(int page_number, bool is_filter, string filters)
    {
        masters_leave page_object = new masters_leave();
        DBConnection  db_connection = new DBConnection();
        DataTable     leaves_data_table = new DataTable();
        ReturnObject  return_object = new ReturnObject();
        string        employee_id, query, company_code = string.Empty;
        int           start_row        = (page_number - 1) * 30;
        int           number_of_record = page_number * 30 + 1;

        try
        {
            employee_id = HttpContext.Current.Session["employee_id"].ToString();
            // if employee is logged in then showing only that employee company  data (  done for royal group client first then implemnted in standard as well )
            if (employee_id != "")
            {
                query        = "select emp_company from employeemaster where emp_code='" + employee_id + "'";
                company_code = db_connection.ExecuteQuery_WithReturnValueString(query);
                query        = "select leavecode as leave_code, leavename as leave_name, CompanyName as company_name, CompanyCode as company_code, EmpCategoryName as employee_category_name, EmpCategoryCode as employee_category_code, MaxLeave as max_leave, MaxLeaveCarryForward as max_leave_carry_forward, woflag as week_off_flag , status as leave_status, LeaveType as leave_type from ( select l.leavecode, l.leavename, c.CompanyName, c.CompanyCode, ec.EmpCategoryName, ec.EmpCategoryCode, l.MaxLeave, l.MaxLeaveCarryForward, l.woflag,l.status, l.LeaveType, ROW_NUMBER() OVER (ORDER BY l.leavecode) as row from LeaveMaster l, CompanyMaster c, EmployeeCategoryMaster ec where l.EmployeeCategoryCode = ec.EmpCategoryCode and l.CompanyCode = c.CompanyCode and  c.CompanyCode='" + company_code + "' ";
            }
            else
            {
                query = "select leavecode as leave_code, leavename as leave_name, CompanyName as company_name, CompanyCode as company_code, EmpCategoryName as employee_category_name, EmpCategoryCode as employee_category_code, MaxLeave as max_leave, MaxLeaveCarryForward as max_leave_carry_forward, woflag as week_off_flag  , status as leave_status, LeaveType as leave_type  from ( select l.leavecode, l.leavename, c.CompanyName, c.CompanyCode, ec.EmpCategoryName, ec.EmpCategoryCode, l.MaxLeave, l.MaxLeaveCarryForward, l.woflag, l.status, l.LeaveType, ROW_NUMBER() OVER (ORDER BY l.leavecode) as row from LeaveMaster l, CompanyMaster c, EmployeeCategoryMaster ec where l.EmployeeCategoryCode = ec.EmpCategoryCode and l.CompanyCode = c.CompanyCode ";
            }

            if (is_filter)
            {
                query = page_object.GetFilterQuery(filters, query);
            }

            query += " ) a where row > " + start_row + " and row < " + number_of_record;

            leaves_data_table = db_connection.ReturnDataTable(query);

            return_object.status      = "success";
            return_object.return_data = JsonConvert.SerializeObject(leaves_data_table, Formatting.Indented);
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "GET_LEAVE_DATA");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while loading Leave data. Please try again. If the error persists, please contact Support.";

            throw;
        }

        return(return_object);
    }
Ejemplo n.º 2
0
    public static ReturnObject DeleteLeave(string current)
    {
        masters_leave page_object            = new masters_leave();
        DBConnection  db_connection          = new DBConnection();
        ReturnObject  return_object          = new ReturnObject();
        Hashtable     leave_data_hash_table  = new Hashtable();
        string        company_code           = string.Empty;
        string        employee_category_code = string.Empty;
        string        leave_code             = string.Empty;

        if (HttpContext.Current.Session["username"] == null)  // checking session expired or not
        {
            return_object = page_object.DoLogout();
        }
        else
        {
            try
            {
                JObject current_data = JObject.Parse(current);
                company_code           = current_data["company_code"].ToString();
                employee_category_code = current_data["employee_category_code"].ToString();
                leave_code             = current_data["leave_code"].ToString();

                leave_data_hash_table.Add("mode", "D");
                leave_data_hash_table.Add("CompanyCode", company_code);
                leave_data_hash_table.Add("EmployeeCategoryCode", employee_category_code);
                leave_data_hash_table.Add("leavecode", leave_code);


                db_connection.ExecuteStoredProcedureWithHashtable_WithoutReturn("Leave", leave_data_hash_table);

                return_object.status      = "success";
                return_object.return_data = "Leave deleted successfully!";
            }
            catch (Exception Ex)
            {
                Logger.LogException(Ex, page, "DELETE_LEAVE");

                return_object.status      = "error";
                return_object.return_data = "An error occurred while deleting this Leave. Please try again. If the error persists, please contact Support.";

                throw;
            }
        }

        return(return_object);
    }
Ejemplo n.º 3
0
    public static ReturnObject EditLeave(string current, string previous)
    {
        masters_leave page_object = new masters_leave();
        DBConnection  db_connection = new DBConnection();
        ReturnObject  return_object = new ReturnObject();
        string        original_leave_name = string.Empty;
        string        company_code = string.Empty;
        string        employee_category_code = string.Empty;
        string        leave_code = string.Empty;
        string        leave_name = string.Empty;
        string        leave_status = string.Empty, leave_type = string.Empty;
        decimal       max_leave = 0;
        decimal       max_leave_carry_forward = 0;
        int           week_off_flag           = 0;
        int           count = 0;

        if (HttpContext.Current.Session["username"] == null)  // checking session expired or not
        {
            return_object = page_object.DoLogout();
        }
        else
        {
            try
            {
                JObject current_data = JObject.Parse(current);
                company_code           = current_data["company_code"].ToString();
                employee_category_code = current_data["employee_category_code"].ToString();
                leave_code             = current_data["leave_code"].ToString();
                leave_name             = current_data["leave_name"].ToString();
                leave_status           = current_data["leave_status"].ToString();
                max_leave = Convert.ToDecimal(current_data["max_leave"]);
                max_leave_carry_forward = Convert.ToDecimal(current_data["max_leave_carry_forward"]);
                week_off_flag           = Convert.ToInt32(current_data["week_off_flag"]);
                leave_type = current_data["leave_type"].ToString();

                JObject previous_data = JObject.Parse(previous);
                original_leave_name = previous_data["leave_name"].ToString();

                if (original_leave_name != leave_name)
                {
                    count = page_object.CheckLeaveName(leave_name, employee_category_code, company_code);
                    if (count > 0)
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Leave Name has been taken. Please try again with a different Name.";

                        return(return_object);
                    }
                }

                page_object.UpdateDatabase("U", company_code, employee_category_code, leave_code, leave_name, max_leave, max_leave_carry_forward, week_off_flag, leave_status, leave_type);

                return_object.status      = "success";
                return_object.return_data = "Leave edited successfully!";
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, page, "EDIT_LEAVE");

                return_object.status      = "error";
                return_object.return_data = "An error occurred while saving Leave details. Please try again. If the error persists, please contact Support.";

                throw;
            }
            finally
            {
                page_object.Dispose();
            }
        }

        return(return_object);
    }