package cn.com.countrygarden.bi.main.controller.project.imports;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;

import cn.com.countrygarden.bi.main.model.dup.SiteResources;
import cn.com.countrygarden.bi.main.model.project.ProjectSignInfo;

public class ProjectSignInfoImports {
	public static final String PATH = "/excel/sing.xlsx";
	/**
	 * 表体
	 * @param dataList
	 * @param workbook
	 * @param sheet
	 */
	 public void createBody(List<ProjectSignInfo> dataList, Workbook workbook, Sheet sheet) {
	        CellStyle style = createBodyStyle(workbook);
	        int rowIndex = 1;
	        for (ProjectSignInfo data : dataList) {
	        	  Row row = sheet.createRow(rowIndex);
	        	  createCell(data.getNo(), style, row, 0);
	        	  createCell(data.getProvincesName(), style, row, 1);
	        	  createCell(data.getOrganName(), style, row, 2);
	        	  createCell(data.getYear(), style, row, 3);
	        	  createCell(data.getFirstQuarterTarget().toString(), style, row, 4);
	        	  createCell(data.getFirstQuarterProgress().toString(), style, row, 5);
	        	  createCell(data.getTwoQuarterTarget().toString(), style, row, 6);
	        	  createCell(data.getTwoQuarterProgress().toString(), style, row, 7);
	        	  createCell(data.getThreeQuarterTarget().toString(), style, row, 8);
	        	  createCell(data.getThreeQuarterProgress().toString(), style, row, 9);
	        	  createCell(data.getFourQuarterTarget().toString(), style, row, 10);
	        	  createCell(data.getFourQuarterProgress().toString(), style, row, 11);
	        	  createCell(data.getYearQuarterTarget().toString(), style, row, 12);
	        	  createCell(data.getYearQuarterProgress().toString(), style, row, 13);
	        	  rowIndex++;
			}
	    }
	 /**
	  * 表头
	  * @param workbook
	  * @param sheet
	  */
	 public void createHeader(Workbook workbook, Sheet sheet) {
    	 int rowIndex = 0;
         CellStyle headerStyle = createHeaderStyle(workbook);
         Row row = sheet.createRow(rowIndex);
         row.setHeight((short) (250 * 2));
         createCell("名次", headerStyle, row, 0);
         createCell("大区", headerStyle, row, 1);
         createCell("区域名称", headerStyle, row, 2);
         createCell("年份", headerStyle, row, 3);
         createCell("第一季度目标", headerStyle, row, 4);
         createCell("第一季度完成度", headerStyle, row, 5);
         //这里有图片服务器再做!
         createCell("第二季度目标", headerStyle, row, 6);
         createCell("第二季度完成度", headerStyle, row, 7);
         createCell("第三季度目标", headerStyle, row, 8);
         createCell("第三季度完成度", headerStyle, row, 9);
         createCell("第四季度目标", headerStyle, row, 10);
         createCell("第四季度完成度", headerStyle, row, 11);
         createCell("年度目标", headerStyle, row, 12);
         createCell("年度完成度", headerStyle, row, 13);
    }
	   public CellStyle createHeaderStyle(Workbook workbook) {
	        CellStyle headerStyle = workbook.createCellStyle();
	        headerStyle.setAlignment(HorizontalAlignment.CENTER);
	        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
	        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	        headerStyle.setWrapText(true);
	        headerStyle.setBorderBottom(BorderStyle.THIN); //下边框
	        headerStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderLeft(BorderStyle.THIN);//左边框
	        headerStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderTop(BorderStyle.THIN);//上边框
	        headerStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderRight(BorderStyle.THIN);//右边框
	        headerStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        return headerStyle;
	    }
	   public void createCell(String value, CellStyle style, Row row, int col) {
	        Cell cell = row.createCell(col);
	        cell.setCellStyle(style);
	        if (value != null) {
	            cell.setCellValue(value);
	        }
	    }

	    public CellStyle createBodyStyle(Workbook workbook) {
	        CellStyle style = workbook.createCellStyle();
	        style.setAlignment(HorizontalAlignment.CENTER);
	        style.setVerticalAlignment(VerticalAlignment.CENTER);
	        style.setWrapText(true);
	        style.setBorderBottom(BorderStyle.THIN); //下边框
	        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderLeft(BorderStyle.THIN);//左边框
	        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderTop(BorderStyle.THIN);//上边框
	        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderRight(BorderStyle.THIN);//右边框
	        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        return style;
	    }
}
