Esempio n. 1
0
    public static ReturnObject DoExport(string filters, bool is_filter)
    {
        masters_branch page_object   = new masters_branch();
        ReturnObject   return_object = new ReturnObject();
        DBConnection   db_connection = new DBConnection();
        DataTable      branch_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 = page_object.GetBaseQuery();

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

            query += " Group by b.BranchCode, b.BranchName, c.CompanyCode, c.CompanyName, b.BranchAddress, b.PhoneNo, b.FaxNo, b.Email) a where row > 0 and row < " + export_limit;

            branch_data = db_connection.ReturnDataTable(query);

            if (branch_data.Rows.Count > 0)
            {
                file_name = page_object.CreateExport(branch_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);
    }
Esempio n. 2
0
    public static ReturnObject EditBranch(string current, string previous, string holiday_groups)
    {
        masters_branch page_object         = new masters_branch();
        DBConnection   db_connection       = new DBConnection();
        ReturnObject   return_object       = new ReturnObject();
        JArray         holiday_groups_data = new JArray();

        string
            original_branch_name = string.Empty, branch_code = string.Empty, branch_name = string.Empty,
            company_code = string.Empty, holiday_group_code = string.Empty,
            address = string.Empty, phone = string.Empty, fax = string.Empty, email = string.Empty, hr_incharge = string.Empty, alternative_hr_incharge = string.Empty;

        int count = 0, i = 0;

        try
        {
            JObject current_data = JObject.Parse(current);
            branch_code             = current_data["branch_code"].ToString();
            branch_name             = current_data["branch_name"].ToString();
            company_code            = current_data["company_code"].ToString();
            address                 = current_data["branch_address"].ToString();
            phone                   = current_data["phone_number"].ToString();
            fax                     = current_data["fax_number"].ToString();
            email                   = current_data["email_address"].ToString();
            hr_incharge             = current_data["Hr_Incharge"].ToString();
            alternative_hr_incharge = current_data["Alternative_Hr_Incharge"].ToString();


            JObject previous_data = JObject.Parse(previous);
            original_branch_name = previous_data["branch_name"].ToString();
            // Parse the array of holiday codes.
            holiday_groups_data = JArray.Parse(holiday_groups);

            if (original_branch_name != branch_name)
            {
                count = page_object.CheckBranchName(branch_name, company_code);
                if (count > 0)
                {
                    return_object.status      = "error";
                    return_object.return_data = "Branch Name has been taken. Please try again with a different Name.";

                    return(return_object);
                }
                else
                {
                    for (i = 0; i < holiday_groups_data.Count; i++)
                    {
                        page_object.UpdateDatabase(branch_code, branch_name, company_code, holiday_groups_data[i].ToString(), address, phone, fax, email, hr_incharge, alternative_hr_incharge, "U");
                    }
                }
            }
            else
            {
                // delete the existing branch data from BranchMaster table.
                page_object.UpdateDatabase(branch_code, branch_name, company_code, "", address, phone, fax, email, hr_incharge, alternative_hr_incharge, "D");

                for (i = 0; i < holiday_groups_data.Count; i++)
                {
                    page_object.UpdateDatabase(branch_code, branch_name, company_code, holiday_groups_data[i].ToString(), address, phone, fax, email, hr_incharge, alternative_hr_incharge, "I");
                }
            }

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

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

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

        return(return_object);
    }