Beispiel #1
0
    public static ReturnObject DoExport()
    {
        masters_company page_object   = new masters_company();
        ReturnObject    return_object = new ReturnObject();
        DBConnection    db_connection = new DBConnection();
        DataTable       company_data  = new DataTable();
        DateTime        now           = DateTime.Now;
        int             export_limit  = Convert.ToInt32(ConfigurationManager.AppSettings["EXPORT_LIMIT"]);

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

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

        try
        {
            query        = "select TOP " + export_limit + " * from CompanyMaster";
            company_data = db_connection.ReturnDataTable(query);

            if (company_data.Rows.Count > 0)
            {
                file_name = page_object.CreateExport(company_data);

                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);
    }
Beispiel #2
0
    public static ReturnObject GetCompanyData(int page_number)
    {
        masters_company page_object = new masters_company();
        string          employee_id, query, company_code = string.Empty;
        DBConnection    db_connection  = new DBConnection();
        DataTable       company_data   = new DataTable();
        ReturnObject    return_object  = new ReturnObject();
        int             start_row      = (page_number - 1) * 30;
        int             number_of_rows = 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 * FROM (select *, ROW_NUMBER() OVER (ORDER BY CompanyCode) as row FROM CompanyMaster where companycode = '" + company_code + "' "; // a where row > " + start_row + " and row < " + number_of_rows;
            }
            else
            {
                query = "select * FROM (select *, ROW_NUMBER() OVER (ORDER BY CompanyCode) as row FROM CompanyMaster";
            }
            query += " ) a where row > " + start_row + " and row < " + number_of_rows;

            company_data = db_connection.ReturnDataTable(query);

            company_data = page_object.SetColumnNames(company_data);

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

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

            throw;
        }

        return(return_object);
    }
