添加小计合计的数据行

	//添加合计行
	private void addSumRow(KDTable table){
//		table.checkParsed();
		if(table.getRowCount() == 0 || table.getRowCount() < 0){
			return;
		}
		IRow firstRow = table.getRow(0);
		if(firstRow.getCell("unitName").getValue() == null){
			return;
		}
		Object tempAdmin = firstRow.getCell("unitName").getValue();
		int total = 0;
		int sum = 0;

		int ctRecruitment = 0;
		int sumCtRecruitment  = 0;

		int iRecruitment = 0;
		int sumIRecruitment = 0;

		int desfocRec = 0;
		int sumDesfocRec = 0;

		Object lastAdminOrg = null;
		boolean flag = true;
		for(int i = 0;i<table.getRowCount();i++){
			IRow row = table.getRow(i);
			if(row.getCell("unitName").getValue() == null
					|| !row.getCell("unitName").getValue().equals(tempAdmin)){
				IRow newRow = table.addRow(row.getRowIndex());
				table.setRowCount(table.getRowCount() + 1);
				newRow.getCell("unitName").setValue("小计");
				newRow.getCell("unitName").getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
				newRow.getStyleAttributes().setBackground(Color.lightGray);
				newRow.getStyleAttributes().setLocked(true);
				lastAdminOrg = table.getRow(i - 1).getCell("area").getValue();
				flag = true;
				newRow.getCell("area").setValue(lastAdminOrg);

				tempAdmin = row.getCell("unitName").getValue();

				newRow.getCell("entrys.recNumber").setValue(new Integer(total));
				sum += total;
				total = 0;


			}else{
				lastAdminOrg = row.getCell("area").getValue();
				if(row.getCell("entrys.recNumber").getValue() != null){
					Integer tempTotal = (Integer) row.getCell("entrys.recNumber").getValue();
					total += tempTotal.intValue();
				}
			}
		}
		
		IRow lastRow = table.addRow(table.getRowCount());
		table.setRowCount(table.getRowCount() + 1);
		lastRow.getCell("entrys.recNumber").setValue(new Integer(total));
		lastRow.getCell("area").setValue(lastAdminOrg);
		if(flag){
			lastRow.getCell("area").setValue(table.getRow(table.getRowCount() - 1).getCell("area").getValue());
		}


		lastRow.getStyleAttributes().setBackground(Color.lightGray);
		lastRow.getCell("unitName").setValue("小计");
		lastRow.getCell("unitName").getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
		lastRow.getStyleAttributes().setLocked(true);

		IRow totalRow = table.addRow(table.getRowCount());
		table.setRowCount(table.getRowCount() + 1);
		totalRow.getCell("entrys.recNumber").setValue(new Integer(sum+total));
	
		totalRow.getStyleAttributes().setBackground(Color.cyan);
		totalRow.getCell("unitName").setValue("合计");
		totalRow.getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
		totalRow.getStyleAttributes().setLocked(true);
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值