Ejemplo n.º 1
0
    public static ReturnObject DoExport()
    {
        outofoffice_approve page_object   = new outofoffice_approve();
        ReturnObject        return_object = new ReturnObject();
        DBConnection        db_connection = new DBConnection();
        DataTable           ooo_data      = new DataTable();
        DateTime            now           = DateTime.Now;
        int export_limit      = Convert.ToInt32(ConfigurationManager.AppSettings["EXPORT_LIMIT"]),
            user_access_level = 0;

        string[] column_names = new string[] { };

        string employee_id = string.Empty,
               query = string.Empty, file_name = string.Empty;

        user_access_level = Convert.ToInt32(HttpContext.Current.Session["access_level"]);
        employee_id       = HttpContext.Current.Session["employee_id"].ToString();

        try
        {
            query = " select TOP " + export_limit + " Emp_ID 'EmployeeID',Emp_Name 'EmployeeName',OOO_type_name 'OutOfOffice Type',FromDateTime ,ToDateTime,";

            query += " CONVERT(VARCHAR, RIGHT('0' +  RTRIM(OOO_Minutes/60),3) + ':' + RIGHT('0' + RTRIM(OOO_Minutes%60),2)) as Hours, ";
            query += " CONVERT(VARCHAR, RIGHT('0' +  RTRIM(Total_OOO_Minutes/60),3) + ':' + RIGHT('0' + RTRIM(Total_OOO_Minutes%60),2)) as TotalHours, ";

            query += " Reason, ";

            if (user_access_level == 3)
            {
                query += " Manager_Name 'Manager Name',Manager_Remark 'Manager Remark', ";
                query += " case when Manager_Status=1 then 'Submiited' when Manager_Status=2 then 'Approved' when Manager_Status=3 then 'Rejected' end as Approval,";
                query += " case when HR_Status=1 then 'Submiited' when HR_Status=2 then 'Approved' when HR_Status=3 then 'Rejected' else 'Manager Action Pending' end as HRApproval";
            }
            if (user_access_level == 1)
            {
                query += " case when Manager_Status=1 then 'Submiited' when Manager_Status=2 then 'Approved' when Manager_Status=3 then 'Rejected' end as Approval";
            }

            query += " from outoffoffice O join OOOType OT on O.OOO_type=OT.OOO_type_id ";

            if (user_access_level == 3)
            {
                query += "where Emp_ID in (select Emp_Code from EmployeeMaster where Emp_Branch=(select Emp_Branch from EmployeeMaster where Emp_Code='" + employee_id + "' ))";
            }
            if (user_access_level == 1)
            {
                query += "where Emp_ID in (select Emp_Code from EmployeeMaster where ManagerID='" + employee_id + "' )";
            }

            ooo_data = db_connection.ReturnDataTable(query);

            query += "order by OOO_ID ";

            if (ooo_data.Rows.Count > 0)
            {
                file_name = page_object.CreateExport(ooo_data, user_access_level);

                return_object.status      = "success";
                return_object.return_data = file_name;
            }
            else
            {
                return_object.status      = "info";
                return_object.return_data = "No data found with the selected filters. Please try again with different filters.";
            }
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "GET_DATA_FOR_EXPORT");

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

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

        return(return_object);
    }
Ejemplo n.º 2
0
    public static ReturnObject DoAction(int action, string comments, string selected_rows)
    {
        outofoffice_approve page_object   = new outofoffice_approve();
        DBConnection        db_connection = new DBConnection();
        ReturnObject        return_object = new ReturnObject();

        List <string> selected_out_off_office = JsonConvert.DeserializeObject <List <string> >(selected_rows);

        string
            query = string.Empty, return_message = string.Empty,
            ooo_status = string.Empty;

        long
            ooo_id = 0;
        int update_flag = 0, Existsing_Status = 0;

        try
        {
            switch (action)
            {
            case 2:
                ooo_status  = "Approved";
                update_flag = 2;
                break;

            case 3:
                ooo_status  = "Rejected";
                update_flag = 3;
                break;
            }

            for (int i = 0; i < selected_out_off_office.Count; i++)
            {
                ooo_id = Convert.ToInt64(selected_out_off_office[i].ToString());

                query            = "select Status from outoffoffice where OOO_ID='" + ooo_id + "' ";
                Existsing_Status = db_connection.ExecuteQuery_WithReturnValueInteger(query);

                if (Existsing_Status == 2)
                {
                    return_message += "Out Off Office punch is already approved" + Environment.NewLine;
                }
                else if (Existsing_Status == 3)
                {
                    return_message += "Out Off Office punch is already rejected" + Environment.NewLine;
                }
                else
                {
                    page_object.ApproveOutOffOffice(ooo_id, update_flag, comments);
                    return_message = "Out Off Office " + ooo_status + " successfully!" + Environment.NewLine;
                }
            }

            return_object.status      = "success";
            return_object.return_data = return_message;
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "UPDATE_OUT_OFF_OFFICE_APPROVAL_STATUS");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while updating Out Off Office Approval Status. Please try again. If the error persists, please contact Support.";
        }
        finally
        {
            page_object.Dispose();
        }

        return(return_object);
    }