我们要求报表可以根据用户的选择来动态进行排序,但是每个报表所显示的列肯定不一样,所以每个报表在实现这个功能的时候,参数提示的时候必然要提供可选的值,到了Java里面,如何从Crystal Report Server上读取这些信息呢?
    public static ValueObjList getReportParameters(int reportID) throws Exception
    {
        String query = "Select SI_PROCESSINFO.SI_PROMPTS From CI_INFOOBJECTS Where si_progid = ‘crystalenterprise.report’ and SI_ID = "
                + reportID;
        IInfoObjects results = query(query);
        ValueObjList result = new ValueObjList();
        if (results == null)
        {
            return result;
        }
        IInfoObject report = (IInfoObject) results.get(0);
        List allParameters = ((IReport) report).getReportParameters();
        IReportParameter reportParameter = null;
        //Fix THRX2282, this maybe crystal report’s bug
        Set parameterNames = new HashSet();
        for (int j = 0; j < allParameters.size(); j++)
        {
            reportParameter = (IReportParameter) allParameters.get(j);
            if (!reportParameter.isInUse())
            {
                continue;
            }
            CrystalReportParamConfigValueObj paramvo = new CrystalReportParamConfigValueObj();
            String name = reportParameter.getParameterName();
            if (name.equals("sortcolumn"))
            {
                IReportParameterValues defaultValues = reportParameter.getDefaultValues();
                Values values = defaultValues.getValues(reportParameter.getValueType());
                for (int m = 0; m < values.size(); m++)
                {
                    ParameterFieldDiscreteValue value = (ParameterFieldDiscreteValue) values.get(m);
                    System.out.println(value.displayText(Locale.ENGLISH));
                }
            }
            if (parameterNames.contains(name))
            {
                continue;
            }
            else
            {
                parameterNames.add(name);
                paramvo.setAttribute(CrystalReportParamConfigAttributes.name, name);
                paramvo.setAttribute(CrystalReportParamConfigAttributes.type, new Integer(reportParameter
                        .getValueType()));
                result.add(paramvo);
            }
        }
        return result;

    }

注意蓝色的代码,特别是defaultValues.getValues(reportParameter.getValueType()),这样我们就可以从服务器上读取到报表随带的参数值列表。

(Visited 22 times, 1 visits today)