package cn.hmsoft.skill.school.ticket;

import java.util.List;
import java.util.Map;

import com.itextpdf.barcodes.Barcode128;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.VerticalAlignment;

import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.helper.pdf.ItextPdfHelper;
import cn.hmsoft.skill.data.dao.std.StdEnrolDao;
import cn.hmsoft.skill.data.model.school.SchoolReg;
import cn.hmsoft.skill.data.model.std.StdEnrolSubject;
import cn.hmsoft.skill.data.model.std.StdReg;
import cn.hmsoft.skill.helper.SkillParamHelper;

public class T8190 extends SkillTicketHelper {

	@Override
	protected void makePdf(Document doc, StdReg std, Image image, StdEnrolDao daoEnrol, SchoolReg school,
			Map<String, Object> enrol, List<StdEnrolSubject> subjectArray) {

		image.scaleAbsolute(120, 160);

//		// 添加标题
//		Table headTable = new Table(new float[] { 1 }).setWidthPercent(100).setBorder(null);
//		headTable
//				.addCell(new Cell(1, 1)
//						.add(school.getSchool_name() + SkillParamHelper.CurrentYear
//								+ (StringHelper.isEmpty(school.getTicket_title()) ? "准考证"
//										: (school.getTicket_title() + "准考证")))
//						.setFontSize(18).setBorder(null).setBold().setTextAlignment(TextAlignment.CENTER)
//						.setHorizontalAlignment(HorizontalAlignment.CENTER).setMarginRight(5));
//
//		doc.add(headTable);

		// 添加标题
		Table headTable = new Table(new float[] { 1 }).setWidthPercent(100).setBorder(null);
		headTable.addCell(new Cell(1, 1).add(school.getSchool_name()).setFontSize(18).setBorder(null).setBold()
				.setTextAlignment(TextAlignment.CENTER).setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setMarginRight(5));
		headTable.addCell(new Cell(1, 1)
				.add(SkillParamHelper.CurrentYear
						+ (StringHelper.isEmpty(school.getTicket_title()) ? "准考证" : (school.getTicket_title()+ "准考证")))
				.setFontSize(18).setBorder(null).setBold().setTextAlignment(TextAlignment.CENTER)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setMarginRight(5));
		doc.add(headTable);
/**
		// 考生信息框
		Table stdTable = new Table(new float[] { 1f, 2.1f, 1, 2, 2f }).setWidthPercent(100);
		
		stdTable.addCell(new Cell(1, 1).add("考生姓名").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER)
				.setHeight(28));
		// 姓名
		stdTable.addCell(new Cell(1, 1).add(std.getStd_name()).setFontSize(16).setBold()
				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));

		stdTable.addCell(new Cell(1, 1).add("性别").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
		// 性别
		stdTable.addCell(new Cell(1, 1).add(std.getStd_sex() == null ? "" : std.getStd_sex()).setFontSize(16).setBold()
				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
	
		// 考生照片
		stdTable.addCell(new Cell((StringHelper.isNotEmpty(school.getSchool_addr()) ? 5 : 4), 1)
				.add(new Paragraph().add(image)).setVerticalAlignment(VerticalAlignment.MIDDLE).setMarginTop(0));
		// stdTable.addCell(new Cell(4, 1).add(
		// stdUploadImage).setVerticalAlignment(VerticalAlignment.MIDDLE).setMarginTop(0));

		stdTable.addCell(new Cell(1, 1).add("身份证号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER)
				.setHeight(28));
		stdTable.addCell(new Cell(1, 3).add(std.getCert_id()).setFontSize(18).setBold()
				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));

		stdTable.addCell(new Cell(1, 1).add("准考证号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
		// 准考证号
		stdTable.addCell(new Cell(1, 1).add(enrol.get("ticket_num").toString()).setFontSize(16).setBold()
				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8).setHeight(28));

		stdTable.addCell(new Cell(1, 1).add("高考报名号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
		// 考级号
		stdTable.addCell(new Cell(1, 1).add(std.getExam_id()).setFontSize(16).setBold()
				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
		
		// 身份证条形码
		 Barcode128 code128 = new Barcode128(doc.getPdfDocument());
		 code128.setCodeType(Barcode128.CODE128);
		// code128.setCode(std.getCert_id());  //身份证条形码
		 code128.setCode(enrol.get("ticket_num").toString());  //准考证条形码
		 code128.setBarHeight(StringHelper.isNotEmpty(school.getSchool_addr()) ? 40 :
		 80);
		 code128.fitWidth(240);
		 // code128.setFont(pdfFont);
		 // code128.setSize(1);
		// code128.setAltText(std.getCert_id()); //身份证条形码
		 code128.setAltText(enrol.get("ticket_num").toString()); //准考证条形码
		 stdTable.addCell(new Cell(1, 4).add(new
		 Image(code128.createFormXObject(doc.getPdfDocument())))
		 .setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.CENTER)
		 .setTextAlignment(TextAlignment.CENTER).setMarginLeft(30));
**/
		
		
		// 考生信息框
				Table stdTable = new Table(new float[] { 0.9f, 2.1f, 2f, 2f }).setWidthPercent(100);
				
				stdTable.addCell(new Cell(1, 1).add("姓名").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
				// 姓名
				stdTable.addCell(new Cell(1, 1).add(std.getStd_name()).setFontSize(16).setBold()
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));

				

				Image qrCodeAsImage = null;
				try {
					//qrCodeAsImage = ItextPdfHelper.createQrCode(std.getCert_id(), doc, 128);
					qrCodeAsImage = ItextPdfHelper.createQrCode(enrol.get("ticket_num").toString(), doc, 128);
					
				} catch (Exception e) {
				}
				stdTable.addCell(new Cell(5, 1).add(new Paragraph().add(qrCodeAsImage))
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setMarginTop(0));

				// 考生照片
				stdTable.addCell(new Cell(5, 1).add(new Paragraph().add(image)).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setMarginTop(0));
				// stdTable.addCell(new Cell(4, 1).add(
				// stdUploadImage).setVerticalAlignment(VerticalAlignment.MIDDLE).setMarginTop(0));


				stdTable.addCell(new Cell(1, 1).add("性别").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
				// 性别
				stdTable.addCell(new Cell(1, 1).add(std.getStd_sex() == null ? "" : std.getStd_sex()).setFontSize(16).setBold()
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
				
				//身份证
				stdTable.addCell(new Cell(1, 1).add("身份证号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));

				stdTable.addCell(
						new Cell(1, 1).add(std.getCert_id()).setFontSize(16).setBold()
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));

				stdTable.addCell(new Cell(1, 1).add("准考证号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
				// 准考证号
				stdTable.addCell(new Cell(1, 1).add(enrol.get("ticket_num").toString()).setFontSize(16).setBold()
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));

				stdTable.addCell(new Cell(1, 1).add("高考报名号").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
				
				stdTable.addCell(new Cell(1, 1).add(std.getExam_id()).setFontSize(16).setBold()
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
				
/*				stdTable.addCell(new Cell(1, 1).add("报考专业").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
						.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
				// 报考专业
				stdTable.addCell(new Cell(1, 1).add(enrol.get("aspect_name").toString()).setFontSize(14)
						.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
						.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));*/
//		stdTable.addCell(new Cell(1, 1).add("报考专业").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
//				.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER)
//				.setHeight(28));
//		// 报考专业
//		stdTable.addCell(new Cell(1, 3).add(enrol.get("aspect_name").toString()).setFontSize(14)
//				.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
//				.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
		if (StringHelper.isNotEmpty(school.getSchool_addr())) {
			stdTable.addCell(new Cell(1, 1).add("考点地址").setFontSize(12).setVerticalAlignment(VerticalAlignment.MIDDLE)
					.setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER));
			// 报考地址
			stdTable.addCell(new Cell(1, 3).add(school.getSchool_addr()).setFontSize(14)
					.setVerticalAlignment(VerticalAlignment.MIDDLE).setHorizontalAlignment(HorizontalAlignment.LEFT)
					.setTextAlignment(TextAlignment.LEFT).setMarginLeft(8));
		}
		doc.add(stdTable.setMarginTop(15));

		Table writeTable = new Table(new float[] { 3, 3, 3,3,3 }).setWidthPercent(100);

		writeTable.addCell(new Cell(1, 1).add("考试科目").setTextAlignment(TextAlignment.CENTER));
		writeTable.addCell(new Cell(1, 1).add("考试日期").setTextAlignment(TextAlignment.CENTER));
		writeTable.addCell(new Cell(1, 1).add("开始时间").setTextAlignment(TextAlignment.CENTER));
		writeTable.addCell(new Cell(1, 1).add("结束时间").setTextAlignment(TextAlignment.CENTER));
		writeTable.addCell(new Cell(1, 1).add("考场地点").setTextAlignment(TextAlignment.CENTER));

		int fontSize = 12;
		// int roomFonSize = 10;

		for (StdEnrolSubject subject : subjectArray) {
			// 考试科目

			writeTable.addCell(new Cell(1, 1).add(subject.getSubject_name()).setTextAlignment(TextAlignment.CENTER)
					.setFontSize(fontSize).setVerticalAlignment(VerticalAlignment.MIDDLE));
			// 考试日期
			writeTable.addCell(new Cell(1, 1).add((subject.getExam_time()).substring(0, 10)).setTextAlignment(TextAlignment.CENTER)
					.setFontSize(fontSize).setVerticalAlignment(VerticalAlignment.MIDDLE));
			
			// 考试时间
			writeTable.addCell(new Cell(1, 1).add((subject.getWait_exam_time()).substring(11,16).replace('-', ' ')).setTextAlignment(TextAlignment.CENTER)
					.setFontSize(fontSize).setVerticalAlignment(VerticalAlignment.MIDDLE));
			// 考试时间
			writeTable.addCell(new Cell(1, 1).add((subject.getExam_time()).substring(11,16).replace('-', ' ')).setTextAlignment(TextAlignment.CENTER)
					.setFontSize(fontSize).setVerticalAlignment(VerticalAlignment.MIDDLE));

			// 考场地址
			writeTable.addCell(new Cell(1, 1).add(subject.getRoom_addr()).setTextAlignment(TextAlignment.CENTER)
					.setVerticalAlignment(VerticalAlignment.MIDDLE));

		}
		doc.add(writeTable.setMarginTop(20));
		// 添加须知
		Table noticeTable2 = new Table(1);
		noticeTable2.setFontSize(11);
		noticeTable2.addCell(new Cell(1, 1).add("考生注意事项").setFontSize(12).setTextAlignment(TextAlignment.CENTER)
				.setBorderBottom(null));
		noticeTable2.addCell(
				new Cell(1, 1).add(school.getTicket_note()).setBorderTop(null).setMarginTop(5).setMarginBottom(20));

		doc.add(noticeTable2.setMarginTop(20));

	}

}
