package cn.pla.xxgc.action;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import cn.pla.xxgc.common.DataConn;
import cn.pla.xxgc.entity.Effort;
import com.lowagie.text.Cell;
import com.lowagie.text.Chapter;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Section;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.document.RtfDocument;
import com.lowagie.text.rtf.style.RtfFont;
import com.lowagie.text.rtf.table.RtfTable;
import com.lowagie.text.rtf.text.RtfParagraph;
import com.lowagie.text.rtf.text.RtfSection;
import com.lowagie.text.*;
import com.lowagie.text.rtf.*;
import com.lowagie.text.pdf.*;
import com.opensymphony.xwork2.Action;
//public class PlanExportAction implements Action {
public class PlanExportAction
{
String SUCCESS = "success";
String prjDesp = "";
/*文字字体*/
// BaseFont bfChinese = BaseFont.createFont("c:/WINDOWS/Fonts/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
// Font titleFont = new Font(bfChinese, 16, Font.BOLD, new Color(0, 0, 0));
// Font title1Font = new Font(bfChinese, 14, Font.BOLD, new Color(0, 0, 0));
// Font title2Font = new Font(bfChinese, 12, Font.BOLD, new Color(0, 0, 0));
// Font contentFont = new Font(bfChinese, 12, Font.NORMAL, new Color(0, 0, 0));
RtfFont titleFont = new RtfFont("黑 体", 16, Font.BOLD, Color.BLACK);
RtfFont title1Font = new RtfFont("黑 体", 14, Font.BOLD, Color.BLACK);
RtfFont title2Font = new RtfFont("黑 体", 12, Font.BOLD, Color.BLACK);
RtfFont title3Font = new RtfFont("黑 体", 12, Font.BOLD, Color.BLACK);
RtfFont contentFont = new RtfFont("宋 体", 12, Font.NORMAL, Color.BLACK);
/*表格字体*/
RtfFont headerFont = new RtfFont("宋 体", 10.5f, Font.BOLD, Color.BLACK);
RtfFont tableContentFont = new RtfFont("宋 体", 10.5f, Font.NORMAL, Color.BLACK);
/*页眉页脚字体*/
RtfFont pageHeaderFont = new RtfFont("宋 体", 10.5f, Font.UNDERLINE, Color.BLACK);
RtfFont pageFooterFont = new RtfFont("宋 体", 9, Font.NORMAL, Color.BLACK);
/*表头*/
public static final String[] tbHeadRef = {"文档资料名称","作者","版本号/日期","性质"};
public static final String[] tbHeadTerm = {"术语/缩写词名称","定义/原文","备注"};
public static final String[] tbHeadLifecycle = {"序号","阶段","入口标准","输入产品","任务","输出产品","出口标准"};
public static final String[] tbHeadWbs = {"WBS编号","一级拆分","二级拆分","三级拆分","规模"};
public static final String[] tbHeadDepWrok = {"子系统名称","代码规模","人均生产率","调整系数","工作量"};
public static final String[] tbHeadMagWork = {"项目开发活动总工作量","该类活动与项目开发活动总工作量比例","工作量","备注"};
public static final String[] tbHeadPrduct = {"类型","名称","交付时间","说明"};
public static final String[] tbPeopRes = {"角色","人员名单","人数","技能要求","到位时间"};
public static final String[] tbTraining = {"培训内容","负责人","培训起止时间","培训对象","培训讲师","免修标准"};
public static final String[] tbResource = {"类别","名称","型号/版本","数量","详细配置","到位时间"};
public static final String[] tbCost = {"类别","说明","金额(万元)"};
public static final String[] tbPhrase = {"编号","阶段名称","阶段目标描述","是否里程碑","开始时间","结束时间"};
public static final String[] tbRegMmeeting = {"例会频率","组织人","参加人"};
public static final String[] tbPeerReview = {"阶段名称","评审对象","评审方式","组织人","参加人"};
public static final String[] tbMileReview = {"里程碑名称","组织人","参加人"};
public static final String[] tbOffset = {"进度偏差","工作量偏差","说明"};
public static final String[] tbRisk = {"编号","风险描述","可能性","严重程度","影响值","风险系数","缓解措施","应急措施","责任人"};
public static final String[] tbCommunication = {"阶段","相关利益者名称","参与活动及方式","参与时间","说明"};
public static final String[] tbDataPlan = {"资料类别","说明","管理责任人","使用审批权限","存档地点"};
public static final String[] tbMeasure = {"测量目标","测量项","责任人","测量方式","测量方式","报告时间","报告对象"};
public static final String[] tbExtraPlan = {"序号","名称","责任人","完成时间","备注"};
/**
* 创建表格,从数据库取出数据
* @param doc Document文档
* @param tbHeader 表头数组
* @param res 数据库查询结果集
*/
public void CreateTable(Document doc,String[] tbHead,ResultSet res) throws Exception
{
int colCount = tbHead.length;
String ss = "";
Table table = new Table(colCount);
table.setBorderColor(new Color(0, 0, 0));
table.setPadding(5);
table.setWidth(90); //表格宽度占页面的90%
table.setAlignment("CENTER");
/*创建表头*/
for(int i=0;i<colCount;i++)
{
Cell cell = new Cell(new Paragraph(tbHead[i],headerFont));
cell.setHorizontalAlignment("CENTER");
cell.setVerticalAlignment("CENTER");
table.addCell(cell);
}
/* 创建表内容*/
while (res.next()) {
for (int j = 0; j < colCount; j++) {
if (res.getString(j + 1) == null)
ss = "空 null";
else
ss = res.getString(j + 1);
Cell cell = new Cell(new Paragraph(ss,tableContentFont));
cell.setHorizontalAlignment("CENTER");
cell.setVerticalAlignment("CENTER");
table.addCell(cell);
}
}
doc.add(table);
}
/**
* 创建只有表头的表格
* @param Document Rtf 文档
* @param tbHead 表头数组
* @param row 默认的空行
*/
public void CreateNullTable(Document doc,String[] tbHead,int rows) throws Exception
{
int colCount = tbHead.length;
Table table = new Table(colCount,rows);
table.setAutoFillEmptyCells(true); //自动填充空单元格以保持行间距一直
table.setBorderColor(new Color(0, 0, 0));
table.setPadding(5);
table.setWidth(90);
/*创建表头*/
for(int i=0;i<colCount;i++)
{
Paragraph para = new Paragraph(tbHead[i],headerFont);
Cell cell = new Cell(para);
cell.setHorizontalAlignment("CENTER");
cell.setVerticalAlignment("CENTER");
table.addCell(cell);
}
doc.add(table);
}
/**
* 创建段落
* @param doc Document文档
* @param text 段落文字
* @param font 字体
*/
public void CreateParagraph(Document doc,String text,RtfFont font) throws Exception
{
Paragraph para = new Paragraph( text, font);
para.setSpacingBefore(6);//段前6磅
para.setLeading(18); //行距18磅~1.5倍行距
if(contentFont == font)
{
para.setIndentationLeft(22.76f); //左缩进22.76磅~2个字符
}
doc.add(para);
}
/**
* 获取数据库查询结果集合,用以填充表格
*/
public ArrayList<ResultSet> getRes()
{
int ProjID = 1;
ArrayList<String> sqlList = new ArrayList<String>();
ArrayList<ResultSet> resList = new ArrayList<ResultSet>();
try
{
DataConn dc = new DataConn();
prjDesp = dc.getSelectSingleValue("select ProjDescription from ppt_project where ID = '"+ProjID+"'");//项目概述
sqlList.add( "select * from ppt_lifecycle where ProjID = '"+ProjID+"'");//生命周期
sqlList.add( "select * from ppt_lifecycle where ProjID = '"+ProjID+"'");//规模估计**
sqlList.add( "select * from ppt_lifecycle where ProjID = '"+ProjID+"'");//开发活动工作量估计**
sqlList.add( "select * from ppt_lifecycle where ProjID = '"+ProjID+"'");//管理活动工作量