Beispiel #3
0
    public static ReturnObject EditCompany(string current, string previous)
    {
        masters_company page_object   = new masters_company();
        ReturnObject    return_object = new ReturnObject();
        string
            previous_company_name = string.Empty,
            company_name          = string.Empty,
            company_code          = string.Empty,
            address = string.Empty,
            phone   = string.Empty,
            fax     = string.Empty,
            email   = string.Empty,
            pin     = string.Empty,
            url     = string.Empty,
            message = string.Empty;

        int count = 0;

        try
        {
            JObject current_data = JObject.Parse(current);
            company_name = current_data["company_name"].ToString();
            company_code = current_data["company_code"].ToString();
            address      = current_data["company_address"].ToString();
            phone        = current_data["phone_number"].ToString();
            fax          = current_data["fax_number"].ToString();
            email        = current_data["email_address"].ToString();
            pin          = current_data["pin_code"].ToString();
            url          = current_data["website"].ToString();

            JObject previous_data = JObject.Parse(previous);
            previous_company_name = previous_data["company_name"].ToString();

            if (previous_company_name != company_name)
            {
                count = page_object.CheckCompanyName(company_name);
                if (count > 0)
                {
                    return_object.status      = "error";
                    return_object.return_data = "Company Name has been taken. Please try again with a different Name.";

                    return(return_object);
                }
            }

            page_object.UpdateDatabase(company_code, company_name, address, phone, fax, email, pin, url, "U");

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

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

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

        return(return_object);
    }
Beispiel #4
0
    public static ReturnObject DeleteCompany(string current)
    {
        masters_company page_object = new masters_company();

        DBConnection db_connection = new DBConnection();
        ReturnObject return_object = new ReturnObject();

        int employee_count          = 0;
        int branch_count            = 0;
        int department_count        = 0;
        int designation_count       = 0;
        int employee_category_count = 0;
        int holiday_list_count      = 0;
        int holiday_group_count     = 0;

        string query        = string.Empty;
        string company_code = string.Empty;
        string company_name = string.Empty;
        string address      = string.Empty;
        string phone        = string.Empty;
        string fax          = string.Empty;
        string email        = string.Empty;
        string pin          = string.Empty;
        string url          = string.Empty;

        try
        {
            JObject current_data = JObject.Parse(current);
            company_name = current_data["company_name"].ToString();
            company_code = current_data["company_code"].ToString();
            address      = current_data["company_address"].ToString();
            phone        = current_data["phone_number"].ToString();
            fax          = current_data["fax_number"].ToString();
            email        = current_data["email_address"].ToString();
            pin          = current_data["pin_code"].ToString();
            url          = current_data["website"].ToString();

            query          = "select count (*) from EmployeeMaster where Emp_Company='" + company_code + "'";
            employee_count = db_connection.GetRecordCount(query);
            if (employee_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Employees have been mapped to this Company. Please delete or reassign the employees.";

                return(return_object);
            }

            query            = "select count (*) from DeptMaster where CompanyCode='" + company_code + "'";
            department_count = db_connection.GetRecordCount(query);
            if (department_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Departments have been mapped to this Company. Please delete or reassign the departments.";

                return(return_object);
            }

            query        = "select count (*) from BranchMaster where CompanyCode='" + company_code + "'";
            branch_count = db_connection.GetRecordCount(query);
            if (branch_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Branches have been mapped to this Company. Please delete or reassign the branches.";

                return(return_object);
            }

            query             = "select count (*) from DesigMaster where CompanyCode='" + company_code + "'";
            designation_count = db_connection.GetRecordCount(query);
            if (designation_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Designations have been mapped to this Company. Please delete or reassign the designations.";

                return(return_object);
            }

            query = "select count (*) from EmployeeCategoryMaster where CompanyCode='" + company_code + "'";
            employee_category_count = db_connection.GetRecordCount(query);
            if (employee_category_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Employee Categories have been mapped to this Company. Please delete or reassign the categories.";

                return(return_object);
            }

            query = "select count (*) from HolidayMaster where CompanyCode = '" + company_code + "' ";
            holiday_list_count = db_connection.GetRecordCount(query);
            if (holiday_list_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Holidays have been mapped to this Company. Please delete or reassign the categories.";

                return(return_object);
            }

            query = "select count (*) from HolidayGroup where CompanyCode = '" + company_code + "' ";
            holiday_group_count = db_connection.GetRecordCount(query);
            if (holiday_group_count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Holiday Groups have been mapped to this Company. Please delete or reassign the categories.";

                return(return_object);
            }

            //TODO: Add query to delete Shift Settings record

            page_object.UpdateDatabase(company_code, company_name, address, phone, fax, email, pin, url, "D");

            query = "delete from Shift where CompanyCode='" + company_code + "'";
            db_connection.ExecuteQuery_WithOutReturnValue(query);

            query = "delete from ShiftEmployee where EmpCompanyCode='" + company_code + "'";
            db_connection.ExecuteQuery_WithOutReturnValue(query);

            query = "delete from LeaveMaster where CompanyCode='" + company_code + "'";
            db_connection.ExecuteQuery_WithOutReturnValue(query);

            return_object.status      = "success";
            return_object.return_data = "Company deleted successfully!";
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "DELETE_COMPANY");

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

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

        return(return_object);
    }
Beispiel #5
0
    public static ReturnObject AddCompany(string current)
    {
        masters_company page_object   = new masters_company();
        ReturnObject    return_object = new ReturnObject();
        string          company_name  = string.Empty;
        string          company_code  = string.Empty;
        string          address       = string.Empty;
        string          phone         = string.Empty;
        string          fax           = string.Empty;
        string          email         = string.Empty;
        string          pin           = string.Empty;
        string          url           = string.Empty;
        string          message       = string.Empty;
        int             count         = 0;

        try
        {
            JObject current_data = JObject.Parse(current);
            company_name = current_data["company_name"].ToString();
            company_code = current_data["company_code"].ToString();
            address      = current_data["company_address"].ToString();
            phone        = current_data["phone_number"].ToString();
            fax          = current_data["fax_number"].ToString();
            email        = current_data["email_address"].ToString();
            pin          = current_data["pin_code"].ToString();
            url          = current_data["website"].ToString();

            count = page_object.CheckCompanyCode(company_code);
            if (count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Company Code has been taken. Please try again with a different Code.";

                return(return_object);
            }

            count = page_object.CheckCompanyName(company_name);
            if (count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "Company Name has been taken. Please try again with a different Name.";

                return(return_object);
            }

            page_object.UpdateDatabase(company_code, company_name, address, phone, fax, email, pin, url, "I");

            // creating default row for Shift Setting
            page_object.CreateShiftSetting(company_code);

            return_object.status      = "success";
            return_object.return_data = "Company added successfully!";
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "ADD_COMPANY");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while adding a new Company. Please try again. If the error persists, please contact Support.";

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

        return(return_object);
    }