⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexiaorepdatasourse.java

📁 文件的上传和下载的实现,用JAva编写,非常简单
💻 JAVA
字号:
 package edu.whut.cwts.pg.hexiao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRAbstractBeanDataSourceProvider;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class HexiaoRepDataSourse extends JRAbstractBeanDataSourceProvider {
	public HexiaoRepDataSourse() {
		super(HexiaoReport.class);
		// TODO Auto-generated constructor stub
	}

	private String hexiaoString;// 传递的核销字符串

	public void setHexiaoString(String hexiaoString) {
		this.hexiaoString = hexiaoString;
	}

	public String getHexiaoString() {
		return hexiaoString;
	}

	public JRDataSource create(JasperReport report) throws JRException {
		String hexiaoString = this.hexiaoString;
		System.out.println(hexiaoString);
		ArrayList hexiaoList0 = new ArrayList();
		ArrayList hexiaoList1 = new ArrayList();
		ArrayList hexiaoList2 = new ArrayList();
		ConnectDB conndb = new ConnectDB();
		String[] str_abc = hexiaoString.split(";");// 我在页面上获取的字符串要将它按";"进行拆分,然后再按照","拆分
		for (int j = 0; j < str_abc.length; j++) {
			hexiaoList0.add(str_abc[j]);
		}
		for (int k = 0; k < hexiaoList0.size(); k++) {
			String ssd = (String) hexiaoList0.get(k);
			String[] str_abc1 = ssd.split(",");// 票证起号、票证止号、票证种类
			hexiaoList1.add(new Pzqz(str_abc1[0], str_abc1[1], str_abc1[2]));
		}
		for (int i = 0; i < hexiaoList1.size(); i++) {
			Pzqz pzqzHexiao = (Pzqz) hexiaoList1.get(i);// 从第一条数据读起
			long fs0 = Long.parseLong(pzqzHexiao.getPzzh())
					- Long.parseLong(pzqzHexiao.getPzqh()) + 1;
			String fs = String.valueOf(fs0); // 获取起号到止号的份数
			String jeTotal = ""; // 定义金额合计
			String zffs = "";
			String zfh="";
			String pzmc="";
			System.out.println(pzqzHexiao.getPzzl());
			if (pzqzHexiao.getPzzl().equals("1")) {
				ArrayList result0 = new ArrayList();
				ArrayList result1 = new ArrayList();
				ArrayList result2 = new ArrayList();
				pzmc = "国际航线收据";
				String sql0 = "select sum(jfje) as jeTotal from gjhc where pzzl='1' and sfzf='否' and  pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				System.out.println(sql0);
				ResultSet rs0 = conndb.executeQuery(sql0);
				if (rs0 == null)
					return null;
				try {
					while (rs0.next()) {
						result0.add(rs0.getString("jeTotal"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				jeTotal = StrUtil.doLing((String) result0.get(0));
				String sql1 = "select count(*) as zffs from pjztb where zfzt='1' and pzzl='1' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				 Assert.pl(sql1);
				ResultSet rs1 = conndb.executeQuery(sql1);
				if (rs1 == null)
					return null;
				try {
					while (rs1.next()) {
						result1.add(rs1.getString("zffs"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				zffs = (String) result1.get(0);
				String sql2="select pzhm from pjztb where zfzt='1' and pzzl='1' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				ResultSet rs2 = conndb.executeQuery(sql2);
				if (rs2 == null)
					return null;
				try {
					while (rs2.next()) {
						//result2.add(rs2.getString("pzhm"));
						zfh= zfh+rs2.getString("pzhm")+"-";
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}		
			}//if
			if (pzqzHexiao.getPzzl().equals("2")) {
				ArrayList result0 = new ArrayList();
				ArrayList result1 = new ArrayList();
				ArrayList result2 = new ArrayList();
				pzmc = "航次缴讫收据";
				String sql0 = "select sum(jfje) as jeTotal from gnhc where sfzf='否' and  pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				 Assert.pl(sql0);
				ResultSet rs0 = conndb.executeQuery(sql0);
				if (rs0 == null)
					return null;
				try {
					while (rs0.next()) {
						result0.add(rs0.getString("jeTotal"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				jeTotal = StrUtil.doLing((String) result0.get(0));
				String sql1 = "select count(*) as zffs from pjztb where zfzt='1' and pzzl='2' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				 Assert.pl(sql1);
				ResultSet rs1 = conndb.executeQuery(sql1);
				if (rs1 == null)
					return null;
				try {
					while (rs1.next()) {
						result1.add(rs1.getString("zffs"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				zffs = (String) result1.get(0);
				String sql2="select pzhm from pjztb where zfzt='1' and pzzl='2' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				ResultSet rs2 = conndb.executeQuery(sql2);
				if (rs2 == null)
					return null;
				try {
					while (rs2.next()) {
						//result2.add(rs2.getString("pzhm"));
						zfh= zfh+rs2.getString("pzhm")+"-";
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}		
			}
			if (pzqzHexiao.getPzzl().equals("3")) {
				ArrayList result0 = new ArrayList();
				ArrayList result1 = new ArrayList();
				ArrayList result2 = new ArrayList();
				pzmc = "统缴收据";
				String sql0 = "select sum(jfje) as jeTotal from tjp where sfzf='否' and  pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				// Assert.pl(sql0);
				ResultSet rs0 = conndb.executeQuery(sql0);
				if (rs0 == null)
					return null;
				try {
					while (rs0.next()) {
						result0.add(rs0.getString("jeTotal"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				jeTotal = StrUtil.doLing((String) result0.get(0));
				String sql1 = "select count(*) as zffs from pjztb where zfzt='1' and pzzl='3' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				// Assert.pl(sql1);
				ResultSet rs1 = conndb.executeQuery(sql1);
				if (rs1 == null)
					return null;
				try {
					while (rs1.next()) {
						result1.add(rs1.getString("zffs"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				zffs = (String) result1.get(0);
				String sql2="select pzhm from pjztb where zfzt='1' and pzzl='3' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				ResultSet rs2 = conndb.executeQuery(sql2);
				if (rs2 == null)
					return null;
				try {
					while (rs2.next()) {
						//result2.add(rs2.getString("pzhm"));
						zfh= zfh+rs2.getString("pzhm")+"-";
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}		
			}
			if (pzqzHexiao.getPzzl().equals("4")) {
				ArrayList result0 = new ArrayList();
				ArrayList result1 = new ArrayList();
				ArrayList result2 = new ArrayList();
				pzmc = "PDA航次缴讫收据";
				String sql0 = "select sum(jfje) as jeTotal from gnhc where pzzl='4' and sfzf='否' and  pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				// Assert.pl(sql0);
				ResultSet rs0 = conndb.executeQuery(sql0);
				if (rs0 == null)
					return null;
				try {
					while (rs0.next()) {
						result0.add(rs0.getString("jeTotal"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				jeTotal =StrUtil.doLing((String) result0.get(0));
				String sql1 = "select count(*) as zffs from pjztb where zfzt='1' and pzzl='4' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				// Assert.pl(sql1);
				ResultSet rs1 = conndb.executeQuery(sql1);
				if (rs1 == null)
					return null;
				try {
					while (rs1.next()) {
						result1.add(rs1.getString("zffs"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				zffs = (String) result1.get(0);
				String sql2="select pzhm from pjztb where zfzt='1' and pzzl='4' and pzhm between '"
						+ pzqzHexiao.getPzqh()
						+ "' and '"
						+ pzqzHexiao.getPzzh() + "'";
				ResultSet rs2 = conndb.executeQuery(sql2);
				if (rs2 == null)
					return null;
				try {
					while (rs2.next()) {
						//result2.add(rs2.getString("pzhm"));
						zfh= zfh+rs2.getString("pzhm")+"-";
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}		
			}
			long fsLong = Long.parseLong(fs);
			long zffsLong = Long.parseLong(zffs);
			float jeTotalFloat = Float.parseFloat(jeTotal);
			hexiaoList2.add(new HexiaoReport(pzmc,pzqzHexiao.getPzqh(),pzqzHexiao.getPzzh(),fsLong,zfh,zffsLong,jeTotalFloat));
		}//for
		System.out.println(hexiaoList2.size());
		HexiaoReport xx=(HexiaoReport)hexiaoList2.get(0);
		System.out.println(xx.getPzmc());
		System.out.println(xx.getQh());
		System.out.println(xx.getZh());
		System.out.println(xx.getFs());
		System.out.println(xx.getZfh());
		System.out.println(xx.getZffs());
		System.out.println(xx.getJe());
		return new JRBeanCollectionDataSource(hexiaoList2);
	}//wai
	 public void dispose(JRDataSource arg0) throws JRException {
			// TODO Auto-generated method stub
			
		}	
}//end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -