예제 #1
0
    public static ReturnObject DoReprocess(string employees, string from_date, string to_date)
    {
        attendance_reprocess page_object       = new attendance_reprocess();
        DBConnection         db_connection     = new DBConnection();
        ReturnObject         return_object     = new ReturnObject();
        Hashtable            reprocessing_data = new Hashtable();
        DataTable            process_flags     = new DataTable();

        if (HttpContext.Current.Session["username"] == null)
        {
            // HttpContext.Current.Response.Redirect("~/logout.aspx", true);
            return_object = page_object.DoLogout();
        }
        else
        {
            List <string> employees_list = JsonConvert.DeserializeObject <List <string> >(employees);

            StringBuilder employee_id_string = new StringBuilder();

            DateTime
                from_date_time, to_date_time;

            string
                query = string.Empty;

            int
                i = 0, process_flag_1 = 0, process_flag_2 = 0;

            try
            {
                query         = "select p.pflag, r.re_flag from ProcessingStatus p, ReprocessFlag r";
                process_flags = db_connection.ReturnDataTable(query);

                if (process_flags.Rows.Count > 0)
                {
                    process_flag_1 = Convert.ToInt32(process_flags.Rows[0]["pflag"]);
                    process_flag_2 = Convert.ToInt32(process_flags.Rows[0]["re_flag"]);
                }

                if (process_flag_1 == 1 || process_flag_2 == 1)
                {
                    return_object.status      = "error";
                    return_object.return_data = "Processing is in progress, please wait.";
                }
                else
                {
                    for (i = 0; i < employees_list.Count; i++)
                    {
                        employee_id_string.Append(employees_list[i]);
                        employee_id_string.Append(",");
                    }

                    if (employee_id_string.ToString() == "")
                    {
                        return_object.status      = "error";
                        return_object.return_data = "Please select at least one employee.";
                    }
                    else
                    {
                        employee_id_string.Remove(employee_id_string.Length - 1, 1);

                        from_date_time = DateTime.ParseExact(from_date, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                        to_date_time   = DateTime.ParseExact(to_date, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                        reprocessing_data.Add("fromdate", from_date_time.ToString("yyyy-MM-dd"));
                        reprocessing_data.Add("todate", to_date_time.ToString("yyyy-MM-dd"));
                        reprocessing_data.Add("empid", employee_id_string.ToString());

                        db_connection.ExecuteStoredProcedureWithHashtable_WithoutReturn("securtimereprocess_Empid", reprocessing_data);

                        return_object.status      = "success";
                        return_object.return_data = "Processing completed successfully!";
                    }
                }
            }

            catch (Exception ex)
            {
                Logger.LogException(ex, page, "REPROCESS_DATA");

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

                throw;
            }
        }

        return(return_object);
    }
예제 #2
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);
    }