Пример #1
0
    public static ReturnObject GetReprocessData(int page_number, string filters)
    {
        attendance_reprocess page_object    = new attendance_reprocess();
        DBConnection         db_connection  = new DBConnection();
        ReturnObject         return_object  = new ReturnObject();
        DataTable            reprocess_data = new DataTable();
        DataTable            coManager_data = new DataTable();
        string query         = string.Empty,
               comanager_id  = string.Empty,
               branch_list   = string.Empty,
               employee_code = string.Empty;

        int
            start_row = (page_number - 1) * 30,
            number_of_rows = page_number * 30 + 1,
            access, count = 0;

        try
        {
            query = page_object.GetBaseQuery();
            query = page_object.GetFilterQuery(filters, query);

            access        = Convert.ToInt32(HttpContext.Current.Session["access_level"]);
            employee_code = HttpContext.Current.Session["username"].ToString();

            if (access == 1 || access == 3)
            {
                //If logged in manager is a delegation manager for any manager, Get the ManagerID to fetch details of related employee
                comanager_id = null;
                count        = db_connection.ExecuteQuery_WithReturnValueInteger("select COUNT(DelidationManagerID) from TbAsignDelegation where DelidationManagerID = '" + employee_code + "' and DeliationStatus = 1 and Convert(date,Getdate()) >= Convert(date,Fromdate) and Convert(date,Getdate()) <= Convert(date,Todate)");

                if (count > 0)
                {
                    coManager_data = db_connection.ReturnDataTable("select ManagerId from TbAsignDelegation where DelidationManagerID = '" + employee_code + "' And DeliationStatus = 1");
                    if (coManager_data.Rows.Count > 0)
                    {
                        foreach (DataRow dr in coManager_data.Rows)
                        {
                            comanager_id += "'" + dr["ManagerId"] + "',";
                        }

                        comanager_id = comanager_id.TrimEnd(',');
                    }
                }

                if (string.IsNullOrEmpty(comanager_id))
                {
                    comanager_id = "'Empty'";
                }

                //get list of branches assigned to logged in manager hr
                branch_list = "'Empty',";

                DataTable branch_data = db_connection.ReturnDataTable("select BranchCode from TbManagerHrBranchMapping where ManagerID = '" + employee_code + "' ");
                if (branch_data.Rows.Count > 0)
                {
                    foreach (DataRow branch in branch_data.Rows)
                    {
                        branch_list += "'" + branch["BranchCode"] + "',";
                    }
                }

                branch_list = branch_list.TrimEnd(',');

                query += " and (Emp_Branch In (" + branch_list + ") Or ManagerID In('" + employee_code + "'," + comanager_id + ") ) ";
            }

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

            reprocess_data = db_connection.ReturnDataTable(query);

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

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

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

        return(return_object);
    }