润乾报表-动态查询

润乾报表提供宏工作机制,因此利用宏可以可以动态组织sql语句,得到实时报表了。

<%@ page contentType="text/html;charset=GBK" %>
<%@ taglib uri="/WEB-INF/runqianReport4.tld" prefix="report" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.runqian.report4.usermodel.Context"%>
<%@ page import="com.runqian.report4.model.ReportDefine"%>
<%@ page import="com.runqian.report4.util.ReportUtils"%>
<%@ page import="com.runqian.report4.usermodel.MacroMetaData"%>
<%@ page import="com.runqian.report4.usermodel.Macro"%>



<%

request.setCharacterEncoding( "GBK" );
String realPath = request.getRealPath("/");

%>




<%

StringBuffer macBuffer = new StringBuffer();//sql 拼串
String reportName ="dsworkinfo.raq"; //模板名称

//---- 接受参数
String sdate ="",edate="",viewcode ="",status="",isLiuId="";
if(request.getParameter("sdate")!=null){
sdate = request.getParameter("sdate");
if(!sdate.equals(""))
macBuffer.append(" and a.writetime >= to_date('"+sdate+"','yyyy-mm-dd') ");
}
if(request.getParameter("edate")!=null){
edate = request.getParameter("edate");
if(!edate.equals(""))
macBuffer.append(" and a.writetime < to_date('"+edate+"','yyyy-mm-dd')+1 ");
}
if(request.getParameter("viewcode")!=null){
viewcode = request.getParameter("viewcode");
if(!viewcode.equals(""))
macBuffer.append(" and b.vc0 like '"+viewcode+"%' ");
}
if(request.getParameter("status")!=null){
status = request.getParameter("status");
if(!status.equals("") && Integer.parseInt(status)>-1)
macBuffer.append(" and a.status = '"+status+"' ");
}
if(request.getParameter("isLiuId")!=null){
isLiuId = request.getParameter("isLiuId");
if(!isLiuId.equals("") && Integer.parseInt(isLiuId)>-1)
{ int liu = Integer.parseInt(isLiuId);
if( liu==0 ){
macBuffer.append(" and b.simply_code like '%LDZCZ' ");
}
else if(liu==1){
macBuffer.append(" and b.simply_code not like '%LDZCZ' ");
}
}
}

//----设置宏替换

Context cxt = new Context(); //构建报表引擎计算环境
ReportDefine rd = (ReportDefine)ReportUtils.read(realPath+"reportFiles"+File.separator+reportName);
MacroMetaData mmd=rd.getMacroMetaData(); //构造宏的元数据
if(mmd.getMacroCount()>0)
{
cxt.setMacroValue(mmd.getMacro(0).getMacroName(),macBuffer.toString());//此模板只设计一个宏
}
String cxtName = "CXT_"+Double.toString(Math.random());
request.setAttribute(cxtName, cxt );

%>





reportFileName="<%=reportName %>"
width="-1"
height="-1"
contextName ="<%=cxtName %>"
/>









你可能感兴趣的:(实用程序)